CustomOrder.php 6.2 KB

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