StoreOrder.php 6.2 KB

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