Merge pull request 'dev' (#534) from dev into main

Reviewed-on: #534
This commit is contained in:
mkm 2025-02-25 11:56:08 +08:00
commit 24ba8d7d6d

View File

@ -4,6 +4,7 @@ namespace app\common\model\store_product_group_price;
use app\common\model\BaseModel;
use app\common\model\store_product_price\StoreProductPrice;
use app\common\model\system_store\SystemStore;
use think\model\concern\SoftDelete;
@ -23,11 +24,19 @@ class StoreProductGroupPrice extends BaseModel
public static function resetProductsPrice($productList, $userShip)
{
$productIds = array_column($productList, 'product_id');
$groupPrices = StoreProductGroupPrice::where('group_id', $userShip)->whereIn('product_id', $productIds)->column('product_id,price_type,base_rate,price');
$groupPrices = StoreProductPrice::whereIn('product_id', $productIds)->column('product_id,purchase,cost,vip_price,price');
$groupPrices = reset_index($groupPrices, 'product_id');
foreach ($productList as &$item) {
if (isset($groupPrices[$item['product_id']])) {
$item['price'] = $groupPrices[$item['product_id']]['price'];
$groupPrice = $groupPrices[$item['product_id']] ?? [];
if (empty($groupPrice)) {
continue;
}
if ($userShip == 4) {
$item['price'] = $groupPrice['cost'];
} elseif ($userShip == 0) {
$item['price'] = $groupPrice['price'];
} else {
$item['price'] = $groupPrice['vip_price'];
}
}
return $productList;
@ -35,9 +44,15 @@ class StoreProductGroupPrice extends BaseModel
public static function resetProductPrice($product, $userShip)
{
$groupPrice = StoreProductGroupPrice::where('group_id', $userShip)->whereIn('product_id', $product['id'])->field('product_id,price_type,base_rate,price')->find();
$groupPrice = StoreProductPrice::whereIn('product_id', $product['id'])->field('product_id,purchase,cost,vip_price,price')->find();
if (!empty($groupPrice) && $groupPrice['product_id'] == $product['id']) {
$product['price'] = $groupPrice['price'];
if ($userShip == 4) {
$product['price'] = $groupPrice['cost'];
} elseif ($userShip == 0) {
$product['price'] = $groupPrice['price'];
} else {
$product['price'] = $groupPrice['vip_price'];
}
}
return $product;
}