StockOutController.php 3.2 KB

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