|
|
@@ -388,4 +388,38 @@ class ProductClass extends BaseClass
|
|
|
return ProductClass::updateByCondition(['id'=>$id,'shopId'=>$shopId],['price'=>$price]);
|
|
|
}
|
|
|
|
|
|
+ //下单时计算商品的价格 linqh 2021.1.28
|
|
|
+ //itemInfo : [{"productId":3,"bigNum":1,"smallNum":2},{"productId":4,"bigNum":1,"smallNum":5}]
|
|
|
+ //返回 [{"productId":3,"price":2.1}]
|
|
|
+ public static function computedPriceByItemInfo(array $itemInfo)
|
|
|
+ {
|
|
|
+ $data = [];
|
|
|
+ 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');
|
|
|
+ $itemData = xhItemService::getByIds($itemIds);
|
|
|
+ $itemData = array_column($itemData, NULL, 'id');
|
|
|
+ foreach ($itemInfo as $v){
|
|
|
+ $productId = $v['productId'];
|
|
|
+ $itemId = $productData[$productId]['itemId']??0;
|
|
|
+ $unitNum = $itemData[$itemId]['unitNum']??0;
|
|
|
+ //大小数量合并多少扎
|
|
|
+ $itemNum = self::mergeItemNum($v['bigNum'],$v['smallNum'],$unitNum);
|
|
|
+ //售卖价格
|
|
|
+ $itemPrice = $productData[$productId]['price']??0;
|
|
|
+ //合计价格
|
|
|
+ $price = bcmul($itemNum,$itemPrice,2);
|
|
|
+ $tmp = [];
|
|
|
+ $tmp['productId'] = $productId;
|
|
|
+ $tmp['price'] = $price;
|
|
|
+ $data[] = $tmp;
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
}
|