feat: 修改商品列表和订单逻辑,根据配置计算价格和抵扣金额

This commit is contained in:
mkm 2024-06-24 18:14:56 +08:00
parent 4a3ba92035
commit 17697bf361
2 changed files with 30 additions and 16 deletions

View File

@ -10,6 +10,7 @@ use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface;
use app\common\model\cate\Cate;
use app\common\model\Config;
//use app\common\model\goods\GoodsLabel;
use think\facade\Db;
@ -102,11 +103,16 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
$this->searchWhere[] = ['cate_id','=',$class_all];
}
}
$off_activity=Config::where('name','off_activity')->value('value');
if($off_activity==1){
$field='id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch';
}else{
$field='id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch';
}
$this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[] = ['stock', '>', 0];
return StoreBranchProduct::where($this->searchWhere)
->field(['id', 'product_id', 'cate_id', 'store_name', 'cost', 'store_id','vip_price','purchase', 'price', 'bar_code', 'image', 'sales', 'store_info', 'delete_time', 'unit', 'batch'])
->field($field)
->with(['className', 'unitName'])
->limit($this->limitOffset, $this->limitLength)
->order($this->sortOrder)

View File

@ -10,6 +10,7 @@ use app\common\logic\BaseLogic;
use app\common\logic\CapitalFlowLogic;
use app\common\logic\PayNotifyLogic;
use app\common\logic\StoreFinanceFlowLogic;
use app\common\model\Config;
use app\common\model\dict\DictData;
use app\common\model\dict\DictType;
use app\common\model\order\Cart;
@ -73,9 +74,14 @@ class OrderLogic extends BaseLogic
self::$activity_price = 0; //活动减少
self::$store_price = 0; //门店零售价
/** 计算价格 */
$off_activity=Config::where('name','off_activity')->value('value');
if($off_activity==1){
$field='id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id';
}else{
$field='id branch_product_id,store_name,image,unit,cost price,vip_price,cost,purchase,product_id';
}
foreach ($cart_select as $k => $v) {
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field('id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id')->withTrashed()->find();
$find = StoreBranchProduct::where(['product_id' => $v['product_id'], 'store_id' => $params['store_id']])->field($field)->withTrashed()->find();
if (!$find) {
continue;
}
@ -86,18 +92,20 @@ class OrderLogic extends BaseLogic
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
$cart_select[$k]['vip'] = 0;
if ($user && $user['user_ship'] == 1) {
//更新 会员为1的时候原价减去会员价
$deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
$cart_select[$k]['vip'] =1;
}
if ($user && $user['user_ship'] == 4) {
//更新 为4商户的时候减去商户价格
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
if($off_activity!=1){
if ($user && $user['user_ship'] == 1) {
//更新 会员为1的时候原价减去会员价
$deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
$cart_select[$k]['vip'] =1;
}
if ($user && $user['user_ship'] == 4) {
//更新 为4商户的时候减去商户价格
$deduction_price_count=bcmul(bcsub($find['price'], $find['cost'], 2),$v['cart_num'],2);
$cart_select[$k]['deduction_price'] =$deduction_price_count;
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
}
}
//利润