Esempio n. 1
0
 public function export_payment($start, $end, $owner)
 {
     $daily_service = new DailyStat();
     $filters = array('salesman' => $owner);
     $result = $daily_service->get_daily_stat($start, $end, $filters, null, null, 0, 0);
     $list = $result['list'];
     $payments = $this->get_payment_by_owner($start, $end, $owner);
     foreach ($list as $key => $value) {
         $list[$key]['ad_app_type'] = $value['ad_app_type'] == ADModel::ANDROID ? 'Android' : 'iOS';
         $list[$key]['status'] = $value['status'] == ADModel::ONLINE ? 'ON' : 'OFF';
         $list[$key]['channel_type'] = ChannelModel::$TYPE[$value['channel_type']];
         $list[$key]['payment_status'] = '';
         foreach ($payments[$value['id']] as $payment) {
             if (!$payment['payment'] || !$payment['rmb']) {
                 $list[$key]['payment_status'] = 'N';
             } else {
                 $list[$key]['paid_time'] .= $payment['paid_time'] . ' ' . $payment['payment_person'] . ' ';
                 $list[$key]['invoice_time'] .= $payment['invoice_time'] . ' ';
                 $list[$key]['invoice_rmb'] .= $payment['invoice_rmb'] . ' ';
                 $list[$key]['real_rmb'] .= $payment['real_rmb'] / 100 . ' ';
                 $list[$key]['comment'] .= $payment['comment'] . ' ';
             }
         }
         $list[$key] = Utils::array_pick($list[$key], Payment::$FIELD_PAYMENT_EXPORT);
     }
     $title = array('渠道名', '渠道全称', '渠道类型', '广告名', '渠道号', '创建时间', '状态', '平台', '广告类型', '扣分', '排序', '激活支出', '深度任务支出', '收入', '红包锁屏收入', '其他收入', 'CPA', '渠道CPA', '单价', '实际价格', '损益价格', '毛利润', '毛利润率(%)', '结算率(%)', '商务负责人', '商务执行人', '是否回款', '回款时间', '开票时间', '开票金额', '实际回款金额', '备注');
     array_unshift($list, $title);
     $excel_service = new Excel();
     $excel_service->export($list, "{$start}至{$end}广告数据分析");
 }
 public function save(array $attr = null)
 {
     $DB = $this->get_write_pdo();
     // 取发票ID或者渠道ID
     $agreement_service = new Agreement();
     $agreement = $agreement_service->get_agreement_by_id(array('agreement_id' => $attr['agreement_number']));
     $attr = array_merge(array('agreement_id' => $agreement['id']), $attr);
     unset($attr['agreement_number']);
     $attr = $attr ? $attr : $this->attributes;
     $new_attr = $this->judge_status($attr, $attr['comment']);
     // 关联的广告信息
     $invoice_ads = $attr['products'];
     unset($attr['products']);
     $incomes = $this->multi_100(Utils::array_pick($attr, self::$INVOICE_INCOMES));
     $attr = array_merge($attr, $new_attr, $incomes, array('apply_time' => date('Y-m-d')));
     // 插入发票表
     $this->save_invoice_info($DB, $attr);
     // 核减发送通知给相应的运营
     if ($attr['income'] != $attr['income_first']) {
         // 查找商务对应的运营
         $admin_service = new Admin();
         $operation_id = $admin_service->get_sale_operation($_SESSION['id']);
         // 记录到通知表
         $notice = new Notification();
         $notice->send(array('uid' => SQLHelper::$lastInsertId, 'admin_id' => $operation_id, 'alarm_type' => Notification::$NEW_INVOICE, 'create_time' => date('Y-m-d H:i:s')));
     }
     $invoice_id = SQLHelper::$lastInsertId;
     $this->attributes = array_merge(array('id' => $invoice_id), $this->attributes);
     $invoice_ad_arr = array();
     if (is_array($invoice_ads)) {
         $invoice_ad_arr = $this->construct_invoice_ads($invoice_ads, $invoice_id);
     }
     // 插入到发票广告关联表
     $this->save_invoice_ad_info($DB, $invoice_ad_arr);
 }
 public function update()
 {
     $data = $this->get_post_data();
     // 有可能通过修改密码popup修改密码
     if ($_REQUEST['newpassword']) {
         $data = Utils::array_pick($_REQUEST, 'oldpassword', 'newpassword', 'repassword');
     }
     // 校验密码
     if ($data['newpassword']) {
         if ($data['newpassword'] != $data['repassword']) {
             $this->exit_with_error(11, '两次输入的密码不一致,请重新输入。', 403);
         }
         if (!preg_match('/[0-9a-zA-Z$!^#_@%&*.]{6,16}/', $data['newpassword'])) {
             $this->exit_with_error(12, '新的密码不合规则,请重新输入。', 403);
         }
         $auth = new Auth();
         if (!$auth->validate($_SESSION['email'], $data['oldpassword'], true)) {
             $this->exit_with_error(13, '旧密码不正确,请重新输入', 403);
         }
         $data['password'] = $auth->encrypt($_SESSION['email'], $data['newpassword']);
         $data = Utils::array_omit($data, 'oldpassword', 'newpassword', 'repassword');
     }
     $service = new User();
     $check = $service->update_me($data);
     if ($check) {
         $this->output(['code' => 0, 'msg' => '修改成功', $data]);
     } else {
         $this->exit_with_error(400, '修改失败', 1);
     }
 }
Esempio n. 4
0
 protected function parse_filter(array $filters = null, array $options = array())
 {
     $defaults = ['to_string' => true];
     $options = array_merge($defaults, $options);
     if (isset($filters['start'])) {
         $filters['stat_date'][] = array('operator' => '>=', 'data' => $filters['start']);
         unset($filters['start']);
     }
     if (isset($filters['end'])) {
         $filters['stat_date'][] = array('operator' => '<=', 'data' => $filters['end']);
         unset($filters['end']);
     }
     $spec = array('date');
     $pick = Utils::array_pick($filters, $spec);
     $filters = Utils::array_omit($filters, $spec);
     list($conditions, $params) = parent::parse_filter($filters, ['to_string' => false]);
     foreach ($pick as $key => $value) {
         switch ($key) {
             case 'date':
                 $conditions[] = "DATE(`stat_date`)=:date";
                 $params[':date'] = $value;
                 break;
         }
     }
     $conditions = $options['to_string'] ? ($options['is_append'] ? ' and ' : '') . implode(' AND ', $conditions) : $options;
     return array($conditions, $params);
 }
Esempio n. 5
0
 /**
  * @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}");
     }
 }
 public function update(array $attr = null)
 {
     $ad_service = new CompetitorAd();
     $me = $_SESSION['id'];
     if (!$ad_service->check_delivery_ad_owner($this->id, $me)) {
         throw new Exception('不是您对接的广告,您不能修改', 100);
     }
     //拆分不同表的数据
     if ($attr['status']) {
         $attr['status_editor'] = $me;
         $attr['status_time'] = date("Y-m-d H:i:s");
     }
     $delivery = Utils::array_pick($attr, self::$FIELDS_DELIVERY);
     //更新广告信息
     $DB_write = $this->get_write_pdo();
     $check = SQLHelper::insert_update($DB_write, self::$T_DELIVERY, $delivery, array('pack_name' => $this->id));
     if (!$check) {
         throw new Exception('修改失败', 101);
     }
     $this->attributes = $attr;
     return $attr;
 }
Esempio n. 7
0
 private function validate_cp($email, $password, $no_log = false)
 {
     $password = $this->encrypt($email, $password);
     $pdo = $this->get_read_pdo();
     $sql = "SELECT `id`, `balance`, `username`, `corp`, `owner`,\n              `last_login_time`, `last_login_ip`\n            FROM `t_diy_user`\n            WHERE `email`=:email AND `password`=:password AND `status`=0";
     $state = $pdo->prepare($sql);
     $state->execute(array(':email' => $email, ':password' => $password));
     $this->user = $user = $state->fetch(PDO::FETCH_ASSOC);
     if ($no_log) {
         return !!$user;
     }
     // 记录这次登录
     $time = date('Y-m-d H:i:s');
     $ip = Utils::get_client_ip();
     $DB = $this->get_write_pdo();
     $success = $user ? 1 : 0;
     $sql = "INSERT INTO `t_diy_user_login_log`\n            (`email`, `ip`, `time`, `success`)\n            VALUES (:email, '{$ip}', '{$time}', {$success})";
     $state = $DB->prepare($sql);
     $state->execute(['email' => $email]);
     if (!$user) {
         return false;
     }
     // 记录最后一次登录
     $me = $user['id'];
     $sql = "UPDATE `t_diy_user`\n            SET `last_login_time`='{$time}', `last_login_ip`='{$ip}'\n            WHERE `id`='{$me}'";
     $DB->exec($sql);
     // 记录到session
     session_start();
     $_SESSION['email'] = $email;
     $_SESSION['id'] = $user['id'];
     $_SESSION['role'] = self::$CP_PERMISSION;
     $_SESSION['fullname'] = $user['username'];
     $_SESSION['balance'] = $user['balance'];
     $_SESSION['last_login'] = array('time' => $user['last_login_time'], 'ip' => $user['last_login_ip']);
     return true;
 }
Esempio n. 8
0
 public function check_ad_info_for_sale(array $ad_info)
 {
     $me = $_SESSION['admin_id'];
     $role = $_SESSION['admin_role'];
     if ($me != Admin::SALE_BOSS) {
         if (!in_array($ad_info['location'], $_SESSION['admin_location'])) {
             unset($ad_info['channel']);
             unset($ad_info['owner_name']);
             unset($ad_info['url']);
             unset($ad_info['user']);
             unset($ad_info['pwd']);
             unset($ad_info['cid']);
         } else {
             if ($me != $ad_info['owner'] && $me != $ad_info['execute_owner'] && !in_array($ad_info['owner'], $_SESSION['admin_associate']) && $role != self::SALE_MANAGER) {
                 unset($ad_info['cid']);
             }
         }
     }
     $ad_info = Utils::array_pick($ad_info, self::$FIELD_AD_INFO_SALE);
     return $ad_info;
 }
 /**
  * @param string $path
  *
  * @return array
  */
 private function parse_plist($path)
 {
     $plist = new CFPropertyList($path, CFPropertyList::FORMAT_BINARY);
     $dict = $plist->getValue('CFDictionary');
     $form = array('ad_name' => $dict->get('CFBundleDisplayName'), 'ad_lib' => $dict->get('CFBundleShortVersionsString'), 'pack_name' => $dict->get('CFBundleIdentifier'), 'process_name' => $dict->get('CFBundleExecutable'));
     foreach ($form as $key => $value) {
         if ($value instanceof CFType) {
             $form[$key] = $value->getValue();
         }
         if ($key == 'ad_lib' && !$value) {
             $ad_lib = $dict->get('CFBundleVersion');
             $form[$key] = $ad_lib instanceof CFType ? $ad_lib->getValue() : '';
         }
     }
     $urls = $dict->get('CFBundleURLTypes');
     $url_schemes = array();
     if ($urls) {
         $urls = $urls->toArray();
         foreach ($urls as $url) {
             $url_schemes[] = $url['CFBundleURLSchemes'];
         }
     }
     $form['url_type'] = implode(';', Utils::array_flatten($url_schemes));
     return $form;
 }
Esempio n. 10
0
 protected function validate(array $attr)
 {
     // 防XSS
     $attr = Utils::array_strip_tags($attr);
     if ($attr['id']) {
         $this->id = $attr['id'];
     }
     if (!$attr['id'] && (!$attr['full_name'] || !$attr['alias'])) {
         $this->error = new Error(20, '缺少关键数据。', 400);
     }
     return $attr;
 }
 public function create()
 {
     $attr = $this->get_post_data();
     $me = $_SESSION['id'];
     $invoice_service = new Invoice();
     $attr = Utils::array_pick($attr, InvoiceModel::$INVOICE_AD_FIELDS);
     if (isset($attr['start'])) {
         $attr['start'] = date($attr['start'] . '-01');
     }
     // 获取结算的广告
     if (isset($attr['products'])) {
         $ads = $attr['products'];
         foreach ($ads as $ad) {
             $nums = $invoice_service->is_invoice($ad['ad_id'], $ad['quote_start_date'], $ad['quote_end_date']);
             if ($nums > 0) {
                 $this->exit_with_error(51, '错误操作,禁止给已经开过发票的广告再次申请', 403);
             }
         }
     }
     $attr = array_merge(array('applicant' => $me), $attr);
     $invoice = new InvoiceModel($attr);
     try {
         $invoice->save($attr);
     } catch (Exception $e) {
         $this->exit_with_error($e->getCode(), $e->getMessage(), 400);
     }
     $this->output(array('code' => 0, 'msg' => 'ok', 'invoice' => $invoice->attributes));
 }
 public function get_stat($ad_app_type)
 {
     $today = date('Y-m-d');
     $start = empty($_REQUEST['start']) ? $today : $_REQUEST['start'];
     $end = empty($_REQUEST['end']) ? $today : $_REQUEST['end'];
     $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';
     $im_cp = $_SESSION['role'] == Auth::$CP_PERMISSION;
     $me = $_SESSION['id'];
     $ad_app_type = trim($ad_app_type) == "android" ? ADModel::ANDROID : ADModel::IOS;
     $filters = array('ad_app_type' => $ad_app_type, 'keyword' => $_REQUEST['keyword'], 'ad_name' => $_REQUEST['ad_name'], 'channel' => $_REQUEST['channel'], $im_cp ? 'create_user' : 'salesman' => $me);
     $filters = Utils::array_pick_effect($filters);
     $ad_service = new AD();
     // 根据广告类型取出所有广告
     $ad_ids = $ad_service->get_ad_ids($filters);
     $result = array('oversea' => false, 'ads' => array());
     $total = array('rmb1' => 0, 'device1' => 0, 'native' => 0, 'native_transfer' => 0, 'task_num' => 0, 'task_rmb' => 0, 'task_ready' => 0, 'cpa' => 0, 'click' => 0, 'install' => 0, 'callback' => 0);
     $ids = array();
     $redis = $this->get_redis();
     $daily_service = new DailyStat();
     for ($date = $start; $date <= $end;) {
         list($ymd, $monthly, $date) = $daily_service->judge_date($date, $end);
         $key = 'diy_stat_ad_install_' . $ymd;
         $value = $redis->get($key);
         if ($value) {
             $redis->setTimeout($key, 86400 * 30);
         } else {
             $value = $daily_service->ad_stat_by_date($ymd, $monthly);
             $value = json_encode($value);
             if ($value && ($monthly || strtotime($ymd) < time() - 3600 * 30)) {
                 $redis->setex($key, 86400 * 30, $value);
             }
         }
         $stat = json_decode($value, true);
         foreach ($stat as $ad_stat) {
             $ad_id = $ad_stat['id'];
             if (!in_array($ad_id, $ad_ids)) {
                 continue;
             }
             $ids = array_unique(array_merge($ids, array($ad_id)));
             foreach ($total as $key => $value) {
                 $result['ads'][$ad_id][$key] += $ad_stat[$key];
                 $total[$key] += $ad_stat[$key];
             }
         }
     }
     $adinfos = $ad_service->get_all_ad_info($filters);
     foreach ($ids as $ad_id) {
         if ($adinfos[$ad_id]['oversea']) {
             continue;
         }
         if (!array_key_exists($ad_id, $adinfos)) {
             continue;
         }
         $comments = $ad_service->get_ad_comments_by_id($ad_id);
         $result['ads'][$ad_id] = array_merge($result['ads'][$ad_id], array('id' => $ad_id, 'channel_id' => $adinfos[$ad_id]['cid'], 'channel' => $adinfos[$ad_id]['channel'], 'agreement' => $adinfos[$ad_id]['agreement'], 'ad_name' => $adinfos[$ad_id]['ad_name'], 'comments' => $comments, 'ctime' => date('m-d', strtotime($adinfos[$ad_id]['create_time'])), 'others' => isset($adinfos[$ad_id]['others']) ? $adinfos[$ad_id]['others'] : '添加注释', 'sdk_type' => $adinfos[$ad_id]['ad_sdk_type'] == 7 ? 'promotions' : ($adinfos[$ad_id]['ad_sdk_type'] == 2 ? 'push' : ($adinfos[$ad_id]['ad_sdk_type'] == 4 ? 'wap' : 'ad_list not_promotions')), 'native_type' => $adinfos[$ad_id]['banner_url'] ? 'native' : '', 'ratio' => $result['ads'][$ad_id]['click'] ? round($result['ads'][$ad_id]['device1'] / $result['ads'][$ad_id]['click'] * 100, 2) : 0, 'click_ratio' => $result['ads'][$ad_id]['click'] ? round($result['ads'][$ad_id]['cpa'] / $result['ads'][$ad_id]['click'] * 100, 2) : 0, 'task_ratio' => $result['ads'][$ad_id]['task_ready'] ? round($result['ads'][$ad_id]['task_num'] / $result['ads'][$ad_id]['task_ready'] * 100, 2) : 0));
     }
     // 总计
     $total['ratio'] = $total['click'] ? round($total['transfer'] / $total['click'] * 100, 2) : 0;
     $total['click_ratio'] = $total['click'] ? round($total['cpa'] / $total['click'] * 100, 2) : 0;
     $total['task_ratio'] = $total['task_ready'] ? round($total['task_num'] / $total['task_ready'] * 100, 2) : 0;
     $result['total'] = array_merge(array('id' => 'amount', 'is_amount' => true), $total);
     $list = array_values($result['ads']);
     $total = count($list);
     // 排序
     $list = $this->get_order_list($list, $order, $seq);
     //分页
     $list = array_slice($list, $page_start, $pagesize);
     if (count($list) > 0) {
         array_push($list, $result['total']);
     }
     $is_android = $ad_app_type == 1 ? true : false;
     $this->output(array('code' => 0, 'msg' => 'get', 'list' => $list, 'total' => $total, 'options' => array('is_android' => $is_android)));
 }
Esempio n. 13
0
 public static function insert_update_multi(PDO $DB, $table, $attr, $return_row_count = true)
 {
     $sql = self::create_insert_update_multi_sql($table, array_keys($attr[0]), count($attr));
     $params = Utils::array_flatten($attr);
     $state = $DB->prepare($sql);
     $result = $state->execute($params);
     self::$info = $state->errorInfo();
     return $result && $return_row_count ? $state->rowCount() : $result;
 }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
 protected function parse_admin_filter(array $filters = null, array $options = array())
 {
     $defaults = ['to_string' => true];
     $options = array_merge($defaults, $options);
     $spec = array('keyword', 'salesman', 'channel', 'follow');
     if (isset($filters['ad_name'])) {
         $filters['a.ad_name'] = $filters['ad_name'];
         unset($filters['ad_name']);
     }
     if (isset($filters['start'])) {
         $filters['create_time'][] = array('operator' => '>=', 'data' => $filters['start']);
         unset($filters['start']);
     }
     if (isset($filters['end'])) {
         $filters['create_time'][] = array('operator' => '<=', 'data' => $filters['start']);
         unset($filters['end']);
     }
     if (isset($filters['owner'])) {
         $filters['b.owner'] = $filters['owner'];
         unset($filters['owner']);
     }
     $pick = Utils::array_pick($filters, $spec);
     $filters = Utils::array_omit($filters, $spec);
     list($conditions, $params) = parent::parse_filter($filters, array('to_string' => false));
     foreach ($pick as $key => $value) {
         switch ($key) {
             case 'keyword':
                 $conditions[] = " (a.`ad_name` LIKE :keyword OR ifnull(h.company_short,ifnull(c.alias,b.channel)) LIKE :keyword)";
                 $params[':keyword'] = '%' . $value . '%';
                 break;
             case 'salesman':
                 $conditions[] = " (b.`owner`=:salesman OR `execute_owner`=:salesman)";
                 $params[':salesman'] = $value;
                 break;
             case 'channel':
                 $conditions[] = " ifnull(h.company_short,ifnull(c.alias,b.channel))=:channel";
                 $params[':channel'] = $value;
                 break;
             case 'follow':
                 $conditions[] = ' b.owner!=execute_owner';
                 break;
         }
     }
     $conditions = $options['to_string'] ? ($options['is_append'] ? ' and ' : '') . implode(' AND ', $conditions) : $options;
     return array($conditions, $params);
 }
Esempio n. 16
0
 /**
  * @param array $filters
  * @param array $options
  *
  * @return array
  */
 protected function parse_filter(array $filters = null, array $options = array())
 {
     $defaults = ['to_string' => true];
     $options = array_merge($defaults, $options);
     $spec = array('keyword', 'today');
     $pick = Utils::array_pick($filters, $spec);
     $filters = Utils::array_omit($filters, $spec);
     list($conditions, $params) = parent::parse_filter($filters, array('to_string' => false));
     foreach ($pick as $key => $value) {
         switch ($key) {
             case 'keyword':
                 if ($value) {
                     $conditions[] = "(`company` LIKE :keyword OR `company_short` LIKE :keyword OR a.`agreement_id` LIKE\n            :keyword)";
                     $params[':keyword'] = '%' . $value . '%';
                 }
                 break;
             case 'today':
                 $value = date('Y-m-d', strtotime($value) - 86400 * 60);
                 $conditions[] = '(`doc_date`>=:protection_begin OR c.`status`=' . ADModel::ONLINE . '
         OR (c.`status`=' . ADModel::OFFLINE . ' AND `status_time`>=:protection_begin))';
                 $params[':protection_begin'] = $value;
                 break;
         }
     }
     $conditions = $options['to_string'] ? ($options['is_append'] ? ' and ' : '') . implode(' AND ', $conditions) : $conditions;
     return array($conditions, $params);
 }
 /**
  * 全部广告数据分析
  */
 public function get_daily_stat()
 {
     $start = $_REQUEST['start'];
     $end = $_REQUEST['end'];
     $order = $_REQUEST['order'];
     $seq = $_REQUEST['seq'] ? $_REQUEST['seq'] : 'asc';
     $page = (int) $_REQUEST['page'];
     $page_size = $_REQUEST['pagesize'] ? $_REQUEST['pagesize'] : 20;
     $filters = array('salesman' => $_SESSION['id'], 'ad_app_type' => $_REQUEST['ad_app_type'], 'channel' => $_REQUEST['channel'], 'ad_name' => $_REQUEST['ad_name'], 'keyword' => $_REQUEST['keyword']);
     $filters = Utils::array_pick_effect($filters);
     $daily_service = new DailyStat();
     $result = $daily_service->get_daily_stat($start, $end, $filters, $order, $seq, $page, $page_size);
     $result['list'] = $this->is_invoice($result['list'], $start, $end);
     $result['code'] = 0;
     $result['msg'] = 'ok';
     $this->output($result);
 }
Esempio n. 18
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);
 }
Esempio n. 19
0
 protected function parse_filter(array $filters = null, array $options = array())
 {
     $defaults = ['to_string' => true];
     $options = array_merge($defaults, $options);
     if (isset($filters['salesman'])) {
         $filters['applicant'] = $filters['salesman'];
         unset($filters['salesman']);
     }
     if (isset($filters['start'])) {
         $filters['apply_time'][] = array('operator' => '>=', 'data' => $filters['start']);
         unset($filters['start']);
     }
     if (isset($filters['end'])) {
         $filters['apply_time'][] = array('operator' => '<=', 'data' => $filters['end']);
         unset($filters['end']);
     }
     if (isset($filters['pass_status'])) {
         $filters['a.status'][] = array('operator' => '>=', 'data' => $filters['pass_status']);
         unset($filters['pass_status']);
     }
     $spec = array('keyword');
     $pick = Utils::array_pick($filters, $spec);
     $filters = Utils::array_omit($filters, $spec);
     list($conditions, $params) = parent::parse_filter($filters, array('to_string' => false));
     foreach ($pick as $key => $value) {
         switch ($key) {
             case 'keyword':
                 if ($value) {
                     $conditions[] = "(`express_number` LIKE :keyword OR `full_name` LIKE :keyword OR `company` LIKE :keyword)";
                     $params[':keyword'] = "%{$value}%";
                 }
                 break;
         }
     }
     $conditions = $options['to_string'] ? ($options['is_append'] ? ' and ' : '') . implode(' AND ', $conditions) : $options;
     return array($conditions, $params);
 }
Esempio n. 20
0
 private function split_attr(array $attr = null, $only_split = false)
 {
     $attr = $attr ? $attr : $this->attributes;
     $callback = Utils::array_pick($attr, self::$FIELDS_CALLBACK);
     $ios = Utils::array_pick($attr, self::$FIELDS_IOS);
     $channel = Utils::array_pick($attr, self::$FIELDS_CHANNEL);
     $diy = Utils::array_pick($attr, self::$FIELDS_DIY);
     $permissions = $attr['permission'];
     $provinces = $attr['provinces'] ? $attr['provinces'] : $attr['put_provinces'];
     if (!$only_split) {
         $me = $_SESSION['id'];
         $im_cp = $_SESSION['role'] == Auth::$CP_PERMISSION;
         $now = date('Y-m-d H:i:s');
         $callback['ad_id'] = $channel['id'] = $ios['ad_id'] = $diy['id'] = $this->id;
         $attr['status'] = 2;
         // 新建,待审核
         $attr['ad_sdk_type'] = 1;
         // 只允许广告墙
         $attr['create_user'] = $me;
         $attr['create_time'] = $now;
         if ($im_cp) {
             $channel['feedback'] = 7;
             $channel['cycle'] = 1;
             $attr['ad_app_type'] = 2;
             $attr['cate'] = 1;
         } else {
             $admin = new Admin();
             $channel = array_merge($channel, $admin->get_owner($attr, $me));
         }
         if ($attr['replace']) {
             $this->replace = $attr['replace-with'];
             $attr['status'] = 3;
             // 欲替换之前的广告
             $attr['status_time'] = $attr['replace-time'];
         }
     }
     $attr = Utils::array_omit($attr, self::$FIELDS_CALLBACK, self::$FIELDS_CHANNEL, self::$FIELDS_IOS, self::$FIELDS_DIY, self::$FIELDS_OMIT);
     if ($only_split) {
         unset($attr['id']);
     }
     return [$callback, $ios, $channel, $diy, $attr, $permissions, $provinces];
 }
Esempio n. 21
0
 /**
  * @param array $filters
  * @param array $options
  *
  * @return array
  */
 protected function parse_filter(array $filters = null, array $options = array())
 {
     $defaults = ['to_string' => true];
     $options = array_merge($defaults, $options);
     $spec = array('keyword', 'salesman');
     $pick = Utils::array_pick($filters, $spec);
     $filters = Utils::array_omit($filters, $spec);
     list($conditions, $params) = parent::parse_filter($filters, array('to_string' => false));
     foreach ($pick as $key => $value) {
         switch ($key) {
             case 'keyword':
                 if ($value) {
                     $conditions[] = "(`alias` LIKE :keyword OR `full_name` LIKE :keyword)";
                     $params[':keyword'] = "%{$value}%";
                 }
                 break;
             case 'salesman':
                 if ($value) {
                     $conditions[] = "(b.`owner`=:salesman OR b.`execute_owner`=:salesman)";
                     $params[':salesman'] = $value;
                 }
                 break;
         }
     }
     $conditions = $options['to_string'] ? ($options['is_append'] ? ' and ' : '') . implode(' AND ', $conditions) : $options;
     return array($conditions, $params);
 }