StockOutController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\merchant\classes\ShopClass;
  4. use bizGhs\order\classes\StockOutOrderClass;
  5. use bizGhs\product\classes\ProductClass;
  6. use common\components\util;
  7. use Yii;
  8. //出库 lqh 2021.1.23
  9. class StockOutController extends BaseController
  10. {
  11. //全部出库 ssh 20220906
  12. public function actionAllOut()
  13. {
  14. $shop = $this->shop;
  15. if ($shop->default == 1) {
  16. util::fail('首店库存不能全部出库');
  17. }
  18. util::fail('功能开发中');
  19. util::complete();
  20. }
  21. //出库列表 lqh 2021.1.23
  22. public function actionList()
  23. {
  24. $get = Yii::$app->request->get();
  25. $orderStatus = isset($get['status']) ? $get['status'] : '';
  26. $where = [];
  27. $where['outShopId'] = $this->shopId;
  28. if (!empty($orderStatus)) {
  29. $where['status'] = $orderStatus;
  30. }
  31. $list = StockOutOrderClass::getOrderList($where);
  32. util::success($list);
  33. }
  34. //新增出库 lqh 2021.1.23
  35. public function actionCreateOrder()
  36. {
  37. $post = Yii::$app->request->post();
  38. $post['sjId'] = $this->sjId;
  39. $post['outShopId'] = $this->shopId;
  40. $post['outMainId'] = $this->mainId;
  41. $post['adminId'] = $this->adminId;
  42. $inShopId = $post['inShopId'] ?? 0;
  43. $now = date('Y-m-d H:i:s');
  44. $date = $post['date'] ?? $now;
  45. $post['outTime'] = $date;
  46. $action = $post['action'] ?? 'wait'; //confirm(直接出库) wait(待出库中)
  47. $post['action'] = $action;
  48. $post['inShopId'] = $inShopId;
  49. $check = StockOutOrderClass::getByCondition(['outShopId' => $this->shopId, 'inShopId' => $inShopId, 'status' => StockOutOrderClass::STATUS_WAIT]);
  50. if ($check) {
  51. util::fail('还有待出库的订单');
  52. }
  53. $ghsItemInfo = $post['itemInfo'] ?? '';
  54. if (empty($ghsItemInfo)) {
  55. util::fail('请选择花材');
  56. }
  57. $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,bigNum:1,smallNum:0}]
  58. if (!is_array($ghsItemInfo)) {
  59. util::fail('花材格式不正确');
  60. }
  61. $connection = Yii::$app->db;
  62. $transaction = $connection->beginTransaction();
  63. try {
  64. //入库门店有效性判断
  65. if ($this->shopId == $inShopId) {
  66. util::fail('不能出库给当前门店');
  67. }
  68. $inShop = ShopClass::getById($inShopId);
  69. if (empty($inShop)) {
  70. util::fail('没有找到门店');
  71. }
  72. ShopClass::valid($inShop, $this->sjId);
  73. $post['inMainId'] = $inShop['mainId'] ?? 0;
  74. ProductClass::valid($ghsItemInfo, $this->mainId);
  75. //判断花材里的信息
  76. foreach ($ghsItemInfo as $v) {
  77. $bigNum = $v['bigNum'] ?? 0;
  78. $smallNum = $v['smallNum'] ?? 0;
  79. if ($bigNum <= 0 && $smallNum <= 0) {
  80. util::fail('花材数量不能为0');
  81. }
  82. }
  83. $post['itemInfo'] = $ghsItemInfo;
  84. $order = StockOutOrderClass::addOrder($post);
  85. if ($order) {
  86. $transaction->commit();
  87. util::success($order);
  88. }
  89. util::fail('出库失败');
  90. } catch (\Exception $exception) {
  91. $transaction->rollBack();
  92. util::fail('出库失败');
  93. }
  94. }
  95. //出库详情 lqh 2021.1.23
  96. public function actionDetail()
  97. {
  98. $orderSn = Yii::$app->request->get('orderSn', '');
  99. $orderData = StockOutOrderClass::getOrderDetail($orderSn, $this->shopId);
  100. util::success($orderData);
  101. }
  102. //确认出库 lqh 2021.1.23
  103. public function actionConfirmOrder()
  104. {
  105. $get = Yii::$app->request->get();
  106. $orderSn = $get['orderSn'];
  107. StockOutOrderClass::confirmOrder($orderSn, $this->shopId, $this->adminId);
  108. util::complete("出库成功");
  109. }
  110. //取消出库 lqh 2021.1.23
  111. public function actionCancelOrder()
  112. {
  113. $get = Yii::$app->request->get();
  114. $orderSn = $get['orderSn'];
  115. StockOutOrderClass::cancelOrder($orderSn, $this->shopId, $this->adminId);
  116. util::complete("取消成功");
  117. }
  118. }