|
|
@@ -8,6 +8,7 @@ namespace bizGhs\item\classes;
|
|
|
|
|
|
|
|
|
use bizGhs\base\classes\BaseClass;
|
|
|
+use bizGhs\item\models\ItemInfo;
|
|
|
use common\components\business;
|
|
|
use common\components\util;
|
|
|
use common\services\xhItemService;
|
|
|
@@ -56,7 +57,7 @@ class ItemInfoClass extends BaseClass
|
|
|
$stockArr = explode('.',$stock);
|
|
|
$stockPiece = 0; //支
|
|
|
if(count($stockArr)===2){
|
|
|
- $stockPiece = bcdiv(bcmul($stockArr[1],$unitNum),100);
|
|
|
+ $stockPiece = bcdiv(bcmul($stockArr[1],$unitNum,1),100,2);
|
|
|
}
|
|
|
return [
|
|
|
'stockBundle'=>$stockBundle,
|
|
|
@@ -64,6 +65,19 @@ class ItemInfoClass extends BaseClass
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ //花材扎、支 转换 统一数
|
|
|
+ public static function mergeItemNum($itemNumBundle,$itemNumPiece,$unitNum)
|
|
|
+ {
|
|
|
+ $stockDecimal = 0;
|
|
|
+ if($unitNum > 0 ){
|
|
|
+ $stockDecimal = bcdiv($itemNumPiece,$unitNum,2);
|
|
|
+ }
|
|
|
+ $itemNum = bcadd($itemNumBundle,$stockDecimal,2);
|
|
|
+ return $itemNum;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//获取常用的itemIds
|
|
|
public static function getOftenItemIds($ghsId)
|
|
|
{
|
|
|
@@ -92,19 +106,26 @@ class ItemInfoClass extends BaseClass
|
|
|
}
|
|
|
$itemId = $itemInfoData['itemId'];
|
|
|
$unitNum = xhItemService::getItemUnitNum($itemId);
|
|
|
- if(!$unitNum){
|
|
|
- util::fail("系统错误");
|
|
|
- }
|
|
|
//转成小数,加库存
|
|
|
- $stockDecimal = bcdiv($itemNumPiece,$unitNum,2);
|
|
|
- $itemNum = bcadd($itemNumBundle,$stockDecimal,2);
|
|
|
- $newStock = bcadd($itemInfoData['stock'],$itemNum);
|
|
|
+ $itemNum = self::mergeItemNum($itemNumBundle,$itemNumPiece,$unitNum);
|
|
|
+ $newStock = bcadd($itemInfoData['stock'],$itemNum,2);
|
|
|
self::updateById($ghsItemInfoId,['stock'=>$newStock]);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- //减库存,允许负库存,负数数量(盘点时)
|
|
|
+ //根据数量加库存
|
|
|
+ public static function addStockByItemNum($ghsItemInfoId,$itemNum)
|
|
|
+ {
|
|
|
+ $itemInfoData =self::getById($ghsItemInfoId);
|
|
|
+ if(!$itemInfoData){
|
|
|
+ util::fail("花材不存在");
|
|
|
+ }
|
|
|
+ $newStock = bcadd($itemInfoData['stock'],$itemNum,2);
|
|
|
+ self::updateById($ghsItemInfoId,['stock'=>$newStock]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
+ //减库存,允许负库存,负数数量(盘点时)
|
|
|
/**
|
|
|
* @param $ghsItemInfoId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
* @param $itemNumBundle 花材数量(扎)
|
|
|
@@ -119,18 +140,26 @@ class ItemInfoClass extends BaseClass
|
|
|
}
|
|
|
$itemId = $itemInfoData['itemId'];
|
|
|
$unitNum = xhItemService::getItemUnitNum($itemId);
|
|
|
- if(!$unitNum){
|
|
|
- util::fail("系统错误");
|
|
|
- }
|
|
|
//转成小数,更新库存
|
|
|
- $stockDecimal = bcdiv($itemNumPiece,$unitNum,2);
|
|
|
- $itemNum = bcadd($itemNumBundle,$stockDecimal,2);
|
|
|
- $newStock = bcsub($itemInfoData['stock'],$itemNum);
|
|
|
+ $itemNum = self::mergeItemNum($itemNumBundle,$itemNumPiece,$unitNum);
|
|
|
+ $newStock = bcsub($itemInfoData['stock'],$itemNum,2);
|
|
|
self::updateById($ghsItemInfoId,['stock'=>$newStock]);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //根据数量加库存
|
|
|
+ public static function decreaseStockByItemNum($ghsItemInfoId,$itemNum)
|
|
|
+ {
|
|
|
+ $itemInfoData =self::getById($ghsItemInfoId);
|
|
|
+ if(!$itemInfoData){
|
|
|
+ util::fail("花材不存在");
|
|
|
+ }
|
|
|
+ $newStock = bcsub($itemInfoData['stock'],$itemNum,2);
|
|
|
+ self::updateById($ghsItemInfoId,['stock'=>$newStock]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
//计算价格
|
|
|
/**
|
|
|
* @param $ghsItemInfoId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
@@ -149,14 +178,29 @@ class ItemInfoClass extends BaseClass
|
|
|
$itemId = $itemInfoData['itemId'];
|
|
|
$unitNum = xhItemService::getItemUnitNum($itemId);
|
|
|
//换算出一支多少钱
|
|
|
- if(!$unitNum){
|
|
|
- util::fail("系统错误");
|
|
|
+ $piecePrice = 0;
|
|
|
+ if($unitNum >0){
|
|
|
+ //有支
|
|
|
+ $unitPrice = bcdiv($price,$unitNum,2);
|
|
|
+ $piecePrice = bcmul($unitPrice,$itemNumPiece,2);
|
|
|
}
|
|
|
- $unitPrice = bcdiv($price,$unitNum,2);
|
|
|
- $bundlePrice = bcmul($price,$itemNumBundle);
|
|
|
- $piecePrice = bcmul($unitPrice,$itemNumPiece);
|
|
|
+ $bundlePrice = bcmul($price,$itemNumBundle,2);
|
|
|
+
|
|
|
$total = bcadd($bundlePrice,$piecePrice,2);
|
|
|
return $total;
|
|
|
}
|
|
|
|
|
|
+ //根据门店ID, 平台花材ID, 获取门店的花材ID
|
|
|
+ public static function getGhsItemInfoId($shopId,$itemId)
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'shopId'=>$shopId,
|
|
|
+ 'itemId'=>$itemId,
|
|
|
+ ];
|
|
|
+ $data = self::getByCondition($where);
|
|
|
+ if($data){
|
|
|
+ return $data['id'];
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|