model = model('OrdersCollect'); $this->view->assign("typeList", $this->model->getTypeList()); $this->view->assign("flagList", $this->model->getFlagList()); $group = model('AuthGroupAccess')->where('uid',$this->auth->id)->find(); $this->vipAdminBindModel = model('VipAdminBind'); $truegroupId = $group->group_id; // if(isset($_GET['channel_id']) && intval($_GET['channel_id'])>0){ // $groupObj = model('AuthGroupAccess')->where('uid',$_GET['channel_id'])->find(); // if($groupObj){ // $thisGroup = $groupObj->group_id; // if($thisGroup > 2){ //判断传过来的不是管理员的id // if($thisGroup==3){ //如果是渠道商 // if($truegroupId <3){ //只有管理员才有此操作 // $this->authId = $_GET['channel_id']; // $thisChannel = model('Admin')->where('id',$this->authId)->find(); // $this->groupId = 3; // $this->assign('channelTitle','当前是渠道商('.$thisChannel->nickname.')的数据'); // $this->assignconfig('channelstr','?channel_id='.$this->authId); // } // }else{ // if($truegroupId <4){ //管理员或渠道商才有此操作 // if($truegroupId == 3){ //如果是从渠道商查来的,判断当前代理商是不是渠道商下属 // $isCh = model('AdminExtend')->where(['admin_id'=>$_GET['channel_id'],'create_by'=>$group->uid])->find(); // if($isCh){ //如果是当前渠道商的下属 // $this->authId = $_GET['channel_id']; // $thisChannel = model('Admin')->where('id',$this->authId)->find(); // $this->groupId = 4; // $this->assign('channelTitle','当前是代理商('.$thisChannel->nickname.')的数据'); // $this->assignconfig('channelstr','?channel_id='.$this->authId); // } // }else{ //管理员查过来的 // $this->authId = $_GET['channel_id']; // $thisChannel = model('Admin')->where('id',$this->authId)->find(); // $this->groupId = 4; // $this->assign('channelTitle','当前是代理商('.$thisChannel->nickname.')的数据'); // $this->assignconfig('channelstr','?channel_id='.$this->authId); // } // // } // } // } // } // // }else{ // $this->authId = $this->auth->id; // $this->groupId = $truegroupId; // $this->assignconfig('channelstr','?channel_id=0'); // } $this->view->assign("groupId",$this->groupId); $this->assignconfig('groupId',$this->groupId); $this->assignconfig('authId',$this->authId); } public function index() { $vipadminIds = model("VipAdminBind") ->where("admin_id_master",$this->auth->id) ->where("flag = 1") ->column("admin_id_slave"); $zeroKey = array_search(0, $vipadminIds); if ($zeroKey !== false) { array_splice($vipadminIds, $zeroKey, 1); } //今天 $today = date('Ymd', time()); //昨天 $yesterday = date('Ymd', strtotime('-1 days')); //本月 $month = date('Ym', time()).'01'; $fields = "sum(recharge_money) recharge_money,sum(recharge_money_benefit) recharge_money_benefit,sum(normal_recharge_orders_count) normal_recharge_orders_count,sum(normal_recharge_orders) normal_recharge_orders,sum(normal_recharge_money) normal_recharge_money,sum(normal_recharge_money_benefit) normal_recharge_money_benefit,sum(normal_recharge_user_suc_count) normal_recharge_user_suc_count,sum(vip_recharge_orders_count) vip_recharge_orders_count,sum(vip_recharge_orders) vip_recharge_orders,sum(vip_recharge_money) vip_recharge_money,sum(pv) pv,sum(uv) uv"; if ($vipadminIds) { $todayData = $this->model ->field($fields) ->where(['type' => '1', 'flag' => '1', 'createdate' => $today]) ->where("admin_id", "in", $vipadminIds) ->find(); //今天自己的数据 $todayAgentData = $this->model ->field($fields) ->where(['type' => '1', 'flag' => '2', 'createdate' => $today]) ->where("admin_id", "in", $vipadminIds) ->find(); //今天代理商的数据 $todayAllData = $this->model ->field($fields) ->where(['type' => '1', 'flag' => '3', 'createdate' => $today]) ->where("admin_id", "in", $vipadminIds) ->find(); //今天所有的数据 $pvuv = Db::table('admin_puv') ->field("sum(pv) pv,sum(uv) uv") ->where('admin_id', "in", $vipadminIds) ->where("updatetime", "egt", strtotime("today")) ->find(); } else { $todayData = $todayAgentData = $todayAllData = false; $pvuv = ['pv' => 0, 'uv' => 0]; } $this->assign('pvuv',$pvuv); if($todayAllData){ if($todayData){ $todayAllData['recharge_money'] = $todayData->recharge_money; $todayAllData['recharge_money_benefit'] = $todayData->recharge_money_benefit; }else{ $todayAllData['recharge_money'] = 0; $todayAllData['recharge_money_benefit'] = 0; } if($todayAgentData){ $todayAllData['agent_recharge'] = $todayAgentData->recharge_money; $todayAllData['agent_recharge_benefit'] = $todayAgentData->recharge_money_benefit; }else{ $todayAllData['agent_recharge'] = 0; $todayAllData['agent_recharge_benefit'] = 0; } } if ($vipadminIds) { $yesterdayData = $this->model ->where(['type' => '1', 'flag' => '1', 'createdate' => $yesterday]) ->where("admin_id", "in", $vipadminIds) ->field($fields) ->find(); //昨天自己的数据 $yesterdayAgentData = $this->model ->where(['type' => '1', 'flag' => '2', 'createdate' => $yesterday]) ->where("admin_id", "in", $vipadminIds) ->field($fields) ->find(); //昨天代理商的数据 $yesterdayAllData = $this->model ->where(['type' => '1', 'flag' => '3', 'createdate' => $yesterday]) ->where("admin_id", "in", $vipadminIds) ->field($fields) ->find(); //昨天所有的数据 } else { $yesterdayData = $yesterdayAgentData = $yesterdayAllData = false; } if(!empty($yesterdayAllData)){ if($yesterdayData){ $yesterdayAllData['recharge_money'] = $yesterdayData->recharge_money; $yesterdayAllData['recharge_money_benefit'] = $yesterdayData->recharge_money_benefit; }else{ $yesterdayAllData['recharge_money'] = 0; $yesterdayAllData['recharge_money_benefit'] = 0; } if($yesterdayAgentData){ $yesterdayAllData['agent_recharge'] = $yesterdayAgentData->recharge_money; $yesterdayAllData['agent_recharge_benefit'] = $yesterdayAgentData->recharge_money_benefit; }else{ $yesterdayAllData['agent_recharge'] = 0; $yesterdayAllData['agent_recharge_benefit'] = 0; } } $monthData = $this->model ->sumCollect($vipadminIds,1,1,$month,$yesterday); //当月自己的数据 $monthAgentData = $this->model ->sumCollect($vipadminIds,1,2,$month,$yesterday); //当月代理商的数据 $monthAllData = $this->model ->sumCollect($vipadminIds,1,3,$month,$yesterday); //当月所有的数据 if(!empty($monthAllData)){ if($monthData){ $monthAllData['recharge_money'] = $monthData->recharge_money; $monthAllData['recharge_money_benefit'] = $monthData->recharge_money_benefit; }else{ $monthAllData['recharge_money'] = 0; $monthAllData['recharge_money_benefit'] = 0; } if($monthAgentData){ $monthAllData['agent_recharge'] = $monthAgentData->recharge_money; $monthAllData['agent_recharge_benefit'] = $monthAgentData->recharge_money_benefit; }else{ $monthAllData['agent_recharge'] = 0; $monthAllData['agent_recharge_benefit'] = 0; } } $allData = $this->model ->sumCollect($vipadminIds,1,1); //汇总自己的数据 $allAgentData = $this->model ->sumCollect($vipadminIds,1,2); //汇总代理商的数据 $allAllData = $this->model ->sumCollect($vipadminIds,1,3); //汇总所有的数据 if($allAllData){ if($allData){ $allAllData['recharge_money'] = $allData->recharge_money; $allAllData['recharge_money_benefit'] = $allData->recharge_money_benefit; }else{ $allAllData['recharge_money'] = 0; $allAllData['recharge_money_benefit'] = 0; } if($allAgentData){ $allAllData['agent_recharge'] = $allAgentData->recharge_money; $allAllData['agent_recharge_benefit'] = $allAgentData->recharge_money_benefit; }else{ $allAllData['agent_recharge'] = 0; $allAllData['agent_recharge_benefit'] = 0; } } $this->assign('today',$todayAllData); $this->assign('yesterday',$yesterdayAllData); $this->assign('month',$monthAllData); $this->assign('all',$allAllData); if ($this->request->isAjax()) { $beginDate = date('Ymd', strtotime('-31 days')); $endDate = date('Ymd', strtotime('-1 days')); list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $condition = []; $condition['type'] = 1; $condition['flag'] = 3; // $total = $this->model // ->where($where) // ->where($condition) // ->where("createdate",$today) // ->where("admin_id","in",$vipadminIds) // ->order($sort, $order) // ->count(); if ($vipadminIds) { $total = model("Admin") ->where("id","in",$vipadminIds) ->count(); $list = $this->model ->alias("a") // ->where($condition) ->join("admin_config ac","a.admin_id = ac.admin_id AND a.type = 1 AND a.flag = 3 AND a.createdate = {$today}","right") // ->where("a.createdate",$today) ->where("ac.admin_id","in",$vipadminIds) ->field("a.type,a.flag,a.createdate,a.recharge_money,a.normal_recharge_money,a.normal_recharge_orders,a.vip_recharge_money ,a.vip_recharge_orders,ac.json,ac.admin_id") ->order("a.recharge_money", "desc") // ->order($sort, $order) ->limit($offset, $limit) ->select(); foreach ($list as &$v){ $v['name'] = $v['json']?json_decode($v['json'])->authorizer_info->nick_name:''; unset($v['json']); } $result = array("total" => $total, "rows" => $list); }else{ $result = array("total" => [], "rows" => 0); } return json($result); } return $this->view->fetch(); } /** * 近30天汇总,不包括今天 * @return \think\response\Json */ public function orderThirtyStatistics(){ list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $vipadminIds = model("VipAdminBind") ->where("admin_id_master",$this->auth->id) ->where("flag = 1") ->column("admin_id_slave"); $beginDate = date('Ymd', strtotime('-30 days')); $endDate = date('Ymd', strtotime('-1 days')); $total = $this->model ->where("type", 1) ->where("flag", 3) ->where("createdate", ">=", $beginDate) ->where("createdate", "<=", $endDate) ->where("admin_id", "in", $vipadminIds) ->group("createdate,type,flag") ->count(); $list = $this->model ->where("type", 1) ->where("flag", 3) ->where("createdate", ">=", $beginDate) ->where("createdate", "<=", $endDate) ->where("admin_id", "in", $vipadminIds) ->field([ "DATE_FORMAT(createdate, '%Y-%m-%d')" => "f_date", "SUM(recharge_money)" => "recharge_money_total", "SUM(normal_recharge_orders)" => "normal_recharge_orders_total", "SUM(normal_recharge_user_suc_count)" => "normal_user_num_total", "SUM(vip_recharge_money)" => "vip_recharge_money_total", "SUM(vip_recharge_orders)" => "vip_recharge_orders_total", "SUM(vip_recharge_user_suc_count)" => "vip_user_num_total", "type","flag" ]) ->group("createdate,type,flag") ->limit($offset,$limit) ->order('createdate', 'desc') ->select(); foreach ($list as $key => &$value){ $list[$key]['money_total'] = $value['recharge_money_total']; $list[$key]['orders_total'] = $value['normal_recharge_orders_total'] + $value['vip_recharge_orders_total']; $list[$key]['user_num_total'] = $value['normal_user_num_total'] + $value['vip_user_num_total']; } $result = array("total" => $total, "rows" => $list); return json($result); } }