/**
  * @param $attr
  */
 private function translate($attr)
 {
     $ad = new AD();
     $types = $ad->get_all_labels(PDO::FETCH_KEY_PAIR);
     $attr['code'] = md5($attr['id'] . BAOBEI_SALT);
     $attr['quote_rmb'] = number_format($attr['quote_rmb'] / 100, 2);
     $attr['ad_type'] = $types[$attr['ad_type']];
     $attr['cate'] = ADModel::$CATE[$attr['cate']];
     $permissions = $ad->get_permissions(['ad_id' => $attr['id']]);
     $permissions = array_values($permissions);
     $attr['permissions'] = implode("\n<br>", $permissions);
     $attr['feedback'] = ADModel::$FEEDBACK[$attr['feedback']];
     $attr['ad_desc'] = preg_replace('/<span style="color: rgb\\(255, 0, 0\\);">(.*?)<\\/span>/', '', $attr['ad_desc']);
     // 过滤掉标红文字
     if (is_numeric($attr['channel'])) {
         $channel = new Channel();
         $attr['channel'] = $channel->get_channel(array('id' => $attr['channel']))[$attr['channel']];
     }
     if ($attr['agreement_id']) {
         $agreement = new Agreement();
         $agreements = $agreement->get_agreements_basic(['id' => $attr['agreement_id']]);
         $agreement = $agreements[$attr['agreement_id']];
         $attr['agreement'] = $agreement['company_short'] ? $agreement['company_short'] : $agreement['company'];
     }
     return $attr;
 }
 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 renew($id)
 {
     $mailer = new Mailer();
     $service = new Agreement();
     $admin = new Admin();
     $me = $_SESSION['id'];
     $managers = [4 => '*****@*****.**', 23 => '*****@*****.**', 45 => '*****@*****.**', 129 => '*****@*****.**'];
     $attr = $this->get_post_data();
     $attr['fullname'] = $_SESSION['fullname'];
     $agreement = $service->get_agreement_by_id(['id' => $id]);
     if (!$agreement) {
         $this->exit_with_error(11, '参数错误', 400);
     }
     if ($agreement['owner'] != $me) {
         $this->exit_with_error(10, '你不能对别人的合同进行操作', 403);
     }
     $agreement['company_type'] = Agreement::$TYPE[$agreement['company_type']];
     $content = $mailer->create('agreement-renew', $agreement, $attr);
     $manager = $admin->get_my_manager($me);
     $to = ['*****@*****.**', $managers[$manager]];
     $cc = ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', $_SESSION['user'] . '@dianjoy.com'];
     $check = $mailer->send($to, '商务申请合同续期', $content, $cc);
     if ($check) {
         $this->output(['code' => 0, 'msg' => '发送成功']);
     } else {
         $this->exit_with_error(20, '发送邮件失败', 400, $check);
     }
 }
 public function get_notice($admin_id, $role, $latest)
 {
     $DB = $this->get_read_pdo();
     $m = new Mustache_Engine();
     $ad_service = new AD();
     $sql = "SELECT `type`\n            FROM `t_alarm_group`\n            WHERE `group`={$role}";
     $types = $DB->query($sql)->fetchAll(PDO::FETCH_COLUMN);
     $types = implode(',', $types);
     $type_sql = $types ? " OR `alarm_type` IN ({$types})" : '';
     // 只取最近一周,再早的估计也没啥处理的必要了
     $date = date('Y-m-d', time() - 86400 * 6);
     $sql = "SELECT a.`id`, `uid`, `user_id`, `app_id`, `ad_id`, a.`status`,\n              `create_time`, `op_time`, `description`, `handler`\n            FROM `t_admin_alarm_log` a LEFT JOIN `t_alarm_type` t ON a.alarm_type=t.id\n            WHERE (`admin_id`='{$admin_id}' {$type_sql})\n              AND `create_time`>'{$date}' AND a.`status`=0 AND a.`id`>{$latest}\n            ORDER BY `id` DESC";
     $alarms = $DB->query($sql)->fetchAll(PDO::FETCH_ASSOC);
     foreach ($alarms as &$alarm) {
         $alarm['id'] = (int) $alarm['id'];
         if ($alarm['ad_id']) {
             if (strlen($alarm['ad_id']) == 32) {
                 $ad = $ad_service->get_ad_info(array('id' => $alarm['ad_id']), 0, 1);
                 $alarm['name'] = $ad['ad_name'];
             }
         } else {
             if ($alarm['uid']) {
                 // 发票通知提醒
                 $invoice_id = $alarm['uid'];
                 $invoice_service = new Invoice();
                 $agreement_service = new Agreement();
                 $invoice = $invoice_service->get_invoice_by_id($invoice_id);
                 $agreement = $agreement_service->get_agreement_by_id(array('id' => $invoice['agreement_id']));
                 $alarm['channel'] = $agreement['company_short'];
                 $admin_service = new Admin();
                 $sale = $admin_service->get_sales_info($alarm['user_id']);
                 $alarm['sale'] = $sale['NAME'];
             }
         }
         $alarm['status'] = (int) $alarm['status'];
         $alarm['handler'] = $m->render($alarm['handler'], $alarm);
     }
     return $alarms;
 }
 /**
  * 取新建广告的表单项,修改广告时当前内容
  * @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));
 }
Beispiel #6
0
 private function get_ad_agreements(array $list)
 {
     $agreements = array();
     foreach ($list as $ad) {
         if ($ad['agreement_id']) {
             $agreements[] = $ad['agreement_id'];
         }
     }
     if ($agreements) {
         $service = new Agreement();
         $agreements = $service->get_agreements_basic(['id' => $agreements]);
         foreach ($list as $key => $ad) {
             if ($ad['agreement_id']) {
                 $list[$key]['agreement'] = $agreements[$ad['agreement_id']]['company_short'];
                 $list[$key]['company'] = $agreements[$ad['agreement_id']]['company'];
             }
         }
     }
     return $list;
 }
 public function get_transfer_ad($ad_id)
 {
     $me = $_SESSION['id'];
     $start = $_REQUEST['start'];
     $end = $_REQUEST['end'];
     $ad_service = new AD();
     $channel = $ad_service->get_ad_channel_by_id($ad_id);
     $agreement_service = new Agreement();
     $agreement = $agreement_service->get_agreement_by_adid($ad_id);
     $agreement_id = $agreement['id'];
     $filters = array('salesman' => $me, 'channel' => $channel);
     // 取出用户在该渠道下的所有广告
     $ads = $ad_service->get_all_ad_info($filters);
     // 取出这段期间内有量的广告
     $quote_service = new Quote();
     $quote_ads = $quote_service->get_all_quote_ad($start, $end);
     $ids = array_unique(array_intersect(array_keys($ads), array_keys($quote_ads)));
     $list = array();
     $invoice_service = new Invoice();
     foreach ($ids as $id) {
         // 剔除该段时间内已经开过票的广告
         $nums = $invoice_service->is_invoice($id, $start, $end);
         if ($nums > 0) {
             continue;
         }
         // 剔除没有关联合同的广告
         if (!isset($ads[$id]['agreement_id'])) {
             continue;
         }
         $ad = array('ad_id' => $id, 'ad_name' => $ads[$id]['ad_name'], 'channel_id' => $ads[$id]['cid'], 'channel' => $agreement_id, 'alias' => $ads[$id]['channel']);
         $list[] = $ad;
     }
     $this->output(array('code' => 0, 'msg' => "get", 'list' => $list));
 }