Agent.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\admin\controller\agent;
  3. use app\common\controller\BaseController;
  4. use app\common\model\China;
  5. use app\common\model\GoodsOrder;
  6. use app\common\model\MissionOrder;
  7. use app\common\model\RescueOrder;
  8. use app\common\model\Seller;
  9. use app\common\model\SkillOrder;
  10. use app\common\model\TaxiOrder;
  11. use app\http\IResponse;
  12. use think\App;
  13. use think\Request;
  14. class Agent extends BaseController
  15. {
  16. protected $model;
  17. public function __construct(App $app = null)
  18. {
  19. parent::__construct($app);
  20. $this->model = new \app\admin\model\agent\Agent();
  21. }
  22. /**
  23. * @desc desc
  24. * @return mixed
  25. * @throws \think\exception\DbException
  26. * @author weichuanbao<654745815@qq.com>
  27. * @date 2021/12/8 0008
  28. */
  29. public function index()
  30. {
  31. $params = input();
  32. $params['card_id'] = input('card_id/s', '');
  33. $params['nickname'] = input('nickname/s', '');
  34. $where['is_agent'] = 2;
  35. if ($params['card_id']) {
  36. $where['card_id'] = ['like', '%' . $params['card_id'] . '%'];
  37. }
  38. if ($params['nickname']) {
  39. $where['nickname'] = ['like', '%' . $params['nickname'] . '%'];
  40. }
  41. $list = $this->model->where($where)
  42. ->order(['id' => 'desc'])
  43. ->paginate(input('limit', 10),false);
  44. return IResponse::paginate($list);
  45. }
  46. /**
  47. * @desc 代理商个人数据统计
  48. * @param $ids
  49. * @return mixed
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. * @author weichuanbao<654745815@qq.com>
  54. * @date 2021/12/8 0008
  55. */
  56. public function personal($ids)
  57. {
  58. $row = $this->model->with(['agent'])->where('is_agent', 2)->find($ids);
  59. if (!$row) {
  60. IResponse::failure('记录不存在');
  61. }
  62. $China = new China();
  63. $Seller = new Seller();
  64. $TaxiOrder = new TaxiOrder();
  65. $GoodsOrder = new GoodsOrder();
  66. $SkillOrder = new SkillOrder();
  67. $MissionOrder = new MissionOrder();
  68. // 所属区域
  69. $region = $China->getValue($row->agent->area_id, 'name');
  70. // 商户数量
  71. $seller = $Seller->where(['area_id' => $row->agent->area_id])->count();
  72. // 订单数据
  73. // 摩的订单,技能订单,商品订单,配送订单
  74. $taxi_order = $TaxiOrder->whereIn('area_id', $row->agent->area_id)->whereNotIn('status', [1])->column('price', 'id');
  75. $skill_order = $SkillOrder->whereIn('area_id', $row->agent->area_id)->whereNotIn('status', [1])->column('price', 'id');
  76. $goods_order = $GoodsOrder->whereIn('area_id', $row->agent->area_id)->whereNotIn('status', [0,5])->column('pay_price', 'id');
  77. $mission_order = $MissionOrder->whereIn('area_id', $row->agent->area_id)->whereNotIn('status', [0,5])->column('price', 'id');
  78. $total_order = count($goods_order) + count($mission_order) + count($skill_order) + count($taxi_order);
  79. $turnover = array_sum($goods_order) + array_sum($mission_order) + array_sum($skill_order) + array_sum($taxi_order);
  80. return IResponse::success([
  81. 'region' => $region,
  82. 'total_order' => $total_order,
  83. 'turnover' => $turnover,
  84. 'seller' => $seller,
  85. 'taxi_order' => $taxi_order,
  86. 'skill_order' => $skill_order,
  87. 'goods_order' => $goods_order,
  88. 'mission_order' => $mission_order,
  89. ]);
  90. }
  91. /**
  92. * @desc desc
  93. * @return mixed
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. * @author weichuanbao<654745815@qq.com>
  98. * @date 2021/12/8 0008
  99. */
  100. public function stats()
  101. {
  102. $user = $this->model->with(['agent'])
  103. ->where('is_agent', 2)
  104. ->select();
  105. $agent_num = count($user);
  106. $total_num = 0;
  107. $total_amount = 0;
  108. if ($user) {
  109. $area_ids = [];
  110. foreach ($user as $item) {
  111. if ($item->agent) {
  112. $area_ids[] = $item->agent->area_id;
  113. }
  114. }
  115. $GoodsOrder = new GoodsOrder();
  116. $MissionOrder = new MissionOrder();
  117. $SkillOrder = new SkillOrder();
  118. $TaxiOrder = new TaxiOrder();
  119. $goods_order = $GoodsOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [0,5])->column('pay_price', 'id');
  120. $mission_order = $MissionOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [0,5])->column('price', 'id');
  121. $skill_order = $SkillOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [1])->column('price', 'id');
  122. $taxi_order = $TaxiOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [1])->column('price', 'id');
  123. $total_amount += array_sum($goods_order) + array_sum($mission_order) + array_sum($skill_order) + array_sum($taxi_order);
  124. $total_num += count($goods_order) + count($mission_order) + count($skill_order) + count($taxi_order);
  125. }
  126. return IResponse::success([
  127. 'agent_num' => $agent_num,
  128. 'total_num' => $total_num,
  129. 'total_amount' => $total_amount,
  130. ], '成功');
  131. }
  132. }