CheckOrderController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. $staff = $this->shopAdmin;
  141. $post['staffName'] = $staff->name ?? '';
  142. $orderSn = $post['orderSn'] ?? '';
  143. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  144. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  145. util::fail("订单不存在");
  146. }
  147. $this->saveOrder($post, false, true);
  148. }
  149. protected function saveOrder($post, $draft = false, $update = false)
  150. {
  151. $shopAdmin = $this->shopAdmin;
  152. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  153. util::fail('超管才能操作');
  154. }
  155. $ghsItemInfo = $post['itemInfo'] ?? '';
  156. if (empty($ghsItemInfo)) {
  157. util::fail('请选择花材');
  158. }
  159. //数据格式 [{productId:0,bigNum:1,smallNum:0}]
  160. $ghsItemInfo = json_decode($ghsItemInfo, true);
  161. if (!is_array($ghsItemInfo)) {
  162. util::fail('花材格式不正确');
  163. }
  164. //判断花材格式,是否属于当前门店
  165. ProductClass::valid($ghsItemInfo, $this->mainId);
  166. foreach ($ghsItemInfo as $key => $item) {
  167. //如果盘点数是99999则转为0
  168. if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
  169. $ghsItemInfo[$key]['bigNum'] = 0;
  170. }
  171. }
  172. $post['itemInfo'] = $ghsItemInfo;
  173. if ($update === true) {
  174. $order = CheckOrderClass::opOrder($post, $draft, $update);
  175. } else {
  176. $order = CheckOrderClass::opOrder($post, $draft, $update);
  177. }
  178. if ($order) {
  179. util::success($order);
  180. }
  181. util::fail();
  182. }
  183. //清空库存 ssh 20231224
  184. public function actionClearStock()
  185. {
  186. ini_set('memory_limit', '2045M');
  187. set_time_limit(0);
  188. $staff = $this->shopAdmin;
  189. if ($staff->mobile != '15280215347' && $staff->founder == 1) {
  190. util::fail('不能清空');
  191. }
  192. $mainId = $this->mainId ?? 0;
  193. $adminId = $this->adminId ?? 0;
  194. $shopId = $this->shopId ?? 0;
  195. $sjId = $this->sjId ?? 0;
  196. $list = ProductClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'stock>' => 0,], null, '*', null, true);
  197. $productList = [];
  198. if (!empty($list)) {
  199. foreach ($list as $key => $info) {
  200. $id = $info->id ?? 0;
  201. if ($info->virtualStock == 0) {
  202. $productList[] = ['productId' => $id, 'bigNum' => 0, 'smallNum' => 0];
  203. }
  204. }
  205. }
  206. if (empty($productList)) {
  207. util::fail('没有花材需要清空');
  208. }
  209. $modifyData = [
  210. 'remark' => '清空库存',
  211. 'sjId' => $sjId,
  212. 'shopId' => $shopId,
  213. 'adminId' => $adminId,
  214. 'mainId' => $mainId,
  215. 'itemInfo' => $productList,
  216. ];
  217. $draft = false;
  218. $update = false;
  219. CheckOrderClass::opOrder($modifyData, $draft, $update);
  220. util::complete('清除成功');
  221. }
  222. }