Order.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\store\controller;
  15. use app\api\controller\Alipay;
  16. use EasyWeChat\Factory;
  17. use library\Controller;
  18. use think\Db;
  19. use app\api\controller\Area;
  20. use app\api\controller\Crontab;
  21. use function GuzzleHttp\Psr7\_caseless_remove;
  22. /**
  23. * 订单记录管理
  24. * Class Order
  25. * @package app\store\controller
  26. */
  27. class Order extends Controller
  28. {
  29. /**
  30. * 绑定数据表
  31. * @var string
  32. */
  33. protected $table = 'store_order';
  34. /**
  35. * 订单记录管理
  36. * @auth true
  37. * @menu true
  38. * @throws \think\Exception
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. * @throws \think\exception\PDOException
  43. */
  44. public function index()
  45. {
  46. $this->root = $this->request->root(true);
  47. $this->title = '订单记录管理';
  48. $array = $this->statistical_order_info();
  49. $this->assign('a', $array);
  50. $this->byWhere(1)->field('a.*,b.name,b.headimg')->order('a.id desc')->page();
  51. }
  52. protected function statistical_order_info()
  53. {
  54. $array = array();
  55. $array['all_order'] = $this->byWhere(2)->where('a.status', '>',0)->count();
  56. $array['all_price'] = $this->byWhere(2)->where('a.status', '>',0)->sum('a.price_total');
  57. $array['weixin_all_price'] = $this->byWhere(2)->where('a.status', '>',0)->where('a.pay_type', '1')->sum('a.price_total');
  58. $array['zfb_all_price'] = $this->byWhere(2)->where('a.status', '>',0)->where('a.pay_type', '2')->sum('a.price_total');
  59. return $array;
  60. }
  61. /**
  62. * 搜索条件
  63. * @return \library\helper\QueryHelper
  64. */
  65. protected function byWhere($type)
  66. {
  67. if ($type == 1) {
  68. $query = $this->_query($this->table);
  69. } elseif ($type == 2) {
  70. $query = Db::name($this->table);
  71. }
  72. $query = $query->alias('a')->join('store_member b', 'a.user_id=b.id');
  73. $query->where('a.status','>',0);
  74. if (isset($_GET['order_no']) && $_GET['order_no']) {
  75. $query->where('a.order_no', 'like','%'.$_GET['order_no'].'%');
  76. }
  77. if (isset($_GET['status']) && $_GET['status'] != '') {
  78. $query->where('a.status', $_GET['status']);
  79. }
  80. if (isset($_GET['pay_status']) && $_GET['pay_status'] != '') {
  81. $query->where('a.pay_status', $_GET['pay_status']);
  82. }
  83. if (isset($_GET['pay_type']) && $_GET['pay_type']) {
  84. $query->where('a.pay_type', $_GET['pay_type']);
  85. }
  86. if (isset($_GET['create_at']) && $_GET['create_at']) {
  87. $time = explode(' - ', $_GET['create_at']);
  88. $start_date_time = $time[0] . ' 00:00:00';
  89. $end_date_time = $time[1] . ' 23:59:59';
  90. $query->whereBetweenTime('a.create_at', $start_date_time, $end_date_time);
  91. }
  92. if (isset($_GET['pay_at']) && $_GET['pay_at']) {
  93. $time = explode(' - ', $_GET['pay_at']);
  94. $start_date_time = $time[0] . ' 00:00:00';
  95. $end_date_time = $time[1] . ' 23:59:59';
  96. $query->whereBetweenTime('a.pay_at', $start_date_time, $end_date_time);
  97. }
  98. if (isset($_GET['user_info']) && $_GET['user_info']) {
  99. $query->where('b.name|b.phone', '=', $_GET['user_info'] );
  100. }
  101. if (isset($_GET['worker_info']) && $_GET['worker_info']) {
  102. $worker_id = Db::name('store_engineer')->where('name|phone', '=', $_GET['worker_info'] )->value('id');
  103. $query->where('worker_id',$worker_id);
  104. }
  105. return $query;
  106. }
  107. /**
  108. * 订单列表处理
  109. * @param array $data
  110. * @throws \think\db\exception\DataNotFoundException
  111. * @throws \think\db\exception\ModelNotFoundException
  112. * @throws \think\exception\DbException
  113. */
  114. protected function _index_page_filter(array &$data)
  115. {
  116. $mids = array_unique(array_merge(array_column($data, 'user_id'), array_column($data, 'user_id')));
  117. $memberList = Db::name('StoreMember')->whereIn('id', $mids)->select();
  118. $wids = array_unique(array_merge(array_column($data, 'worker_id'), array_column($data, 'worker_id')));
  119. $workerList = Db::name('store_engineer')->whereIn('id', $wids)->select();
  120. foreach ($data as &$vo) {
  121. list($vo['member'], $vo['worker']) = [[],[]];
  122. foreach ($memberList as $member) if ($member['id'] === $vo['user_id']) {
  123. $vo['member'] = $member;
  124. }
  125. foreach ($workerList as $worker) if ($worker['id'] === $vo['worker_id']) {
  126. $vo['worker'] = $worker;
  127. }
  128. $vo['serve_title'] = Db::name('store_goods')->where('id',$vo['goods_id'])->value('title');
  129. }
  130. }
  131. /**
  132. * 表单数据处理
  133. * @param array $data
  134. * @throws \think\Exception
  135. * @throws \think\db\exception\DataNotFoundException
  136. * @throws \think\db\exception\ModelNotFoundException
  137. * @throws \think\exception\DbException
  138. * @throws \think\exception\PDOException
  139. */
  140. protected function _form_filter(array &$data)
  141. {
  142. if ($this->request->isGet()) {
  143. //接单人员信息
  144. if($data['worker_id']){
  145. $data['worker_info'] = Db::name('store_engineer')->field('name,phone')->where('id',$data['worker_id'])->find();
  146. }
  147. $this->data = $data;
  148. }
  149. }
  150. /**
  151. * 订单详情
  152. * @auth true
  153. * @throws \think\Exception
  154. * @throws \think\db\exception\DataNotFoundException
  155. * @throws \think\db\exception\ModelNotFoundException
  156. * @throws \think\exception\DbException
  157. * @throws \think\exception\PDOException
  158. */
  159. public function order_detail()
  160. {
  161. $this->_form($this->table);
  162. }
  163. }