where('first_pay', 1)->first(); $this->first_pay = $first_pay; $this->FirstCharge = (int)$first_pay->favorable_price; $this->FirstChargeGive = (int)$first_pay->give; $this->FirstGiftID = (int)$first_pay->gift_id; } /** * 获取支付金额 * @param int $GiftsID 礼包ID * @param int $user_id 用户ID * @param int $payAmt 支付金额(元) * @return array|void [$give, $favorable_price, $Recharge, $czReason, $cjReason] 赠送金额,赠送金额+充值金额,充值金额,充值原因,彩金原因 */ public function getPayInfo($GiftsID, $user_id, $payAmt) { $give = $czReason = $cjReason = $Recharge = $favorable_price = $second_give = 0; // 判断是不是首冲礼包 if (!empty($GiftsID)) { if ($GiftsID < 100) { // 礼包--首冲 $GiftsData = [ 'UserID' => $user_id, 'GiftsID' => $GiftsID, 'BuyCount' => 1, 'LastBuyDate' => date('Y-m-d H:i:s') ]; // 卖出去数量 +1 DB::connection('write')->table('QPAccountsDB.dbo.FirstRechargeGifts')->where('GiftsID', $GiftsID)->increment('TotalCount'); $userGifts = DB::connection('write')->table('QPAccountsDB.dbo.UserFirstRechargeGifts')->where('UserID', $user_id)->where('GiftsID', $GiftsID)->first(); if ($userGifts) { DB::connection('write')->table('QPAccountsDB.dbo.UserFirstRechargeGifts')->where('UserID', $user_id)->where('GiftsID', $GiftsID)->increment('BuyCount'); } else { DB::connection('write')->table('QPAccountsDB.dbo.UserFirstRechargeGifts')->insert($GiftsData); } // 给服务端更新首冲状态 DB::connection('write')->table('QPAccountsDB.dbo.UserTabData') ->where('UserID', $user_id) ->update(['RechargeGiftTime' => date('Y-m-d H:i:s')]); $Gifts = DB::connection('write')->table('QPAccountsDB.dbo.FirstRechargeGifts')->where('GiftsID', $GiftsID)->first(); $favorable_price = $Gifts->AllScore; $give = $Gifts->ExtraScore; $Recharge = $Gifts->Price; $czReason = 50; $cjReason = 51; } elseif ($GiftsID > 100 && $GiftsID < 200) { // 周卡 $CardID = $GiftsID - 100; $WeeklyCard = DB::connection('write')->table('QPPlatformDB.dbo.MonthCard')->where('CardID', $CardID)->first(); $favorable_price = $WeeklyCard->FirstReward / 100; $Recharge = $WeeklyCard->Price; } elseif (false) {//$GiftsID == 200 || $GiftsID == 201) { // 20元首充 $RechargeNum = $this->FirstCharge * NumConfig::NUM_VALUE; $give = $this->FirstChargeGive; // 赠送 $firstPayExists = DB::table(TableName::QPAccountsDB() . 'UserRechargeActive')->where('UserID', $user_id)->first(); if (!$firstPayExists) { DB::table(TableName::QPAccountsDB() . 'UserRechargeActive') ->insert([ 'UserID' => $user_id, 'RechargeNum' => $RechargeNum, 'RewardDate' => date('Ymd'), 'FinishDate' => date('Ymd'), 'TotalReward' => $RechargeNum + ($this->FirstChargeGive * NumConfig::NUM_VALUE), 'CreateTime' => now() ]); } $favorable_price = $this->FirstCharge + $this->FirstChargeGive; // 充值 $Recharge = $this->FirstCharge; // 充值 $czReason = 1; $cjReason = 45; } elseif ($GiftsID == 200 || $GiftsID == 201 || $GiftsID == 211 || $GiftsID == 212) { // 引导付费礼包档位1 + 引导付费礼包档位2 $first = DB::table('agent.dbo.recharge_gear')->where('gift_id', $GiftsID)->first(); if ($first) { $Recharge = $first->favorable_price; // 充值 $give = $first->give; $second_give = $first->second_give ?? 0; $favorable_price = $give + $Recharge; // 直接得到的金币 $czReason = 1; $cjReason = 45; $RechargeNum = $Recharge * NumConfig::NUM_VALUE; if (!DB::table(TableName::QPAccountsDB() . 'UserRechargeActive')->where('UserID', $user_id)->exists()) { DB::table(TableName::QPAccountsDB() . 'UserRechargeActive') ->insert([ 'UserID' => $user_id, 'RechargeNum' => $RechargeNum, 'RewardDate' => date('Ymd'), 'FinishDate' => date('Ymd'), 'TotalReward' => ($favorable_price + $second_give) * NumConfig::NUM_VALUE, 'CreateTime' => now() ]); } } } else if ($GiftsID > 300) { // 查找送的金额 $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('first_pay', 0)->where('money', $payAmt)->where('gift_id', $GiftsID)->select('favorable_price', 'give')->first(); $Recharge = $recharge_gear->favorable_price; $give = $recharge_gear->give; $favorable_price = $Recharge + $give; $czReason = 1; $cjReason = 45; } } else { // 普通订单 // 查找送的金额 $RechargeTimes=DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $user_id)->value('RechargeTimes')??0; $Status = 1; // if($RechargeTimes>=4) { // }else{ // $Status=$RechargeTimes+3; // } $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('first_pay', 0)->where('status', $Status)->where('money', $payAmt)->select('favorable_price', 'give')->first(); if(!$recharge_gear){ $Recharge=$payAmt; $give=0; }else{ $Recharge = $recharge_gear->favorable_price; $give = $recharge_gear->give; } $favorable_price = $Recharge + $give; $czReason = 1; $cjReason = 45; } return [$give, $favorable_price, $Recharge, $czReason, $cjReason, $second_give]; } /** * 添加玩家充值记录 * @param $user_id * @param $payAmt * @param $favorable_price * @param $order_sn * @param $GiftsID * @param $Recharge * @param $czReason * @param $give * @param $cjReason * @param $AdId * @param $eventType */ public function addRecord($user_id, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $AdId, $eventType) { if ($payAmt > 0) { // 增加玩家充值金额 $query = DB::connection('write')->table('QPAccountsDB.dbo.YN_VIPAccount') ->where('UserID', $user_id) ->value('Recharge'); if ($query) { DB::connection('write')->table('QPAccountsDB.dbo.YN_VIPAccount') ->where('UserID', $user_id) ->increment('Recharge', $payAmt); } else { DB::connection('write')->table('QPAccountsDB.dbo.YN_VIPAccount') ->where('UserID', $user_id) ->insert(['Recharge' => $payAmt, 'UserID' => $user_id]); } try { if($query>=100){ $user=GlobalUserInfo::getGameUserInfo('UserID',$user_id); if($user){ if($user->Channel == 99){ GlobalUserInfo::where('UserID', $user_id)->update([ 'Channel' => 50]); // $user->Channel = 50; // $user->save(); } } } }catch (\Exception $exception){ } } if ($Recharge > 0) { // 添加日志记录表 StoredProcedure::addPlatformData($user_id, 3, $Recharge * NumConfig::NUM_VALUE); // 增加用户金币变化记录 $AfterScore = RecordScoreInfo::addScore($user_id, ($Recharge * NumConfig::NUM_VALUE), $czReason); #充值 if ($AfterScore) { RecordScoreInfo::addScore($user_id, ($give * NumConfig::NUM_VALUE), $cjReason, $AfterScore); #赠送彩金 } } $favorable_price = $favorable_price * NumConfig::NUM_VALUE; $firstScore = DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $user_id)->value('Score'); $Score = $favorable_price + $firstScore; if ($payAmt > 0) { try { $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo') ->where('UserID', $user_id) ->first(); $channelConfig = DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel', $userInfo->Channel)->first(); // Util::WriteLog('xxxxx', [$userInfo->Channel, $channelConfig, $query, $firstScore, $channelConfig->Rate > 0 && $channelConfig->ContrlScore > 0, $channelConfig->MinScore * NumConfig::NUM_VALUE > $firstScore]); if ($channelConfig && !$query) { if ($channelConfig->Rate > 0 && $channelConfig->ContrlScore > 0) { if ($channelConfig->MinScore * NumConfig::NUM_VALUE >= $firstScore) { $openGames = config('games.openKGame'); $query = DB::table('QPTreasureDB.dbo.UserScoreControl')->where('UserID', $user_id)->first(); if (!$query) { $build_sql = DB::connection('write')->table('QPTreasureDB.dbo.UserScoreControl'); //Util::WriteLog('control_old_user',$list); $data = [ 'ControlScore' => (int)($channelConfig->ContrlScore * NumConfig::NUM_VALUE), 'EffectiveScore' => 0, 'ControlKindID' => -1, 'Remarks' => '', 'InsertDate' => date('Y-m-d H:i:s'), 'ControlRadian' => 0 ]; $build_sql->updateOrInsert(['UserID' => $user_id], $data); foreach ($openGames as $GameID) { $KindData = [ 'UserID' => $user_id, 'KindID' => $GameID, 'ControlRadian' => $channelConfig->Rate, 'ControlDate' => date('Y-m-d H:i:s') ]; DB::connection('write')->table('QPTreasureDB.dbo.UserControlKind')->updateOrInsert(['UserID' => $user_id, 'KindID' => $GameID], $KindData); } } } } } } catch (\Exception $exception) { } // 记录订单变化后金币 DB::connection('write')->table('agent.dbo.order') ->where('order_sn', $order_sn) ->update(['after_amount' => $Score]); // 增加用户充值变化值 RecordUserDataStatistics::updateOrAdd($user_id, 0, $payAmt); } // 不是周卡的时候执行 if ($GiftsID < 100 || $GiftsID >= 200) { // 增加用户金币 DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $user_id)->increment('Score', $favorable_price); } // 充值推广佣金 // (new AgentUser())->reward($user_id, $payAmt, $order_sn); // // 周卡 -- 执行存储过程 if (isset($GiftsID) && $GiftsID > 100 && $GiftsID < 200) { $CardID = (int)$GiftsID - 100; StoredProcedure::BuyMonthCard($user_id, $CardID, $order_sn); // 开始执行时间 $startTime = Helper::millisecond(); Log::info('GSP_GP_BuyMonthCard 执行时间:' . ((Helper::millisecond() - $startTime) / 1000)); } //设置第二天要领取 if (isset($GiftsID) && $GiftsID >= 200 && $GiftsID < 300 ) { $first = DB::table('agent.dbo.recharge_gear')->where('gift_id', $GiftsID)->select('gift_id', 'money', 'give', 'favorable_price', 'second_give')->first(); if ($first && $first->second_give > 0) { $fpkey = 'Firstpay_' . $user_id; $data = (array)$first; $data['buytime'] = time(); $data['czReason'] = $czReason; $data['cjReason'] = $cjReason; Redis::set($fpkey, json_encode($data)); DB::table(TableName::agent() . 'guide_payment')->updateOrInsert([ 'UserID' => $user_id, 'GiftID' => $GiftsID, 'CreateTime' => now() ], ['UserID' => $user_id]); } } //设置第二天要领取 if (!empty($GiftsID) && $GiftsID >= 300 && $GiftsID < 400 ) { Redis::del('repay_temp_'.$user_id); } // 数据统计后台 -- 充值记录添加 (new RechargeWithDraw())->recharge($user_id, $payAmt); // (new RechargeWithDraw())->recharge($user_id, $Recharge); if ($AdId && $payAmt) AfEvent::dispatch([$user_id, $payAmt, $AdId, $eventType]); try { //新邀请 (new AgentController())->processDeposit($user_id, $payAmt,$order_sn); // AgentService::recordPerformance($user_id, $payAmt * NumConfig::NUM_VALUE); } catch (\Exception $exception) { Util::WriteLog("AgentService", $exception->getTraceAsString()); } return [$Score]; } /** * 执行存储过程 * @param $user_id * @param $payAmt * @param $favorable_price * @param $Score * @param $GiftsID */ public function storedProcedure($user_id, $payAmt, $favorable_price, $Score, $GiftsID) { // 开始执行时间 $startTime = Helper::millisecond(); // 执行存储过程 -- 防刷机制 StoredProcedure::SetUserTabType($user_id); Log::info('GSP_GP_SetUserTabType12 执行时间:' . ((Helper::millisecond() - $startTime) / 1000)); # 单控标签 -- 执行存储过程 StoredProcedure::user_label($user_id, 1, $payAmt); Log::info('CheckAccountsLabel 执行时间:' . ((Helper::millisecond() - $startTime) / 1000)); // 服务器通知 $url = config('transfer.stock')['url'] . 'notifyPay'; Log::info('中转服参数 ' . json_encode([ 'userid' => $user_id, 'getScore' => $favorable_price, 'score' => $Score, 'giftsid' => empty($GiftsID) ? 0 : $GiftsID, 'url' => $url ])); $res = (new HttpCurl())->service($url, ['userid' => $user_id, 'getScore' => $favorable_price, 'score' => $Score, 'giftsid' => empty($GiftsID) ? 0 : $GiftsID]); Log::info('中转服 执行时间:' . ((Helper::millisecond() - $startTime) / 1000), [ 'res' => $res, ]); // AF 事件 // (new AppflyerEvent())->event($user_id, '', 'af_purchase_new', $payAmt); // Log::info('AF 执行时间:' . ((Helper::millisecond() - $startTime) / 1000)); } }