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; }