CheckOrderController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. $staff = $this->shopAdmin;
  94. $post['staffName'] = $staff->name ?? '';
  95. $this->saveOrder($post, false, false);
  96. }
  97. //盘点存草稿 lqh 2021.1.22
  98. public function actionCreateDraft()
  99. {
  100. $shopAdmin = $this->shopAdmin;
  101. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  102. util::fail('超管才能操作');
  103. }
  104. $post = Yii::$app->request->post();
  105. $post['sjId'] = $this->sjId;
  106. $post['shopId'] = $this->shopId;
  107. $post['adminId'] = $this->adminId;
  108. //ssh 20210827
  109. util::fail('草稿功能取消');
  110. $this->saveOrder($post, true, false);
  111. }
  112. //编辑草稿 ,继续保存草稿
  113. public function actionUpdateDraft()
  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. $staff = $this->shopAdmin;
  124. $post['staffName'] = $staff->name ?? '';
  125. $orderSn = $post['orderSn'] ?? '';
  126. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  127. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  128. util::fail("订单不存在");
  129. }
  130. $this->saveOrder($post, true, true);
  131. }
  132. //编辑草稿, 确认
  133. public function actionUpdateOrder()
  134. {
  135. $shopAdmin = $this->shopAdmin;
  136. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  137. util::fail('超管才能操作');
  138. }
  139. $post = Yii::$app->request->post();
  140. $post['sjId'] = $this->sjId;
  141. $post['shopId'] = $this->shopId;
  142. $post['mainId'] = $this->mainId;
  143. $post['adminId'] = $this->adminId;
  144. $staff = $this->shopAdmin;
  145. $post['staffName'] = $staff->name ?? '';
  146. $orderSn = $post['orderSn'] ?? '';
  147. $orderData = CheckOrderClass::orderExist($orderSn, $this->shopId);
  148. if ($orderData['status'] != CheckOrderClass::STATUS_DRAFT) {
  149. util::fail("订单不存在");
  150. }
  151. $this->saveOrder($post, false, true);
  152. }
  153. protected function saveOrder($post, $draft = false, $update = false)
  154. {
  155. $shopAdmin = $this->shopAdmin;
  156. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  157. util::fail('超管才能操作');
  158. }
  159. //限制花大苪文员修改库存
  160. if (in_array($this->mainId, [8164])) {
  161. if (in_array($this->adminId, [10771, 26263, 4])) {
  162. util::fail('不能修改哦');
  163. }
  164. }
  165. $ghsItemInfo = $post['itemInfo'] ?? '';
  166. if (empty($ghsItemInfo)) {
  167. util::fail('请选择花材');
  168. }
  169. //数据格式 [{productId:0,bigNum:1,smallNum:0}]
  170. $ghsItemInfo = json_decode($ghsItemInfo, true);
  171. if (!is_array($ghsItemInfo)) {
  172. util::fail('花材格式不正确');
  173. }
  174. //判断花材格式,是否属于当前门店
  175. ProductClass::valid($ghsItemInfo, $this->mainId);
  176. foreach ($ghsItemInfo as $key => $item) {
  177. //如果盘点数是99999则转为0
  178. if (isset($item['bigNum']) && $item['bigNum'] == 99999) {
  179. $ghsItemInfo[$key]['bigNum'] = 0;
  180. }
  181. }
  182. $post['itemInfo'] = $ghsItemInfo;
  183. if ($update === true) {
  184. $order = CheckOrderClass::opOrder($post, $draft, $update);
  185. } else {
  186. $order = CheckOrderClass::opOrder($post, $draft, $update);
  187. }
  188. if ($order) {
  189. util::success($order);
  190. }
  191. util::fail();
  192. }
  193. //清空库存 ssh 20231224
  194. public function actionClearStock()
  195. {
  196. ini_set('memory_limit', '2045M');
  197. set_time_limit(0);
  198. $staff = $this->shopAdmin;
  199. $could = $staff->mobile == '15280215347' ? true : false;
  200. $mainId = $this->mainId;
  201. if (getenv('YII_ENV') == 'production') {
  202. //源花汇小周可以清花材
  203. if ($mainId == 10536) {
  204. if (in_array($this->adminId, [11648])) {
  205. $could = true;
  206. }
  207. }
  208. //花瀚鲜花供应链
  209. if ($mainId == 14499) {
  210. if (in_array($this->adminId, [11961, 11976])) {
  211. $could = true;
  212. }
  213. }
  214. //徐记花卉
  215. if ($mainId == 10866) {
  216. if (in_array($this->adminId, [11964])) {
  217. $could = true;
  218. }
  219. }
  220. } else {
  221. if ($mainId == 812) {
  222. if (in_array($this->adminId, [1091])) {
  223. $could = true;
  224. }
  225. }
  226. }
  227. if ($could == false) {
  228. util::fail('无法清空库存');
  229. }
  230. $mainId = $this->mainId ?? 0;
  231. $adminId = $this->adminId ?? 0;
  232. $shopId = $this->shopId ?? 0;
  233. $sjId = $this->sjId ?? 0;
  234. $list = ProductClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'stock>' => 0,], null, '*', null, true);
  235. $productList = [];
  236. if (!empty($list)) {
  237. foreach ($list as $key => $info) {
  238. $id = $info->id ?? 0;
  239. if ($info->virtualStock == 0) {
  240. $productList[] = ['productId' => $id, 'bigNum' => 0, 'smallNum' => 0];
  241. }
  242. }
  243. }
  244. if (empty($productList)) {
  245. util::fail('没有花材需要清空');
  246. }
  247. $modifyData = [
  248. 'remark' => '清空库存',
  249. 'sjId' => $sjId,
  250. 'shopId' => $shopId,
  251. 'adminId' => $adminId,
  252. 'mainId' => $mainId,
  253. 'itemInfo' => $productList,
  254. ];
  255. $draft = false;
  256. $update = false;
  257. CheckOrderClass::opOrder($modifyData, $draft, $update);
  258. util::complete('清除成功');
  259. }
  260. }