Пример #1
0
 public function log_sm($id, $url, $pack_name, $app_name)
 {
     // 记到表里
     $attr = ['ad_id' => $id, 'url' => $url, 'user' => $_SESSION['id'], 'sm' => self::HAS];
     $DB = $this->get_write_pdo();
     $count = SQLHelper::insert($DB, self::$TABLE, $attr, true);
     $admin = new Admin();
     $me = $admin->get_user_info(['id' => $_SESSION['id']]);
     $me = array_values($me)[0];
     $attr['name'] = $me;
     // 给相关人发邮件
     $mailer = new Mailer();
     $to = ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'];
     $subject = '【点乐自助平台】监测到包含数盟SDK的包上传';
     $content = $mailer->create('spy-sm', array_merge($attr, array('pack_name' => $pack_name, 'app_name' => $app_name)));
     $check = $mailer->send($to, $subject, $content);
     return $count && $check;
 }
 /**
  * 取个人的所有申请
  */
 public function get_list()
 {
     $me = $_SESSION['id'];
     $keyword = isset($_REQUEST['keyword']) ? trim($_REQUEST['keyword']) : '';
     $page = (int) $_REQUEST['page'];
     $pagesize = isset($_REQUEST['pagesize']) ? (int) $_REQUEST['pagesize'] : 10;
     $start = $page * $pagesize;
     $service = $this->get_service();
     $ad_service = new AD();
     $applies = $service->get_list($me, $keyword, $start, $pagesize);
     $labels = array('set_status' => '上/下线', 'set_job_num' => '每日限量', 'set_rmb' => '今日余量', 'set_ad_url' => '替换包', 'set_quote_rmb' => '报价');
     $today = date('Y-m-d');
     $expires = array();
     $handler = array();
     $ad_ids = array();
     foreach ($applies as $index => $apply) {
         $apply = array_filter($apply, function ($value) {
             return isset($value);
         });
         // 修改每日限额同时修改今日余量
         if (array_key_exists('set_rmb', $apply) && array_key_exists('set_job_num', $apply)) {
             $apply['attr'] = 'set_job_num';
             $apply['label'] = $labels['set_job_num'];
             $apply['after'] = $apply['set_job_num'];
             $apply['extra'] = true;
         } else {
             // 普通处理
             foreach ($apply as $key => $value) {
                 if (preg_match('/^set_\\w+/', $key)) {
                     $apply['attr'] = $key;
                     $apply['label'] = $labels[$key];
                     $apply['after'] = $value;
                     break;
                 }
             }
         }
         if (!$apply['handler'] && $apply['attr']) {
             // 尚未处理,取之前的值
             $ad_ids[] = $apply['adid'];
         }
         if ($apply['attr'] == 'set_rmb') {
             if ($apply['create_time'] < $today) {
                 $expires[] = $apply['id'];
                 unset($applies[$index]);
                 break;
             }
             $ad_ids[] = $apply['adid'];
         }
         $apply['is_url'] = $apply['attr'] == 'set_ad_url';
         $apply['is_status'] = $apply['attr'] == 'set_status';
         // 没有匹配的值对,则是替换广告
         if (!$apply['attr'] && !$apply['value']) {
             $apply['label'] = '替换广告';
             $apply['after'] = $apply['adid'];
             $apply['is_replace'] = true;
         }
         $handler[] = $apply['handler'];
         $applies[$index] = $apply;
     }
     // 作废申请
     $service->update(array('status' => Apply::EXPIRED), $expires);
     // 取用户姓名
     $handlers = array_filter(array_unique($handler));
     if ($handlers) {
         $admin_service = new Admin();
         $users = $admin_service->get_user_info(array('id' => $handlers));
         foreach ($applies as $index => $apply) {
             $applies[$index]['handler'] = isset($users[$apply['handler']]) ? $users[$apply['handler']] : $apply['handler'];
         }
     }
     // 取广告信息然后回填数据
     $ad_info = $ad_service->get_ad_info(array('id' => array_filter(array_unique($ad_ids))));
     foreach ($applies as $index => $apply) {
         if (!$apply['handler'] && $apply['attr']) {
             // 尚未处理,取之前的值
             $key = substr($apply['attr'], 4);
             $apply['before'] = $ad_info[$apply['adid']][$key];
         }
         $applies[$index] = $apply;
     }
     $total = $service->get_total_number($me, $keyword);
     $this->output(array('code' => 0, 'msg' => 'fetched', 'total' => $total, 'list' => array_values($applies)));
 }
Пример #3
0
 /**
  * 取广告列表
  * @author Meathill
  * @since 0.1.0
  */
 public function get_list()
 {
     $service = new AD();
     $job_service = new Job();
     $admin = new Admin();
     $me = $_SESSION['id'];
     $im_cp = Auth::is_cp();
     $pagesize = isset($_REQUEST['pagesize']) ? (int) $_REQUEST['pagesize'] : 10;
     $page = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : 0;
     $page_start = $page * $pagesize;
     $order = isset($_REQUEST['order']) ? trim($_REQUEST['order']) : 'create_time';
     $seq = isset($_REQUEST['seq']) ? trim($_REQUEST['seq']) : 'DESC';
     $filters = array('keyword' => $_REQUEST['keyword'], 'pack_name' => $_REQUEST['pack_name'], 'status' => [0, 1, 2, 3, 4], $im_cp ? 'create_user' : 'salesman' => $me);
     if (isset($_REQUEST['agreement_id'])) {
         $filters['agreement_id'] = $_REQUEST['agreement_id'];
     }
     if (isset($_REQUEST['channel'])) {
         $filters['channel'] = $_REQUEST['channel'];
     }
     if (isset($_REQUEST['ad_name'])) {
         $filters['ad_name'] = $_REQUEST['ad_name'];
     }
     $ads = $service->get_ad_info($filters, $page_start, $pagesize, array($order => $seq));
     $total = $service->get_ad_number($filters);
     $ad_ids = array_unique(array_keys(array_filter($ads)));
     $ops = $admin->get_ad_ops($ad_ids);
     $users = array();
     $decline = array();
     foreach ($ads as $id => $ad) {
         $users[] = $ad['execute_owner'];
         if ($ad['status'] == ADModel::REJECTED) {
             $decline[] = $id;
         }
     }
     // 取商务名单
     $user_service = new Admin();
     $users = $user_service->get_user_info(array('id' => array_filter(array_unique($users))));
     // 取当前申请
     $apply = new Apply();
     $applies = $apply->get_list_by_id($ad_ids);
     $applies_by_ad = array();
     foreach ($applies as $id => $apply) {
         $adid = $apply['adid'];
         if (!is_array($applies_by_ad[$adid])) {
             $applies_by_ad[$adid] = array();
         }
         unset($apply['adid']);
         $apply = array_filter($apply, function ($value) {
             return isset($value);
         });
         // 同时有每日限量和今日余量说明是要修改每日限量
         if (array_key_exists('set_job_num', $apply) && array_key_exists('set_rmb', $apply)) {
             unset($apply['set_rmb']);
         }
         $key = array_keys($apply)[0];
         // 因为过滤掉了没有内容的键,又删掉了adid,只剩下要操作的key了
         $apply[$key . '_id'] = $id;
         $applies_by_ad[$adid][] = $apply;
     }
     // 取计划任务
     $ad_jobs = $job_service->get_ad_daily_job($ad_ids);
     // 取上下线计划任务
     $on_off_jobs = $job_service->get_ad_on_off_job($ad_ids);
     // 取被拒绝的广告的附言
     $decline = array_unique(array_filter($decline));
     $declines = null;
     if ($decline) {
         $comment_service = new Comment();
         $declines = $comment_service->get_comment(array('ad_id' => $decline, 'pack_name' => ''));
     }
     // 获取备注记录
     $comments = $service->get_ad_comments($ad_ids);
     $result = array();
     foreach ($ads as $id => $ad) {
         $apply = array();
         if (is_array($applies_by_ad[$id])) {
             foreach ($applies_by_ad[$id] as $item) {
                 $apply = array_merge($apply, $item);
             }
         }
         $decline = (array) $declines[$id];
         $job_num = array_key_exists($id, $ad_jobs) ? $ad_jobs[$id]['jobnum'] : 0;
         $job_num = $job_num > 0 || !$im_cp ? $job_num : (int) $ad['job_num'];
         $on_off = $on_off_jobs[$id];
         $result[] = array_merge($ad, $apply, array('id' => $id, 'status' => (int) $ad['status'], 'execute_owner' => $users[$ad['execute_owner']], 'job_num' => $job_num, 'job_time' => substr($ad_jobs[$id]['jobtime'], 11, 5), 'reject' => $decline, 'cm_others' => $comments[$id], 'op' => $ops[$id], 'search_flag' => (int) $ad['search_flag'], 'on_off' => $on_off));
     }
     $this->output(array('code' => 0, 'msg' => 'get', 'total' => $total, 'list' => $result));
 }