StockOutController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. //出库 linqh 2021.1.23
  9. class StockOutController extends BaseController
  10. {
  11. //出库列表 linqh 2021.1.23
  12. public function actionList()
  13. {
  14. $get = Yii::$app->request->get();
  15. $orderStatus = isset($get['status']) ? $get['status'] : '';
  16. $where = [];
  17. $where['outShopId'] = $this->shopId;
  18. if (!empty($orderStatus)) {
  19. $where['status'] = $orderStatus;
  20. }
  21. $list = StockOutOrderClass::getOrderList($where);
  22. util::success($list);
  23. }
  24. //新增出库 linqh 2021.1.23
  25. public function actionCreateOrder()
  26. {
  27. $post = Yii::$app->request->post();
  28. $post['merchantId'] = $this->sjId;
  29. $post['outShopId'] = $this->shopId;
  30. $post['adminId'] = $this->adminId;
  31. $inShopId = $post['inShopId']??0;
  32. $now = date('Y-m-d H:i:s');
  33. $date = $post['date']??$now;
  34. $post['outTime'] = $date;
  35. $action = $post['action']??'wait'; //confirm(直接出库) wait(待出库中)
  36. $post['action'] = $action;
  37. //判断 入库的门店ID是否有效
  38. $post['inShopId'] = $inShopId;
  39. //是否判断 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. //入库门店有效性判断
  53. if($this->shopId==$inShopId){
  54. util::fail('不能出库给当前门店');
  55. }
  56. $inShop = ShopClass::getById($inShopId);
  57. ShopClass::valid($inShop,$this->sjId);
  58. ProductClass::valid($ghsItemInfo,$this->shopId);
  59. //判断花材里的信息
  60. foreach ($ghsItemInfo as $v){
  61. $bigNum = $v['bigNum']??0;
  62. $smallNum = $v['smallNum']??0;
  63. if($bigNum <=0 && $smallNum <=0){
  64. util::fail('花材数量不能为0');
  65. }
  66. }
  67. $post['itemInfo'] = $ghsItemInfo;
  68. $order = StockOutOrderClass::addOrder($post);
  69. if($order){
  70. util::success($order);
  71. }else{
  72. util::fail();
  73. }
  74. }
  75. //
  76. //出库详情 linqh 2021.1.23
  77. public function actionDetail()
  78. {
  79. $orderSn = Yii::$app->request->get('orderSn','');
  80. $orderData = StockOutOrderClass::getOrderDetail($orderSn,$this->shopId);
  81. util::success($orderData);
  82. }
  83. //确认出库 linqh 2021.1.23
  84. public function actionConfirmOrder()
  85. {
  86. $get = Yii::$app->request->get();
  87. $orderSn = $get['orderSn'];
  88. StockOutOrderClass::confirmOrder($orderSn,$this->shopId,$this->adminId);
  89. util::complete("出库成功");
  90. }
  91. //取消出库 linqh 2021.1.23
  92. public function actionCancelOrder()
  93. {
  94. $get = Yii::$app->request->get();
  95. $orderSn = $get['orderSn'];
  96. StockOutOrderClass::cancelOrder($orderSn,$this->shopId,$this->adminId);
  97. util::complete("取消成功");
  98. }
  99. }