model = new \app\admin\model\agent\Agent(); } /** * @desc desc * @return mixed * @throws \think\exception\DbException * @author weichuanbao<654745815@qq.com> * @date 2021/12/8 0008 */ public function index() { $params = input(); $params['card_id'] = input('card_id/s', ''); $params['nickname'] = input('nickname/s', ''); $where['is_agent'] = 2; if ($params['card_id']) { $where['card_id'] = ['like', '%' . $params['card_id'] . '%']; } if ($params['nickname']) { $where['nickname'] = ['like', '%' . $params['nickname'] . '%']; } $list = $this->model->where($where) ->order(['id' => 'desc']) ->paginate(input('limit', 10),false); return IResponse::paginate($list); } /** * @desc 代理商个人数据统计 * @param $ids * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author weichuanbao<654745815@qq.com> * @date 2021/12/8 0008 */ public function personal($ids) { $row = $this->model->with(['agent'])->where('is_agent', 2)->find($ids); if (!$row) { IResponse::failure('记录不存在'); } $China = new China(); $Seller = new Seller(); $TaxiOrder = new TaxiOrder(); $GoodsOrder = new GoodsOrder(); $SkillOrder = new SkillOrder(); $MissionOrder = new MissionOrder(); // 所属区域 $region = $China->getValue($row->agent->area_id, 'name'); // 商户数量 $seller = $Seller->where(['area_id' => $row->agent->area_id])->count(); // 订单数据 // 摩的订单,技能订单,商品订单,配送订单 $taxi_order = $TaxiOrder->whereIn('area_id', $row->agent->area_id)->whereNotIn('status', [1])->column('price', 'id'); $skill_order = $SkillOrder->whereIn('area_id', $row->agent->area_id)->whereNotIn('status', [1])->column('price', 'id'); $goods_order = $GoodsOrder->whereIn('area_id', $row->agent->area_id)->whereNotIn('status', [0,5])->column('pay_price', 'id'); $mission_order = $MissionOrder->whereIn('area_id', $row->agent->area_id)->whereNotIn('status', [0,5])->column('price', 'id'); $total_order = count($goods_order) + count($mission_order) + count($skill_order) + count($taxi_order); $turnover = array_sum($goods_order) + array_sum($mission_order) + array_sum($skill_order) + array_sum($taxi_order); return IResponse::success([ 'region' => $region, 'total_order' => $total_order, 'turnover' => $turnover, 'seller' => $seller, 'taxi_order' => $taxi_order, 'skill_order' => $skill_order, 'goods_order' => $goods_order, 'mission_order' => $mission_order, ]); } /** * @desc desc * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author weichuanbao<654745815@qq.com> * @date 2021/12/8 0008 */ public function stats() { $user = $this->model->with(['agent']) ->where('is_agent', 2) ->select(); $agent_num = count($user); $total_num = 0; $total_amount = 0; if ($user) { $area_ids = []; foreach ($user as $item) { if ($item->agent) { $area_ids[] = $item->agent->area_id; } } $GoodsOrder = new GoodsOrder(); $MissionOrder = new MissionOrder(); $SkillOrder = new SkillOrder(); $TaxiOrder = new TaxiOrder(); $goods_order = $GoodsOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [0,5])->column('pay_price', 'id'); $mission_order = $MissionOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [0,5])->column('price', 'id'); $skill_order = $SkillOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [1])->column('price', 'id'); $taxi_order = $TaxiOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [1])->column('price', 'id'); $total_amount += array_sum($goods_order) + array_sum($mission_order) + array_sum($skill_order) + array_sum($taxi_order); $total_num += count($goods_order) + count($mission_order) + count($skill_order) + count($taxi_order); } return IResponse::success([ 'agent_num' => $agent_num, 'total_num' => $total_num, 'total_amount' => $total_amount, ], '成功'); } }