CheckOrderController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace ghs\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 lqh
  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. //分配库存 ssh 20230720
  30. public function actionSendStock()
  31. {
  32. $shopAdmin = $this->shopAdmin;
  33. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  34. util::fail('超管才能盘点');
  35. }
  36. $post = Yii::$app->request->post();
  37. $post['sjId'] = $this->sjId;
  38. $post['shopId'] = $this->shopId;
  39. $post['adminId'] = $this->adminId;
  40. $post['mainId'] = $this->mainId;
  41. $this->saveOrder($post, false, false);
  42. }
  43. //盘点确认 lqh 2021.1.22
  44. public function actionCreateOrder()
  45. {
  46. $shopAdmin = $this->shopAdmin;
  47. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  48. util::fail('超管才能盘点');
  49. }
  50. $post = Yii::$app->request->post();
  51. $post['sjId'] = $this->sjId;
  52. $post['shopId'] = $this->shopId;
  53. $post['adminId'] = $this->adminId;
  54. $post['mainId'] = $this->mainId;
  55. $this->saveOrder($post, false, false);
  56. }
  57. //盘点存草稿 lqh 2021.1.22
  58. public function actionCreateDraft()
  59. {
  60. $shopAdmin = $this->shopAdmin;
  61. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  62. util::fail('超管才能操作');
  63. }
  64. $post = Yii::$app->request->post();
  65. $post['sjId'] = $this->sjId;
  66. $post['shopId'] = $this->shopId;
  67. $post['adminId'] = $this->adminId;
  68. //ssh 20210827
  69. util::fail('草稿功能取消');
  70. $this->saveOrder($post, true, false);
  71. }
  72. //编辑草稿 ,继续保存草稿
  73. public function actionUpdateDraft()
  74. {
  75. $shopAdmin = $this->shopAdmin;
  76. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  77. util::fail('超管才能操作');
  78. }
  79. $post = Yii::$app->request->post();
  80. $post['sjId'] = $this->sjId;
  81. $post['shopId'] = $this->shopId;
  82. $post['adminId'] = $this->adminId;
  83. $orderSn = $post['orderSn'] ?? '';
  84. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  85. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  86. util::fail("订单不存在");
  87. }
  88. $this->saveOrder($post, true, true);
  89. }
  90. //编辑草稿, 确认
  91. public function actionUpdateOrder()
  92. {
  93. $shopAdmin = $this->shopAdmin;
  94. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  95. util::fail('超管才能操作');
  96. }
  97. $post = Yii::$app->request->post();
  98. $post['sjId'] = $this->sjId;
  99. $post['shopId'] = $this->shopId;
  100. $post['mainId'] = $this->mainId;
  101. $post['adminId'] = $this->adminId;
  102. $orderSn = $post['orderSn'] ?? '';
  103. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  104. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  105. util::fail("订单不存在");
  106. }
  107. $this->saveOrder($post, false, true);
  108. }
  109. protected function saveOrder($post, $draft = false, $update = false)
  110. {
  111. $shopAdmin = $this->shopAdmin;
  112. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  113. util::fail('超管才能操作');
  114. }
  115. $ghsItemInfo = $post['itemInfo'] ?? '';
  116. if (empty($ghsItemInfo)) {
  117. util::fail('请选择花材');
  118. }
  119. //数据格式 [{productId:0,bigNum:1,smallNum:0}]
  120. $ghsItemInfo = json_decode($ghsItemInfo, true);
  121. if (!is_array($ghsItemInfo)) {
  122. util::fail('花材格式不正确');
  123. }
  124. //判断花材格式,是否属于当前门店
  125. ProductClass::valid($ghsItemInfo, $this->mainId);
  126. foreach ($ghsItemInfo as $key => $item) {
  127. //如果盘点数是99999则转为0
  128. if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
  129. $ghsItemInfo[$key]['bigNum'] = 0;
  130. }
  131. }
  132. $post['itemInfo'] = $ghsItemInfo;
  133. if ($update === true) {
  134. //编辑
  135. $order = CheckOrderClass::opOrder($post, $draft, $update);
  136. } else {
  137. $order = CheckOrderClass::opOrder($post, $draft, $update);
  138. }
  139. if ($order) {
  140. util::success($order);
  141. }
  142. util::fail();
  143. }
  144. }