|
|
@@ -34,7 +34,7 @@ class ItemInfoClass extends BaseClass
|
|
|
$itemIds = array_column($list,'itemId');
|
|
|
//获取相应的图片,名称,py
|
|
|
$where = ['id'=>$itemIds];
|
|
|
- $data = xhItemService::getAllByCondition($where,null,'id,name,pyName,cover,unitNum');
|
|
|
+ $data = xhItemService::getAllByCondition($where,null,'*');
|
|
|
if(!empty($data)){
|
|
|
$data = array_column($data, NULL, 'id');
|
|
|
foreach ($list as $k=>$v){
|
|
|
@@ -45,11 +45,21 @@ class ItemInfoClass extends BaseClass
|
|
|
$list[$k]['stockBundle'] = $stockInfo['stockBundle'];
|
|
|
$list[$k]['stockPiece'] = $stockInfo['stockPiece'];
|
|
|
$list[$k]['itemName'] = $data[$v['itemId']]['name']??'';
|
|
|
+ $list[$k]['unitCount'] = $unitNum?2:1;
|
|
|
+ $list[$k]['bigUnit'] = xhItemService::getUnitName($data[$v['itemId']]['bigUnit']);
|
|
|
+ $list[$k]['smallUnit'] =xhItemService::getUnitName($data[$v['itemId']]['smallUnit']);
|
|
|
}
|
|
|
}
|
|
|
return $list;
|
|
|
}
|
|
|
|
|
|
+ //根据花材ID,库存=》 计算出多少扎,多少支
|
|
|
+ public static function formatStockByItemId($itemId,$stock)
|
|
|
+ {
|
|
|
+ $unitNum = xhItemService::getItemUnitNum($itemId);
|
|
|
+ return self::formatStock($stock,$unitNum);
|
|
|
+ }
|
|
|
+
|
|
|
//花材的库存转换: 库存是小数,根据各个花材的unitNum, 计算出多少扎,多少支
|
|
|
public static function formatStock($stock,$unitNum)
|
|
|
{
|
|
|
@@ -65,6 +75,12 @@ class ItemInfoClass extends BaseClass
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ public static function mergeItemNumByItemId($itemNumBundle,$itemNumPiece,$itemId)
|
|
|
+ {
|
|
|
+ $unitNum = xhItemService::getItemUnitNum($itemId);
|
|
|
+ return self::mergeItemNum($itemNumBundle,$itemNumPiece,$unitNum);
|
|
|
+ }
|
|
|
+
|
|
|
//花材扎、支 转换 统一数
|
|
|
public static function mergeItemNum($itemNumBundle,$itemNumPiece,$unitNum)
|
|
|
{
|
|
|
@@ -116,12 +132,13 @@ class ItemInfoClass extends BaseClass
|
|
|
//根据数量加库存
|
|
|
public static function addStockByItemNum($ghsItemInfoId,$itemNum)
|
|
|
{
|
|
|
- $itemInfoData =self::getById($ghsItemInfoId);
|
|
|
+ $itemInfoData =self::getById($ghsItemInfoId,true);
|
|
|
if(!$itemInfoData){
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
- $newStock = bcadd($itemInfoData['stock'],$itemNum,2);
|
|
|
- self::updateById($ghsItemInfoId,['stock'=>$newStock]);
|
|
|
+ $newStock = bcadd($itemInfoData->stock,$itemNum,2);
|
|
|
+ $itemInfoData->stock = $newStock;
|
|
|
+ $itemInfoData->save();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -134,7 +151,7 @@ class ItemInfoClass extends BaseClass
|
|
|
*/
|
|
|
public static function decreaseStock($ghsItemInfoId,$itemNumBundle,$itemNumPiece)
|
|
|
{
|
|
|
- $itemInfoData =self::getById($ghsItemInfoId);
|
|
|
+ $itemInfoData =self::getById($ghsItemInfoId,true);
|
|
|
if(!$itemInfoData){
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
@@ -143,7 +160,8 @@ class ItemInfoClass extends BaseClass
|
|
|
//转成小数,更新库存
|
|
|
$itemNum = self::mergeItemNum($itemNumBundle,$itemNumPiece,$unitNum);
|
|
|
$newStock = bcsub($itemInfoData['stock'],$itemNum,2);
|
|
|
- self::updateById($ghsItemInfoId,['stock'=>$newStock]);
|
|
|
+ $itemInfoData->stock = $newStock;
|
|
|
+ $itemInfoData->save();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -192,15 +210,21 @@ class ItemInfoClass extends BaseClass
|
|
|
|
|
|
//根据门店ID, 平台花材ID, 获取门店的花材ID
|
|
|
public static function getGhsItemInfoId($shopId,$itemId)
|
|
|
+ {
|
|
|
+ $data = self::getGhsItemInfoDataByItemId($shopId,$itemId);
|
|
|
+ if($data){
|
|
|
+ return $data['id'];
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getGhsItemInfoDataByItemId($shopId,$itemId)
|
|
|
{
|
|
|
$where = [
|
|
|
'shopId'=>$shopId,
|
|
|
'itemId'=>$itemId,
|
|
|
];
|
|
|
$data = self::getByCondition($where);
|
|
|
- if($data){
|
|
|
- return $data['id'];
|
|
|
- }
|
|
|
- return 0;
|
|
|
+ return $data;
|
|
|
}
|
|
|
}
|