Area.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * User: Qinii
  4. * Date: 2020-06-05
  5. * Time: 09:41
  6. */
  7. namespace app\controller\api\area;
  8. use app\common\dao\store\order\StoreOrderDao;
  9. use app\Request;
  10. use think\App;
  11. use app\common\repositories\article\ArticleRepository as repository;
  12. use crmeb\basic\BaseController;
  13. use think\facade\Db;
  14. class Area extends BaseController
  15. {
  16. /**
  17. * @var repository
  18. */
  19. protected $repository;
  20. /**
  21. * StoreBrand constructor.
  22. * @param App $app
  23. * @param repository $repository
  24. */
  25. public function __construct(App $app)
  26. {
  27. parent::__construct($app);
  28. }
  29. /**
  30. * 区域详情
  31. * @return mixed
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function detail()
  37. {
  38. $uid = $this->request->uid();
  39. $data = [];
  40. $user = Db::name('user')->where('uid', $uid)->find();
  41. $month = $this->request->param('month', '') ?: date('Y-m');
  42. $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
  43. $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
  44. if (!in_array($user['user_group'], [5, 6]))
  45. return app('json')->fail('您不是区域代理');
  46. $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $user['manage_address'])->cache('code:' . $user['manage_address'], 7200)->column('name');
  47. $data['area_name'] = join($data['area_name']);
  48. $query1 = Db::name('store_order')
  49. ->where('uid', $uid)
  50. ->whereBetween('create_time', [$startMonth, $endMonth])
  51. ->where('paid', 1);
  52. $query2 = Db::name('store_order')
  53. ->where('uid', $uid)
  54. ->whereBetween('create_time', [$startMonth, $endMonth])
  55. ->where('paid', 1)
  56. ->where('mer_id', systemConfig('mer_365'));
  57. $query3 = Db::name('store_order')
  58. ->where('uid', $uid)
  59. ->whereBetween('create_time', [$startMonth, $endMonth])
  60. ->where('paid', 1)
  61. ->where('is_dacang', 1);
  62. $query4 = Db::name('store_order')
  63. ->where('uid', $uid)
  64. ->whereBetween('create_time', [$startMonth, $endMonth])
  65. ->where('paid', 1)
  66. ->where('is_dacang', 2);
  67. $query1_1 = clone $query1;
  68. $query2_1 = clone $query2;
  69. $query3_1 = clone $query3;
  70. $query4_1 = clone $query4;
  71. $data['success_order']['amount'] = $query1->sum('pay_price');
  72. $data['success_order']['shop_amount'] = $query2->sum('pay_price');
  73. $data['success_order']['gong_amount'] = $query3->sum('pay_price');
  74. $data['success_order']['self_amount'] = $query4->sum('pay_price');
  75. $data['clear_order']['amount'] = $query1_1->where('is_settlement', 1)->sum('pay_price');
  76. $data['clear_order']['shop_amount'] = $query2_1->where('is_settlement', 1)->sum('pay_price');
  77. $data['clear_order']['gong_amount'] = $query3_1->where('is_settlement', 1)->sum('pay_price');
  78. $data['clear_order']['self_amount'] = $query4_1->where('is_settlement', 1)->sum('pay_price');
  79. return app('json')->success($data);
  80. }
  81. /*收益*/
  82. public function recommend_agency()
  83. {
  84. $uid = $this->request->uid();
  85. $month = $this->request->param('month', '') ?: date('Y-m');
  86. $agency_list = Db::name('user')
  87. ->field('phone,user_group,up_agency_time,manage_address')
  88. ->whereIn('user_group', [5, 6])
  89. ->whereIn('spread_uid', $uid)
  90. ->select()
  91. ->toArray();
  92. foreach ($agency_list as &$agency){
  93. $agency['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $agency['manage_address'])->cache('code:' . $agency['manage_address'], 7200)->column('name');
  94. $agency['area_name'] = join($agency['area_name']);
  95. $agency['area_award_money'] =Db::name('user_bill')
  96. ->where('uid',$uid)
  97. ->where('status',1)
  98. ->where('month',$month)
  99. ->whereIn('commission_type',[12])
  100. ->sum('number');
  101. $agency['area_award_money_sum'] =Db::name('user_bill')
  102. ->where('uid',$uid)
  103. ->where('status',1)
  104. ->where('month',$month)
  105. ->whereIn('commission_type',[7,12,19])
  106. ->sum('number');
  107. $agency['invite_agency_money'] =Db::name('user_bill')
  108. ->where('uid',$uid)
  109. ->where('status',1)
  110. ->where('month',$month)
  111. ->whereIn('commission_type',[14])
  112. ->sum('number');
  113. }
  114. return app('json')->success($agency_list);
  115. }
  116. }