/** * 取新建广告的表单项,修改广告时当前内容 * @author Meathill * @since 0.1.0 * @param $id */ public function init($id) { $CM = $this->get_cm(); $service = new AD(); $admin = new Admin(); $labels = $service->get_all_labels(); $permissions = $service->get_all_permissions(); $me = $_SESSION['id']; $im_cp = $_SESSION['role'] == Auth::$CP_PERMISSION; $init = array('ad_app_type' => $im_cp ? 2 : 1, 'ad_type' => 0, 'cate' => 1, 'cpc_cpa' => 'cpa', 'put_level' => 3, 'imsi' => 0, 'put_net' => 0, 'net_type' => 0, 'put_jb' => 0, 'put_ipad' => 0, 'salt' => substr(md5(time()), 0, 8), 'url_type' => '', 'province_type' => 0, 'share_text' => '', 'down_type' => 0); $options = array('cates' => array('试用', '注册'), 'net_types' => array('全部', '移动', '联通', '电信'), 'channel_types' => ChannelModel::$TYPE, 'ad_types' => $labels, 'permissions' => $permissions, 'provinces' => $CM->provinces, 'sales' => false, 'cp' => $im_cp); $agreement = new Agreement(); if (!$im_cp) { $init = array_merge($init, array('ratio' => 1, 'feedback' => 0, 'cycle' => 0)); $relative_sales = $options['sales'] = $admin->get_sales_by_me($me); if ($relative_sales) { $relative = array(); foreach ($relative_sales as $key => $value) { $relative[] = array('key' => $key, 'value' => $value); } $options["relativeSales"] = $relative; } $options['agreements'] = $agreement->get_my_agreement(['today' => date('Y-m-d')]); } if ($id === 'init') { $this->output(array('code' => 0, 'msg' => 'init', 'ad' => $init, 'options' => $options)); } // 广告内容 if (!$service->check_ad_owner($id)) { $this->exit_with_error(20, '您无法查询此广告的详细信息', 401); } $res = $service->get_ad_info(array('id' => $id), 0, 1); $res['id'] = $id; $ad_shoot = preg_replace('/^,|,$/', '', $res['ad_shoot']); $ad_shoots = preg_split('/,+/', $ad_shoot); if (is_array($ad_shoots)) { foreach ($ad_shoots as $key => $ad_shoot) { $ad_shoots[$key] = $this->createCompletePath($ad_shoot); } $res['ad_shoot'] = $ad_shoots; } $res['ad_url'] = $this->createCompletePath($res['ad_url']); $res['pic_path'] = $this->createCompletePath($res['pic_path']); // 取计划任务,得投放量 $job_service = new Job(); $job = $job_service->get_ad_daily_job($id); $job = (array) $job[$id]; // 省份 if ($res['province_type'] == 1) { $location = new Location(); $provinces = $location->get_provinces_by_ad($id); $res['put_provinces'] = array_values(array_unique($provinces)); } // 被据广告读原因 if ($res['status'] == 4) { $op_log = new ADOperationLogger(); $log = $op_log->get_log(array('adid' => $id, 'type' => 'ad', 'action' => 'decline')); $res['decline'] = $log; } // 点评 $res['comments'] = $service->get_comments(array('ad_id' => $id)); // 今天的投放情况 $stat = new Stat(); $today = date('Y-m-d'); $filter = [':ad_id' => $id, ':date' => $today]; $clicks = $stat->get_ad_click_by_hour($filter); $transfer = $stat->get_ad_transfer_by_hour($filter); $today_stat = []; for ($hour = 0; $hour < 24; $hour++) { $item = array('hour' => $today . ' ' . $hour); if (isset($clicks[$hour])) { $item['click'] = (int) $clicks[$hour]; } if (isset($transfer[$hour])) { $item['transfer'] = (int) $transfer[$hour]; } $today_stat[] = $item; } if (in_array($res['status'], array(0, 1))) { // 备注 $comments = $service->get_ad_comments(array($id)); $res = array_merge($res, array('cm_others' => $comments[$id])); } $result = array_merge($init, $res, $job); $result['today_stat'] = $today_stat; $this->output(array('code' => 0, 'msg' => 'fetched', 'ad' => $result, 'options' => $options)); }
public function get_list($output = true) { $query = trim($_REQUEST['keyword']); if (!$query) { $this->output(array('code' => 0, 'msg' => '没有关键词')); } // 取广告,100个基本等于不限 $season = date('Y-m-d', time() - 86400 * 90); $today = date('Y-m-d'); $yesterday = date('Y-m-d', time() - 86400); $service = new AD(); $transfer = new Transfer(); $ads = $service->get_ad_info(array('keyword' => $query, 'status' => array(0, 1), 'oversea' => 0, 'ad_app_type' => 1), 0, 100); $ad_ids = array_keys($ads); // 取广告运行状态 $rmb_out = $transfer->get_ad_transfer(array('ad_id' => $ad_ids, 'start' => $season, 'end' => $today), 'ad_id'); // 取下线申请 $apply_service = new Apply(); $applies = $apply_service->get_offline_apply(array('adid' => $ad_ids)); // 取广告结算状态 $payment_service = new Payment(); $quote_service = new Quote(); $payments = $payment_service->get_payment($ad_ids, $season, $today); $quotes = $quote_service->get_quote($ad_ids, $season, $today); foreach ($payments as $payment) { $ad_id = $payment['id']; $month = substr($payment['month'], 0, 7); $ads[$ad_id]['payment'] += (int) $payment['rmb']; $ads[$ad_id]['quote'] += (int) $quotes[$ad_id][$month]; } // 取饱和度 $job = new Job(); $yesterday_job = $job->get_log(array('ad_id' => $ad_ids, 'start' => $yesterday, 'end' => $today)); $yesterday = $transfer->get_ad_transfer(array('ad_id' => $ad_ids, 'date' => $yesterday), 'ad_id'); $delivery = array(); foreach ($ad_ids as $ad_id) { $pack_name = $ads[$ad_id]['pack_name']; $delivery[$pack_name] = $this->parse_history($ad_id, $ads[$ad_id], $yesterday_job[$ad_id], $yesterday[$ad_id], $delivery[$pack_name]); } // 取点评记录 $pack_info = array(); foreach ($ads as $ad) { $pack_info[$ad['pack_name']] = $ad['ad_name']; } $pack_names = array_unique(array_filter(array_keys($pack_info))); $comments_by_pack_name = array(); if ($pack_names) { $comments = $service->get_comments(array('pack_name' => $pack_names)); foreach ($comments as $comment) { $pack_name = $comment['pack_name']; $array = $comments_by_pack_name[$pack_name]; $array = is_array($array) ? $array : array('ad_name' => $pack_info[$pack_name], 'pack_name' => $pack_name, 'comments' => array()); $array['comments'][] = $comment; $comments_by_pack_name[$pack_name] = $array; } } $result = array(); foreach ($ads as $key => $ad) { $item = Utils::array_pick($ad, 'ad_name', 'others', 'create_time', 'quote_rmb', 'payment', 'quote'); $item['transfer'] = (int) $rmb_out[$key]; $item['payment_percent'] = $item['quote'] != 0 ? round($item['payment'] / $item['quote'] * 100, 2) : 0; $item['id'] = $key; $item['offline_msg'] = $applies[$key]; $item['feedback'] = $ad['feedback']; $item['is_full'] = $this->check_is_full($delivery[$ad['pack_name']]); if (!$item['is_full']) { $item['fullness'] = $this->get_fullness($delivery[$ad['pack_name']]); } $result[] = $item; } // 按照回款率第一,下线请求,有无备注,有无推广的优先级进行排序 usort($result, function ($a, $b) { if ($a['payment_percent'] != $b['payment_percent']) { return $a['payment_percent'] < $b['payment_percent'] ? 1 : -1; } if ($a['offline_msg'] && !$b['offline_msg'] || !$a['offline_msg'] && $b['offline_msg']) { return $a['offline_msg'] ? -1 : 1; } if ($a['others'] && !$b['others'] || !$a['others'] && $b['others']) { return $a['others'] ? -1 : 1; } if ($a['transfer'] != $b['transfer']) { return $b['transfer'] - $a['transfer']; } return strcmp($a['create_time'], $b['create_time']); }); $result = ['code' => 0, 'msg' => 'fetch', 'list' => array_slice($result, 0, 20), 'ad_comments' => array_values($comments_by_pack_name)]; if ($output) { $this->output($result); } return $result; }