feat: 增加会员折扣功能
This commit is contained in:
parent
69236a50d2
commit
ae5f0044b3
@ -13,6 +13,7 @@ use app\common\logic\PayNotifyLogic;
|
|||||||
use app\common\model\dict\DictData;
|
use app\common\model\dict\DictData;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\model\system_store\SystemStoreStaff;
|
use app\common\model\system_store\SystemStoreStaff;
|
||||||
|
use app\common\model\user\User;
|
||||||
use app\common\model\user\UserAddress;
|
use app\common\model\user\UserAddress;
|
||||||
use Webman\RedisQueue\Redis;
|
use Webman\RedisQueue\Redis;
|
||||||
use hg\apidoc\annotation as ApiDoc;
|
use hg\apidoc\annotation as ApiDoc;
|
||||||
@ -141,7 +142,8 @@ class OrderController extends BaseApiController
|
|||||||
// $pay_type = (int)$this->request->post('pay_type');
|
// $pay_type = (int)$this->request->post('pay_type');
|
||||||
// $auth_code = $this->request->post('auth_code'); //微信支付条码
|
// $auth_code = $this->request->post('auth_code'); //微信支付条码
|
||||||
$params = $this->request->post();
|
$params = $this->request->post();
|
||||||
$res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, null, $params);
|
$user=User::where('id',$this->userId)->find();
|
||||||
|
$res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params);
|
||||||
if ($res == false) {
|
if ($res == false) {
|
||||||
$msg = OrderLogic::getError();
|
$msg = OrderLogic::getError();
|
||||||
if ($msg == '购物车为空') {
|
if ($msg == '购物车为空') {
|
||||||
|
@ -61,17 +61,16 @@ class OrderLogic extends BaseLogic
|
|||||||
self::setError('购物车为空');
|
self::setError('购物车为空');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
// try {
|
||||||
self::$total_price = 0;
|
self::$total_price = 0;
|
||||||
self::$pay_price = 0;
|
self::$pay_price = 0;
|
||||||
self::$cost = 0; //成本
|
self::$cost = 0; //成本
|
||||||
self::$profit = 0; //利润
|
self::$profit = 0; //利润
|
||||||
self::$activity_price = 0; //活动减少
|
self::$activity_price = 0; //活动减少
|
||||||
|
|
||||||
/** 计算价格 */
|
/** 计算价格 */
|
||||||
$check = DictType::where('type', 'activities')->find();
|
|
||||||
foreach ($cart_select as $k => $v) {
|
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,cost,product_id')->find();
|
$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,product_id')->find();
|
||||||
if (!$find) {
|
if (!$find) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -80,16 +79,16 @@ class OrderLogic extends BaseLogic
|
|||||||
$cart_select[$k]['price'] = $find['price'];
|
$cart_select[$k]['price'] = $find['price'];
|
||||||
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
|
$cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价
|
||||||
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
|
$cart_select[$k]['deduction_price'] =self::$activity_price;//抵扣金额
|
||||||
if (isset($check) && $check['status'] == 1) {
|
if ($user && $user['user_ship'] >= 1) {
|
||||||
//零售价*折扣率
|
$deduction_price_count=bcmul(bcsub($find['price'], $find['vip_price'], 2),$v['cart_num'],2);
|
||||||
$activity_price = bcmul($find['price'], 0.9, 2);
|
|
||||||
$deduction_price_count=bcmul(bcsub($find['price'], $activity_price, 2),$v['cart_num'], 2);
|
|
||||||
$cart_select[$k]['deduction_price'] =$deduction_price_count;
|
$cart_select[$k]['deduction_price'] =$deduction_price_count;
|
||||||
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
|
self::$activity_price = bcadd(self::$activity_price, $deduction_price_count, 2);
|
||||||
$find['price'] = $activity_price;
|
$onePrice = bcsub($find['vip_price'], $find['cost'], 2);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$onePrice = bcsub($find['price'], $find['cost'], 2);
|
||||||
}
|
}
|
||||||
//利润
|
//利润
|
||||||
$onePrice = bcsub($find['price'], $find['cost'], 2);
|
|
||||||
$cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
|
$cart_select[$k]['profit'] = bcmul($v['cart_num'], $onePrice, 2); //利润
|
||||||
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //成本
|
$cart_select[$k]['cost'] = bcmul($v['cart_num'], $find['cost'], 2) ?? 0; //成本
|
||||||
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
|
$cart_select[$k]['pay_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单支付金额
|
||||||
@ -115,8 +114,7 @@ class OrderLogic extends BaseLogic
|
|||||||
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
|
self::$cost = bcadd(self::$cost, $cart_select[$k]['cost'], 2);
|
||||||
self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
|
self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2);
|
||||||
}
|
}
|
||||||
//TODO 收单打9.9折 会员按照比例打折 等级按照充值去升级
|
$pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额
|
||||||
$pay_price = self::$pay_price;
|
|
||||||
$vipPrice = 0;
|
$vipPrice = 0;
|
||||||
//成本价 收益
|
//成本价 收益
|
||||||
$order = [
|
$order = [
|
||||||
@ -135,7 +133,7 @@ class OrderLogic extends BaseLogic
|
|||||||
'shipping_type' => $params['shipping_type'] ?? 2, //配送方式 1=快递 ,2=门店自提
|
'shipping_type' => $params['shipping_type'] ?? 2, //配送方式 1=快递 ,2=门店自提
|
||||||
'activity' => '减免',
|
'activity' => '减免',
|
||||||
'activity_price' => self::$activity_price,
|
'activity_price' => self::$activity_price,
|
||||||
'activities' => $check['status'],
|
'activities' => self::$activity_price>0?1:0,
|
||||||
'deduction_price' => self::$activity_price
|
'deduction_price' => self::$activity_price
|
||||||
|
|
||||||
];
|
];
|
||||||
@ -143,10 +141,10 @@ class OrderLogic extends BaseLogic
|
|||||||
if ($params['store_id']) {
|
if ($params['store_id']) {
|
||||||
$order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
|
$order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
self::setError($e->getMessage());
|
// self::setError($e->getMessage());
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
return ['order' => $order, 'cart_list' => $cart_select];
|
return ['order' => $order, 'cart_list' => $cart_select];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user