feat(CartList): 添加满减活动逻辑和会员价格计算
This commit is contained in:
parent
3c2f945514
commit
af396c6b16
@ -39,6 +39,7 @@ class StoreProductLogic extends BaseLogic
|
|||||||
$data = [
|
$data = [
|
||||||
'store_name' => $params['store_name'],
|
'store_name' => $params['store_name'],
|
||||||
'image' => $params['image'],
|
'image' => $params['image'],
|
||||||
|
'store_info' => $params['store_info'] ?? '',
|
||||||
'bar_code' => $params['bar_code'] ?? '',
|
'bar_code' => $params['bar_code'] ?? '',
|
||||||
'cate_id' => $params['cate_id'],
|
'cate_id' => $params['cate_id'],
|
||||||
'unit' => $params['unit'],
|
'unit' => $params['unit'],
|
||||||
@ -140,6 +141,7 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'store_name' => $params['store_name'],
|
'store_name' => $params['store_name'],
|
||||||
'image' => $params['image'],
|
'image' => $params['image'],
|
||||||
'bar_code' => $params['bar_code'] ?? '',
|
'bar_code' => $params['bar_code'] ?? '',
|
||||||
|
'store_info' => $params['store_info'] ?? '',
|
||||||
'cate_id' => $params['cate_id'],
|
'cate_id' => $params['cate_id'],
|
||||||
'unit' => $params['unit'],
|
'unit' => $params['unit'],
|
||||||
'stock' => $params['stock'],
|
'stock' => $params['stock'],
|
||||||
@ -181,6 +183,7 @@ class StoreProductLogic extends BaseLogic
|
|||||||
'cost' => $params['cost'],'unit'=>$params['unit'],
|
'cost' => $params['cost'],'unit'=>$params['unit'],
|
||||||
'batch'=>$params['batch'],'store_name'=>$params['store_name'],
|
'batch'=>$params['batch'],'store_name'=>$params['store_name'],
|
||||||
'manufacturer_information' => $params['manufacturer_information']??'',
|
'manufacturer_information' => $params['manufacturer_information']??'',
|
||||||
|
'store_info' => $params['store_info']??'',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
|
@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists;
|
|||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
use app\common\model\order\Cart;
|
use app\common\model\order\Cart;
|
||||||
use app\common\lists\ListsExtendInterface;
|
use app\common\lists\ListsExtendInterface;
|
||||||
|
use app\common\model\Config;
|
||||||
use app\common\model\dict\DictType;
|
use app\common\model\dict\DictType;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||||
@ -23,6 +24,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
|
|||||||
|
|
||||||
protected $total_price = 0;
|
protected $total_price = 0;
|
||||||
protected $activity_price = 0;
|
protected $activity_price = 0;
|
||||||
|
protected $off_activity = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,27 +62,33 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
|
|||||||
return $item;
|
return $item;
|
||||||
})
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
// $check = DictType::where('type', 'activities')->find();
|
$off_activity = Config::where('name', 'off_activity')->value('value');
|
||||||
|
$this->off_activity=$off_activity;
|
||||||
$user = User::where('id', $userId)->find();
|
$user = User::where('id', $userId)->find();
|
||||||
foreach ($list as $key => &$item) {
|
foreach ($list as $key => &$item) {
|
||||||
|
|
||||||
$find = StoreBranchProduct::where(['product_id' => $item['product_id'],'store_id' => $item['store_id']])
|
$find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']])
|
||||||
->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price')
|
->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price')
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->find();
|
->find();
|
||||||
|
|
||||||
if ($find) {
|
if ($find) {
|
||||||
if ($user && $user['user_ship'] == 1) {
|
if($off_activity==1){
|
||||||
//更新 会员为1的时候原价减去会员价
|
$this->activity_price = bcadd(bcmul($item['cost'],$item['cart_num'], 2), $this->activity_price, 2);
|
||||||
$deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$item['cart_num'],2);
|
|
||||||
$this->activity_price = bcadd($this->activity_price, $deduction_price_count, 2);
|
|
||||||
}elseif ($user && $user['user_ship'] == 4) {
|
|
||||||
//更新 为4商户的时候减去商户价格
|
|
||||||
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$item['cart_num'],2);
|
|
||||||
$this->activity_price = bcadd( $this->activity_price, $deduction_price_count, 2);
|
|
||||||
}else{
|
}else{
|
||||||
$this->activity_price =0;
|
if ($user && $user['user_ship'] == 1) {
|
||||||
|
//更新 会员为1的时候原价减去会员价
|
||||||
|
$deduction_price_count = bcmul(bcsub($find['price'], $find['vip_price'], 2), $item['cart_num'], 2);
|
||||||
|
$this->activity_price = bcadd($this->activity_price, $deduction_price_count, 2);
|
||||||
|
} elseif ($user && $user['user_ship'] == 4) {
|
||||||
|
//更新 为4商户的时候减去商户价格
|
||||||
|
$deduction_price_count = bcmul(bcsub($find['price'], $find['cost'], 2), $item['cart_num'], 2);
|
||||||
|
$this->activity_price = bcadd($this->activity_price, $deduction_price_count, 2);
|
||||||
|
} else {
|
||||||
|
$this->activity_price = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2);
|
$item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2);
|
||||||
$this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2);
|
$this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2);
|
||||||
$item['imgs'] = $find['image'];
|
$item['imgs'] = $find['image'];
|
||||||
@ -111,10 +119,19 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
|
|||||||
|
|
||||||
public function extend()
|
public function extend()
|
||||||
{
|
{
|
||||||
return [
|
$data= [
|
||||||
|
'off_activity' => $this->off_activity,
|
||||||
'total_price' => $this->total_price,
|
'total_price' => $this->total_price,
|
||||||
'activity_price' => $this->activity_price,
|
'activity_price' => $this->activity_price,
|
||||||
'pay_price'=> bcsub($this->total_price, $this->activity_price, 2)
|
'msg' => '',
|
||||||
|
'pay_price' => bcsub($this->total_price, $this->activity_price, 2)
|
||||||
];
|
];
|
||||||
|
if($this->off_activity==1){
|
||||||
|
$data['pay_price']=$this->activity_price;
|
||||||
|
if($this->activity_price<500){
|
||||||
|
$data['msg']='还差'.bcsub(500,$this->activity_price,2).'元可参与满减活动';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user