StockOutController.php 4.0 KB

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