WashOrder.php 6.7 KB

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