|
|
@@ -31,12 +31,17 @@ class ProductClass extends BaseClass
|
|
|
//取得itemIds
|
|
|
$itemIds = array_column($list, 'itemId');
|
|
|
//获取相应的图片,名称,py
|
|
|
- $where = ['id' => ['in', $itemIds]];
|
|
|
+ $where = ['id' => ['in', $itemIds]];
|
|
|
$data = xhItemService::getAllByCondition($where, null, '*');
|
|
|
if (!empty($data)) {
|
|
|
$data = array_column($data, NULL, 'id');
|
|
|
foreach ($list as $k => $v) {
|
|
|
- $cover = self::groupImg($data[$v['itemId']]['cover']);
|
|
|
+ if (isset($data[$v['itemId']]['cover']) && !empty($data[$v['itemId']]['cover'])) {
|
|
|
+ $cover = self::groupImg($data[$v['itemId']]['cover']);
|
|
|
+ } else {
|
|
|
+ //没有图片时取默认图片 shish 2021.2.18
|
|
|
+ $cover = Yii::$app->params['imgHost'] . '/hhb_small.png';
|
|
|
+ }
|
|
|
$unitNum = $data[$v['itemId']]['unitNum'] ?? 0;
|
|
|
$stockInfo = self::formatStock($v['stock'], $unitNum);
|
|
|
$list[$k]['cover'] = $cover;
|
|
|
@@ -71,7 +76,7 @@ class ProductClass extends BaseClass
|
|
|
public static function formatStock($stock, $unitNum)
|
|
|
{
|
|
|
$pn = true; //正数
|
|
|
- if($stock < 0 ){
|
|
|
+ if ($stock < 0) {
|
|
|
$pn = false;
|
|
|
$stock = abs($stock);
|
|
|
}
|
|
|
@@ -79,14 +84,14 @@ class ProductClass extends BaseClass
|
|
|
$stockArr = explode('.', $stock);
|
|
|
$smallNum = 0; //支
|
|
|
if (count($stockArr) === 2) {
|
|
|
- $smallNum = bcmul(($stock-$bigNum),$unitNum);
|
|
|
+ $smallNum = bcmul(($stock - $bigNum), $unitNum);
|
|
|
}
|
|
|
- if(!$pn){
|
|
|
- $bigNum *=-1;
|
|
|
- $smallNum *=-1;
|
|
|
+ if (!$pn) {
|
|
|
+ $bigNum *= -1;
|
|
|
+ $smallNum *= -1;
|
|
|
}
|
|
|
return [
|
|
|
- 'bigNum' => $bigNum,
|
|
|
+ 'bigNum' => $bigNum,
|
|
|
'smallNum' => $smallNum,
|
|
|
];
|
|
|
}
|
|
|
@@ -160,6 +165,7 @@ class ProductClass extends BaseClass
|
|
|
|
|
|
|
|
|
//todo 库存修改 加锁
|
|
|
+
|
|
|
/**
|
|
|
* 对商品ID 加库存
|
|
|
* @param $productId 商品ID
|
|
|
@@ -222,6 +228,7 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
//计算价格
|
|
|
+
|
|
|
/**
|
|
|
* @param $productId 门店下的花材ID(xhGhsItemInfo 主键ID)
|
|
|
* @param $bigNum 花材数量(扎)
|
|
|
@@ -280,24 +287,24 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
//补全itemId (针对入库时 当前门店下无对应的花材 itemId) linqh 2021.1.24
|
|
|
- public static function complementProduct($merchantId,$shopId, $itemInfo)
|
|
|
+ public static function complementProduct($merchantId, $shopId, $itemInfo)
|
|
|
{
|
|
|
- $itemIds = array_column($itemInfo,"itemId");
|
|
|
- $itemData = array_column($itemInfo,null,"itemId");
|
|
|
- $productData = self::getGhsProductDataByItemIds($shopId,$itemIds);
|
|
|
+ $itemIds = array_column($itemInfo, "itemId");
|
|
|
+ $itemData = array_column($itemInfo, null, "itemId");
|
|
|
+ $productData = self::getGhsProductDataByItemIds($shopId, $itemIds);
|
|
|
|
|
|
- if(count($productData) !== count($itemIds)){
|
|
|
- $productDataItemIds = array_column($productData,'itemId');
|
|
|
+ if (count($productData) !== count($itemIds)) {
|
|
|
+ $productDataItemIds = array_column($productData, 'itemId');
|
|
|
//取差集
|
|
|
- $diffItemIds = array_diff($itemIds,$productDataItemIds);
|
|
|
- if($diffItemIds){
|
|
|
+ $diffItemIds = array_diff($itemIds, $productDataItemIds);
|
|
|
+ if ($diffItemIds) {
|
|
|
//新增到product表,price = itemPrice (出库时的售价), stock=0
|
|
|
- foreach ($diffItemIds as $v){
|
|
|
+ foreach ($diffItemIds as $v) {
|
|
|
$addData = [];
|
|
|
$addData['merchantId'] = $merchantId;
|
|
|
$addData['shopId'] = $shopId;
|
|
|
$addData['itemId'] = $v;
|
|
|
- $addData['price'] = $itemData[$v]['itemPrice']??0;
|
|
|
+ $addData['price'] = $itemData[$v]['itemPrice'] ?? 0;
|
|
|
self::add($addData);
|
|
|
}
|
|
|
}
|
|
|
@@ -341,38 +348,38 @@ class ProductClass extends BaseClass
|
|
|
//订单退回库存
|
|
|
public static function backStockByOrderItemInfo($orderItemInfo)
|
|
|
{
|
|
|
- foreach ($orderItemInfo as $v){
|
|
|
- ProductClass::addStockByItemNum($v['productId'],$v['itemNum']);
|
|
|
+ foreach ($orderItemInfo as $v) {
|
|
|
+ ProductClass::addStockByItemNum($v['productId'], $v['itemNum']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//库存告警的itemIds (库存数量少于告警数量) linqh 2021.1.26
|
|
|
- public static function getItemIdsWarning($merchantId,$shopId)
|
|
|
+ public static function getItemIdsWarning($merchantId, $shopId)
|
|
|
{
|
|
|
//获取当前门店下的 itemId=>stock
|
|
|
- $productData = ProductClass::getAllList("itemId,stock",['shopId'=>$shopId]);
|
|
|
+ $productData = ProductClass::getAllList("itemId,stock", ['shopId' => $shopId]);
|
|
|
$productItemStock = [];
|
|
|
- if($productData){
|
|
|
- foreach ($productData as $v){
|
|
|
+ if ($productData) {
|
|
|
+ foreach ($productData as $v) {
|
|
|
$productItemStock[$v['itemId']] = $v['stock'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取merchantId 下 对应的itemId=>stockWaring
|
|
|
- $itemData = ItemClass::getAllList("itemId,stockWarning",['merchantId'=>$merchantId]);
|
|
|
+ $itemData = ItemClass::getAllList("itemId,stockWarning", ['merchantId' => $merchantId]);
|
|
|
$itemStockWaring = [];
|
|
|
- if($itemData){
|
|
|
- foreach ($itemData as $v){
|
|
|
+ if ($itemData) {
|
|
|
+ foreach ($itemData as $v) {
|
|
|
$itemStockWaring[$v['itemId']] = $v['stockWarning'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//取库存数量少于告警数量 的itemId
|
|
|
$itemIds = [];
|
|
|
- foreach ($productItemStock as $k=>$v){
|
|
|
- $stockWaring = $itemStockWaring[$k]??0;
|
|
|
- if($v < $stockWaring) {
|
|
|
+ foreach ($productItemStock as $k => $v) {
|
|
|
+ $stockWaring = $itemStockWaring[$k] ?? 0;
|
|
|
+ if ($v < $stockWaring) {
|
|
|
$itemIds[] = $k;
|
|
|
}
|
|
|
}
|
|
|
@@ -380,15 +387,15 @@ class ProductClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
//获取当前门店下商品信息 linqh 2021.1.28
|
|
|
- public static function getProductData($id,$shopId,$obj=false)
|
|
|
+ public static function getProductData($id, $shopId, $obj = false)
|
|
|
{
|
|
|
- return ProductClass::getByCondition(['id'=>$id,'shopId'=>$shopId],$obj);
|
|
|
+ return ProductClass::getByCondition(['id' => $id, 'shopId' => $shopId], $obj);
|
|
|
}
|
|
|
|
|
|
//修改价格 linqh 2021.1.28
|
|
|
- public static function changePrice($id,$shopId,$price,$priceLabel)
|
|
|
+ public static function changePrice($id, $shopId, $price, $priceLabel)
|
|
|
{
|
|
|
- return ProductClass::updateByCondition(['id'=>$id,'shopId'=>$shopId],['price'=>$price,'priceLabel'=>$priceLabel]);
|
|
|
+ return ProductClass::updateByCondition(['id' => $id, 'shopId' => $shopId], ['price' => $price, 'priceLabel' => $priceLabel]);
|
|
|
}
|
|
|
|
|
|
//下单时计算商品的价格 linqh 2021.1.28
|
|
|
@@ -397,26 +404,26 @@ class ProductClass extends BaseClass
|
|
|
public static function computedPriceByItemInfo(array $itemInfo)
|
|
|
{
|
|
|
$data = [];
|
|
|
- if(empty($itemInfo)){
|
|
|
+ if (empty($itemInfo)) {
|
|
|
return $data;
|
|
|
}
|
|
|
$productIds = array_column($itemInfo, 'productId');
|
|
|
$productData = ProductClass::getProductByIds($productIds);
|
|
|
$productData = array_column($productData, NULL, 'id');
|
|
|
|
|
|
- $itemIds = array_column($productData,'itemId');
|
|
|
+ $itemIds = array_column($productData, 'itemId');
|
|
|
$itemData = xhItemService::getByIds($itemIds);
|
|
|
$itemData = array_column($itemData, NULL, 'id');
|
|
|
- foreach ($itemInfo as $v){
|
|
|
+ foreach ($itemInfo as $v) {
|
|
|
$productId = $v['productId'];
|
|
|
- $itemId = $productData[$productId]['itemId']??0;
|
|
|
- $unitNum = $itemData[$itemId]['unitNum']??0;
|
|
|
+ $itemId = $productData[$productId]['itemId'] ?? 0;
|
|
|
+ $unitNum = $itemData[$itemId]['unitNum'] ?? 0;
|
|
|
//大小数量合并多少扎
|
|
|
- $itemNum = self::mergeItemNum($v['bigNum'],$v['smallNum'],$unitNum);
|
|
|
+ $itemNum = self::mergeItemNum($v['bigNum'], $v['smallNum'], $unitNum);
|
|
|
//售卖价格
|
|
|
- $itemPrice = $productData[$productId]['price']??0;
|
|
|
+ $itemPrice = $productData[$productId]['price'] ?? 0;
|
|
|
//合计价格
|
|
|
- $price = bcmul($itemNum,$itemPrice,2);
|
|
|
+ $price = bcmul($itemNum, $itemPrice, 2);
|
|
|
$tmp = [];
|
|
|
$tmp['productId'] = $productId;
|
|
|
$tmp['price'] = $price;
|