StoreOrder.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace app\order\controller;
  3. use app\common\model\GoodsOrder;
  4. use library\Controller;
  5. use library\tools\Data;
  6. use think\Db;
  7. use app\common\model\GoodsOrderItem;
  8. /**
  9. * 商品订单
  10. * Class StoreOrder
  11. * @package app\order\controller
  12. */
  13. class StoreOrder extends Controller
  14. {
  15. protected $table = 'StoreOrder';
  16. /**
  17. * 订单列表
  18. * @auth true
  19. * @menu true
  20. * @throws \think\Exception
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. * @throws \think\exception\DbException
  24. * @throws \think\exception\PDOException
  25. */
  26. public function index()
  27. {
  28. $this->title = '订单管理';
  29. $this->order_status = [0=>'待支付',1=>'已支付[待发货]',2=>'已发货[待收货]',3=>'已收货[待评论]',4=>'已完成',9=>'已取消'];
  30. $this->pay_state = ['待支付','已支付'];
  31. $this->all_pay_type = all_pay_type();
  32. $query = $this->_query($this->table);
  33. $where = [];
  34. if($this->request->request('tel'))$where[]= ['u.phone','like','%'.$this->request->request('tel').'%'];
  35. if($this->request->request('user_name'))$where[]= ['u.name','like','%'.$this->request->request('user_name').'%'];
  36. if($this->request->request('order_no')) $where[]= ['o.order_no','like','%'.$this->request->request('order_no').'%'];
  37. if($this->request->request('pay_state',-1) > -1) $where[]= ['o.pay_state','=',$this->request->request('pay_state')];
  38. if($this->request->request('order_status',-1) > -1) $where[]= ['o.status','=',$this->request->request('order_status')];
  39. $query->alias('o')
  40. ->field('o.* , u.name ,u.phone as user_phone,u.headimg')
  41. ->join('store_member u',' o.user_id = u.id ','LEFT');
  42. if(!empty($where)) $query->where($where);
  43. $query ->order('o.id desc')->page();
  44. }
  45. /**
  46. * 订单列表处理
  47. * @param array $data
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. * @throws \think\exception\DbException
  51. */
  52. protected function _index_page_filter(array &$data)
  53. {
  54. foreach ($data as &$vo) {
  55. $vo['item_list'] = GoodsOrderItem::field('i.num,i.sell_price,g.name,i.goods_spec')
  56. ->alias('i')
  57. ->where(['i.order_id'=>$vo['id']])
  58. ->leftJoin('StoreGoods g','g.id = i.goods_id')
  59. ->select();
  60. }
  61. }
  62. /**
  63. * 修改快递
  64. * @auth true
  65. * @throws \think\Exception
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. * @throws \think\exception\PDOException
  70. */
  71. public function express()
  72. {
  73. if ($this->request->isGet()) {
  74. $where = ['is_deleted' => '0', 'status' => '1'];
  75. $this->expressList = Db::name('express_company')->where($where)->order('sort desc,id desc')->select();
  76. }
  77. $this->_form($this->table);
  78. }
  79. /**
  80. * 快递表单处理
  81. * @param array $vo
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. * @throws \think\exception\DbException
  85. */
  86. protected function _express_form_filter(&$vo)
  87. {
  88. if ($this->request->isPost()) {
  89. $order = Db::name($this->table)->where(['id' => $vo['id']])->find();
  90. if (empty($order)) $this->error('订单查询异常,请稍候再试!');
  91. $express = Db::name('express_company')->where(['express_code' => $vo['express_company_code']])->find();
  92. if (empty($express)) $this->error('发货快递公司异常,请重新选择快递公司!');
  93. $vo['express_company_title'] = $express['express_title'];
  94. $vo['express_send_at'] = empty($order['express_send_at']) ? date('Y-m-d H:i:s') : $order['express_send_at'];
  95. $vo['express_state'] = '1';
  96. $vo['status'] = '2';
  97. }
  98. }
  99. /**
  100. * 订单详情
  101. * @auth true
  102. * @menu true
  103. * @throws \think\Exception
  104. * @throws \think\db\exception\DataNotFoundException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. * @throws \think\exception\DbException
  107. * @throws \think\exception\PDOException
  108. */
  109. public function detail()
  110. {
  111. $this->title = '订单详情';
  112. $this->_form($this->table);
  113. }
  114. /**
  115. * 订单发货
  116. * @auth true
  117. * @menu true
  118. * @throws \think\Exception
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\ModelNotFoundException
  121. * @throws \think\exception\DbException
  122. * @throws \think\exception\PDOException
  123. */
  124. public function deliver()
  125. {
  126. $this->title = '发货';
  127. $this->express_company = Db::name('express_company')->field('id,express_title')->select();
  128. $this->_form($this->table,'deliver');
  129. }
  130. /**
  131. * 表单数据处理
  132. * @auth true
  133. * @menu true
  134. * @param array $data
  135. */
  136. protected function _form_filter(&$data)
  137. {
  138. if ($this->request->isGet() && $this->request->action() == 'detail'){
  139. $this->order_item = GoodsOrderItem::where(['o.order_id'=>$data['id']])
  140. ->alias('o')
  141. ->field('o.*,g.name,g.cover')
  142. ->leftJoin('StoreGoods g','g.id=o.goods_id')
  143. ->select()->toArray();
  144. $this->data = $data;
  145. }
  146. if ($this->request->isPost() && $this->request->action() == 'deliver') {
  147. $express_company = Db::name('express_company')->field('id,express_title')->find($data['express_company_id']);
  148. $data['express_company_title'] = $express_company['express_title'] ? $express_company['express_title'] : '';
  149. $data['express_send_at'] = date("Y-m-d H:i:s");
  150. $data['express_state'] = 1;
  151. }
  152. }
  153. }