ShopOrder.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace app\admin\controller\mall;
  3. use app\admin\logic\ShopOrderLogic;
  4. use app\common\controller\AdminController;
  5. use app\validate\admin\mall\shopOrder\EditStatus;
  6. use app\validate\admin\user\user\PhoneSet;
  7. use EasyAdmin\annotation\ControllerAnnotation;
  8. use EasyAdmin\annotation\NodeAnotation;
  9. use think\App;
  10. use think\exception\ValidateException;
  11. use think\facade\Db;
  12. use app\admin\model\dao\ShopOrder as ShopOrderDao;
  13. /**
  14. * @ControllerAnnotation(title="shop_order")
  15. */
  16. class ShopOrder extends AdminController
  17. {
  18. use \app\admin\traits\Curd;
  19. public function __construct(App $app)
  20. {
  21. parent::__construct($app);
  22. $this->model = new \app\common\model\ShopOrder();
  23. }
  24. /**
  25. * @NodeAnotation(title="列表")
  26. */
  27. public function index()
  28. {
  29. if ($this->request->isAjax()) {
  30. list($page, $limit, $where) = $this->buildTableParames();
  31. list($count, $list) = ShopOrderLogic::getList($page, $limit, $where);
  32. $data = [
  33. 'code' => 0,
  34. 'msg' => '',
  35. 'count' => $count,
  36. 'data' => $list,
  37. ];
  38. return json($data);
  39. }
  40. return $this->fetch();
  41. }
  42. /**
  43. * @NodeAnotation(title="修改备注")
  44. */
  45. public function editdesc($id)
  46. {
  47. if ($this->request->isPost()) {
  48. $post = $this->request->post();
  49. $row = $this->model->where('order_id', $id)->find();
  50. empty($row) && $this->error('取消失败');
  51. $row->order_remark = $post['error_text'];
  52. Db::startTrans();
  53. try {
  54. $row->save();
  55. Db::commit();
  56. } catch (\Exception $e) {
  57. Db::rollback();
  58. $this->error('设置失败' . $e->getMessage());
  59. }
  60. $this->success('设置成功');
  61. }
  62. $row = ShopOrderDao::getOrderById($id);
  63. $this->assign('info', $row);
  64. return $this->fetch();
  65. }
  66. /**
  67. * @NodeAnotation(title="修改订单状态")
  68. */
  69. public function editstatus($id)
  70. {
  71. if ($this->request->isPost()) {
  72. $post = $this->request->post();
  73. try {
  74. validate(EditStatus::class)->check($post);
  75. } catch (ValidateException $e) {
  76. $this->error($e->getMessage());
  77. }
  78. $result = ShopOrderLogic::editStatus($post['id'], $post['status']);
  79. if ($result !== true) {
  80. $this->error($result);
  81. }
  82. $this->success('修改订单状态成功');
  83. }
  84. $row = $this->model->where('order_id', $id)->find();
  85. $row['status_map'] = ShopOrderLogic::getStatusMap();
  86. $this->assign('info', $row);
  87. return $this->fetch('editstatus');
  88. }
  89. /**
  90. * @NodeAnotation(title="列表")
  91. */
  92. public function details($orderId)
  93. {
  94. $order = $this->model->where(['order_id' => $orderId])->with(['user', 'goods', 'shipping'])->find()->toArray();
  95. if ($order['status'] == 5 || $order['status'] == 6) {
  96. // 新的地址
  97. $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find();
  98. $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
  99. $order['shipping']['sp_id'] = 99999;
  100. $order['shipping']['sp_mobile'] = $newAddress_info['mobile'];
  101. $order['shipping']['sp_name'] = $newAddress_info['name'];
  102. $order['shipping']['sp_mergename'] = $newAddress_info['mergename'];
  103. }
  104. $this->assign('data', $order);
  105. return $this->fetch();
  106. }
  107. /**
  108. * 订单配送列表(疑似无效)
  109. * @NodeAnotation(title="列表")
  110. */
  111. public function delivery($orderId)
  112. {
  113. $express = Db::name('express')->field('id,name,code')->select()->toArray();
  114. $shipping = Db::name('shop_order_shipping')->where(['order_id' => $orderId])->findOrEmpty();
  115. $order = Db::name('shop_order')->where('order_id', $shipping['order_id'])->find();
  116. $this->assign('express', $express);
  117. if ($order['status'] == 5 || $order['status'] == 6) {
  118. // 新的地址
  119. $ygOrderInfo = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $order['order_sn']))->find();
  120. $newAddress_info = Db::name('user_address')->where('id', $ygOrderInfo['address_id'])->find();
  121. $shipping['sp_id'] = 99999;
  122. $shipping['sp_mobile'] = $newAddress_info['mobile'];
  123. $shipping['sp_name'] = $newAddress_info['name'];
  124. $shipping['sp_mergename'] = $newAddress_info['mergename'];
  125. }
  126. $this->assign('shipping', $shipping);
  127. return $this->fetch();
  128. }
  129. /**
  130. * 订单配送设置物流信息(疑似无效)
  131. * @NodeAnotation(title="列表")
  132. */
  133. public function deliverySave()
  134. {
  135. if ($this->request->isPost()) {
  136. $data = $this->request->post();
  137. if (empty($data['order_id'])) {
  138. return json(['code' => 0, 'msg' => '参数错误']);
  139. }
  140. if (empty($data['ship_number']) || empty($data['ship_name'])) {
  141. return json(['code' => 0, 'msg' => '物流信息不能为空']);
  142. }
  143. $ex = explode('_', $data['ship_name']);
  144. // 发货
  145. if ($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [5])->find()) {
  146. $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]);
  147. $yg_orderinfo = Db::name('yg_order')->where('order_sn', $order_info['order_sn'])->find();
  148. Db::name('yg_buy_record')->where('yg_id', $yg_orderinfo['id'])->where('status', 3)->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 4]);
  149. // 重新发货
  150. } elseif ($order_info = Db::name('shop_order')->where(['order_id' => $data['order_id']])->where('status', 'in', [6])->find()) {
  151. $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 6]);
  152. $yg_orderinfo = Db::name('yg_order')->where('order_sn', $order_info['order_sn'])->find();
  153. Db::name('yg_buy_record')->where('yg_id', $yg_orderinfo['id'])->where('status', 4)->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number']]);
  154. } else {
  155. $res = Db::name('shop_order')->where(['order_id' => $data['order_id']])->save(['ship_code' => $ex[0], 'ship_name' => $ex[1], 'ship_number' => $data['ship_number'], 'status' => 2]);
  156. }
  157. if (!$res) {
  158. return json(['code' => 0, 'msg' => '操作失败']);
  159. }
  160. return json(['code' => 1, 'msg' => '操作成功']);
  161. }
  162. }
  163. }