StoreOrder.php 7.2 KB

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