コード例 #1
0
ファイル: Task.class.php プロジェクト: banketree/lemon-grass
 /**
  * @param $ad_id
  * @param $name
  * @param $desc
  * @param $step_rmb
  * @param $type
  * @param $delta
  * @param $param
  * @param $probability
  */
 private function create_task($ad_id, $name, $desc, $step_rmb, $type, $delta, $param, $probability)
 {
     $DB = $this->get_write_pdo();
     $task_id = Utils::create_id();
     $now = date('Y-m-d H:i:s');
     $sql = "INSERT INTO `t_task`\n            (`id`, `ad_id`, `step_rmb`, `type`, `delta`, `name`, `desc`,\n              `create_time`, `status`, `param`, `probability`)\n            VALUES (:id, :ad_id, :step_rmb, :type, :delta, :name, :desc,\n              '{$now}', :status, :param, :probability)\n            ON DUPLICATE KEY UPDATE `status`=:status, `create_time`='{$now}',\n              `name`=:name, `desc`=:desc, `probability`=:probability";
     $state = $DB->prepare($sql);
     $check = $state->execute(array(':id' => $task_id, ':ad_id' => $ad_id, ':step_rmb' => $step_rmb, ':type' => $type, ':delta' => $delta, ':name' => $name, ':desc' => $desc, ':status' => self::ON, ':param' => $param, ':probability' => $probability));
     if ($check) {
         $log = new ADOperationLogger($DB);
         $log->log($ad_id, 'task', 'add', "{$step_rmb}, {$type}, {$delta}, {$name}, {$desc}, {$param}, {$probability} => {$task_id}");
     }
 }
コード例 #2
0
ファイル: Job.service.php プロジェクト: banketree/lemon-grass
 public function remove_on_off_job($id, $job_time)
 {
     $off_job = $this->get_ad_on_off_job($id);
     if ($off_job && $off_job['jobtime'] != $job_time) {
         //删除原有的计划任务
         $id = $off_job['id'];
         $this->del_job($off_job['linkid'], $id);
         // log it
         $log = new ADOperationLogger();
         $log->log($id, 'job', 'remove', "jobid: {$id}", 0);
     }
 }
コード例 #3
0
 /**
  * 记录操作
  *
  * @param $is_edit
  * @param $attr
  * @param string $message
  */
 private function log($is_edit, $attr, $message = '')
 {
     $logger = new ADOperationLogger();
     unset($attr['id']);
     if ($is_edit) {
         // 为避免大量中文被转码占空间,先把备注取出来,json_encode完再放回去
         $others = '';
         if ($attr['others']) {
             $others = $attr['others'];
             $attr['others'] = '{{others}}';
         }
         $comment = json_encode($attr);
         if ($others) {
             $comment = str_replace('{{others}}', $others, $comment);
             $attr['others'] = $others;
         }
         $logger->log($this->id, 'ad', 'edit', "{$comment}\n[{$message}]");
     } else {
         $logger->log($this->id, 'ad', 'add', $attr['others'], 0);
     }
 }
コード例 #4
0
 /**
  * 创建新广告
  * @author Meathill
  * @since 0.1.0
  * @param string $key
  */
 public function create($key)
 {
     if ($key != 'init') {
         $this->exit_with_error(10, '请求错误', 400);
     }
     $CM = $this->get_cm();
     $im_cp = $_SESSION['role'] == Auth::$CP_PERMISSION;
     $now = date('Y-m-d H:i:s');
     $attr = $this->get_post_data();
     $id = $attr['id'] = $attr['id'] ? $attr['id'] : Utils::create_id();
     $user = $im_cp ? new User() : null;
     $left = 0;
     // 校验CP用户
     if ($im_cp && !$user->has_enough_money($attr)) {
         $this->exit_with_error(1, '您的余额不足', 402);
     }
     $ad = new ADModel($attr);
     if ($ad->error) {
         $this->exit_with_error($ad->error);
     }
     try {
         if ($im_cp) {
             // 扣费
             $left = $user->lock_money_for_ad($attr['quote_rmb'], $attr['total_num']);
         }
         $ad->save();
     } catch (ADException $e) {
         $this->exit_with_error($e->getCode(), $e->getMessage(), 400, SQLHelper::$info);
     }
     $client_email = $attr['file-email'];
     $replace_id = $ad->replace;
     // 给运营发新广告通知
     $notice = new Notification();
     $notice_status = $notice->send(array('ad_id' => $id, 'alarm_type' => Notification::$NEW_AD, 'create_time' => $now));
     // 给运营发邮件
     $mail = new Mailer();
     $subject = ($im_cp ? '广告主' : '商务') . '[' . $_SESSION['fullname'] . ']创建新广告:' . $attr['channel'] . ' ' . $attr['ad_name'];
     $mail->send(OP_MAIL, $subject, $mail->create('ad-new', $attr, array('owner' => $_SESSION['fullname'], 'cate' => $CM->ad_cate[$attr['cate']])));
     if (!$im_cp) {
         // 给广告主发送报备邮件
         if ($client_email) {
             $this->baobei($client_email, $attr);
         }
         // 给运营发修改申请
         if ($replace_id) {
             $this->send_apply($id, array('replace_id' => $replace_id, 'message' => $attr['others']));
             return;
         }
     }
     // log it
     $log = new ADOperationLogger();
     $log->log($id, 'ad', 'add', $attr['others'], 0);
     $result = array('code' => 0, 'msg' => '创建广告成功。相关通知' . ($notice_status ? '已发' : '失败'), 'notice' => $notice_status ? '通知已发' : '通知失败', 'ad' => array('id' => $id));
     if ($im_cp) {
         $result['me'] = ['balance' => $left];
     }
     $this->output($result);
 }