| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace app\admin\controller\agent;
- use app\common\controller\BaseController;
- use app\common\model\China;
- use app\common\model\GoodsOrder;
- use app\common\model\MissionOrder;
- use app\common\model\RescueOrder;
- use app\common\model\Seller;
- use app\common\model\SkillOrder;
- use app\common\model\TaxiOrder;
- use app\http\IResponse;
- use think\App;
- use think\Request;
- class Agent extends BaseController
- {
- protected $model;
- public function __construct(App $app = null)
- {
- parent::__construct($app);
- $this->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,
- ], '成功');
- }
- }
|