|
|
@@ -2,8 +2,11 @@
|
|
|
|
|
|
namespace bizHd\order\classes;
|
|
|
|
|
|
+use biz\stock\classes\GoodsStockRecordClass;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
use bizGhs\stock\classes\StockRecordClass;
|
|
|
+use bizGhs\stock\services\StockRecordService;
|
|
|
+use bizHd\goods\classes\GoodsClass;
|
|
|
use common\components\business;
|
|
|
use Yii;
|
|
|
use bizHd\base\classes\BaseClass;
|
|
|
@@ -94,16 +97,103 @@ class OrderGoodsClass extends BaseClass
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- //制作成品库存变更方法(加成品库存,减花材库存) todo
|
|
|
- public static function changeStockByMakeGoods()
|
|
|
+ //制作成品库存变更方法(加成品库存,减花材库存(消耗、损耗))
|
|
|
+ //消耗花材信息:$consumeItemInfo = [{"id":12233,"num":1,"unitType":0}]
|
|
|
+ //损耗花材信息:$wastageItemInfo = [{"id":12233,"num":1,"unitType":0}]
|
|
|
+ //id 是当前产品的id,单价unitType 是当前单位类型,0表示大单位,1表示小单位,默认0 num 是当前花材数量
|
|
|
+ public static function changeStockByMakeGoods($orderSn,$sjId,$shopId,$mainId,$goodsId,$goodsNum,$consumeItemInfo,$wastageItemInfo)
|
|
|
{
|
|
|
-
|
|
|
+ //加成品库存
|
|
|
+ GoodsClass::addStock($goodsId,$mainId,$goodsNum);
|
|
|
+ //成品流水记录
|
|
|
+ $data = [];
|
|
|
+ $data['sjId'] = $sjId;
|
|
|
+ $data['shopId'] = $shopId;
|
|
|
+ $data['mainId'] = $mainId;
|
|
|
+ $data['orderSn'] = $orderSn;
|
|
|
+ $data['goodsId'] = $goodsId;
|
|
|
+ $data['goodsNum'] = $goodsNum;
|
|
|
+ GoodsStockRecordClass::addMakeGoods($data);
|
|
|
+ //花材消耗
|
|
|
+ if(!empty($consumeItemInfo)){
|
|
|
+ foreach ($consumeItemInfo as $v){
|
|
|
+ //库存减少
|
|
|
+ $bigNum = 0;
|
|
|
+ $smallNum = 0;
|
|
|
+ $productId = $v['id'];
|
|
|
+ if($v['unitType']==0){
|
|
|
+ //大单位
|
|
|
+ $bigNum = $v['num'];
|
|
|
+ }else{
|
|
|
+ //小单位
|
|
|
+ $smallNum = $v['num'];
|
|
|
+ }
|
|
|
+ //扣库存
|
|
|
+ $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, true);
|
|
|
+ //记录流流水
|
|
|
+ $productData = ProductClass::getById($productId);
|
|
|
+ $record = [];
|
|
|
+ $record['sjId'] = $sjId;
|
|
|
+ $record['shopId'] = $shopId;
|
|
|
+ $record['mainId'] = $productData['mainId'];
|
|
|
+ $record['orderSn'] = $orderSn;
|
|
|
+ $record['itemId'] = $productData['itemId'];
|
|
|
+ $record['productId'] = $productId;
|
|
|
+ $record['itemNum'] = $stockInfo['itemNum'];
|
|
|
+ $record['oldStock'] = $stockInfo['oldStock'];
|
|
|
+ $record['newStock'] =$stockInfo['newStock']; //
|
|
|
+ StockRecordClass::makeGoodsConsume($record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //花材损耗
|
|
|
+ if(!empty($wastageItemInfo)){
|
|
|
+ foreach ($wastageItemInfo as $v){
|
|
|
+ //库存减少
|
|
|
+ $bigNum = 0;
|
|
|
+ $smallNum = 0;
|
|
|
+ $productId = $v['id'];
|
|
|
+ if($v['unitType']==0){
|
|
|
+ //大单位
|
|
|
+ $bigNum = $v['num'];
|
|
|
+ }else{
|
|
|
+ //小单位
|
|
|
+ $smallNum = $v['num'];
|
|
|
+ }
|
|
|
+ //扣库存
|
|
|
+ $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, true);
|
|
|
+ //记录流流水
|
|
|
+ $productData = ProductClass::getById($productId);
|
|
|
+ $record = [];
|
|
|
+ $record['sjId'] = $sjId;
|
|
|
+ $record['shopId'] = $shopId;
|
|
|
+ $record['mainId'] = $productData['mainId'];
|
|
|
+ $record['orderSn'] = $orderSn;
|
|
|
+ $record['itemId'] = $productData['itemId'];
|
|
|
+ $record['productId'] = $productId;
|
|
|
+ $record['itemNum'] = $stockInfo['itemNum'];
|
|
|
+ $record['oldStock'] = $stockInfo['oldStock'];
|
|
|
+ $record['newStock'] =$stockInfo['newStock']; //
|
|
|
+ StockRecordClass::makeGoodsWastage($record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- //销售成品库存变更方法(减库存) todo
|
|
|
- public static function changeStockBySellGoods()
|
|
|
+ //销售成品库存变更方法(减库存)
|
|
|
+ public static function changeStockBySellGoods($orderSn,$sjId,$shopId,$mainId,$goodsId,$goodsNum)
|
|
|
{
|
|
|
-
|
|
|
+ //加成品库存
|
|
|
+ GoodsClass::decreaseStock($goodsId,$mainId,$goodsNum);
|
|
|
+ //成品流水记录
|
|
|
+ $data = [];
|
|
|
+ $data['sjId'] = $sjId;
|
|
|
+ $data['shopId'] = $shopId;
|
|
|
+ $data['mainId'] = $mainId;
|
|
|
+ $data['orderSn'] = $orderSn;
|
|
|
+ $data['goodsId'] = $goodsId;
|
|
|
+ $data['goodsNum'] = $goodsNum;
|
|
|
+ GoodsStockRecordClass::sellGoods($data);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
}
|