123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Elton
- * Date: 2019/8/9
- * Time: 14:05
- */
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\main\constants\OrderContents;
- use app\main\constants\PayConstants;
- class Guideappcollect extends Backend
- {
- protected $model = null;
- protected $noNeedRight = ['*'];
- public function _initialize()
- {
- parent::_initialize(); // TODO: Change the autogenerated stub
- $this->model = model('GuideAppCollect');
- }
- public function index()
- {
- $admin_id = $this->auth->id;
- if ($this->request->isAjax()) {
- // 判断管理员身份 [普通代理商 | 渠道商 | 配号代理商]
- if ($this->group == 4) {
- //普通代理商
- $data = $this->onlyOrderCollectData($admin_id);
- } else {
- //渠道商 | 配号代理商
- $data = $this->mergeData($admin_id);
- }
- $total = count($data);
- $result = array("total" => $total, "rows" => $data);
- return json($result);
- }
- $this->assign('admin_groupid', $this->group);
- $this->assignconfig('admin_groupid', $this->group);
- return $this->view->fetch();
- }
- /**
- * 普通代理商仅显示充值人数和充值金额
- * @param $admin_id
- * @return array
- */
- public function onlyOrderCollectData($admin_id)
- {
- $order_data = $this->getOrdersCollect($admin_id);
- $result = [];
- if(is_array($order_data)){
- $order_data = array_values($order_data);
- foreach ($order_data as $key => $item) {
- if (!empty($item)) {
- $result[$key]['createdate'] = $item['createdate'];
- $result[$key]['recharge_money'] = $item['recharge_money'];
- $result[$key]['recharge_user_num'] = $item['recharge_user_suc_count'];
- }
- }
- }
- return $result;
- }
- public function mergeData($admin_id)
- {
- $base_data = $this->getBaseData($admin_id);
- $order_data = $this->getOrdersCollect($admin_id);
- $user_app_data = $this->getUserAppCollect($admin_id);
- $result = [];
- if($base_data){
- foreach ($base_data as $key => $item) {
- if(!empty($order_data[$key])){
- $base_data[$key]['recharge_money'] = $order_data[$key]['recharge_money'];
- $base_data[$key]['recharge_user_num'] = $order_data[$key]['recharge_user_suc_count'];
- }else{
- $base_data[$key]['recharge_money'] = 0;
- $base_data[$key]['recharge_user_num'] = 0;
- }
- if(!empty($user_app_data[$key])){
- $base_data[$key]['import_num'] = $user_app_data[$key]['increase_bind_code'];
- }else{
- $base_data[$key]['import_num'] = 0;
- }
- // uv_view_total 曝光量
- if ($base_data[$key]['uv_view_total']) {
- $base_data[$key]['importapp_rate'] = sprintf("%.2f", ($base_data[$key]['import_num'] / $base_data[$key]['uv_view_total']) * 100) . '%';
- } else {
- $base_data[$key]['importapp_rate'] = 0;
- }
- // uv_view_total 曝光量
- if ($base_data[$key]['uv_total']) {
- $base_data[$key]['click_rate'] = sprintf("%.2f", ($base_data[$key]['import_num'] / $base_data[$key]['uv_total']) * 100) . '%';
- } else {
- $base_data[$key]['click_rate'] = 0;
- }
- $result[] = $base_data[$key];
- }
- }
- return $result;
- }
- /**
- * @param $admin_id 渠道商ID
- * @return array 按日期汇总打点统计数据
- */
- public function getBaseData($admin_id)
- {
- $res = [];
- $data = $this->model->where(['type' => 1, 'admin_id' => $admin_id])->select();
- if ($data) {
- foreach ($data as $key => $item) {
- $key = $item['createdate'];
- $res[$key] = $item;
- if( $item['uv_total'] == 0){
- $res[$key]['click_rate'] = 0;
- }else{
- $res[$key]['click_rate'] = $item['import_num'] / $item['uv_total']; //点击率
- }
- if($item['uv_view_total'] == 0){
- $res[$key]['importapp_rate'] = 0; //导端率
- }else{
- $res[$key]['importapp_rate'] = $item['import_num'] / $item['uv_view_total']; //导端率
- }
- }
- return $res;
- }
- }
- /**
- * 获取订单统计数据
- * @param $admin_id
- * @return array
- */
- public function getOrdersCollect($admin_id)
- {
- $res = [];
- if ($this->group == 4) {
- // 普通代理商
- $data = model('OrdersCollect')->where([
- 'type' => OrderContents::ORDER_COLLECT_TYPE_DAY,
- 'admin_id' => $admin_id,
- 'flag' => OrderContents::ORDER_COLLECT_FLAG_SELF,
- 'business_line' => PayConstants::BUSINESS_APP
- ])->select();
- } else {
- $data = model('OrdersCollect')->where([
- 'type' => OrderContents::ORDER_COLLECT_TYPE_DAY,
- 'admin_id' => $admin_id,
- 'flag' => OrderContents::ORDER_COLLECT_FLAG_ALL,
- 'business_line' => PayConstants::BUSINESS_APP
- ])->select();
- }
- if ($data) {
- foreach ($data as $key => $item) {
- $key = $item['createdate'];
- $res[$key] = $item;
- }
- }
- return $res;
- }
- /**
- * 获取导端用户统计数据
- * @param $admin_id
- * @return array
- */
- public function getUserAppCollect($admin_id)
- {
- $res = [];
- $data = model('UserAppCollect')->where(['type' => 1, 'admin_id' => $admin_id])->select();
- if ($data) {
- foreach ($data as $key => $item) {
- $key = $item['createdate'];
- $res[$key] = $item;
- }
- }
- return $res;
- }
- }
|