This commit is contained in:
manghe 2025-03-23 18:55:08 +00:00
parent 1c78652e88
commit 06f919c6f8
2 changed files with 209 additions and 112 deletions

View File

@ -17,8 +17,8 @@ class Config extends Base
{
// 查询盒子类型数据
$goodsTypeList = Db::name('goods_type')
->field('value, sort_order, name')
->where('is_show', 1)
->field('value, sort_order,is_show, name,pay_wechat,pay_balance,pay_currency,pay_currency2,pay_coupon,is_deduction')
// ->where('is_show', 1)
->order('sort_order')
->select()
->toArray();

View File

@ -20,6 +20,7 @@ use think\facade\Db;
use \think\Request;
use app\common\model\CouponReceive as CouponReceiveModel;
use app\common\model\UserCoupon;
use app\common\model\GoodsType;
class Goods extends Base
{
@ -517,14 +518,21 @@ class Goods extends Base
$num = request()->param('goods_num/d', 0); #第几箱
$use_money_is = request()->param('use_money_is/d', 0); #0不抵扣 1抵扣
$use_integral_is = request()->param('use_integral_is/d', 0); #0不抵扣 1抵扣
$use_money2_is = request()->param('use_money2_is/d', 0); #0不抵扣 1抵扣 货币2抵扣
$coupon_id = request()->param('coupon_id/d', 0); //优惠券
#盒子信息
$goods = Goodsmodel::field('title,imgurl_detail,type,price,status,is_shou_zhe,quanju_xiangou')->where(['id' => $goods_id])
$goods = Goodsmodel::field('title,imgurl_detail,type,price,status,is_shou_zhe,quanju_xiangou,lock_is,choujiang_xianzhi,lock_time')->where(['id' => $goods_id])
->find();
if (!$goods) {
return $this->renderError("盒子不存在");
}
# 获取盒子类型配置
$goodsType = \app\common\model\GoodsType::where('value', $goods['type'])->find();
if (!$goodsType) {
return $this->renderError("盒子类型配置不存在");
}
if ($goods['status'] != 1) {
return $this->renderError("盒子已下架");
}
@ -569,6 +577,7 @@ class Goods extends Base
$box_price = $goods['price'];
//是否首抽五折
$shou_zhe_price = 0;
$is_shou_zhe = 0;
if ($goods['type'] != 5 && $goods['type'] != 10) {
$is_chou = Order::field('id')->where([['user_id', '=', $user['id']], ['status', '=', 1]])->find();
$is_chou2 = Order::field('id')->where([['is_shou_zhe', '=', 1], ['status', '=', 1], ['user_id', '=', $user['id']]])->find();
@ -584,77 +593,120 @@ class Goods extends Base
#使用优惠券
$coupon_price = 0;
# 判断是否可使用优惠券
if ($shou_zhe_price <= 0 && !empty($coupon_id) && $goodsType['pay_coupon'] == 1) {
# 获取优惠券信息
$coupon = CouponReceiveModel::where([
'id' => $coupon_id,
'status' => 0,
'user_id' => $user['id']
])->where('man_price', '<=', $price)
->where('end_time', '>', time()) # 确保优惠券未过期
->find();
if ($shou_zhe_price <= 0 && !empty($coupon_id) && $goods['type'] != 5 && $goods['type'] != 10) {
$coupon = CouponReceiveModel::where(['id' => $coupon_id, 'status' => 0, 'user_id' => $user['id']])->where('man_price', '<=', $price)->find();
if ($coupon) {
$coupon_price = $coupon['price'];
} else {
$coupon_id = 0;
}
} else {
$coupon_id = 0;
}
$price = bcsub("$price", "$coupon_price", 2);
if ($price <= 0) {
$price = 0;
}
$order_zhe_total = $price;
if ($goods['type'] == 10) {
$use_integral_is = 0;
}
if ($goods['type'] == 1 || $goods['type'] == 3 || $goods['type'] == 6 || $goods['type'] == 11 || $goods['type'] == 10) {
$zhe = 0;
if ($shou_zhe_price <= 0) {
$vip_info = UserVip::where(['id' => $user['vip']])->find();
if ($vip_info && $vip_info['discount'] > 0 && $goods['type'] != 10) {
$zhe = $vip_info['discount'];
$zhe_bl = bcdiv("$zhe", "10", 2);
$order_zhe_total = $price = bcmul("$price", "$zhe_bl", 2);
}
#吧唧币抵扣
$use_integral = 0;
if ($use_integral_is == 1 && $goods['type'] != 10) {
$price = $price * 100;
if ($user['integral'] >= $price) {
$use_integral = $price;
# 初始化变量
$use_money = 0; # 余额抵扣
$use_integral = 0; # 货币1抵扣
$use_money2 = 0; # 货币2抵扣
$zhe = 0; # 会员折扣
if ($shou_zhe_price <= 0) {
$iszhifu = 0;
# 货币1抵扣
if ($use_integral_is == 1 && $goodsType['pay_currency'] == 1) {
$price_in_currency = $price * 100; # 1:100比例
if ($goodsType['is_deduction'] == 1) {
# 抵扣模式
if ($user['integral'] >= $price_in_currency) {
$use_integral = $price_in_currency;
$price = 0;
} else {
$use_integral = $user['integral'];
$price = bcsub("$price", "{$user['integral']}", 2);
$price = bcsub("$price", bcdiv("$use_integral", "100", 2), 2);
}
} else {
# 支付模式
if ($user['integral'] >= $price_in_currency) {
$use_integral = $price_in_currency;
$price = 0;
$iszhifu++;
} else {
# 支付模式下货币不足无法抵扣
$use_integral = 0;
return $this->renderError('金额不足');
}
$price = $price / 100;
}
#余额抵扣
$use_money = 0;
if ($use_money_is == 1) {
}
# 余额抵扣
if ($use_money_is == 1 && $goodsType['pay_balance'] == 1) {
if ($goodsType['is_deduction'] == 1) {
# 抵扣模式
if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
} else {
$use_money = $user['money'];#
$price = bcsub("$price", "{$user['money']}", 2);
$use_money = $user['money'];
$price = bcsub("$price", "$use_money", 2);
}
} else {
# 支付模式
if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
$iszhifu++;
} else {
# 支付模式下余额不足无法抵扣
$use_money = 0;
return $this->renderError('金额不足');
}
}
} else {
$use_integral = 0;
$use_money = 0;
}
$use_score = 0;
} elseif ($goods['type'] == 5) {
#折扣
$zhe = 0;
#微信支付
$price = 0;
#吧唧币抵扣
$use_integral = 0;
#余额抵扣
$use_money = 0;
#积分
$use_score = $order_total;
} else {
return $this->renderError("非法请求");
# 货币2抵扣
if ($use_money2_is == 1 && $goodsType['pay_currency2'] == 1) {
$price_in_currency2 = $price * 100; # 1:100比例
if ($goodsType['is_deduction'] == 1) {
# 抵扣模式
if (isset($user['money2']) && $user['money2'] >= $price_in_currency2) {
$use_money2 = $price_in_currency2;
$price = 0;
} else if (isset($user['money2'])) {
$use_money2 = $user['money2'];
$price = bcsub("$price", bcdiv("$use_money2", "100", 2), 2);
}
} else {
# 支付模式
if (isset($user['money2']) && $user['money2'] >= $price_in_currency2) {
$use_money2 = $price_in_currency2;
$price = 0;
$iszhifu++;
} else {
# 支付模式下货币2不足无法抵扣
$use_money2 = 0;
return $this->renderError('金额不足');
}
}
}
if ($goodsType['is_deduction'] == 0 && $iszhifu == 0 && $goodsType['pay_wechat'] == 0) {
return $this->renderError('请选择支付方式');
}
}
#抽奖数量
$goods['prize_num'] = $prize_num;
@ -669,8 +721,8 @@ class Goods extends Base
'use_integral_money' => round(round($use_integral, 2) / 100, 2),
'money' => round($user['money'], 2),
'use_money' => round($use_money, 2),
'score' => $user['score'],
'use_score' => $use_score,
'score' => $user['money2'],
'use_score' => $use_money2,
'coupon_price' => round($coupon_price, 2),
'coupon_id' => $coupon_id
];
@ -679,7 +731,7 @@ class Goods extends Base
/**
* 下单计算金额
* 创建订单
*/
public function orderbuy()
{
@ -693,18 +745,25 @@ class Goods extends Base
$num = request()->param('goods_num/d', 0); #第几箱
$use_money_is = request()->param('use_money_is/d', 0); #0不抵扣 1抵扣 余额抵扣
$use_integral_is = request()->param('use_integral_is/d', 0); #0不抵扣 1抵扣 货币1抵扣
$use_money2_is = request()->param('use_integral_is/d', 0); #0不抵扣 1抵扣 货币2抵扣
$use_money2_is = request()->param('use_money2_is/d', 0); #0不抵扣 1抵扣 货币2抵扣
$coupon_id = request()->param('coupon_id/d', 0); //优惠券
#盒子信息
$goods = Goodsmodel::field('title,imgurl_detail,type,price,status,lock_is,choujiang_xianzhi,lock_time,is_shou_zhe')->where(['id' => $goods_id])
$goods = Goodsmodel::field('title,imgurl_detail,type,price,status,is_shou_zhe,quanju_xiangou,lock_is,choujiang_xianzhi,lock_time')->where(['id' => $goods_id])
->find();
if (!$goods) {
return $this->renderError("盒子不存在");
}
# 获取盒子类型配置
$goodsType = \app\common\model\GoodsType::where('value', $goods['type'])->find();
if (!$goodsType) {
return $this->renderError("盒子类型配置不存在");
}
if ($goods['status'] != 1) {
return $this->renderError("盒子已下架");
}
$goods['imgurl_detail'] = imageUrl($goods['imgurl_detail']);
if (RegInt($num)) {
return $this->renderError("箱号选择错误");
}
@ -792,8 +851,18 @@ class Goods extends Base
$order_total = $order_zhe_total = $price;
#使用优惠券
$coupon_price = 0;
if ($shou_zhe_price <= 0 && !empty($coupon_id) && $goods['type'] != 5 && $goods['type'] != 10) {
$coupon = CouponReceiveModel::where(['id' => $coupon_id, 'status' => 0, 'user_id' => $user['id']])->where('man_price', '<=', $price)->find();
# 判断是否可使用优惠券
if ($shou_zhe_price <= 0 && !empty($coupon_id) && $goods['type'] != 5 && $goods['type'] != 10 && $goodsType['pay_coupon'] == 1) {
# 获取优惠券信息
$coupon = CouponReceiveModel::where([
'id' => $coupon_id,
'status' => 0,
'user_id' => $user['id']
])->where('man_price', '<=', $price)
->where('end_time', '>', time()) # 确保优惠券未过期
->find();
if ($coupon) {
$coupon_price = $coupon['price'];
} else {
@ -808,69 +877,96 @@ class Goods extends Base
$price = 0;
}
$order_zhe_total = $price;
if (
$goods['type'] == 1 ||
$goods['type'] == 3 ||
$goods['type'] == 6 ||
$goods['type'] == 11 || $goods['type'] == 10
) {
#折扣
$zhe = 0;
if ($shou_zhe_price <= 0 && $goods['type'] != 10) {
$vip_info = UserVip::where(['id' => $user['vip']])->find();
if ($vip_info && $vip_info['discount'] > 0) {
$zhe = $vip_info['discount'];
$zhe_bl = bcdiv("$zhe", "10", 2);
$order_zhe_total = $price = bcmul("$price", "$zhe_bl", 2);
}
#货币1抵扣
$use_integral = 0;
if ($use_integral_is == 1 && $goods['type'] != 10) {
$price = $price * 100;
if ($user['integral'] >= $price) {
$use_integral = $price;
$price = 0;
} else {
$use_integral = $user['integral'];
$price = bcsub("$price", "{$user['integral']}", 2);
}
$price = $price / 100;
}
#余额抵扣
$use_money = 0;
if ($use_money_is == 1) {
if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
} else {
$use_money = $user['money'];#
$price = bcsub("$price", "{$user['money']}", 2);
}
}
} else {
$use_integral = 0;
$use_money = 0;
}
# 初始化变量
$use_integral = 0; # 货币1抵扣
$use_money = 0; # 余额抵扣
$use_money2 = 0; # 货币2抵扣
$use_score = 0; # 积分抵扣
$zhe = 0; # 会员折扣
$use_score = 0;
} elseif ($goods['type'] == 5) {
#折扣
$zhe = 0;
#微信支付
# 积分赏只用积分支付
if ($goods['type'] == 5) {
$price = 0;
#货币1币抵扣
$use_integral = 0;
#余额抵扣
$use_money = 0;
#积分
$use_score = $order_total;
if ($user['score'] < $use_score) {
return $this->renderError("积分不足");
}
} else {
return $this->renderError("非法请求");
# 对于非积分赏类型,应用会员折扣
if ($shou_zhe_price <= 0) {
# 货币1抵扣
if ($use_integral_is == 1 && $goodsType['pay_currency'] == 1) {
$price_in_currency = $price * 100; # 1:100比例
if ($goodsType['is_deduction'] == 1) {
# 抵扣模式
if ($user['integral'] >= $price_in_currency) {
$use_integral = $price_in_currency;
$price = 0;
} else {
$use_integral = $user['integral'];
$price = bcsub("$price", bcdiv("$use_integral", "100", 2), 2);
}
} else {
# 支付模式
if ($user['integral'] >= $price_in_currency) {
$use_integral = $price_in_currency;
$price = 0;
} else {
# 支付模式下货币不足无法抵扣
$use_integral = 0;
}
}
}
# 余额抵扣
if ($use_money_is == 1 && $goodsType['pay_balance'] == 1) {
if ($goodsType['is_deduction'] == 1) {
# 抵扣模式
if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
} else {
$use_money = $user['money'];
$price = bcsub("$price", "$use_money", 2);
}
} else {
# 支付模式
if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
} else {
# 支付模式下余额不足无法抵扣
$use_money = 0;
}
}
}
# 货币2抵扣
if ($use_money2_is == 1 && $goodsType['pay_currency2'] == 1) {
$price_in_currency2 = $price * 100; # 1:100比例
if ($goodsType['is_deduction'] == 1) {
# 抵扣模式
if (isset($user['money2']) && $user['money2'] >= $price_in_currency2) {
$use_money2 = $price_in_currency2;
$price = 0;
} else if (isset($user['money2'])) {
$use_money2 = $user['money2'];
$price = bcsub("$price", bcdiv("$use_money2", "100", 2), 2);
}
} else {
# 支付模式
if (isset($user['money2']) && $user['money2'] >= $price_in_currency2) {
$use_money2 = $price_in_currency2;
$price = 0;
} else {
# 支付模式下货币2不足无法抵扣
$use_money2 = 0;
}
}
}
}
}
#一番赏锁箱
@ -986,7 +1082,8 @@ class Goods extends Base
'order_zhe_total' => $order_zhe_total,#订单折扣金额
'price' => $price,#微信支付
'use_money' => $use_money,#余额抵扣
'use_integral' => $use_integral,#吧唧币抵扣
'use_integral' => $use_integral,#货币1抵扣
'use_money2' => $use_money2,#货币2抵扣
'use_score' => $use_score,#积分抵扣
'zhe' => $zhe,#会员折扣
'goods_id' => $goods_id,