修改无限赏订单

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

View File

@ -174,8 +174,8 @@ class AliNotify extends Base
} }
/* /*
* 支付宝支付回调修改订单状态 * 支付宝支付回调修改订单状态
*/ */
public function alipay_notify() public function alipay_notify()
{ {
//原始订单号 //原始订单号
@ -184,232 +184,232 @@ class AliNotify extends Base
$trade_no = input('trade_no'); $trade_no = input('trade_no');
//交易状态 //交易状态
$trade_status = input('trade_status'); $trade_status = input('trade_status');
$ext_infos=input('ext_infos'); $ext_infos = input('ext_infos');
$table = input('subject'); $table = input('subject');
// Log::info('alipay_notify=================$out_trade_no' . $out_trade_no); // Log::info('alipay_notify=================$out_trade_no' . $out_trade_no);
// Log::info('alipay_notify=================$trade_no' . $out_trade_no); // Log::info('alipay_notify=================$trade_no' . $out_trade_no);
// Log::info('$table=================$table'.$table ); // Log::info('$table=================$table'.$table );
Db::name('pay_log')->insert([ Db::name('pay_log')->insert([
'user_id' => '11', 'user_id' => '11',
'out_trade_no' => $out_trade_no, 'out_trade_no' => $out_trade_no,
'addtime' => time(), 'addtime' => time(),
'trade_no' => $trade_no, 'trade_no' => $trade_no,
'content'=>$trade_status 'content' => $trade_status
]); ]);
if ( $trade_status == 'TRADE_SUCCESS') { if ($trade_status == 'TRADE_SUCCESS') {
// try { // try {
// $orderInfo111 = Order::where('order_num', '=', $out_trade_no) // $orderInfo111 = Order::where('order_num', '=', $out_trade_no)
// ->where('status', '=', 0) // ->where('status', '=', 0)
// ->find(); // ->find();
// if($orderInfo111){ // if($orderInfo111){
// $user111 = User::where('id', $orderInfo111['user_id'])->find(); // $user111 = User::where('id', $orderInfo111['user_id'])->find();
// if($user111){ // if($user111){
// Db::name('wxpay_log')->insert([ // Db::name('wxpay_log')->insert([
// 'order_no' => $data['out_trade_no'], // 'order_no' => $data['out_trade_no'],
// 'content' => json_encode($data), // 'content' => json_encode($data),
// 'type' => 2, // 'type' => 2,
// 'user_id' => $user111['id'], // 'user_id' => $user111['id'],
// 'addtime' => time(), // 'addtime' => time(),
// ]); // ]);
// } // }
// } // }
// } catch (\Throwable $e) { // } catch (\Throwable $e) {
// $this->CallbackSuccess(); // $this->CallbackSuccess();
// } // }
$user = null; $user = null;
if ($table == 'user_recharge') {#余额充值 if ($table == 'user_recharge') {#余额充值
$orderInfo = UserRecharge::where('order_num', '=', $out_trade_no) $orderInfo = UserRecharge::where('order_num', '=', $out_trade_no)
->where(['status' => 1]) ->where(['status' => 1])
->find(); ->find();
#这个订单存在状态对 #这个订单存在状态对
if ($orderInfo && $orderInfo['status'] == 1) { if ($orderInfo && $orderInfo['status'] == 1) {
$user = User::where('id', $orderInfo['user_id'])->find();
$user_id = $orderInfo['user_id'];
$money = $orderInfo['money'];
Db::startTrans();
#修改订单状态
$res[] = UserRecharge::field('status,pay_time')
->where(['id' => $orderInfo['id']])->update([
'status' => 2,
'pay_time' => time(),
]);
$res[] = User::changeMoney($user_id, $money, 2, '在线充值');
#记录微信支付
$res[] = ProfitPay::insert([
'user_id' => $user_id,
'order_num' => $out_trade_no,
'change_money' => $money,
'content' => '支付宝',
'pay_type' => 2,#1微信 2支付宝
'addtime' => time(),
]);
if (resCheck($res)) {
Db::commit();
echo 'success';
} else {
Db::rollback();
echo 'fail';
}
}else{
echo 'success';
Log::info('$orderInfo=================重复');
return;
}
} elseif ($table == 'order_yfs' || $table == 'order_lts' || $table == 'order_zzs') {#抽赏一番赏 擂台赏
$orderInfo = Order::where('order_num', '=', $out_trade_no)
->where('status', '=', 0)
->find();
$user = User::where('id', $orderInfo['user_id'])->find(); $user = User::where('id', $orderInfo['user_id'])->find();
#这个订单存在状态对
if ($orderInfo && $orderInfo['status'] == 0) {
$user_id = $orderInfo['user_id'];
$price = $orderInfo['price'];
Db::startTrans(); $user_id = $orderInfo['user_id'];
try { $money = $orderInfo['money'];
#开盒子 Db::startTrans();
$res[] = $this->drawprize_notice($user_id, $orderInfo['id'], $orderInfo['goods_id'], $orderInfo['num']); #修改订单状态
$res[] = UserRecharge::field('status,pay_time')
$this->wx_gf_fahuo($user_id, $orderInfo['order_num']); ->where(['id' => $orderInfo['id']])->update([
#广告收益回调 'status' => 2,
if (!empty($orderInfo['click_id']) && !empty($orderInfo['ad_id'])) { 'pay_time' => time(),
$order_ad_num = Order::where('user_id', '=', $user_id)->where('status', '=', 1)->where('ad_id', '>', 0)->where('click_id', '>', 0)->where('price', '>', 0)->count(); ]);
if ($order_ad_num <= 1) { $res[] = User::changeMoney($user_id, $money, 2, '在线充值');
#记录微信支付
$this->ad_notify($orderInfo['ad_id'], $orderInfo['click_id']); $res[] = ProfitPay::insert([
'user_id' => $user_id,
} 'order_num' => $out_trade_no,
'change_money' => $money,
} 'content' => '支付宝',
} catch (\Throwable $e) { 'pay_type' => 2,#1微信 2支付宝
Db::rollback(); 'addtime' => time(),
#卡单了 ]);
Order::field('kd_is')->where(['id' => $orderInfo['id']]) if (resCheck($res)) {
->update(['kd_is' => 1]); Db::commit();
#通知微信 echo 'success';
$this->CallbackSuccess(); } else {
} Db::rollback();
#记录微信支付 echo 'fail';
$res[] = ProfitPay::insert([
'user_id' => $user_id,
'order_num' => $out_trade_no,
'change_money' => $price,
'content' => '购买盒子' . $orderInfo['goods_title'],
'pay_type' => 2,#1微信 2支付宝
'addtime' => time(),
]);
if (resCheck($res)) {
Db::commit();
} else {
Db::rollback();
}
} }
} elseif ($table == 'order_wxs') {#抽赏无限赏 } else {
$orderInfo = Order::where('order_num', '=', $out_trade_no) echo 'success';
->where('status', '=', 0) Log::info('$orderInfo=================重复');
->find(); return;
$user = User::where('id', $orderInfo['user_id'])->find(); }
#这个订单存在状态对 } elseif ($table == 'order_yfs' || $table == 'order_lts' || $table == 'order_zzs') {#抽赏一番赏 擂台赏
if ($orderInfo && $orderInfo['status'] == 0) { $orderInfo = Order::where('order_num', '=', $out_trade_no)
$user_id = $orderInfo['user_id']; ->where('status', '=', 0)
$price = $orderInfo['price']; ->find();
Db::startTrans(); $user = User::where('id', $orderInfo['user_id'])->find();
$res[] = $this->infinite_drawprize_notice($user_id, $orderInfo['id'], $orderInfo['goods_id']); #这个订单存在状态对
#记录微信支付 if ($orderInfo && $orderInfo['status'] == 0) {
$res[] = ProfitPay::insert([ $user_id = $orderInfo['user_id'];
'user_id' => $user_id, $price = $orderInfo['price'];
'order_num' => $out_trade_no,
'change_money' => $price, Db::startTrans();
'content' => '购买盒子' . $orderInfo['goods_title'], try {
'pay_type' => 2,#1微信 2支付宝 #开盒子
'addtime' => time(), $res[] = $this->drawprize_notice($user_id, $orderInfo['id'], $orderInfo['goods_id'], $orderInfo['num']);
]);
$this->wx_gf_fahuo($user_id, $orderInfo['order_num']); $this->wx_gf_fahuo($user_id, $orderInfo['order_num']);
#广告收益回调 #广告收益回调
if (!empty($orderInfo['click_id']) && !empty($orderInfo['ad_id'])) { if (!empty($orderInfo['click_id']) && !empty($orderInfo['ad_id'])) {
$order_ad_num = Order::where('user_id', '=', $user_id)->where('status', '=', 1)->where('ad_id', '>', 0)->where('click_id', '>', 0)->where('price', '>', 0)->count(); $order_ad_num = Order::where('user_id', '=', $user_id)->where('status', '=', 1)->where('ad_id', '>', 0)->where('click_id', '>', 0)->where('price', '>', 0)->count();
if ($order_ad_num <= 1) { if ($order_ad_num <= 1) {
$this->ad_notify($orderInfo['ad_id'], $orderInfo['click_id']); $this->ad_notify($orderInfo['ad_id'], $orderInfo['click_id']);
} }
}
if (resCheck($res)) {
Db::commit();
} else {
Db::rollback();
} }
} catch (\Throwable $e) {
Db::rollback();
#卡单了
Order::field('kd_is')->where(['id' => $orderInfo['id']])
->update(['kd_is' => 1]);
#通知微信
$this->CallbackSuccess();
} }
} elseif ($table == 'order_ckj') {#抽赏抽卡机 #记录微信支付
$orderInfo = Order::where('order_num', '=', $out_trade_no) $res[] = ProfitPay::insert([
->where('status', '=', 0) 'user_id' => $user_id,
->where('order_type', '=', 4) 'order_num' => $out_trade_no,
->find(); 'change_money' => $price,
$user = User::where('id', $orderInfo['user_id'])->find(); 'content' => '购买盒子' . $orderInfo['goods_title'],
#这个订单存在状态对 'pay_type' => 2,#1微信 2支付宝
if ($orderInfo && $orderInfo['status'] == 0) { 'addtime' => time(),
$user_id = $orderInfo['user_id']; ]);
$price = $orderInfo['price']; if (resCheck($res)) {
Db::startTrans(); Db::commit();
$res[] = $this->cardextractor_drawprize_notice($user_id, $orderInfo['id'], $orderInfo['goods_id']); } else {
#记录微信支付 Db::rollback();
$res[] = ProfitPay::insert([
'user_id' => $user_id,
'order_num' => $out_trade_no,
'change_money' => $price,
'content' => '购买盒子' . $orderInfo['goods_title'],
'pay_type' => 2,#1微信 2支付宝
'addtime' => time(),
]);
$this->wx_gf_fahuo($user_id, $orderInfo['order_num']);
if (resCheck($res)) {
Db::commit();
} else {
Db::rollback();
}
} }
} elseif ($table == 'order_list_send') {#背包发货
$orderInfo = OrderListSend::where('send_num', '=', $out_trade_no)
->where('status', '=', 0)
->find();
$user = User::where('id', $orderInfo['user_id'])->find();
#这个订单存在状态对
if ($orderInfo && $orderInfo['status'] == 0) {
$user_id = $orderInfo['user_id'];
$freight = $orderInfo['freight'];
Db::startTrans();
$res[] = $this->reward_order_handle($user_id, $orderInfo['id']);
#记录微信支付
$res[] = ProfitPay::insert([
'user_id' => $user_id,
'order_num' => $out_trade_no,
'change_money' => $freight,
'content' => '背包发货',
'pay_type' => 2,#1微信 2支付宝
'addtime' => time(),
]);
$this->wx_gf_fahuo($user_id, $orderInfo['order_num']);
if (resCheck($res)) {
Db::commit();
} else {
Db::rollback();
}
}
} elseif ($table == 'order_js') {
} }
} elseif ($table == 'order_wxs') {#抽赏无限赏
$orderInfo = Order::where('order_num', '=', $out_trade_no)
->where('status', '=', 0)
->find();
$user = User::where('id', $orderInfo['user_id'])->find();
#这个订单存在状态对
if ($orderInfo && $orderInfo['status'] == 0) {
$user_id = $orderInfo['user_id'];
$price = $orderInfo['price'];
Db::startTrans();
$res[] = $this->infinite_drawprize_notice($user_id, $orderInfo['id'], $orderInfo['goods_id']);
#记录微信支付
$res[] = ProfitPay::insert([
'user_id' => $user_id,
'order_num' => $out_trade_no,
'change_money' => $price,
'content' => '购买盒子' . $orderInfo['goods_title'],
'pay_type' => 2,#1微信 2支付宝
'addtime' => time(),
]);
$this->wx_gf_fahuo($user_id, $orderInfo['order_num']);
#广告收益回调
if (!empty($orderInfo['click_id']) && !empty($orderInfo['ad_id'])) {
$order_ad_num = Order::where('user_id', '=', $user_id)->where('status', '=', 1)->where('ad_id', '>', 0)->where('click_id', '>', 0)->where('price', '>', 0)->count();
if ($order_ad_num <= 1) {
$this->ad_notify($orderInfo['ad_id'], $orderInfo['click_id']);
}
}
if (resCheck($res)) {
Db::commit();
} else {
Db::rollback();
}
}
} elseif ($table == 'order_ckj') {#抽赏抽卡机
$orderInfo = Order::where('order_num', '=', $out_trade_no)
->where('status', '=', 0)
->where('order_type', '=', 4)
->find();
$user = User::where('id', $orderInfo['user_id'])->find();
#这个订单存在状态对
if ($orderInfo && $orderInfo['status'] == 0) {
$user_id = $orderInfo['user_id'];
$price = $orderInfo['price'];
Db::startTrans();
$res[] = $this->cardextractor_drawprize_notice($user_id, $orderInfo['id'], $orderInfo['goods_id']);
#记录微信支付
$res[] = ProfitPay::insert([
'user_id' => $user_id,
'order_num' => $out_trade_no,
'change_money' => $price,
'content' => '购买盒子' . $orderInfo['goods_title'],
'pay_type' => 2,#1微信 2支付宝
'addtime' => time(),
]);
$this->wx_gf_fahuo($user_id, $orderInfo['order_num']);
if (resCheck($res)) {
Db::commit();
} else {
Db::rollback();
}
}
} elseif ($table == 'order_list_send') {#背包发货
$orderInfo = OrderListSend::where('send_num', '=', $out_trade_no)
->where('status', '=', 0)
->find();
$user = User::where('id', $orderInfo['user_id'])->find();
#这个订单存在状态对
if ($orderInfo && $orderInfo['status'] == 0) {
$user_id = $orderInfo['user_id'];
$freight = $orderInfo['freight'];
Db::startTrans();
$res[] = $this->reward_order_handle($user_id, $orderInfo['id']);
#记录微信支付
$res[] = ProfitPay::insert([
'user_id' => $user_id,
'order_num' => $out_trade_no,
'change_money' => $freight,
'content' => '背包发货',
'pay_type' => 2,#1微信 2支付宝
'addtime' => time(),
]);
$this->wx_gf_fahuo($user_id, $orderInfo['order_num']);
if (resCheck($res)) {
Db::commit();
} else {
Db::rollback();
}
}
} elseif ($table == 'order_js') {
}
@ -434,7 +434,7 @@ class AliNotify extends Base
}else{ } else {
echo "fail"; echo "fail";
} }
@ -756,25 +756,25 @@ class AliNotify extends Base
->find(); ->find();
if ($order) { if ($order) {
//判断是否限制购买一次 //判断是否限制购买一次
$sbuser=User::where(['id' => $user_id])->find(); $sbuser = User::where(['id' => $user_id])->find();
$sbgoods=User::where(['id' => $goods_id])->find(); $sbgoods = User::where(['id' => $goods_id])->find();
$user_xiangou_count = OrderList::field('id')->where('goods_id', '=', $goods_id) $user_xiangou_count = OrderList::field('id')->where('goods_id', '=', $goods_id)
->where('num', '=', $num) ->where('num', '=', $num)
->where('shang_id', 'between', [10, 38]) ->where('shang_id', 'between', [10, 38])
->where('order_type', 'in', [1, 3, 5, 6, 11]) ->where('order_type', 'in', [1, 3, 5, 6, 11])
->where('user_id', '=', $user_id) ->where('user_id', '=', $user_id)
->count(); ->count();
if (($sbgoods['type'] == 6 ||$sbgoods['type'] == 1) && $sbgoods['quanju_xiangou'] > 0) { if (($sbgoods['type'] == 6 || $sbgoods['type'] == 1) && $sbgoods['quanju_xiangou'] > 0) {
if($user_xiangou_count>= $sbgoods['quanju_xiangou']){ if ($user_xiangou_count >= $sbgoods['quanju_xiangou']) {
Log::info('====用户id'.$user_id.'试图作弊,已停发本次赏品'); Log::info('====用户id' . $user_id . '试图作弊,已停发本次赏品');
Log::info('====用户id'.$user_id.'试图作弊,已停发本次赏品'); Log::info('====用户id' . $user_id . '试图作弊,已停发本次赏品');
Log::info('====用户id'.$user_id.'试图作弊,已停发本次赏品'); Log::info('====用户id' . $user_id . '试图作弊,已停发本次赏品');
$res1[] = 0; $res1[] = 0;
return $res1; return $res1;
} }
} }
@ -797,6 +797,10 @@ class AliNotify extends Base
if ($order['use_score'] > 0) { if ($order['use_score'] > 0) {
$res[] = User::changeScore($order['user_id'], -$order['use_score'], 2, '购买盒子' . $order['goods_title']); $res[] = User::changeScore($order['user_id'], -$order['use_score'], 2, '购买盒子' . $order['goods_title']);
} }
if ($order['use_money2'] > 0) {
$res[] = User::changeMoney2($order['user_id'], -$order['use_money2'], 2, '购买盒子' . $order['goods_title']);
}
#判断一下优惠券 #判断一下优惠券
if (!empty($order['coupon_id'])) { if (!empty($order['coupon_id'])) {
$coupon = CouponReceiveModel::where(['id' => $order['coupon_id'], 'status' => 0])->update(['status' => 1]); $coupon = CouponReceiveModel::where(['id' => $order['coupon_id'], 'status' => 0])->update(['status' => 1]);
@ -808,11 +812,11 @@ class AliNotify extends Base
$res[] = User::distribution($order); $res[] = User::distribution($order);
#分销奖励 #分销奖励
//对对碰 //对对碰
$ddp_goods=Goods::where('id',$goods_id)->find(); $ddp_goods = Goods::where('id', $goods_id)->find();
if($ddp_goods&&($ddp_goods['is_ddp']==1||$ddp_goods['is_zp']==1)){ if ($ddp_goods && ($ddp_goods['is_ddp'] == 1 || $ddp_goods['is_zp'] == 1)) {
}else{ } else {
#普通奖品========================================================== #普通奖品==========================================================
$res[] = $this->ordinary_prize_notice($order); $res[] = $this->ordinary_prize_notice($order);
#普通奖品========================================================== #普通奖品==========================================================
@ -827,83 +831,83 @@ class AliNotify extends Base
} }
if($ddp_goods&&$ddp_goods['is_zp']==1){ if ($ddp_goods && $ddp_goods['is_zp'] == 1) {
$goodslist_xz = GoodsList::where(['goods_id' => $ddp_goods['id']]) $goodslist_xz = GoodsList::where(['goods_id' => $ddp_goods['id']])
->order('pro asc') ->order('pro asc')
->select()->toArray(); ->select()->toArray();
$randomValue = mt_rand(1, 100); // 生成0到100之间的随机数 $randomValue = mt_rand(1, 100); // 生成0到100之间的随机数
$nowpro=0; $nowpro = 0;
$read_goods=[]; $read_goods = [];
foreach ($goodslist_xz as $key => &$value1) { foreach ($goodslist_xz as $key => &$value1) {
$nowpro+=$value1['pro']; $nowpro += $value1['pro'];
if($randomValue<$nowpro){ if ($randomValue < $nowpro) {
$read_goods=$value1; $read_goods = $value1;
Db::name('error_log')->insert([ Db::name('error_log')->insert([
'user_id' => $user_id,
'goods_id' => $ddp_goods['id'],
'addtime' => time(),
'content'=>'支付宝付费抽奖开启概率'.$randomValue.',累计概率'.$nowpro.',本商品概率'.$value1['pro'].',本商品名称'.$value1['title'].',抽取id'.$user_id,
'trade_no' => '55'
]);
$randomValue=99999;
}
}
$order_goods = [
'order_id' => $order_id,
'user_id' => $user_id, 'user_id' => $user_id,
'status' => 0,#0未操作 1选择兑换 2选择发货 'goods_id' => $ddp_goods['id'],
'goods_id' =>$read_goods['goods_id'],
'num' => 1,
'shang_id' => $read_goods['shang_id'],
'goodslist_id' => $read_goods['id'],
'goodslist_title' => $read_goods['title'],
'goodslist_imgurl' => $read_goods['imgurl'],
'goodslist_price' => $read_goods['price'],
'goodslist_money' => $read_goods['money'],
'goodslist_type' => $read_goods['goods_type'],
'goodslist_sale_time' => $read_goods['sale_time'],
'addtime' => time(), 'addtime' => time(),
'prize_code' => $read_goods['prize_code'], 'content' => '支付宝付费抽奖开启概率' . $randomValue . ',累计概率' . $nowpro . ',本商品概率' . $value1['pro'] . ',本商品名称' . $value1['title'] . ',抽取id' . $user_id,
'order_type' => 11, 'trade_no' => '55'
'order_list_id' => 0,
'xz_id'=>0
];
]);
$randomValue = 99999;
$res[] =OrderList::insert($order_goods); }
}else if($ddp_goods&&$ddp_goods['is_ddp']==1){
$touch = Db::name('touch_user_list')->where('goods_id',$goods_id)->where('user_id',$user_id)
->find();
$mystatus=3;
if($ddp_goods['ddp_type']==2){
$mystatus=4;
} }
$updata=[
'cards'=>'', $order_goods = [
'user_xy'=>0, 'order_id' => $order_id,
'is_xy'=>0, 'user_id' => $user_id,
'xy'=>'', 'status' => 0,#0未操作 1选择兑换 2选择发货
'status'=>$mystatus, 'goods_id' => $read_goods['goods_id'],
'user_id'=>$user_id, 'num' => 1,
'goods_id'=>$goods_id, 'shang_id' => $read_goods['shang_id'],
'order_id'=>$order['id'], 'goodslist_id' => $read_goods['id'],
'update_time' => time(), 'goodslist_title' => $read_goods['title'],
'num'=>0 'goodslist_imgurl' => $read_goods['imgurl'],
'goodslist_price' => $read_goods['price'],
'goodslist_money' => $read_goods['money'],
'goodslist_type' => $read_goods['goods_type'],
'goodslist_sale_time' => $read_goods['sale_time'],
'addtime' => time(),
'prize_code' => $read_goods['prize_code'],
'order_type' => 11,
'order_list_id' => 0,
'xz_id' => 0
]; ];
if ($touch) {
$res[]=Db::name('touch_user_list')->where('goods_id',$goods_id)->where('user_id',$user_id)
->update($updata);
}else{ $res[] = OrderList::insert($order_goods);
$res[]=Db::name('touch_user_list')->insert($updata);
} else if ($ddp_goods && $ddp_goods['is_ddp'] == 1) {
$touch = Db::name('touch_user_list')->where('goods_id', $goods_id)->where('user_id', $user_id)
->find();
$mystatus = 3;
if ($ddp_goods['ddp_type'] == 2) {
$mystatus = 4;
}
$updata = [
'cards' => '',
'user_xy' => 0,
'is_xy' => 0,
'xy' => '',
'status' => $mystatus,
'user_id' => $user_id,
'goods_id' => $goods_id,
'order_id' => $order['id'],
'update_time' => time(),
'num' => 0
];
if ($touch) {
$res[] = Db::name('touch_user_list')->where('goods_id', $goods_id)->where('user_id', $user_id)
->update($updata);
} else {
$res[] = Db::name('touch_user_list')->insert($updata);
} }
}else{ } else {
#特殊奖品********************************************************** #特殊奖品**********************************************************
#普通奖品余量信息 #普通奖品余量信息
@ -1138,7 +1142,7 @@ class AliNotify extends Base
'addtime' => time(), 'addtime' => time(),
'prize_code' => $ordinary_prize_info['prize_code'], 'prize_code' => $ordinary_prize_info['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'is_fd'=>$ordinary_prize_info['is_fd'] 'is_fd' => $ordinary_prize_info['is_fd']
]; ];
#减少库存 #减少库存
$res[] = GoodsList::field('surplus_stock') $res[] = GoodsList::field('surplus_stock')
@ -1155,79 +1159,80 @@ class AliNotify extends Base
/** /**
* openFd 福袋开启 * openFd 福袋开启
*/ */
protected function openFd($goods_id, $num){ protected function openFd($goods_id, $num)
{
$res = []; $res = [];
$all_order_list = OrderList::field('id,num,user_id,goods_id,is_fd,status,goodslist_id')->where('goods_id', '=', $goods_id) $all_order_list = OrderList::field('id,num,user_id,goods_id,is_fd,status,goodslist_id')->where('goods_id', '=', $goods_id)
->where('num', '=', $num) ->where('num', '=', $num)
->where('is_fd', '=', 1) ->where('is_fd', '=', 1)
->where('status', '=', 0) ->where('status', '=', 0)
->order('id asc') ->order('id asc')
->select()->toArray(); ->select()->toArray();
if (count($all_order_list)>0) { if (count($all_order_list) > 0) {
$orders=[]; $orders = [];
$goodss=[]; $goodss = [];
$goodslist_read=[]; $goodslist_read = [];
$readindex=0; $readindex = 0;
$v_goods=null; $v_goods = null;
foreach ($all_order_list as $order) { foreach ($all_order_list as $order) {
if(!$v_goods){ if (!$v_goods) {
$v_goods=GoodsList::field('id,prize_code,is_fd')->where(['id'=>$order['goodslist_id']])->find(); $v_goods = GoodsList::field('id,prize_code,is_fd')->where(['id' => $order['goodslist_id']])->find();
} }
if($v_goods['is_fd']==1){ if ($v_goods['is_fd'] == 1) {
$orders[]=[ $orders[] = [
'id'=>$order['id'], 'id' => $order['id'],
'recovery_num'=>$order['user_id'].'FD'."|".$order['id'], 'recovery_num' => $order['user_id'] . 'FD' . "|" . $order['id'],
'status'=>4, 'status' => 4,
'choice_time'=>time() 'choice_time' => time()
]; ];
if(count($goodslist_read)==0){ if (count($goodslist_read) == 0) {
$goodslist_xz = GoodsList::where(['xz_pid' => $v_goods['prize_code']]) $goodslist_xz = GoodsList::where(['xz_pid' => $v_goods['prize_code']])
->order('pro asc') ->order('pro asc')
->select()->toArray(); ->select()->toArray();
foreach ($goodslist_xz as $key => &$value1) { foreach ($goodslist_xz as $key => &$value1) {
for ($i = 0; $i < $value1['pro']; $i++) { for ($i = 0; $i < $value1['pro']; $i++) {
$goodslist_read[]=$value1; $goodslist_read[] = $value1;
} }
} }
shuffle($goodslist_read); shuffle($goodslist_read);
shuffle($goodslist_read); shuffle($goodslist_read);
} }
$read_goods=$goodslist_read[$readindex]; $read_goods = $goodslist_read[$readindex];
$readindex++; $readindex++;
$goodss[] = [ $goodss[] = [
'order_id' => 0, 'order_id' => 0,
'user_id' => $order['user_id'], 'user_id' => $order['user_id'],
'status' => 0,#0未操作 1选择兑换 2选择发货 'status' => 0,#0未操作 1选择兑换 2选择发货
'goods_id' =>$read_goods['goods_id'], 'goods_id' => $read_goods['goods_id'],
'num' => 0, 'num' => 0,
'shang_id' => $read_goods['shang_id'], 'shang_id' => $read_goods['shang_id'],
'goodslist_id' => $read_goods['id'], 'goodslist_id' => $read_goods['id'],
'goodslist_title' => $read_goods['title'], 'goodslist_title' => $read_goods['title'],
'goodslist_imgurl' => $read_goods['imgurl'], 'goodslist_imgurl' => $read_goods['imgurl'],
'goodslist_price' => $read_goods['price'], 'goodslist_price' => $read_goods['price'],
'goodslist_money' => $read_goods['money'], 'goodslist_money' => $read_goods['money'],
'goodslist_type' => $read_goods['goods_type'], 'goodslist_type' => $read_goods['goods_type'],
'goodslist_sale_time' => $read_goods['sale_time'], 'goodslist_sale_time' => $read_goods['sale_time'],
'addtime' => time(), 'addtime' => time(),
'prize_code' => $read_goods['prize_code'], 'prize_code' => $read_goods['prize_code'],
'order_type' => 10, 'order_type' => 10,
'order_list_id' => 0, 'order_list_id' => 0,
'xz_id'=>$order['id'] 'xz_id' => $order['id']
]; ];
} }
} }
$orderList=new OrderList; $orderList = new OrderList;
$res[]=$orderList->saveAll($orders); $res[] = $orderList->saveAll($orders);
$res[] =OrderList::insertAll($goodss); $res[] = OrderList::insertAll($goodss);
}else{ } else {
$res[] = 1; $res[] = 1;
} }
return $res; return $res;
@ -1285,7 +1290,7 @@ class AliNotify extends Base
'prize_code' => $special_prize['prize_code'], 'prize_code' => $special_prize['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'order_list_id' => $order_list_id, 'order_list_id' => $order_list_id,
'is_fd'=>$special_prize['is_fd'] 'is_fd' => $special_prize['is_fd']
]; ];
#增加销量 #增加销量
$res[] = GoodsList::field('surplus_stock') $res[] = GoodsList::field('surplus_stock')
@ -1397,8 +1402,8 @@ class AliNotify extends Base
$res = []; $res = [];
$goods_id = $order['goods_id']; $goods_id = $order['goods_id'];
$flwgoods= Goods::where(['id' => $goods_id])->find(); $flwgoods = Goods::where(['id' => $goods_id])->find();
if($flwgoods['is_flw']==1){ if ($flwgoods['is_flw'] == 1) {
Log::info('拦截福利屋直接开箱' . $goods_id); Log::info('拦截福利屋直接开箱' . $goods_id);
$res[] = 1; $res[] = 1;
return $res; return $res;
@ -1437,29 +1442,29 @@ class AliNotify extends Base
#中奖奖项 #中奖奖项
$ordinary_prize_info = $v; $ordinary_prize_info = $v;
if($v['is_xz']==1&&($v['is_hgxz']==0&&$v['is_fd']==0)){ if ($v['is_xz'] == 1 && ($v['is_hgxz'] == 0 && $v['is_fd'] == 0)) {
$goodslist_xz = GoodsList::where(['xz_pid' => $v['prize_code']]) $goodslist_xz = GoodsList::where(['xz_pid' => $v['prize_code']])
->order('pro asc') ->order('pro asc')
->select()->toArray(); ->select()->toArray();
$randomValue = mt_rand(1, 100); // 生成0到100之间的随机数 $randomValue = mt_rand(1, 100); // 生成0到100之间的随机数
$nowpro=0; $nowpro = 0;
$read_goods=[]; $read_goods = [];
foreach ($goodslist_xz as $key => &$value1) { foreach ($goodslist_xz as $key => &$value1) {
$nowpro+=$value1['pro']; $nowpro += $value1['pro'];
if($randomValue<$nowpro){ if ($randomValue < $nowpro) {
$read_goods=$value1; $read_goods = $value1;
Db::name('error_log')->insert([ Db::name('error_log')->insert([
'user_id' => '33', 'user_id' => '33',
'goods_id' => '44', 'goods_id' => '44',
'addtime' => time(), 'addtime' => time(),
'content'=>'支付宝回调触发抽取概率'.$randomValue.',累计概率'.$nowpro.',本商品概率'.$value1['pro'].',本商品名称'.$value1['title'].',抽取id'.$user_id, 'content' => '支付宝回调触发抽取概率' . $randomValue . ',累计概率' . $nowpro . ',本商品概率' . $value1['pro'] . ',本商品名称' . $value1['title'] . ',抽取id' . $user_id,
'trade_no' => '55' 'trade_no' => '55'
]); ]);
$randomValue=99999; $randomValue = 99999;
} }
} }
@ -1481,10 +1486,10 @@ class AliNotify extends Base
'prize_code' => $read_goods['prize_code'], 'prize_code' => $read_goods['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'order_list_id' => $order_list_id, 'order_list_id' => $order_list_id,
'is_fd'=>$read_goods['is_fd'] 'is_fd' => $read_goods['is_fd']
]; ];
}else{ } else {
$order_goods[] = [ $order_goods[] = [
'order_id' => 0, 'order_id' => 0,
'user_id' => $user_id, 'user_id' => $user_id,
@ -1503,7 +1508,7 @@ class AliNotify extends Base
'prize_code' => $ordinary_prize_info['prize_code'], 'prize_code' => $ordinary_prize_info['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'order_list_id' => $order_list_id, 'order_list_id' => $order_list_id,
'is_fd'=>$ordinary_prize_info['is_fd'] 'is_fd' => $ordinary_prize_info['is_fd']
]; ];
} }
#减少库存 #减少库存
@ -1552,7 +1557,7 @@ class AliNotify extends Base
'prize_code' => $ordinary_prize_info['prize_code'], 'prize_code' => $ordinary_prize_info['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'order_list_id' => $order_list_id, 'order_list_id' => $order_list_id,
'is_fd'=>$ordinary_prize_info['is_fd'] 'is_fd' => $ordinary_prize_info['is_fd']
]; ];
#减少库存 #减少库存
$res[] = GoodsList::field('surplus_stock') $res[] = GoodsList::field('surplus_stock')
@ -1723,7 +1728,7 @@ class AliNotify extends Base
'prize_code' => $prize_info['prize_code'], 'prize_code' => $prize_info['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'luck_no' => $luck_no, 'luck_no' => $luck_no,
'is_fd'=>$prize_info['is_fd'] 'is_fd' => $prize_info['is_fd']
]; ];
#入库=== #入库===
$res[] = OrderList::insert($save_prize_info); $res[] = OrderList::insert($save_prize_info);
@ -1822,7 +1827,7 @@ class AliNotify extends Base
'prize_code' => $prize_info['prize_code'], 'prize_code' => $prize_info['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'luck_no' => $luck_no, 'luck_no' => $luck_no,
'is_fd'=>$prize_info['is_fd'] 'is_fd' => $prize_info['is_fd']
]; ];
#入库=== #入库===
$res[] = OrderList::insert($save_prize_info); $res[] = OrderList::insert($save_prize_info);
@ -2173,7 +2178,7 @@ class AliNotify extends Base
'addtime' => time(), 'addtime' => time(),
'prize_code' => $prize_info['prize_code'], 'prize_code' => $prize_info['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'is_fd'=>$prize_info['is_fd'] 'is_fd' => $prize_info['is_fd']
]; ];
if ($prize_info['special_stock'] >= 1) { if ($prize_info['special_stock'] >= 1) {
#减少库存 #减少库存
@ -2405,7 +2410,7 @@ class AliNotify extends Base
'prize_code' => $prize_info['prize_code'], 'prize_code' => $prize_info['prize_code'],
'order_type' => $order_type, 'order_type' => $order_type,
'luck_no' => $luck_no, 'luck_no' => $luck_no,
'is_fd'=>$prize_info['is_fd'] 'is_fd' => $prize_info['is_fd']
]; ];
#入库=== #入库===
$res[] = OrderList::insert($save_prize_info); $res[] = OrderList::insert($save_prize_info);

View File

@ -324,9 +324,6 @@ class Infinite extends Base
return $this->renderSuccess("请求成功", $new_data); return $this->renderSuccess("请求成功", $new_data);
} }
/** /**
* 下单计算金额 * 下单计算金额
*/ */
@ -337,6 +334,7 @@ class Infinite extends Base
$goods_id = request()->param('goods_id/d', 0); #盒子ID $goods_id = request()->param('goods_id/d', 0); #盒子ID
$use_money_is = request()->param('use_money_is/d', 0); #0不抵扣 1抵扣 $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_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'); //优惠券 $coupon_id = request()->param('coupon_id/d'); //优惠券
#盒子信息 #盒子信息
@ -345,6 +343,13 @@ class Infinite extends Base
if (!$goods) { if (!$goods) {
return $this->renderError("盒子不存在"); return $this->renderError("盒子不存在");
} }
# 获取盒子类型配置
$goodsType = \app\common\model\GoodsType::where('value', $goods['type'])->find();
if (!$goodsType) {
return $this->renderError("盒子类型配置不存在");
}
if ($goods['status'] != 1) { if ($goods['status'] != 1) {
return $this->renderError("盒子已下架"); return $this->renderError("盒子已下架");
} }
@ -379,80 +384,150 @@ class Infinite extends Base
#订单金额 微信支付金额 #订单金额 微信支付金额
$order_total = $order_zhe_total = $price; $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 ($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) { if ($coupon) {
$coupon_price = $coupon['price']; $coupon_price = $coupon['price'];
} else {
$coupon_id = 0;
} }
} else { } else {
$coupon_id = 0; $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); $price = bcsub("$price", "$coupon_price", 2);
if ($price <= 0) { if ($price <= 0) {
$price = 0; $price = 0;
} }
$order_zhe_total = $price; $order_zhe_total = $price;
$zhe = 0;
# 会员折扣
$vip_info = UserVip::where(['id' => $user['vip']])->find(); $vip_info = UserVip::where(['id' => $user['vip']])->find();
if ($vip_info && $vip_info['discount'] > 0 && $goods['type'] != 10) { if ($vip_info && $vip_info['discount'] > 0 && $goods['type'] != 10) {
$zhe = $vip_info['discount']; $zhe = $vip_info['discount'];
$zhe_bl = bcdiv("$zhe", "10", 2); $zhe_bl = bcdiv("$zhe", "10", 2);
$order_zhe_total = $price = bcmul("$price", "$zhe_bl", 2); $order_zhe_total = $price = bcmul("$price", "$zhe_bl", 2);
} }
#吧唧币抵扣
$use_integral = 0; $iszhifu = 0;
// if ($use_integral_is == 1) { # 货币1抵扣吧唧币
// if ($user['integral'] >= $price) { if ($use_integral_is == 1 && $goodsType['pay_currency'] == 1 && $goods_type != 10) {
// $use_integral = $price; $price_in_currency = $price * 100; # 1:100比例
// $price = 0; if ($goodsType['is_deduction'] == 1) {
// } else { # 抵扣模式
// $use_integral = $user['integral']; if ($user['integral'] >= $price_in_currency) {
// $price = bcsub("$price", "{$user['integral']}", 2); $use_integral = $price_in_currency;
// } $price = 0;
// } } else {
if ($use_integral_is == 1 && $goods_type != 10) { $use_integral = $user['integral'];
$price = $price * 100; $price = bcsub("$price", bcdiv("$use_integral", "100", 2), 2);
if ($user['integral'] >= $price) { }
$use_integral = $price;
$price = 0;
} else { } 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 ($use_money_is == 1 && $goodsType['pay_balance'] == 1) {
if ($user['money'] >= $price) { if ($goodsType['is_deduction'] == 1) {
$use_money = $price; # 抵扣模式
$price = 0; if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
} else {
$use_money = $user['money'];
$price = bcsub("$price", "$use_money", 2);
}
} else { } 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 { } else {
$coupon_id = 0; $coupon_id = 0;
$coupon_price = 0; $coupon_price = 0;
$use_integral = 0; $use_integral = 0;
$use_money = 0; $use_money = 0;
$use_money2 = 0;
$zhe = 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; $goods['prize_num'] = $prize_num;
@ -467,6 +542,8 @@ class Infinite extends Base
'use_integral_money' => round(round($use_integral, 2) / 100, 2), 'use_integral_money' => round(round($use_integral, 2) / 100, 2),
'money' => round($user['money'], 2), 'money' => round($user['money'], 2),
'use_money' => round($use_money, 2), 'use_money' => round($use_money, 2),
'score' => isset($user['money2']) ? $user['money2'] : 0,
'use_score' => $use_money2,
'coupon_id' => $coupon_id, 'coupon_id' => $coupon_id,
'coupon_price' => round($coupon_price, 2), 'coupon_price' => round($coupon_price, 2),
]; ];
@ -488,6 +565,7 @@ class Infinite extends Base
$prize_num = request()->param('prize_num/d', 0); #抽几发 $prize_num = request()->param('prize_num/d', 0); #抽几发
$use_money_is = request()->param('use_money_is/d', 0); #0不抵扣 1抵扣 $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_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'); //优惠券 $coupon_id = request()->param('coupon_id'); //优惠券
$is_mibao = request()->param('is_mibao/d', 0); //连击赏下 是否是抽的秘宝池 1是 0否 $is_mibao = request()->param('is_mibao/d', 0); //连击赏下 是否是抽的秘宝池 1是 0否
@ -497,6 +575,13 @@ class Infinite extends Base
if (!$goods) { if (!$goods) {
return $this->renderError("盒子不存在"); return $this->renderError("盒子不存在");
} }
# 获取盒子类型配置
$goodsType = \app\common\model\GoodsType::where('value', $goods['type'])->find();
if (!$goodsType) {
return $this->renderError("盒子类型配置不存在");
}
if ($goods['status'] != 1) { if ($goods['status'] != 1) {
return $this->renderError("盒子已下架"); return $this->renderError("盒子已下架");
} }
@ -572,25 +657,44 @@ class Infinite extends Base
#订单金额 微信支付金额 #订单金额 微信支付金额
$order_total = $order_zhe_total = $price; $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) { if ($is_shou_zhe == 1) {
$coupon_id = 0; $coupon_id = 0;
$coupon_price = 0; $coupon_price = 0;
$use_integral = 0; $use_integral = 0;
$use_money = 0; $use_money = 0;
$use_money2 = 0;
#折扣 #折扣
$zhe = 0; $zhe = 0;
} else { } else {
#使用优惠券 # 判断是否可使用优惠券
$coupon_price = 0; if (!empty($coupon_id) && $goodsType['pay_coupon'] == 1) {
if (!empty($coupon_id)) { # 获取优惠券信息
$coupon = CouponReceiveModel::where(['id' => $coupon_id, 'status' => 0, 'user_id' => $user['id']])->where('man_price', '<=', $price)->find(); $coupon = CouponReceiveModel::where([
'id' => $coupon_id,
'status' => 0,
'user_id' => $user['id']
])->where('man_price', '<=', $price)
->where('end_time', '>', time()) # 确保优惠券未过期
->find();
if ($coupon) { if ($coupon) {
$coupon_price = $coupon['price']; $coupon_price = $coupon['price'];
} else {
$coupon_id = 0;
} }
} else {
$coupon_id = 0;
} }
$price = bcsub("$price", "$coupon_price", 2);
$price = bcsub("$price", "$coupon_price", 2);
if ($price <= 0) { if ($price <= 0) {
$price = 0; $price = 0;
@ -600,39 +704,95 @@ class Infinite extends Base
#折扣 #折扣
$zhe = 0; $zhe = 0;
$vip_info = UserVip::where(['id' => $user['vip']])->find(); $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 = $vip_info['discount'];
$zhe_bl = bcdiv("$zhe", "10", 2); $zhe_bl = bcdiv("$zhe", "10", 2);
$order_zhe_total = $price = bcmul("$price", "$zhe_bl", 2); $order_zhe_total = $price = bcmul("$price", "$zhe_bl", 2);
} }
#吧唧币抵扣
$use_integral = 0; $iszhifu = 0;
if ($use_integral_is == 1 && $goods['type'] != 10) { # 货币1抵扣吧唧币
$price = $price * 100; if ($use_integral_is == 1 && $goodsType['pay_currency'] == 1 && $goods['type'] != 10) {
if ($user['integral'] >= $price) { $price_in_currency = $price * 100; # 1:100比例
$use_integral = $price; if ($goodsType['is_deduction'] == 1) {
$price = 0; # 抵扣模式
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 { } 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 ($use_money_is == 1 && $goodsType['pay_balance'] == 1) {
if ($user['money'] >= $price) { if ($goodsType['is_deduction'] == 1) {
$use_money = $price; # 抵扣模式
$price = 0; if ($user['money'] >= $price) {
$use_money = $price;
$price = 0;
} else {
$use_money = $user['money'];
$price = bcsub("$price", "$use_money", 2);
}
} else { } 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 = (new \app\common\server\RedisHelper())->getRedis();
$redis_key = "kpw_infinite_orderbuy" . '_' . $user['id']; $redis_key = "kpw_infinite_orderbuy" . '_' . $user['id'];
$redis_key_info = $redis->get($redis_key); $redis_key_info = $redis->get($redis_key);
@ -657,6 +817,7 @@ class Infinite extends Base
'price' => $price,#微信支付 'price' => $price,#微信支付
'use_money' => $use_money,#余额抵扣 'use_money' => $use_money,#余额抵扣
'use_integral' => $use_integral,#吧唧币抵扣 'use_integral' => $use_integral,#吧唧币抵扣
'use_money2' => $use_money2,#货币2抵扣
'use_score' => 0,#积分抵扣 'use_score' => 0,#积分抵扣
'zhe' => $zhe,#会员折扣 'zhe' => $zhe,#会员折扣
'goods_id' => $goods_id, 'goods_id' => $goods_id,

View File

@ -528,6 +528,7 @@ class Notify extends Base
if ($order['use_score'] > 0) { if ($order['use_score'] > 0) {
$res[] = User::changeScore($order['user_id'], -$order['use_score'], 2, '购买盒子' . $order['goods_title']); $res[] = User::changeScore($order['user_id'], -$order['use_score'], 2, '购买盒子' . $order['goods_title']);
} }
# 扣货币2
if ($order['use_money2'] > 0) { if ($order['use_money2'] > 0) {
$res[] = User::changeMoney2($order['user_id'], -$order['use_money2'], 2, '购买盒子' . $order['goods_title']); $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) 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 = []; $res = [];
$goods_id = $order['goods_id']; $goods_id = $order['goods_id'];
$num = $order['num']; $num = $order['num'];
@ -1117,7 +1032,8 @@ class Notify extends Base
if ($order['use_integral'] > 0) { if ($order['use_integral'] > 0) {
$res[] = User::changeIntegral($order['user_id'], -$order['use_integral'], 2, '购买盒子' . $order['goods_title']); $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']); $res[] = User::changeMoney2($order['user_id'], -$order['use_money2'], 2, '购买盒子' . $order['goods_title']);
} }
@ -1555,10 +1471,14 @@ class Notify extends Base
if ($order['use_money'] > 0) { if ($order['use_money'] > 0) {
$res[] = User::changeMoney($order['user_id'], -$order['use_money'], 3, '购买盒子' . $order['goods_title']); $res[] = User::changeMoney($order['user_id'], -$order['use_money'], 3, '购买盒子' . $order['goods_title']);
} }
#扣吧唧币 #扣货币1
if ($order['use_integral'] > 0) { if ($order['use_integral'] > 0) {
$res[] = User::changeIntegral($order['user_id'], -$order['use_integral'], 2, '购买盒子' . $order['goods_title']); $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'])) { if (!empty($order['coupon_id'])) {
$coupon = CouponReceiveModel::where(['id' => $order['coupon_id'], 'status' => 0])->update(['status' => 1]); $coupon = CouponReceiveModel::where(['id' => $order['coupon_id'], 'status' => 0])->update(['status' => 1]);