修改无限赏订单

This commit is contained in:
manghe 2025-03-31 15:53:25 +00:00
parent f1b5ff9a0b
commit f556969469
3 changed files with 661 additions and 575 deletions

File diff suppressed because it is too large Load Diff

View File

@ -324,9 +324,6 @@ class Infinite extends Base
return $this->renderSuccess("请求成功", $new_data);
}
/**
* 下单计算金额
*/
@ -337,6 +334,7 @@ class Infinite extends Base
$goods_id = request()->param('goods_id/d', 0); #盒子ID
$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'); //优惠券
#盒子信息
@ -345,6 +343,13 @@ class Infinite extends Base
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("盒子已下架");
}
@ -379,80 +384,150 @@ class Infinite extends Base
#订单金额 微信支付金额
$order_total = $order_zhe_total = $price;
# 初始化变量
$use_money = 0; # 余额抵扣
$use_integral = 0; # 货币1抵扣
$use_money2 = 0; # 货币2抵扣
$zhe = 0; # 会员折扣
$coupon_price = 0; # 优惠券金额
#首抽半价
if ($shou_zhe_price <= 0) {
# 判断是否可使用优惠券
if (!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();
#使用优惠券
$coupon_price = 0;
if (!empty($coupon_id)) {
$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;
$coupon = CouponReceiveModel::where(['status' => 0, 'user_id' => $user['id']])->where('man_price', '<=', $price)->order('price desc')->find();
if ($coupon) {
$coupon_price = $coupon['price'];
$coupon_id = $coupon['id'];
}
}
$price = bcsub("$price", "$coupon_price", 2);
if ($price <= 0) {
$price = 0;
}
$order_zhe_total = $price;
$zhe = 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) {
// if ($user['integral'] >= $price) {
// $use_integral = $price;
// $price = 0;
// } else {
// $use_integral = $user['integral'];
// $price = bcsub("$price", "{$user['integral']}", 2);
// }
// }
if ($use_integral_is == 1 && $goods_type != 10) {
$price = $price * 100;
if ($user['integral'] >= $price) {
$use_integral = $price;
$price = 0;
$iszhifu = 0;
# 货币1抵扣吧唧币
if ($use_integral_is == 1 && $goodsType['pay_currency'] == 1 && $goods_type != 10) {
$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 {
$use_integral = $user['integral'];
$price = bcsub("$price", "{$user['integral']}", 2);
# 支付模式
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 ($user['money'] >= $price) {
$use_money = $price;
$price = 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 {
$use_money = $user['money'];#
$price = bcsub("$price", "{$user['money']}", 2);
# 支付模式
if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
$iszhifu++;
} else {
# 支付模式下余额不足无法抵扣
$use_money = 0;
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('请选择支付方式');
}
} else {
$coupon_id = 0;
$coupon_price = 0;
$use_integral = 0;
$use_money = 0;
$use_money2 = 0;
$zhe = 0;
}
#一发
$goods['price_one'] = (bcmul("{$goods['price']}", "1", 2)) * 1;
#三发
$goods['price_three'] = (bcmul("{$goods['price']}", "3", 2)) * 1;
#五连发
$goods['price_five'] = (bcmul("{$goods['price']}", "5", 2)) * 1;
#十连发
$goods['price_ten'] = (bcmul("{$goods['price']}", "10", 2)) * 1;
#五十发
$goods['price_five_ten'] = (bcmul("{$goods['price']}", "50", 2)) * 1;
#抽奖数量
$goods['prize_num'] = $prize_num;
@ -467,6 +542,8 @@ class Infinite extends Base
'use_integral_money' => round(round($use_integral, 2) / 100, 2),
'money' => round($user['money'], 2),
'use_money' => round($use_money, 2),
'score' => isset($user['money2']) ? $user['money2'] : 0,
'use_score' => $use_money2,
'coupon_id' => $coupon_id,
'coupon_price' => round($coupon_price, 2),
];
@ -488,6 +565,7 @@ class Infinite extends Base
$prize_num = request()->param('prize_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'); //优惠券
$is_mibao = request()->param('is_mibao/d', 0); //连击赏下 是否是抽的秘宝池 1是 0否
@ -497,6 +575,13 @@ class Infinite extends Base
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("盒子已下架");
}
@ -572,26 +657,45 @@ class Infinite extends Base
#订单金额 微信支付金额
$order_total = $order_zhe_total = $price;
# 初始化变量
$use_money = 0; # 余额抵扣
$use_integral = 0; # 货币1抵扣
$use_money2 = 0; # 货币2抵扣
$zhe = 0; # 会员折扣
$coupon_price = 0; # 优惠券金额
#使用折扣
if ($is_shou_zhe == 1) {
$coupon_id = 0;
$coupon_price = 0;
$use_integral = 0;
$use_money = 0;
$use_money2 = 0;
#折扣
$zhe = 0;
} else {
#使用优惠券
$coupon_price = 0;
if (!empty($coupon_id)) {
$coupon = CouponReceiveModel::where(['id' => $coupon_id, 'status' => 0, 'user_id' => $user['id']])->where('man_price', '<=', $price)->find();
# 判断是否可使用优惠券
if (!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 ($coupon) {
$coupon_price = $coupon['price'];
} else {
$coupon_id = 0;
}
} else {
$coupon_id = 0;
}
$price = bcsub("$price", "$coupon_price", 2);
if ($price <= 0) {
$price = 0;
}
@ -600,39 +704,95 @@ class Infinite extends Base
#折扣
$zhe = 0;
$vip_info = UserVip::where(['id' => $user['vip']])->find();
if ($vip_info && $vip_info['discount'] > 0) {
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;
$price = 0;
$iszhifu = 0;
# 货币1抵扣吧唧币
if ($use_integral_is == 1 && $goodsType['pay_currency'] == 1 && $goods['type'] != 10) {
$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 {
$use_integral = $user['integral'];
$price = bcsub("$price", "{$user['integral']}", 2);
# 支付模式
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 ($user['money'] >= $price) {
$use_money = $price;
$price = 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 {
$use_money = $user['money'];#
$price = bcsub("$price", "{$user['money']}", 2);
# 支付模式
if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
$iszhifu++;
} else {
# 支付模式下余额不足无法抵扣
$use_money = 0;
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('请选择支付方式');
}
}
$redis = (new \app\common\server\RedisHelper())->getRedis();
$redis_key = "kpw_infinite_orderbuy" . '_' . $user['id'];
$redis_key_info = $redis->get($redis_key);
@ -657,6 +817,7 @@ class Infinite extends Base
'price' => $price,#微信支付
'use_money' => $use_money,#余额抵扣
'use_integral' => $use_integral,#吧唧币抵扣
'use_money2' => $use_money2,#货币2抵扣
'use_score' => 0,#积分抵扣
'zhe' => $zhe,#会员折扣
'goods_id' => $goods_id,

View File

@ -528,6 +528,7 @@ class Notify extends Base
if ($order['use_score'] > 0) {
$res[] = User::changeScore($order['user_id'], -$order['use_score'], 2, '购买盒子' . $order['goods_title']);
}
# 扣货币2
if ($order['use_money2'] > 0) {
$res[] = User::changeMoney2($order['user_id'], -$order['use_money2'], 2, '购买盒子' . $order['goods_title']);
}
@ -869,93 +870,7 @@ class Notify extends Base
*/
protected function special_prize_notice($order, $first_count)
{
// $res = [];
// $goods_id = $order['goods_id'];
// $num = $order['num'];
// $order_type = $order['order_type'];
// #盒子
// $goods_info = Goods::field('prize_num,stock')->where(['id' => $goods_id])->find();
// #特殊奖品存在where('goods_id', '=', $goods_id)
// $special_prize = GoodsList::where('goods_id', '=', $goods_id)
// ->where('num', '=', $num)
// ->where('surplus_stock', '>', 0)
// ->where('shang_id', '=', self::$shang_give_quan_id)
// ->order('prize_num desc')
// ->select();
// // dd($special_prize);
// foreach ($special_prize as $value){
// $surplus_give_stock = $value ? $value['surplus_stock'] : 0;
// // dd($value);
// if ($value && $surplus_give_stock > 0) {
// #符合条件的订单
// $quan_prize_num = $value['prize_num'];
// $prize_num_data = OrderList::field('id,user_id,count(`id`) as all_num')
// ->where('goods_id', '=', $goods_id)
// ->where('num', '=', $num)
// ->where('order_type', '=', $order_type)
// ->where('shang_id', '=', self::$shang_give_w_id)
// ->having('all_num', '>=', $quan_prize_num)
// ->group('user_id')
// ->select()->toArray();
// // dd($quan_prize_num);
// if ($prize_num_data) {
// #多个随机
// shuffle($prize_num_data);
// $quan_prize_info = $prize_num_data[0];
// $user_id = $quan_prize_info['user_id'];
// $order_goods = [
// 'order_id' => 0,
// 'user_id' => $user_id,
// 'status' => 0,#0未操作 1选择兑换 2选择发货
// 'goods_id' => $goods_id,
// 'num' => $num,
// 'shang_id' => $value['shang_id'],
// 'goodslist_id' => $value['id'],
// 'goodslist_title' => $value['title'],
// 'goodslist_imgurl' => $value['imgurl'],
// 'goodslist_price' => $value['price'],
// 'goodslist_money' => $value['money'],
// 'goodslist_type' => $value['goods_type'],
// 'goodslist_sale_time' => $value['sale_time'],
// 'addtime' => time(),
// 'prize_code' => $value['prize_code'],
// 'order_type' => $order_type,
// 'order_list_id' => 0,
// ];
// #新增奖品列表
// $res[] = OrderList::insert($order_goods);
// #减少库存
// $res[] = GoodsList::field('surplus_stock')
// ->where(['id' => $special_prize['id']])
// ->dec('surplus_stock')
// ->update();
// }
// }
// #赏品
// $goods_list_zd = GoodsList::where(['goods_id' => $goods_id])
// ->where(['num' => 1])
// ->select()->toArray();
// if ($goods_list_zd) {
// #循环数据
// $save_sports_data = [];
// $start_num = $goods_info['stock'] + 1;
// for ($i = $start_num; $i <= $start_num; $i++) {
// foreach ($goods_list_zd as $k => $v) {
// unset($v['id']);
// unset($v['num']);
// $v['num'] = $i;
// $v['surplus_stock'] = $v['stock'];
// $save_sports_data[] = $v;
// }
// }
// #添加赏品
// $res[] = GoodsList::insertAll($save_sports_data);
// #增加库存
// $res[] = Goods::where(['id' => $goods_id])->inc('stock', 1)->update();
// }
// }
// return $res;
$res = [];
$goods_id = $order['goods_id'];
$num = $order['num'];
@ -1117,7 +1032,8 @@ class Notify extends Base
if ($order['use_integral'] > 0) {
$res[] = User::changeIntegral($order['user_id'], -$order['use_integral'], 2, '购买盒子' . $order['goods_title']);
}
if ($order['money2'] > 0) {
#
if ($order['use_money2'] > 0) {
$res[] = User::changeMoney2($order['user_id'], -$order['use_money2'], 2, '购买盒子' . $order['goods_title']);
}
@ -1255,7 +1171,7 @@ class Notify extends Base
$res[] = OrderList::insert($save_prize_info);
}
//去除秘宝池次数
if ($infinite_goods['type'] == 9 && $order['is_mibao'] == 1) {
User::where('id', $user_id)->dec('mb_number', $prize_num)->update();
@ -1555,10 +1471,14 @@ class Notify extends Base
if ($order['use_money'] > 0) {
$res[] = User::changeMoney($order['user_id'], -$order['use_money'], 3, '购买盒子' . $order['goods_title']);
}
#扣吧唧币
#扣货币1
if ($order['use_integral'] > 0) {
$res[] = User::changeIntegral($order['user_id'], -$order['use_integral'], 2, '购买盒子' . $order['goods_title']);
}
//扣除货币2
if ($order['use_money2'] > 0) {
$res[] = User::changeMoney2($order['user_id'], -$order['use_money2'], 2, '购买盒子' . $order['goods_title']);
}
#判断一下优惠券
if (!empty($order['coupon_id'])) {
$coupon = CouponReceiveModel::where(['id' => $order['coupon_id'], 'status' => 0])->update(['status' => 1]);