CheckOrderController.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 20240720
  10. public function actionLoan()
  11. {
  12. $get = Yii::$app->request->get();
  13. $inId = $get['inId'] ?? 0;
  14. $outId = $get['outId'] ?? 0;
  15. $num = $get['num'] ?? 0;
  16. if ($num <= 0) {
  17. util::fail('借数量不足');
  18. }
  19. $shop = $this->shop;
  20. $staff = $this->shopAdmin;
  21. CheckOrderClass::loanStock($inId, $outId, $num, $shop, $staff);
  22. util::complete('操作成功');
  23. }
  24. //订单列表 ssh 2021.1.14
  25. public function actionList()
  26. {
  27. $get = Yii::$app->request->get();
  28. $orderStatus = isset($get['status']) ? $get['status'] : '';
  29. $where = [];
  30. $where['shopId'] = $this->shopId;
  31. if (!empty($orderStatus)) {
  32. $where['status'] = $orderStatus;
  33. }
  34. $list = CheckOrderClass::getOrderList($where);
  35. util::success($list);
  36. }
  37. //订单详情 2021.1.22 lqh
  38. public function actionDetail()
  39. {
  40. $orderSn = Yii::$app->request->get('orderSn', '');
  41. $orderData = CheckOrderClass::getOrderDetail($orderSn, $this->shopId);
  42. util::success($orderData);
  43. }
  44. //分配库存 ssh 20230720
  45. public function actionSendStock()
  46. {
  47. $shopAdmin = $this->shopAdmin;
  48. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  49. util::fail('超管才能盘点');
  50. }
  51. $post = Yii::$app->request->post();
  52. $motherId = $post['motherId'] ?? 0;
  53. $mother = ProductClass::getById($motherId, true);
  54. if (empty($mother) || $mother->mainId != $this->mainId) {
  55. util::fail('无法操作');
  56. }
  57. $motherName = $mother->name ?? '';
  58. $ghsItemInfo = $post['itemInfo'] ?? '';
  59. if (empty($ghsItemInfo)) {
  60. util::fail('请选择花材');
  61. }
  62. $itemList = json_decode($ghsItemInfo, true);
  63. if (empty($itemList)) {
  64. util::fail('没有花材');
  65. }
  66. $totalNum = 0;
  67. foreach ($itemList as $key => $item) {
  68. $currentNum = $item['bigNum'] ?? 0;
  69. $totalNum = bcadd($totalNum, $currentNum, 2);
  70. }
  71. if ($totalNum > $mother->stock) {
  72. util::fail($motherName . "不足{$totalNum}扎");
  73. }
  74. $motherBigNum = bcsub($mother->stock, $totalNum, 2);
  75. $motherBigNum = floatval($motherBigNum);
  76. $ids = array_column($itemList, 'productId');
  77. $infoList = ProductClass::getByIds($ids, null, 'id');
  78. if (!empty($infoList)) {
  79. foreach ($itemList as $itemKey => $itemVal) {
  80. $productId = $itemVal['productId'] ?? 0;
  81. $bigNum = $itemVal['bigNum'] ?? 0;
  82. $addBigNum = $infoList[$productId]['stock'] ?? 0;
  83. $newBigNum = bcadd($bigNum, $addBigNum, 2);
  84. $itemList[$itemKey]['bigNum'] = $newBigNum;
  85. }
  86. }
  87. $itemList[] = ['productId' => $motherId, 'bigNum' => $motherBigNum, 'smallNum' => 0];
  88. $newJson = json_encode($itemList);
  89. $post['itemInfo'] = $newJson;
  90. $post['sjId'] = $this->sjId;
  91. $post['shopId'] = $this->shopId;
  92. $post['adminId'] = $this->adminId;
  93. $post['mainId'] = $this->mainId;
  94. $this->saveOrder($post, false, false);
  95. }
  96. //盘点确认 lqh 2021.1.22
  97. public function actionCreateOrder()
  98. {
  99. $shopAdmin = $this->shopAdmin;
  100. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  101. util::fail('超管才能盘点');
  102. }
  103. $post = Yii::$app->request->post();
  104. $post['sjId'] = $this->sjId;
  105. $post['shopId'] = $this->shopId;
  106. $post['adminId'] = $this->adminId;
  107. $post['mainId'] = $this->mainId;
  108. $staff = $this->shopAdmin;
  109. $post['staffName'] = $staff->name ?? '';
  110. $this->saveOrder($post, false, false);
  111. }
  112. //盘点存草稿 lqh 2021.1.22
  113. public function actionCreateDraft()
  114. {
  115. $shopAdmin = $this->shopAdmin;
  116. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  117. util::fail('超管才能操作');
  118. }
  119. $post = Yii::$app->request->post();
  120. $post['sjId'] = $this->sjId;
  121. $post['shopId'] = $this->shopId;
  122. $post['adminId'] = $this->adminId;
  123. //ssh 20210827
  124. util::fail('草稿功能取消');
  125. $this->saveOrder($post, true, false);
  126. }
  127. //编辑草稿 ,继续保存草稿
  128. public function actionUpdateDraft()
  129. {
  130. $shopAdmin = $this->shopAdmin;
  131. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  132. util::fail('超管才能操作');
  133. }
  134. $post = Yii::$app->request->post();
  135. $post['sjId'] = $this->sjId;
  136. $post['shopId'] = $this->shopId;
  137. $post['adminId'] = $this->adminId;
  138. $staff = $this->shopAdmin;
  139. $post['staffName'] = $staff->name ?? '';
  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, true, true);
  146. }
  147. //编辑草稿, 确认
  148. public function actionUpdateOrder()
  149. {
  150. $shopAdmin = $this->shopAdmin;
  151. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  152. util::fail('超管才能操作');
  153. }
  154. $post = Yii::$app->request->post();
  155. $post['sjId'] = $this->sjId;
  156. $post['shopId'] = $this->shopId;
  157. $post['mainId'] = $this->mainId;
  158. $post['adminId'] = $this->adminId;
  159. $staff = $this->shopAdmin;
  160. $post['staffName'] = $staff->name ?? '';
  161. $orderSn = $post['orderSn'] ?? '';
  162. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  163. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  164. util::fail("订单不存在");
  165. }
  166. $this->saveOrder($post, false, true);
  167. }
  168. protected function saveOrder($post, $draft = false, $update = false)
  169. {
  170. $shopAdmin = $this->shopAdmin;
  171. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  172. util::fail('超管才能操作');
  173. }
  174. $ghsItemInfo = $post['itemInfo'] ?? '';
  175. if (empty($ghsItemInfo)) {
  176. util::fail('请选择花材');
  177. }
  178. //数据格式 [{productId:0,bigNum:1,smallNum:0}]
  179. $ghsItemInfo = json_decode($ghsItemInfo, true);
  180. if (!is_array($ghsItemInfo)) {
  181. util::fail('花材格式不正确');
  182. }
  183. //判断花材格式,是否属于当前门店
  184. ProductClass::valid($ghsItemInfo, $this->mainId);
  185. foreach ($ghsItemInfo as $key => $item) {
  186. //如果盘点数是99999则转为0
  187. if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
  188. $ghsItemInfo[$key]['bigNum'] = 0;
  189. }
  190. }
  191. $post['itemInfo'] = $ghsItemInfo;
  192. if ($update === true) {
  193. $order = CheckOrderClass::opOrder($post, $draft, $update);
  194. } else {
  195. $order = CheckOrderClass::opOrder($post, $draft, $update);
  196. }
  197. if ($order) {
  198. util::success($order);
  199. }
  200. util::fail();
  201. }
  202. //清空库存 ssh 20231224
  203. public function actionClearStock()
  204. {
  205. ini_set('memory_limit', '2045M');
  206. set_time_limit(0);
  207. $staff = $this->shopAdmin;
  208. $could = $staff->mobile == '15280215347' ? true : false;
  209. $mainId = $this->mainId;
  210. if (getenv('YII_ENV') == 'production') {
  211. //源花汇小周可以清花材
  212. if ($mainId == 10536) {
  213. if (in_array($this->adminId, [11648])) {
  214. $could = true;
  215. }
  216. }
  217. } else {
  218. if ($mainId == 812) {
  219. if (in_array($this->adminId, [1091])) {
  220. $could = true;
  221. }
  222. }
  223. }
  224. if ($could == false) {
  225. util::fail('无法清空库存');
  226. }
  227. $mainId = $this->mainId ?? 0;
  228. $adminId = $this->adminId ?? 0;
  229. $shopId = $this->shopId ?? 0;
  230. $sjId = $this->sjId ?? 0;
  231. $list = ProductClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'stock>' => 0,], null, '*', null, true);
  232. $productList = [];
  233. if (!empty($list)) {
  234. foreach ($list as $key => $info) {
  235. $id = $info->id ?? 0;
  236. if ($info->virtualStock == 0) {
  237. $productList[] = ['productId' => $id, 'bigNum' => 0, 'smallNum' => 0];
  238. }
  239. }
  240. }
  241. if (empty($productList)) {
  242. util::fail('没有花材需要清空');
  243. }
  244. $modifyData = [
  245. 'remark' => '清空库存',
  246. 'sjId' => $sjId,
  247. 'shopId' => $shopId,
  248. 'adminId' => $adminId,
  249. 'mainId' => $mainId,
  250. 'itemInfo' => $productList,
  251. ];
  252. $draft = false;
  253. $update = false;
  254. CheckOrderClass::opOrder($modifyData, $draft, $update);
  255. util::complete('清除成功');
  256. }
  257. }