Пример #1
0
 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);
     }
 }
Пример #3
0
 public function log_sm($id, $url, $pack_name, $app_name)
 {
     // 记到表里
     $attr = ['ad_id' => $id, 'url' => $url, 'user' => $_SESSION['id'], 'sm' => self::HAS];
     $DB = $this->get_write_pdo();
     $count = SQLHelper::insert($DB, self::$TABLE, $attr, true);
     $admin = new Admin();
     $me = $admin->get_user_info(['id' => $_SESSION['id']]);
     $me = array_values($me)[0];
     $attr['name'] = $me;
     // 给相关人发邮件
     $mailer = new Mailer();
     $to = ['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'];
     $subject = '【点乐自助平台】监测到包含数盟SDK的包上传';
     $content = $mailer->create('spy-sm', array_merge($attr, array('pack_name' => $pack_name, 'app_name' => $app_name)));
     $check = $mailer->send($to, $subject, $content);
     return $count && $check;
 }
 public function get_list()
 {
     $pagesize = isset($_REQUEST['pagesize']) ? (int) $_REQUEST['pagesize'] : 100;
     $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 0;
     $page_start = $page * $pagesize;
     $filters = array('keyword' => $_REQUEST['keyword']);
     $service = new Channel();
     $admin = new Admin();
     $me = $_SESSION['id'];
     $relative = array();
     $relative_sales = $admin->get_sales_by_me($me);
     if ($relative_sales) {
         foreach ($relative_sales as $id => $value) {
             $relative[] = array('key' => $id, 'value' => $value);
         }
     }
     $channel_list = $service->get_my_channel($filters, $page_start, $pagesize);
     $total = $service->get_my_channel_total();
     $this->output(array('code' => 0, 'msg' => 'get', 'list' => $channel_list, 'total' => $total, 'options' => array('channel_types' => ChannelModel::$TYPE, 'relativeSales' => $relative_sales)));
 }
Пример #5
0
 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;
 }
Пример #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];
 }
Пример #7
0
 public function get_daily_ad_stat($id, $start, $end)
 {
     $redis = $this->get_redis();
     $ad_service = new AD();
     $ad_info = $ad_service->get_ad_info_by_id($id);
     $ad_transfer_service = new AdTransferStat();
     $transfer = $ad_transfer_service->get_ad_transfer_stat_by_ad($id, $start, $end);
     $happy_lock_transfer = $ad_transfer_service->get_ad_transfer_by_user($id, $start, $end, HappylockStat::HAPPY_LOCK_USER_ID);
     $magic_transfer = $ad_transfer_service->get_ad_transfer_by_user($id, $start, $end, HappylockStat::MAGIC_USER_ID);
     $task_stat_service = new TaskStat();
     $task = $task_stat_service->get_ad_task_outcome_by_date($start, $end, $id);
     $limited_task = $task_stat_service->get_ad_limit_task_outcome_by_date($start, $end, $id);
     $happy_lock_service = new HappylockStat();
     $happy_lock_task = $happy_lock_service->get_ad_happy_lock_task_stat($id, $start, $end, TaskStat::TASK_ES_TYPE);
     $happy_lock_limited_task = $happy_lock_service->get_ad_happy_lock_task_stat($id, $start, $end, TaskStat::LIMITED_TASK_ES_TYPE);
     $quote_service = new QuoteStat();
     $quote = $quote_service->get_ad_quote($id, $start, $end);
     $total = array('transfer' => 0, 'cpa' => 0, 'income' => 0, 'outcome' => 0);
     $total_cost = 0;
     $out = 0;
     $result['list'] = array();
     for ($stamp = strtotime($start); $stamp <= strtotime($end); $stamp += 86400) {
         $date = date("Y-m-d", $stamp);
         $value = json_decode($redis->get('admin_stat_daily_ratio_' . $date), true);
         $total_cost += $value['total_cost'];
         $out += $value['out'];
         $stat = array('date' => $date, 'transfer' => (int) $transfer[$date]['transfer_total'], 'cpa' => (int) $quote[$date]['nums'], 'quote_rmb' => isset($quote[$date]) ? $quote[$date]['quote_rmb'] : $ad_info['quote_rmb'], 'ratio' => $transfer[$date]['transfer_total'] ? round((int) $quote[$date]['nums'] / (int) $transfer[$date]['transfer_total'] * 100, 2) : 0, 'real' => $transfer[$date]['transfer_total'] ? round((int) $quote[$date]['nums'] * (int) $quote[$date]['quote_rmb'] / (int) $transfer[$date]['transfer_total'] / 100, 2) : 0, 'outcome' => $transfer[$date]['rmb_total'] + $task[$date] + $limited_task[$date] - ($happy_lock_transfer[$date]['rmb'] + $happy_lock_task[$date] + $happy_lock_limited_task[$date]) / 2 - $magic_transfer[$date]['rmb'], 'income' => (int) $quote[$date]['nums'] * (int) $quote[$date]['quote_rmb']);
         $result['list'][] = $stat;
         foreach ($total as $key => $value) {
             $total[$key] += $stat[$key];
         }
     }
     $tmp_out = $out == 0 ? 1 : $out;
     $ratio = $total_cost / $tmp_out;
     $total['ratio'] = $total['transfer'] ? round((int) $total['cpa'] / (int) $total['transfer'] * 100, 2) : 0;
     $total['real'] = $total['transfer'] ? round((int) $total['income'] / (int) $total['transfer'] / 100, 2) : 0;
     $total['is_amount'] = true;
     $result['list'][] = $total;
     foreach ($result['list'] as $key => $value) {
         $result['list'][$key]['profit'] = round($value['income'] * TAX_RATIO - $value['outcome'] * $ratio, 2);
     }
     $is_admin = $_SESSION['admin_role'] != Admin::SALE && $_SESSION['admin_role'] != Admin::SALE_MANAGER;
     if (!$is_admin) {
         $admin_service = new Admin();
         $ad_info = $admin_service->check_ad_info_for_sale($ad_info);
     }
     $ad_info['is_admin'] = $is_admin;
     $result['ad'] = $ad_info;
     return $result;
 }
 /**
  * 取个人的所有申请
  */
 public function get_list()
 {
     $me = $_SESSION['id'];
     $keyword = isset($_REQUEST['keyword']) ? trim($_REQUEST['keyword']) : '';
     $page = (int) $_REQUEST['page'];
     $pagesize = isset($_REQUEST['pagesize']) ? (int) $_REQUEST['pagesize'] : 10;
     $start = $page * $pagesize;
     $service = $this->get_service();
     $ad_service = new AD();
     $applies = $service->get_list($me, $keyword, $start, $pagesize);
     $labels = array('set_status' => '上/下线', 'set_job_num' => '每日限量', 'set_rmb' => '今日余量', 'set_ad_url' => '替换包', 'set_quote_rmb' => '报价');
     $today = date('Y-m-d');
     $expires = array();
     $handler = array();
     $ad_ids = array();
     foreach ($applies as $index => $apply) {
         $apply = array_filter($apply, function ($value) {
             return isset($value);
         });
         // 修改每日限额同时修改今日余量
         if (array_key_exists('set_rmb', $apply) && array_key_exists('set_job_num', $apply)) {
             $apply['attr'] = 'set_job_num';
             $apply['label'] = $labels['set_job_num'];
             $apply['after'] = $apply['set_job_num'];
             $apply['extra'] = true;
         } else {
             // 普通处理
             foreach ($apply as $key => $value) {
                 if (preg_match('/^set_\\w+/', $key)) {
                     $apply['attr'] = $key;
                     $apply['label'] = $labels[$key];
                     $apply['after'] = $value;
                     break;
                 }
             }
         }
         if (!$apply['handler'] && $apply['attr']) {
             // 尚未处理,取之前的值
             $ad_ids[] = $apply['adid'];
         }
         if ($apply['attr'] == 'set_rmb') {
             if ($apply['create_time'] < $today) {
                 $expires[] = $apply['id'];
                 unset($applies[$index]);
                 break;
             }
             $ad_ids[] = $apply['adid'];
         }
         $apply['is_url'] = $apply['attr'] == 'set_ad_url';
         $apply['is_status'] = $apply['attr'] == 'set_status';
         // 没有匹配的值对,则是替换广告
         if (!$apply['attr'] && !$apply['value']) {
             $apply['label'] = '替换广告';
             $apply['after'] = $apply['adid'];
             $apply['is_replace'] = true;
         }
         $handler[] = $apply['handler'];
         $applies[$index] = $apply;
     }
     // 作废申请
     $service->update(array('status' => Apply::EXPIRED), $expires);
     // 取用户姓名
     $handlers = array_filter(array_unique($handler));
     if ($handlers) {
         $admin_service = new Admin();
         $users = $admin_service->get_user_info(array('id' => $handlers));
         foreach ($applies as $index => $apply) {
             $applies[$index]['handler'] = isset($users[$apply['handler']]) ? $users[$apply['handler']] : $apply['handler'];
         }
     }
     // 取广告信息然后回填数据
     $ad_info = $ad_service->get_ad_info(array('id' => array_filter(array_unique($ad_ids))));
     foreach ($applies as $index => $apply) {
         if (!$apply['handler'] && $apply['attr']) {
             // 尚未处理,取之前的值
             $key = substr($apply['attr'], 4);
             $apply['before'] = $ad_info[$apply['adid']][$key];
         }
         $applies[$index] = $apply;
     }
     $total = $service->get_total_number($me, $keyword);
     $this->output(array('code' => 0, 'msg' => 'fetched', 'total' => $total, 'list' => array_values($applies)));
 }
Пример #9
0
 /**
  * 取新建广告的表单项,修改广告时当前内容
  * @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));
 }
Пример #10
0
 /**
  * 获取发票详情信息
  * @param $filters
  * @param int $page_start
  * @param int $pagesize
  * @param null $order
  * @return array
  */
 public function get_invoice_info($filters, $page_start = 0, $pagesize = 10, $order = null, $all = false)
 {
     $DB = $this->get_read_pdo();
     if (!array_key_exists('status', $filters)) {
         $filters['a.status'][] = array('operator' => '>', 'data' => 1);
     } else {
         $filters['a.status'] = $filters['status'];
         unset($filters['status']);
     }
     list($conditions, $params) = $this->parse_filter($filters);
     if ($order) {
         $order = 'ORDER BY ' . $this->get_order($order);
     }
     if (!$all) {
         $sql = "SELECT a.`id`,`applicant`,`apply_time`,`full_name`,`company`,`income`,`income_first`,\n            `handle_time`,`number`,`express_number`,`reason`,a.`status`,a.`comment`,`attachment`,\n            c.`agreement_id` as `agreement_number`\n            FROM `t_invoice` a LEFT JOIN `t_channel_map` b\n            ON a.`channel_id` = b.`id`\n            LEFT JOIN `t_agreement` c ON a.`agreement_id` = c.`id`\n            WHERE {$conditions}\n            {$order}\n            LIMIT {$page_start}, {$pagesize}";
     } else {
         $sql = "SELECT a.`id`,`applicant`,`apply_time`,`full_name`,`company`,`income`,`income_first`,\n            `handle_time`,`number`,`express_number`,`reason`,a.`status`,a.`comment`,`attachment`,\n            c.`agreement_id` as `agreement_number`\n            FROM `t_invoice` a LEFT JOIN `t_channel_map` b\n            ON a.`channel_id` = b.`id`\n            LEFT JOIN `t_agreement` c ON a.`agreement_id` = c.`id`\n            WHERE {$conditions}\n            {$order}";
     }
     $state = $DB->prepare($sql);
     $state->execute($params);
     $invoices = $state->fetchAll(PDO::FETCH_ASSOC);
     $result = array();
     $is_beijing = false;
     if (!$all) {
         $admin_service = new Admin();
         $me = $_SESSION['id'];
         $sale = $admin_service->get_sales_info($me);
         if (strstr($sale['location'], ',') || trim($sale['location']) === '北京') {
             $is_beijing = true;
         }
         $is_show = false;
         foreach ($invoices as $id => $value) {
             if ($value['income'] != $value['income_first']) {
                 // 核减
                 $open = 8;
             } else {
                 // 不核减
                 if ($value['comment'] || trim($value['comment']) != "") {
                     // 特批
                     $open = 18;
                 } else {
                     // 不特批
                     $open = 28;
                 }
             }
             if ($value['comment'] || $value['attachment']) {
                 $is_show = true;
             }
             $result[] = array_merge($value, array('is_beijing' => $is_beijing, 'status' => (int) $value['status'], 'open' => $open, 'is_show' => $is_show));
             $is_show = false;
         }
         return $result;
     } else {
         foreach ($invoices as $id => $value) {
             // 只返回有附件或者有特批的发票
             if ($value['attachment'] || $value['comment']) {
                 $admin_service = new Admin();
                 $sale = $admin_service->get_sales_info($value['applicant']);
                 // 判断用户区域是不是北京
                 if (strstr($sale['location'], ',') || trim($sale['location']) === '北京') {
                     $is_beijing = true;
                 }
                 $result[] = array_merge($value, array('sale' => $sale['NAME'], 'is_beijing' => $is_beijing, 'status' => (int) $value['status']));
                 $is_beijing = false;
             }
         }
         $total = count($result);
         $result = array_slice($result, $page_start, $pagesize);
         return array($result, $total);
     }
 }
 public function init($id)
 {
     $me = $_SESSION['id'];
     $invoice_service = new Invoice();
     $admin_service = new Admin();
     $agreement_service = new Agreement();
     // 获取收款方业务负责人
     $chargers = $admin_service->get_chargers($me);
     $applicant = $admin_service->get_sales_info($me);
     $is_assistant = false;
     if ($chargers) {
         $is_assistant = true;
     }
     $options = array('types' => InvoiceModel::$TYPE, 'content_types' => InvoiceModel::$CONTENT_TYPE, 'is_assistant' => $is_assistant);
     if ($id === 'init') {
         $this->get_init_params($chargers, $applicant, $options);
     }
     $res = $invoice_service->get_invoice_by_id($id);
     if ($res['agreement_id']) {
         $agreement = $agreement_service->get_agreement_by_id(array('id' => $res['agreement_id']));
         // 结算单收款方信息
         $accept = InvoiceModel::$ACCEPT[$agreement['company_dianjoy']];
     }
     $products = $invoice_service->get_invoice_ad_by_invoiceid($id);
     $res = array_merge(array('products' => $products, 'chargers' => $chargers, 'company' => $agreement['company'], 'company_short' => $agreement['company_short'], 'agreement_number' => $agreement['agreement_id'], 'cycle' => $agreement['cycle'], 'rmb' => $agreement['rmb'], 'agreement_comment' => $agreement['comment'], 'ad_name' => $agreement['ad_name'], 'sign_date' => $agreement['sign_date'], 'company_dianjoy' => $agreement['company_dianjoy'], 'accept_company' => $accept['accept_company'], 'accept_bank' => $accept['accept_bank'], 'accept_account' => $accept['accept_account']), $res);
     if (count($products) > 0) {
         $res = array_merge($res, array('income' => round($res['income'] / 100, 2), 'income_first' => round($res['income_first'] / 100, 2), 'joy_income' => round($res['joy_income'] / 100, 2), 'red_ad_income' => round($res['red_ad_income'] / 100, 2), 'red_ios_income' => round($res['red_ios_income'] / 100, 2)));
     }
     if ($res['status'] == 40) {
         $options = array_merge(array('view' => true), $options);
     }
     $this->output(array('code' => 0, 'msg' => 'fetched', 'invoice' => $res, 'options' => $options));
 }
Пример #12
0
 /**
  * 取当前用户的助理和被助理
  * @return array|null|string
  */
 public function get_assistant()
 {
     $me = $_SESSION['id'];
     $admin = new Admin();
     $sales = $admin->get_sales_by_me($me);
     $owner = $admin->get_owner(null, $me);
     if ($sales) {
         $sales = array_keys($sales);
     }
     if ($owner) {
         $sales = array_unique(array_merge(array_values($owner), (array) $sales));
     }
     return array_values($sales);
 }