StockOutController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. //出库 linqh 2021.1.23
  10. class StockOutController extends BaseController
  11. {
  12. //出库列表 linqh 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. //新增出库 linqh 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['adminId'] = $this->adminId;
  32. $inShopId = $post['inShopId'] ?? 0;
  33. $now = date('Y-m-d H:i:s');
  34. $date = $post['date'] ?? $now;
  35. $post['outTime'] = $date;
  36. $action = $post['action'] ?? 'wait'; //confirm(直接出库) wait(待出库中)
  37. $post['action'] = $action;
  38. $post['inShopId'] = $inShopId;
  39. $check = StockOutOrderClass::getByCondition(['outShopId' => $this->shopId, 'inShopId' => $inShopId, 'status' => StockOutOrderClass::STATUS_WAIT]);
  40. if ($check) {
  41. util::fail('还有待出库的订单');
  42. }
  43. $ghsItemInfo = $post['itemInfo'] ?? '';
  44. if (empty($ghsItemInfo)) {
  45. util::fail('请选择花材');
  46. }
  47. $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,bigNum:1,smallNum:0}]
  48. if (!is_array($ghsItemInfo)) {
  49. util::fail('花材格式不正确');
  50. }
  51. //入库门店有效性判断
  52. if ($this->shopId == $inShopId) {
  53. util::fail('不能出库给当前门店');
  54. }
  55. $inShop = ShopClass::getById($inShopId);
  56. if (empty($inShop)) {
  57. util::fail('没有找到门店');
  58. }
  59. ShopClass::valid($inShop, $this->sjId);
  60. ProductClass::valid($ghsItemInfo, $this->mainId);
  61. //判断花材里的信息
  62. foreach ($ghsItemInfo as $v) {
  63. $bigNum = $v['bigNum'] ?? 0;
  64. $smallNum = $v['smallNum'] ?? 0;
  65. if ($bigNum <= 0 && $smallNum <= 0) {
  66. util::fail('花材数量不能为0');
  67. }
  68. }
  69. $post['itemInfo'] = $ghsItemInfo;
  70. $order = StockOutOrderClass::addOrder($post);
  71. if ($order) {
  72. util::success($order);
  73. } else {
  74. util::fail();
  75. }
  76. }
  77. //出库详情 linqh 2021.1.23
  78. public function actionDetail()
  79. {
  80. $orderSn = Yii::$app->request->get('orderSn', '');
  81. $orderData = StockOutOrderClass::getOrderDetail($orderSn, $this->shopId);
  82. util::success($orderData);
  83. }
  84. //确认出库 linqh 2021.1.23
  85. public function actionConfirmOrder()
  86. {
  87. $get = Yii::$app->request->get();
  88. $orderSn = $get['orderSn'];
  89. StockOutOrderClass::confirmOrder($orderSn, $this->shopId, $this->adminId);
  90. util::complete("出库成功");
  91. }
  92. //取消出库 linqh 2021.1.23
  93. public function actionCancelOrder()
  94. {
  95. $get = Yii::$app->request->get();
  96. $orderSn = $get['orderSn'];
  97. StockOutOrderClass::cancelOrder($orderSn, $this->shopId, $this->adminId);
  98. util::complete("取消成功");
  99. }
  100. }