StockOutController.php 3.2 KB

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