|
|
@@ -1,25 +1,18 @@
|
|
|
<?php
|
|
|
-/**
|
|
|
- * User: admin
|
|
|
- * Date Time: 2021/1/13 17:12
|
|
|
- */
|
|
|
-
|
|
|
-namespace bizGhs\item\classes;
|
|
|
+namespace bizGhs\product\classes;
|
|
|
|
|
|
|
|
|
use bizGhs\base\classes\BaseClass;
|
|
|
-use bizGhs\item\models\ItemInfo;
|
|
|
use common\components\business;
|
|
|
use common\components\util;
|
|
|
use common\services\xhItemService;
|
|
|
-
|
|
|
-class ItemInfoClass extends BaseClass
|
|
|
+class ProductClass extends BaseClass
|
|
|
{
|
|
|
|
|
|
- public static $baseFile = '\bizGhs\item\models\ItemInfo';
|
|
|
+ public static $baseFile = '\bizGhs\product\models\Product';
|
|
|
|
|
|
//根据itemIds获取相应的花材信息
|
|
|
- public static function getItemInfoByItemIds(array $itemIds)
|
|
|
+ public static function getProductInfoByItemIds(array $itemIds)
|
|
|
{
|
|
|
$where = ['itemId'=>['in',$itemIds],'delStatus'=>0];
|
|
|
$data = self::getAllList('*',$where);
|
|
|
@@ -42,8 +35,8 @@ class ItemInfoClass extends BaseClass
|
|
|
$unitNum = $data[$v['itemId']]['unitNum']??0;
|
|
|
$stockInfo = self::formatStock($v['stock'],$unitNum);
|
|
|
$list[$k]['cover'] = $coverInfo['coverUrl'];
|
|
|
- $list[$k]['stockBundle'] = $stockInfo['stockBundle'];
|
|
|
- $list[$k]['stockPiece'] = $stockInfo['stockPiece'];
|
|
|
+ $list[$k]['bigNum'] = $stockInfo['bigNum'];
|
|
|
+ $list[$k]['smallNum'] = $stockInfo['smallNum'];
|
|
|
$list[$k]['itemName'] = $data[$v['itemId']]['name']??'';
|
|
|
$list[$k]['unitCount'] = $unitNum?2:1;
|
|
|
$list[$k]['bigUnit'] = xhItemService::getUnitName($data[$v['itemId']]['bigUnit']);
|
|
|
@@ -67,11 +60,11 @@ class ItemInfoClass extends BaseClass
|
|
|
$stockArr = explode('.',$stock);
|
|
|
$stockPiece = 0; //支
|
|
|
if(count($stockArr)===2){
|
|
|
- $stockPiece = bcdiv(bcmul($stockArr[1],$unitNum,1),100,2);
|
|
|
+ $stockPiece = bcdiv(bcmul($stockArr[1],$unitNum,1),100);
|
|
|
}
|
|
|
return [
|
|
|
- 'stockBundle'=>$stockBundle,
|
|
|
- 'stockPiece'=>$stockPiece,
|
|
|
+ 'bigNum'=>$stockBundle,
|
|
|
+ 'smallNum'=>(int)$stockPiece,
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -95,9 +88,9 @@ class ItemInfoClass extends BaseClass
|
|
|
|
|
|
|
|
|
//获取常用的itemIds
|
|
|
- public static function getOftenItemIds($ghsId)
|
|
|
+ public static function getOftenItemIds($merchantId)
|
|
|
{
|
|
|
- $data = self::getAllList("itemId",['ghsId'=>$ghsId],'actualSold desc');
|
|
|
+ $data = self::getAllList("itemId",['merchantId'=>$merchantId],'actualSold desc');
|
|
|
if($data){
|
|
|
$data = array_column($data,'itemId');
|
|
|
}
|
|
|
@@ -109,91 +102,91 @@ class ItemInfoClass extends BaseClass
|
|
|
//加库存,允许负库存,负数数量(盘点时)
|
|
|
|
|
|
/**
|
|
|
- * @param $ghsItemInfoId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
+ * @param $productId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
* @param $itemNumBundle 花材数量(扎)
|
|
|
* @param $itemNumPiece 花材数量(支)
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public static function addStock($ghsItemInfoId,$itemNumBundle,$itemNumPiece)
|
|
|
+ public static function addStock($productId,$itemNumBundle,$itemNumPiece)
|
|
|
{
|
|
|
- $itemInfoData =self::getById($ghsItemInfoId);
|
|
|
- if(!$itemInfoData){
|
|
|
+ $productData =self::getById($productId);
|
|
|
+ if(!$productData){
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
- $itemId = $itemInfoData['itemId'];
|
|
|
+ $itemId = $productData['itemId'];
|
|
|
$unitNum = xhItemService::getItemUnitNum($itemId);
|
|
|
//转成小数,加库存
|
|
|
$itemNum = self::mergeItemNum($itemNumBundle,$itemNumPiece,$unitNum);
|
|
|
- $newStock = bcadd($itemInfoData['stock'],$itemNum,2);
|
|
|
- self::updateById($ghsItemInfoId,['stock'=>$newStock]);
|
|
|
+ $newStock = bcadd($productData['stock'],$itemNum,2);
|
|
|
+ self::updateById($productId,['stock'=>$newStock]);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//根据数量加库存
|
|
|
- public static function addStockByItemNum($ghsItemInfoId,$itemNum)
|
|
|
+ public static function addStockByItemNum($productId,$itemNum)
|
|
|
{
|
|
|
- $itemInfoData =self::getById($ghsItemInfoId,true);
|
|
|
- if(!$itemInfoData){
|
|
|
+ $productData =self::getById($productId,true);
|
|
|
+ if(!$productData){
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
- $newStock = bcadd($itemInfoData->stock,$itemNum,2);
|
|
|
- $itemInfoData->stock = $newStock;
|
|
|
- $itemInfoData->save();
|
|
|
+ $newStock = bcadd($productData->stock,$itemNum,2);
|
|
|
+ $productData->stock = $newStock;
|
|
|
+ $productData->save();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//减库存,允许负库存,负数数量(盘点时)
|
|
|
/**
|
|
|
- * @param $ghsItemInfoId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
+ * @param $productId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
* @param $itemNumBundle 花材数量(扎)
|
|
|
* @param $itemNumPiece 花材数量(支)
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public static function decreaseStock($ghsItemInfoId,$itemNumBundle,$itemNumPiece)
|
|
|
+ public static function decreaseStock($productId,$itemNumBundle,$itemNumPiece)
|
|
|
{
|
|
|
- $itemInfoData =self::getById($ghsItemInfoId,true);
|
|
|
- if(!$itemInfoData){
|
|
|
+ $productData =self::getById($productId,true);
|
|
|
+ if(!$productData){
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
- $itemId = $itemInfoData['itemId'];
|
|
|
+ $itemId = $productData['itemId'];
|
|
|
$unitNum = xhItemService::getItemUnitNum($itemId);
|
|
|
//转成小数,更新库存
|
|
|
$itemNum = self::mergeItemNum($itemNumBundle,$itemNumPiece,$unitNum);
|
|
|
- $newStock = bcsub($itemInfoData['stock'],$itemNum,2);
|
|
|
- $itemInfoData->stock = $newStock;
|
|
|
- $itemInfoData->save();
|
|
|
+ $newStock = bcsub($productData->stock,$itemNum,2);
|
|
|
+ $productData->stock = $newStock;
|
|
|
+ $productData->save();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
//根据数量加库存
|
|
|
- public static function decreaseStockByItemNum($ghsItemInfoId,$itemNum)
|
|
|
+ public static function decreaseStockByItemNum($productId,$itemNum)
|
|
|
{
|
|
|
- $itemInfoData =self::getById($ghsItemInfoId);
|
|
|
- if(!$itemInfoData){
|
|
|
+ $productData =self::getById($productId);
|
|
|
+ if(!$productData){
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
- $newStock = bcsub($itemInfoData['stock'],$itemNum,2);
|
|
|
- self::updateById($ghsItemInfoId,['stock'=>$newStock]);
|
|
|
+ $newStock = bcsub($productData['stock'],$itemNum,2);
|
|
|
+ self::updateById($productId,['stock'=>$newStock]);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//计算价格
|
|
|
/**
|
|
|
- * @param $ghsItemInfoId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
+ * @param $productId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
* @param $itemNumBundle 花材数量(扎)
|
|
|
* @param $itemNumPiece 花材数量(支)
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public static function computedPrice($ghsItemInfoId,$itemNumBundle,$itemNumPiece)
|
|
|
+ public static function computedPrice($productId,$itemNumBundle,$itemNumPiece)
|
|
|
{
|
|
|
//获取itemId的价格
|
|
|
- $itemInfoData = self::getById($ghsItemInfoId);
|
|
|
- if(!$itemInfoData){
|
|
|
+ $productData = self::getById($productId);
|
|
|
+ if(!$productData){
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
- $price = $itemInfoData['price'];
|
|
|
- $itemId = $itemInfoData['itemId'];
|
|
|
+ $price = $productData['price'];
|
|
|
+ $itemId = $productData['itemId'];
|
|
|
$unitNum = xhItemService::getItemUnitNum($itemId);
|
|
|
//换算出一支多少钱
|
|
|
$piecePrice = 0;
|
|
|
@@ -209,16 +202,16 @@ class ItemInfoClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
//根据门店ID, 平台花材ID, 获取门店的花材ID
|
|
|
- public static function getGhsItemInfoId($shopId,$itemId)
|
|
|
+ public static function getGhsProductId($shopId,$itemId)
|
|
|
{
|
|
|
- $data = self::getGhsItemInfoDataByItemId($shopId,$itemId);
|
|
|
+ $data = self::getGhsProductDataByItemId($shopId,$itemId);
|
|
|
if($data){
|
|
|
return $data['id'];
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- public static function getGhsItemInfoDataByItemId($shopId,$itemId)
|
|
|
+ public static function getGhsProductDataByItemId($shopId,$itemId)
|
|
|
{
|
|
|
$where = [
|
|
|
'shopId'=>$shopId,
|