diff --git a/app/api/controller/AliNotify.php b/app/api/controller/AliNotify.php index 09fb732..1eaf824 100755 --- a/app/api/controller/AliNotify.php +++ b/app/api/controller/AliNotify.php @@ -43,10 +43,10 @@ class AliNotify extends Base // 获取微信支付配置 $wxpayConfig = \app\common\helper\WxPayHelper::getWxPayConfig(); $merchant = $wxpayConfig['merchant']; - + // 使用随机商户的密钥 static::$secretKey = $merchant['keys']; - + // 获取公众号密钥 static::$secretKeyAccount = getConfig('wechatofficialaccount')['keys']; } @@ -172,10 +172,10 @@ class AliNotify extends Base } return $res; } - + /* - * 支付宝支付回调修改订单状态 - */ + * 支付宝支付回调修改订单状态 + */ public function alipay_notify() { //原始订单号 @@ -184,236 +184,236 @@ class AliNotify extends Base $trade_no = input('trade_no'); //交易状态 $trade_status = input('trade_status'); - $ext_infos=input('ext_infos'); + $ext_infos = input('ext_infos'); $table = input('subject'); - + // Log::info('alipay_notify=================$out_trade_no' . $out_trade_no); // Log::info('alipay_notify=================$trade_no' . $out_trade_no); // Log::info('$table=================$table'.$table ); Db::name('pay_log')->insert([ - 'user_id' => '11', - 'out_trade_no' => $out_trade_no, - 'addtime' => time(), - 'trade_no' => $trade_no, - 'content'=>$trade_status - ]); - - if ( $trade_status == 'TRADE_SUCCESS') { - - - - // try { - // $orderInfo111 = Order::where('order_num', '=', $out_trade_no) - // ->where('status', '=', 0) - // ->find(); - // if($orderInfo111){ - // $user111 = User::where('id', $orderInfo111['user_id'])->find(); - // if($user111){ - // Db::name('wxpay_log')->insert([ - // 'order_no' => $data['out_trade_no'], - // 'content' => json_encode($data), - // 'type' => 2, - // 'user_id' => $user111['id'], - // 'addtime' => time(), - // ]); - // } - // } - - // } catch (\Throwable $e) { - // $this->CallbackSuccess(); - // } - $user = null; - if ($table == 'user_recharge') {#余额充值 - $orderInfo = UserRecharge::where('order_num', '=', $out_trade_no) - ->where(['status' => 1]) - ->find(); - #这个订单存在状态对 - 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_id' => '11', + 'out_trade_no' => $out_trade_no, + 'addtime' => time(), + 'trade_no' => $trade_no, + 'content' => $trade_status + ]); + + if ($trade_status == 'TRADE_SUCCESS') { + + + + // try { + // $orderInfo111 = Order::where('order_num', '=', $out_trade_no) + // ->where('status', '=', 0) + // ->find(); + // if($orderInfo111){ + // $user111 = User::where('id', $orderInfo111['user_id'])->find(); + // if($user111){ + // Db::name('wxpay_log')->insert([ + // 'order_no' => $data['out_trade_no'], + // 'content' => json_encode($data), + // 'type' => 2, + // 'user_id' => $user111['id'], + // 'addtime' => time(), + // ]); + // } + // } + + // } catch (\Throwable $e) { + // $this->CallbackSuccess(); + // } + $user = null; + if ($table == 'user_recharge') {#余额充值 + $orderInfo = UserRecharge::where('order_num', '=', $out_trade_no) + ->where(['status' => 1]) + ->find(); + #这个订单存在状态对 + if ($orderInfo && $orderInfo['status'] == 1) { $user = User::where('id', $orderInfo['user_id'])->find(); - #这个订单存在状态对 - if ($orderInfo && $orderInfo['status'] == 0) { - $user_id = $orderInfo['user_id']; - $price = $orderInfo['price']; - Db::startTrans(); - try { - #开盒子 - $res[] = $this->drawprize_notice($user_id, $orderInfo['id'], $orderInfo['goods_id'], $orderInfo['num']); - - $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']); - - } - - } - } catch (\Throwable $e) { - Db::rollback(); - #卡单了 - Order::field('kd_is')->where(['id' => $orderInfo['id']]) - ->update(['kd_is' => 1]); - #通知微信 - $this->CallbackSuccess(); - } - #记录微信支付 - $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(); - } + $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'; } - } 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(), - ]); + } 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(); + #这个订单存在状态对 + if ($orderInfo && $orderInfo['status'] == 0) { + $user_id = $orderInfo['user_id']; + $price = $orderInfo['price']; + + Db::startTrans(); + try { + #开盒子 + $res[] = $this->drawprize_notice($user_id, $orderInfo['id'], $orderInfo['goods_id'], $orderInfo['num']); $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(); } + } 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) - ->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(); - } + #记录微信支付 + $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_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') { + + } + + + + // try { // Db::name('wxpay_log')->insert([ // 'order_no' => $data['out_trade_no'], @@ -426,22 +426,22 @@ class AliNotify extends Base // } catch (\Throwable $e) { // $this->CallbackSuccess(); // } - - - - - - - - - }else{ + + + + + + + + + } else { echo "fail"; } - - - + + + } - + /** * * 获取支付结果通知数据 @@ -756,26 +756,26 @@ class AliNotify extends Base ->find(); if ($order) { - //判断是否限制购买一次 - $sbuser=User::where(['id' => $user_id])->find(); - $sbgoods=User::where(['id' => $goods_id])->find(); - $user_xiangou_count = OrderList::field('id')->where('goods_id', '=', $goods_id) - ->where('num', '=', $num) - ->where('shang_id', 'between', [10, 38]) - ->where('order_type', 'in', [1, 3, 5, 6, 11]) - ->where('user_id', '=', $user_id) - ->count(); - - if (($sbgoods['type'] == 6 ||$sbgoods['type'] == 1) && $sbgoods['quanju_xiangou'] > 0) { - if($user_xiangou_count>= $sbgoods['quanju_xiangou']){ - Log::info('====用户id'.$user_id.'试图作弊,已停发本次赏品'); - Log::info('====用户id'.$user_id.'试图作弊,已停发本次赏品'); - Log::info('====用户id'.$user_id.'试图作弊,已停发本次赏品'); - $res1[] = 0; - return $res1; - } - } - + //判断是否限制购买一次 + $sbuser = User::where(['id' => $user_id])->find(); + $sbgoods = User::where(['id' => $goods_id])->find(); + $user_xiangou_count = OrderList::field('id')->where('goods_id', '=', $goods_id) + ->where('num', '=', $num) + ->where('shang_id', 'between', [10, 38]) + ->where('order_type', 'in', [1, 3, 5, 6, 11]) + ->where('user_id', '=', $user_id) + ->count(); + + if (($sbgoods['type'] == 6 || $sbgoods['type'] == 1) && $sbgoods['quanju_xiangou'] > 0) { + if ($user_xiangou_count >= $sbgoods['quanju_xiangou']) { + Log::info('====用户id' . $user_id . '试图作弊,已停发本次赏品'); + Log::info('====用户id' . $user_id . '试图作弊,已停发本次赏品'); + Log::info('====用户id' . $user_id . '试图作弊,已停发本次赏品'); + $res1[] = 0; + return $res1; + } + } + #改变状态 @@ -797,6 +797,10 @@ class AliNotify extends Base if ($order['use_score'] > 0) { $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'])) { $coupon = CouponReceiveModel::where(['id' => $order['coupon_id'], 'status' => 0])->update(['status' => 1]); @@ -808,103 +812,103 @@ class AliNotify extends Base $res[] = User::distribution($order); #分销奖励 //对对碰 - $ddp_goods=Goods::where('id',$goods_id)->find(); - if($ddp_goods&&($ddp_goods['is_ddp']==1||$ddp_goods['is_zp']==1)){ - - }else{ - #普通奖品========================================================== + $ddp_goods = Goods::where('id', $goods_id)->find(); + if ($ddp_goods && ($ddp_goods['is_ddp'] == 1 || $ddp_goods['is_zp'] == 1)) { + + } else { + #普通奖品========================================================== $res[] = $this->ordinary_prize_notice($order); #普通奖品========================================================== } - + #判断是否发积分 发券 $res[] = User::is_integral_coupon($order); - + //升级欧气值 if ($order['price'] > 0) { User::ou_qi_level_up($order['user_id'], $order['price']); } - - if($ddp_goods&&$ddp_goods['is_zp']==1){ - - $goodslist_xz = GoodsList::where(['goods_id' => $ddp_goods['id']]) - ->order('pro asc') - ->select()->toArray(); - $randomValue = mt_rand(1, 100); // 生成0到100之间的随机数 - $nowpro=0; - $read_goods=[]; - foreach ($goodslist_xz as $key => &$value1) { - $nowpro+=$value1['pro']; - if($randomValue<$nowpro){ - $read_goods=$value1; - 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, - 'status' => 0,#0未操作 1选择兑换 2选择发货 - '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(), - 'prize_code' => $read_goods['prize_code'], - 'order_type' => 11, - 'order_list_id' => 0, - 'xz_id'=>0 - ]; - - - $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; + if ($ddp_goods && $ddp_goods['is_zp'] == 1) { + + $goodslist_xz = GoodsList::where(['goods_id' => $ddp_goods['id']]) + ->order('pro asc') + ->select()->toArray(); + $randomValue = mt_rand(1, 100); // 生成0到100之间的随机数 + $nowpro = 0; + $read_goods = []; + foreach ($goodslist_xz as $key => &$value1) { + $nowpro += $value1['pro']; + if ($randomValue < $nowpro) { + $read_goods = $value1; + 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; + } } - $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 + + $order_goods = [ + 'order_id' => $order_id, + 'user_id' => $user_id, + 'status' => 0,#0未操作 1选择兑换 2选择发货 + '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(), + '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[]=Db::name('touch_user_list')->insert($updata); + + + + $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; } - - }else{ - + $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 { + #特殊奖品********************************************************** #普通奖品余量信息 $goodslist = GoodsList::field('sum(`stock`) as stock, sum(`surplus_stock`) as surplus_stock') @@ -926,7 +930,7 @@ class AliNotify extends Base if ($goodslist['surplus_stock'] <= 0) { // var_dump($goodslist['surplus_stock']); $res[] = $this->openFd($goods_id, $num); - + $res[] = $this->special_prize_notice($order, $first_count); // var_dump($res); #擂台赏 @@ -948,8 +952,8 @@ class AliNotify extends Base ->update($save_update); } #特殊奖品********************************************************** - - + + } } else { $res[] = 0; @@ -1138,7 +1142,7 @@ class AliNotify extends Base 'addtime' => time(), 'prize_code' => $ordinary_prize_info['prize_code'], 'order_type' => $order_type, - 'is_fd'=>$ordinary_prize_info['is_fd'] + 'is_fd' => $ordinary_prize_info['is_fd'] ]; #减少库存 $res[] = GoodsList::field('surplus_stock') @@ -1155,79 +1159,80 @@ class AliNotify extends Base /** * openFd 福袋开启 */ - protected function openFd($goods_id, $num){ + protected function openFd($goods_id, $num) + { $res = []; $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('is_fd', '=', 1) - ->where('status', '=', 0) - ->order('id asc') - ->select()->toArray(); - - if (count($all_order_list)>0) { - $orders=[]; - $goodss=[]; - $goodslist_read=[]; - $readindex=0; - $v_goods=null; + ->where('num', '=', $num) + ->where('is_fd', '=', 1) + ->where('status', '=', 0) + ->order('id asc') + ->select()->toArray(); + + if (count($all_order_list) > 0) { + $orders = []; + $goodss = []; + $goodslist_read = []; + $readindex = 0; + $v_goods = null; foreach ($all_order_list as $order) { - if(!$v_goods){ - $v_goods=GoodsList::field('id,prize_code,is_fd')->where(['id'=>$order['goodslist_id']])->find(); + if (!$v_goods) { + $v_goods = GoodsList::field('id,prize_code,is_fd')->where(['id' => $order['goodslist_id']])->find(); } - - if($v_goods['is_fd']==1){ - $orders[]=[ - 'id'=>$order['id'], - 'recovery_num'=>$order['user_id'].'FD'."|".$order['id'], - 'status'=>4, - 'choice_time'=>time() + + if ($v_goods['is_fd'] == 1) { + $orders[] = [ + 'id' => $order['id'], + 'recovery_num' => $order['user_id'] . 'FD' . "|" . $order['id'], + 'status' => 4, + 'choice_time' => time() ]; - if(count($goodslist_read)==0){ - - $goodslist_xz = GoodsList::where(['xz_pid' => $v_goods['prize_code']]) + if (count($goodslist_read) == 0) { + + $goodslist_xz = GoodsList::where(['xz_pid' => $v_goods['prize_code']]) ->order('pro asc') ->select()->toArray(); - + foreach ($goodslist_xz as $key => &$value1) { for ($i = 0; $i < $value1['pro']; $i++) { - $goodslist_read[]=$value1; + $goodslist_read[] = $value1; } } shuffle($goodslist_read); shuffle($goodslist_read); } - $read_goods=$goodslist_read[$readindex]; + $read_goods = $goodslist_read[$readindex]; $readindex++; $goodss[] = [ - 'order_id' => 0, - 'user_id' => $order['user_id'], - 'status' => 0,#0未操作 1选择兑换 2选择发货 - 'goods_id' =>$read_goods['goods_id'], - 'num' => 0, - '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(), - 'prize_code' => $read_goods['prize_code'], - 'order_type' => 10, - 'order_list_id' => 0, - 'xz_id'=>$order['id'] - ]; + 'order_id' => 0, + 'user_id' => $order['user_id'], + 'status' => 0,#0未操作 1选择兑换 2选择发货 + 'goods_id' => $read_goods['goods_id'], + 'num' => 0, + '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(), + 'prize_code' => $read_goods['prize_code'], + 'order_type' => 10, + 'order_list_id' => 0, + 'xz_id' => $order['id'] + ]; } - + } - $orderList=new OrderList; - $res[]=$orderList->saveAll($orders); + $orderList = new OrderList; + $res[] = $orderList->saveAll($orders); - $res[] =OrderList::insertAll($goodss); - - }else{ + $res[] = OrderList::insertAll($goodss); + + } else { $res[] = 1; } return $res; @@ -1285,7 +1290,7 @@ class AliNotify extends Base 'prize_code' => $special_prize['prize_code'], 'order_type' => $order_type, 'order_list_id' => $order_list_id, - 'is_fd'=>$special_prize['is_fd'] + 'is_fd' => $special_prize['is_fd'] ]; #增加销量 $res[] = GoodsList::field('surplus_stock') @@ -1396,14 +1401,14 @@ class AliNotify extends Base // return $res; $res = []; $goods_id = $order['goods_id']; - - $flwgoods= Goods::where(['id' => $goods_id])->find(); - if($flwgoods['is_flw']==1){ + + $flwgoods = Goods::where(['id' => $goods_id])->find(); + if ($flwgoods['is_flw'] == 1) { Log::info('拦截福利屋直接开箱' . $goods_id); $res[] = 1; return $res; } - + $num = $order['num']; $order_type = $order['order_type']; #特殊奖品存在 @@ -1436,33 +1441,33 @@ class AliNotify extends Base $order_list_id = $prize_info['id']; #中奖奖项 $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']]) - ->order('pro asc') - ->select()->toArray(); + ->order('pro asc') + ->select()->toArray(); $randomValue = mt_rand(1, 100); // 生成0到100之间的随机数 - $nowpro=0; - $read_goods=[]; + $nowpro = 0; + $read_goods = []; foreach ($goodslist_xz as $key => &$value1) { - $nowpro+=$value1['pro']; - if($randomValue<$nowpro){ - $read_goods=$value1; + $nowpro += $value1['pro']; + if ($randomValue < $nowpro) { + $read_goods = $value1; Db::name('error_log')->insert([ 'user_id' => '33', 'goods_id' => '44', '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' - - ]); - - $randomValue=99999; + + ]); + + $randomValue = 99999; } } - + $order_goods[] = [ 'order_id' => 0, 'user_id' => $user_id, @@ -1481,10 +1486,10 @@ class AliNotify extends Base 'prize_code' => $read_goods['prize_code'], 'order_type' => $order_type, 'order_list_id' => $order_list_id, - 'is_fd'=>$read_goods['is_fd'] + 'is_fd' => $read_goods['is_fd'] ]; - - }else{ + + } else { $order_goods[] = [ 'order_id' => 0, 'user_id' => $user_id, @@ -1503,7 +1508,7 @@ class AliNotify extends Base 'prize_code' => $ordinary_prize_info['prize_code'], 'order_type' => $order_type, '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'], 'order_type' => $order_type, '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') @@ -1723,7 +1728,7 @@ class AliNotify extends Base 'prize_code' => $prize_info['prize_code'], 'order_type' => $order_type, 'luck_no' => $luck_no, - 'is_fd'=>$prize_info['is_fd'] + 'is_fd' => $prize_info['is_fd'] ]; #入库=== $res[] = OrderList::insert($save_prize_info); @@ -1822,7 +1827,7 @@ class AliNotify extends Base 'prize_code' => $prize_info['prize_code'], 'order_type' => $order_type, 'luck_no' => $luck_no, - 'is_fd'=>$prize_info['is_fd'] + 'is_fd' => $prize_info['is_fd'] ]; #入库=== $res[] = OrderList::insert($save_prize_info); @@ -2173,7 +2178,7 @@ class AliNotify extends Base 'addtime' => time(), 'prize_code' => $prize_info['prize_code'], 'order_type' => $order_type, - 'is_fd'=>$prize_info['is_fd'] + 'is_fd' => $prize_info['is_fd'] ]; if ($prize_info['special_stock'] >= 1) { #减少库存 @@ -2405,7 +2410,7 @@ class AliNotify extends Base 'prize_code' => $prize_info['prize_code'], 'order_type' => $order_type, 'luck_no' => $luck_no, - 'is_fd'=>$prize_info['is_fd'] + 'is_fd' => $prize_info['is_fd'] ]; #入库=== $res[] = OrderList::insert($save_prize_info); @@ -2459,7 +2464,7 @@ class AliNotify extends Base { //微信官方发货 $wxServer = new \app\common\server\Wx($this->app); - + $access_token = $wxServer->get_access_token(); $open_id = Db::name('user')->where('id', $user_id)->value('openid'); $wxServer->post_order($open_id, $access_token, $order_num); diff --git a/app/api/controller/Infinite.php b/app/api/controller/Infinite.php index 71da83b..15e95a2 100755 --- a/app/api/controller/Infinite.php +++ b/app/api/controller/Infinite.php @@ -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, diff --git a/app/api/controller/Notify.php b/app/api/controller/Notify.php index 2130b82..60cce45 100755 --- a/app/api/controller/Notify.php +++ b/app/api/controller/Notify.php @@ -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]);