StockOutController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. $shopAdmin = $this->shopAdmin;
  29. $roleId = $shopAdmin['roleId'] ?? 0;
  30. $role = AdminRoleClass::getById($roleId);
  31. $roleName = $role['roleName'] ?? '';
  32. if ($roleName == '员工') {
  33. util::fail('您没有权限操作哦');
  34. }
  35. $post = Yii::$app->request->post();
  36. $post['sjId'] = $this->sjId;
  37. $post['outShopId'] = $this->shopId;
  38. $post['adminId'] = $this->adminId;
  39. $inShopId = $post['inShopId'] ?? 0;
  40. $now = date('Y-m-d H:i:s');
  41. $date = $post['date'] ?? $now;
  42. $post['outTime'] = $date;
  43. $action = $post['action'] ?? 'wait'; //confirm(直接出库) wait(待出库中)
  44. $post['action'] = $action;
  45. //判断 入库的门店ID是否有效
  46. $post['inShopId'] = $inShopId;
  47. //是否判断 inShopId 下还有未完成出库的订单?
  48. $check = StockOutOrderClass::getByCondition(['outShopId' => $this->shopId, 'inShopId' => $inShopId, 'status' => StockOutOrderClass::STATUS_WAIT]);
  49. if ($check) {
  50. util::fail('还有待出库的订单');
  51. }
  52. $ghsItemInfo = $post['itemInfo'] ?? '';
  53. if (empty($ghsItemInfo)) {
  54. util::fail('请选择花材');
  55. }
  56. $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,bigNum:1,smallNum:0}]
  57. if (!is_array($ghsItemInfo)) {
  58. util::fail('花材格式不正确');
  59. }
  60. //入库门店有效性判断
  61. if ($this->shopId == $inShopId) {
  62. util::fail('不能出库给当前门店');
  63. }
  64. $inShop = ShopClass::getById($inShopId);
  65. if (empty($inShop)) {
  66. util::fail('没有找到门店');
  67. }
  68. ShopClass::valid($inShop, $this->sjId);
  69. ProductClass::valid($ghsItemInfo, $this->shopId);
  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. util::success($order);
  82. } else {
  83. util::fail();
  84. }
  85. }
  86. //
  87. //出库详情 linqh 2021.1.23
  88. public function actionDetail()
  89. {
  90. $orderSn = Yii::$app->request->get('orderSn', '');
  91. $orderData = StockOutOrderClass::getOrderDetail($orderSn, $this->shopId);
  92. util::success($orderData);
  93. }
  94. //确认出库 linqh 2021.1.23
  95. public function actionConfirmOrder()
  96. {
  97. $get = Yii::$app->request->get();
  98. $orderSn = $get['orderSn'];
  99. StockOutOrderClass::confirmOrder($orderSn, $this->shopId, $this->adminId);
  100. util::complete("出库成功");
  101. }
  102. //取消出库 linqh 2021.1.23
  103. public function actionCancelOrder()
  104. {
  105. $get = Yii::$app->request->get();
  106. $orderSn = $get['orderSn'];
  107. StockOutOrderClass::cancelOrder($orderSn, $this->shopId, $this->adminId);
  108. util::complete("取消成功");
  109. }
  110. }