CheckOrderController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. $motherId = $post['motherId'] ?? 0;
  38. $mother = ProductClass::getById($motherId, true);
  39. if (empty($mother) || $mother->mainId != $this->mainId) {
  40. util::fail('无法操作');
  41. }
  42. $motherName = $mother->name ?? '';
  43. $ghsItemInfo = $post['itemInfo'] ?? '';
  44. if (empty($ghsItemInfo)) {
  45. util::fail('请选择花材');
  46. }
  47. $itemList = json_decode($ghsItemInfo, true);
  48. if (empty($itemList)) {
  49. util::fail('没有花材');
  50. }
  51. $totalNum = 0;
  52. foreach ($itemList as $key => $item) {
  53. $currentNum = $item['bigNum'] ?? 0;
  54. $totalNum = bcadd($totalNum, $currentNum, 2);
  55. }
  56. if ($totalNum > $mother->stock) {
  57. util::fail($motherName . "不足{$totalNum}扎");
  58. }
  59. $motherBigNum = bcsub($mother->stock, $totalNum, 2);
  60. $motherBigNum = floatval($motherBigNum);
  61. $ids = array_column($itemList, 'productId');
  62. $infoList = ProductClass::getByIds($ids, null, 'id');
  63. if (!empty($infoList)) {
  64. foreach ($itemList as $itemKey => $itemVal) {
  65. $productId = $itemVal['productId'] ?? 0;
  66. $bigNum = $itemVal['bigNum'] ?? 0;
  67. $addBigNum = $infoList[$productId]['stock'] ?? 0;
  68. $newBigNum = bcadd($bigNum, $addBigNum, 2);
  69. $itemList[$itemKey]['bigNum'] = $newBigNum;
  70. }
  71. }
  72. $itemList[] = ['productId' => $motherId, 'bigNum' => $motherBigNum, 'smallNum' => 0];
  73. $newJson = json_encode($itemList);
  74. $post['itemInfo'] = $newJson;
  75. $post['sjId'] = $this->sjId;
  76. $post['shopId'] = $this->shopId;
  77. $post['adminId'] = $this->adminId;
  78. $post['mainId'] = $this->mainId;
  79. $this->saveOrder($post, false, false);
  80. }
  81. //盘点确认 lqh 2021.1.22
  82. public function actionCreateOrder()
  83. {
  84. $shopAdmin = $this->shopAdmin;
  85. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  86. util::fail('超管才能盘点');
  87. }
  88. $post = Yii::$app->request->post();
  89. $post['sjId'] = $this->sjId;
  90. $post['shopId'] = $this->shopId;
  91. $post['adminId'] = $this->adminId;
  92. $post['mainId'] = $this->mainId;
  93. $this->saveOrder($post, false, false);
  94. }
  95. //盘点存草稿 lqh 2021.1.22
  96. public function actionCreateDraft()
  97. {
  98. $shopAdmin = $this->shopAdmin;
  99. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  100. util::fail('超管才能操作');
  101. }
  102. $post = Yii::$app->request->post();
  103. $post['sjId'] = $this->sjId;
  104. $post['shopId'] = $this->shopId;
  105. $post['adminId'] = $this->adminId;
  106. //ssh 20210827
  107. util::fail('草稿功能取消');
  108. $this->saveOrder($post, true, false);
  109. }
  110. //编辑草稿 ,继续保存草稿
  111. public function actionUpdateDraft()
  112. {
  113. $shopAdmin = $this->shopAdmin;
  114. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  115. util::fail('超管才能操作');
  116. }
  117. $post = Yii::$app->request->post();
  118. $post['sjId'] = $this->sjId;
  119. $post['shopId'] = $this->shopId;
  120. $post['adminId'] = $this->adminId;
  121. $orderSn = $post['orderSn'] ?? '';
  122. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  123. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  124. util::fail("订单不存在");
  125. }
  126. $this->saveOrder($post, true, true);
  127. }
  128. //编辑草稿, 确认
  129. public function actionUpdateOrder()
  130. {
  131. $shopAdmin = $this->shopAdmin;
  132. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  133. util::fail('超管才能操作');
  134. }
  135. $post = Yii::$app->request->post();
  136. $post['sjId'] = $this->sjId;
  137. $post['shopId'] = $this->shopId;
  138. $post['mainId'] = $this->mainId;
  139. $post['adminId'] = $this->adminId;
  140. $orderSn = $post['orderSn'] ?? '';
  141. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  142. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  143. util::fail("订单不存在");
  144. }
  145. $this->saveOrder($post, false, true);
  146. }
  147. protected function saveOrder($post, $draft = false, $update = false)
  148. {
  149. $shopAdmin = $this->shopAdmin;
  150. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  151. util::fail('超管才能操作');
  152. }
  153. $ghsItemInfo = $post['itemInfo'] ?? '';
  154. if (empty($ghsItemInfo)) {
  155. util::fail('请选择花材');
  156. }
  157. //数据格式 [{productId:0,bigNum:1,smallNum:0}]
  158. $ghsItemInfo = json_decode($ghsItemInfo, true);
  159. if (!is_array($ghsItemInfo)) {
  160. util::fail('花材格式不正确');
  161. }
  162. //判断花材格式,是否属于当前门店
  163. ProductClass::valid($ghsItemInfo, $this->mainId);
  164. foreach ($ghsItemInfo as $key => $item) {
  165. //如果盘点数是99999则转为0
  166. if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
  167. $ghsItemInfo[$key]['bigNum'] = 0;
  168. }
  169. }
  170. $post['itemInfo'] = $ghsItemInfo;
  171. if ($update === true) {
  172. //编辑
  173. $order = CheckOrderClass::opOrder($post, $draft, $update);
  174. } else {
  175. $order = CheckOrderClass::opOrder($post, $draft, $update);
  176. }
  177. if ($order) {
  178. util::success($order);
  179. }
  180. util::fail();
  181. }
  182. }