feat: 新增用户运费和优惠活动判断逻辑

This commit is contained in:
mkm 2024-07-09 17:04:53 +08:00
parent a8fa7dd540
commit 21b36295d9
3 changed files with 21 additions and 29 deletions

View File

@ -25,6 +25,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
protected $total_price = 0;
protected $activity_price = 0;
protected $off_activity = 0;
protected $user_ship = 0;
/**
@ -63,11 +64,12 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
})
->toArray();
$off_activity = Config::where('name', 'off_activity')->value('value');
$this->off_activity=$off_activity;
$user_ship = User::where('id', $userId)->value('user_ship');
if (in_array($user_ship, [4, 5, 6, 7])) {
$off_activity=1;
}
$this->user_ship=$user_ship;
$this->off_activity=$off_activity;
foreach ($list as $key => &$item) {
$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')
@ -112,17 +114,24 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
$data= [
'off_activity' => $this->off_activity,
'total_price' => $this->total_price,
'msg' => '您已选购满500元支付成功后即可获得'.bcmul($this->total_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。',
'msg' => '',
'pay_price' => $this->total_price
];
if($this->user_ship==0){
$data['msg']='您已选购满500元支付成功后即可获得'.bcmul($this->total_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。';
}
if($this->off_activity==0){//1
$this->activity_price = $this->total_price;
$data['pay_price']=$this->activity_price;
if($this->activity_price<500){
$data['msg']='还差'.bcsub(500,$this->activity_price,2).'即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。';
if($this->user_ship==0){
$data['msg']='还差'.bcsub(500,$this->activity_price,2).'即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。';
}
$data['pay_price']= $this->activity_price;
}else{
$data['msg']= '您已选购满500元支付成功后即可获得'.bcmul($this->activity_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。';
if($this->user_ship==0){
$data['msg']= '您已选购满500元支付成功后即可获得'.bcmul($this->activity_price,0.1,2).'元品牌礼品兑换券,可到线下门店兑换礼品。';
}
}
}
return $data;

View File

@ -23,7 +23,8 @@ use think\facade\Db;
*/
class ProductLists extends BaseApiDataLists implements ListsSearchInterface, ListsSortInterface, ListsExtendInterface
{
protected $off_activity = 0;
protected $user_ship = 0;
/**
* @notes 设置搜索条件
@ -79,7 +80,8 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
$order = [$field => $order];
}
$fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock';
$off_activity = Config::where('name', 'off_activity')->value('value');
$this->off_activity = $off_activity;
$this->searchWhere[] = ['status', '=', 1];
// $this->searchWhere[] = ['stock', '>', 0];
return StoreBranchProduct::where($this->searchWhere)
@ -107,27 +109,12 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
{
$price = 'price';
$op_price = 'price';
$off_activity = 0;
$uid=0;
if($this->request->get('uid')){
$uid=$this->request->get('uid');
}elseif($this->userId>0){
$uid=$this->userId;
}
if ($uid > 0) {
$user_ship = User::where('id', $uid)->value('user_ship');
if (in_array($user_ship, [4, 5, 6, 7])) {
$price = 'cost';
$op_price = 'price';
}
}
$off_activity = Config::where('name', 'off_activity')->value('value');
if ($off_activity == 1) {
if ($this->off_activity == 1) {
$price = 'cost';
$op_price = 'price';
}
$data = [
'off_activity' => $off_activity,
'off_activity' => $this->off_activity,
'price' => $price,
'op_price' => $op_price,
];

View File

@ -94,14 +94,10 @@ class OrderLogic extends BaseLogic
}
unset($cart_select[$k]['id']);
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
if ($off_activity == 1) {
if ($off_activity == 1 || in_array($user['user_ship'], [4, 5, 6, 7])) {
$price = $find['cost'];
} else {
if ($user && in_array($user['user_ship'], [4, 5, 6, 7])) {
$price = $find['cost'];
} else {
$price = $find['price'];
}
$price = $find['price'];
}
$cart_select[$k]['price'] = $price;
$cart_select[$k]['cost'] = $find['cost'];