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. 2
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. 3
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(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. 6
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. 7
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;
 }
Esempio n. 8
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. 9
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. 10
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;
 }
 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));
 }
Esempio n. 12
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);
 }
Esempio n. 13
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);
 }