CheckOrderController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\order\classes\CheckOrderClass;
  4. use bizGhs\product\classes\ProductClass;
  5. use Yii;
  6. use common\components\util;
  7. class CheckOrderController extends BaseController
  8. {
  9. //订单列表 ssh 2021.1.14
  10. public function actionList()
  11. {
  12. $get = Yii::$app->request->get();
  13. $orderStatus = isset($get['status']) ? $get['status'] : '';
  14. $where = [];
  15. $where['shopId'] = $this->shopId;
  16. if (!empty($orderStatus)) {
  17. $where['status'] = $orderStatus;
  18. }
  19. $list = CheckOrderClass::getOrderList($where);
  20. util::success($list);
  21. }
  22. //订单详情 2021.1.22 linqh
  23. public function actionDetail()
  24. {
  25. $orderSn = Yii::$app->request->get('orderSn', '');
  26. $orderData = CheckOrderClass::getOrderDetail($orderSn, $this->shopId);
  27. util::success($orderData);
  28. }
  29. //盘点确认 linqh 2021.1.22
  30. public function actionCreateOrder()
  31. {
  32. $post = Yii::$app->request->post();
  33. $post['sjId'] = $this->sjId;
  34. $post['shopId'] = $this->shopId;
  35. $post['adminId'] = $this->adminId;
  36. //盘点是否有未处理的草稿,有的话先处理之前的草稿??
  37. //todo
  38. $this->saveOrder($post, false, false);
  39. }
  40. //盘点存草稿 linqh 2021.1.22
  41. public function actionCreateDraft()
  42. {
  43. $post = Yii::$app->request->post();
  44. $post['sjId'] = $this->sjId;
  45. $post['shopId'] = $this->shopId;
  46. $post['adminId'] = $this->adminId;
  47. $this->saveOrder($post, true, false);
  48. }
  49. //编辑草稿 ,继续保存草稿
  50. public function actionUpdateDraft()
  51. {
  52. $post = Yii::$app->request->post();
  53. $post['sjId'] = $this->sjId;
  54. $post['shopId'] = $this->shopId;
  55. $post['adminId'] = $this->adminId;
  56. $orderSn = $post['orderSn'] ?? '';
  57. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  58. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  59. util::fail("订单不存在");
  60. }
  61. $this->saveOrder($post, true, true);
  62. }
  63. //编辑草稿, 确认
  64. public function actionUpdateOrder()
  65. {
  66. $post = Yii::$app->request->post();
  67. $post['sjId'] = $this->sjId;
  68. $post['shopId'] = $this->shopId;
  69. $post['adminId'] = $this->adminId;
  70. $orderSn = $post['orderSn'] ?? '';
  71. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  72. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  73. util::fail("订单不存在");
  74. }
  75. $this->saveOrder($post, false, true);
  76. }
  77. protected function saveOrder($post, $draft = false, $update = false)
  78. {
  79. $ghsItemInfo = $post['itemInfo'] ?? '';
  80. if (empty($ghsItemInfo)) {
  81. util::fail('请选择花材');
  82. }
  83. $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,bigNum:1,smallNum:0}]
  84. if (!is_array($ghsItemInfo)) {
  85. util::fail('花材格式不正确');
  86. }
  87. //判断花材格式,是否属于当前门店
  88. ProductClass::valid($ghsItemInfo, $this->mainId);
  89. $post['itemInfo'] = $ghsItemInfo;
  90. if ($update === true) {
  91. //编辑
  92. $order = CheckOrderClass::opOrder($post, $draft, $update);
  93. } else {
  94. $order = CheckOrderClass::opOrder($post, $draft, $update);
  95. }
  96. if ($order) {
  97. util::success($order);
  98. } else {
  99. util::fail();
  100. }
  101. }
  102. }