StockOutController.php 4.0 KB

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