修改自营门店价格

This commit is contained in:
lewis 2025-01-21 16:37:04 +08:00
parent 393659cdf5
commit 92c0eac1fc
4 changed files with 41 additions and 28 deletions

View File

@ -13,6 +13,7 @@ use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
/**
@ -67,31 +68,31 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
$off_activity = Config::where('name', 'off_activity')->value('value');
$user_ship = User::where('id', $userId)->value('user_ship');
$field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
if (in_array($user_ship, [4, 6, 7])) {
if (in_array($user_ship, [4, 6, 7]) && !empty($this->params['store_id']) && !SystemStore::isSelfOperate($this->params['store_id'])) {
$field = 'id,id product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
}
$this->user_ship = $user_ship;
$this->off_activity = $off_activity;
foreach ($list as $key => &$item) {
$find = StoreProduct::where(['id' => $item['product_id']])
$product = StoreProduct::where(['id' => $item['product_id']])
->field($field)
->find();
$find = StoreProductGroupPrice::resetProductPrice($find, $user_ship);
if ($find) {
$product = StoreProductGroupPrice::resetStoreProductPrice($product, $user_ship, $this->params['store_id'] ?? 0);
if ($product) {
if ($off_activity == 1) {
$this->activity_price = bcadd(bcmul($find['cost'], $item['cart_num'], 2), $this->activity_price, 2);
$this->activity_price = bcadd(bcmul($product['cost'], $item['cart_num'], 2), $this->activity_price, 2);
}
if ($off_activity == 0 && $user_ship == 5 && $find['top_cate_id'] == 15189) {
$find['price'] = $find['cost'];
if ($off_activity == 0 && $user_ship == 5 && $product['top_cate_id'] == 15189) {
$product['price'] = $product['cost'];
}
$item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2);
$item['goods_total_price'] = bcmul($item['cart_num'], $product['price'], 2);
$this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2);
$item['batch'] = $find['batch'];
$item['imgs'] = $find['image'];
$item['price'] = $find['price'];
$item['cost'] = $find['cost'];
$item['goods_name'] = $find['store_name'];
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
$item['batch'] = $product['batch'];
$item['imgs'] = $product['image'];
$item['price'] = $product['price'];
$item['cost'] = $product['cost'];
$item['goods_name'] = $product['store_name'];
$item['unit_name'] = StoreProductUnit::where('id', $product['unit'])->value('name');
}
}
return $list;

View File

@ -129,7 +129,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
return $item;
})
->toArray();
$list = StoreProductGroupPrice::resetStoreProductPrice($list, $user_ship, $this->params['store_id'] ?? 0);
$list = StoreProductGroupPrice::resetStoreProductsPrice($list, $user_ship, $this->params['store_id'] ?? 0);
return $list;
}

View File

@ -42,7 +42,7 @@ class StoreProductGroupPrice extends BaseModel
return $product;
}
public static function resetStoreProductPrice($productList, $userShip, $shopId)
public static function resetStoreProductsPrice($productList, $userShip, $shopId)
{
if ($shopId > 0 && SystemStore::isSelfOperate($shopId) && $userShip > 0) {
foreach ($productList as &$item) {
@ -53,5 +53,15 @@ class StoreProductGroupPrice extends BaseModel
return self::resetProductsPrice($productList, $userShip);
}
}
public static function resetStoreProductPrice($product, $userShip, $shopId)
{
if ($shopId > 0 && SystemStore::isSelfOperate($shopId) && $userShip > 0) {
$product['price'] = $product['vip_price'] > 0 ? $product['vip_price'] : $product['price'];
return $product;
} else {
return self::resetProductPrice($product, $userShip);
}
}
}

View File

@ -11,6 +11,7 @@ use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStoreStaff;
use app\common\model\user\User;
use app\common\lists\ListsExtendInterface;
use app\common\model\store_product\StoreProduct;
@ -57,6 +58,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
return $item;
})
->toArray();
$storeId = SystemStoreStaff::where('id', $this->adminId)->value('store_id');
$off_activity = Config::where('name', 'off_activity')->value('value');
$off_activity = 0;
$this->off_activity = $off_activity;
@ -72,28 +74,28 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
// }
}
foreach ($list as $key => &$item) {
$find = StoreProduct::where(['id' => $item['product_id']])
$product = StoreProduct::where(['id' => $item['product_id']])
->field('id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id')
->find();
if ($find) {
$find = StoreProductGroupPrice::resetProductPrice($find, $user_ship);
if ($product) {
$product = StoreProductGroupPrice::resetStoreProductPrice($product, $user_ship, $storeId);
if ($off_activity == 1) {
$this->activity_price = bcadd(bcmul($find['cost'], $item['cart_num'], 2), $this->activity_price, 2);
$item['price'] = $find['cost'];
$this->activity_price = bcadd(bcmul($product['cost'], $item['cart_num'], 2), $this->activity_price, 2);
$item['price'] = $product['cost'];
} else {
$item['price'] = $find['price'];
$item['price'] = $product['price'];
if ($user_ship==4) {
$item['price'] = $find['cost'];
$item['price'] = $product['cost'];
}
}
$item['pay_price'] = bcmul($item['cart_num'], $item['price'], 2);
$item['total_price'] = bcmul($item['cart_num'], $find['price'], 2);
$item['total_price'] = bcmul($item['cart_num'], $product['price'], 2);
$this->total_price = bcadd($this->total_price, $item['total_price'], 2);
$this->pay_price = bcadd($this->pay_price, $item['pay_price'], 2);
$item['image'] = $find['image'];
$item['cost'] = $find['cost'];
$item['store_name'] = $find['store_name'];
$unit = StoreProductUnit::where('id', $find['unit'])->find();
$item['image'] = $product['image'];
$item['cost'] = $product['cost'];
$item['store_name'] = $product['store_name'];
$unit = StoreProductUnit::where('id', $product['unit'])->find();
if($unit){
$item['unit_name']=$unit['name'];
$item['is_bulk']=$unit['is_bulk'];