AgentController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Facade\TableName;
  4. use App\Game\AgentLinks;
  5. use App\Game\AgentUser;
  6. use App\Game\GlobalUserInfo;
  7. use App\Game\QuickAccountPass;
  8. use App\Game\QuickAccountPassStore;
  9. use App\Game\Services\AgentService;
  10. use App\Game\Services\OuroGameService;
  11. use App\Game\Services\PgSoftService;
  12. use App\Game\Services\RouteService;
  13. use App\Game\Services\ServerService;
  14. use App\Game\WebChannelConfig;
  15. use App\Http\Controllers\Api\AgentClickController;
  16. use App\Http\Controllers\Controller;
  17. use App\Http\helper\NumConfig;
  18. use App\Http\logic\api\OrderLogic;
  19. use App\Jobs\Order;
  20. use App\Models\AccountsInfo;
  21. use App\Models\AccountWithDrawInfo;
  22. use App\Models\Treasure\GameScoreInfo;
  23. use App\Notification\TelegramBot;
  24. use App\Services\OrderServices;
  25. use App\Services\PayMentService;
  26. use App\Util;
  27. use App\Utility\SetNXLock;
  28. use GuzzleHttp\Client;
  29. use Illuminate\Http\Request;
  30. use Illuminate\Support\Facades\Cookie;
  31. use Illuminate\Support\Facades\Crypt;
  32. use Illuminate\Support\Facades\DB;
  33. use Illuminate\Support\Facades\Hash;
  34. use Illuminate\Support\Facades\Log;
  35. use Illuminate\Support\Facades\Redis;
  36. use Illuminate\Support\Facades\Validator;
  37. use PDO;
  38. // use Yansongda\Pay\Log;
  39. class AgentController extends Controller
  40. {
  41. protected $client;
  42. protected $url;
  43. public function __construct()
  44. {
  45. $this->client = new Client();
  46. $this->url=str_replace('https','http',env('APP_URL'));
  47. }
  48. public function modifyBindChannel(Request $request)
  49. {
  50. $GlobalUID=$request->GlobalUID;
  51. $Channel=$request->bindChannel;
  52. $gUser=GlobalUserInfo::getGameUserInfo('GlobalUID',$GlobalUID);
  53. $gUser->Channel=$Channel;
  54. $gUser->save();
  55. AgentLinks::where('GlobalUID',$GlobalUID)->update(['Channel'=>$Channel]);
  56. $UserID=ServerService::GlobalToUserID($GlobalUID);
  57. $user = AccountsInfo::where('UserID',$UserID)->first();
  58. AccountsInfo::where('UserID',$UserID)->update(['Channel'=>$Channel]);
  59. if ($user && $user->Channel != $Channel) {
  60. Log::info("用戶渠道修改", ['UserID'=>$UserID, 'orgChannel'=>$user->Channel, 'Channel'=>$Channel]);
  61. AgentClickController::changePlatformData($user->Channel, $Channel);
  62. }
  63. }
  64. public function newAgent(Request $request)
  65. {
  66. $guser=json_decode($request->gi,true);
  67. $newacc=json_decode($request->ai,true);
  68. $ua=json_decode($request->ua,true);
  69. $gs=json_decode($request->gs,true);
  70. unset($guser['ID']);
  71. $pdo = DB::connection('write')->getPdo();
  72. $pdo->setAttribute(PDO::SQLSRV_ATTR_DIRECT_QUERY, true);
  73. DB::connection('write')->unprepared("set identity_insert QPAccountsDB.dbo.AccountsInfo on;");
  74. DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->insert($newacc);
  75. DB::connection('write')->unprepared("set identity_insert QPAccountsDB.dbo.AccountsInfo off;");
  76. $pdo->setAttribute(PDO::SQLSRV_ATTR_DIRECT_QUERY, false);
  77. // DB::connection('write')->table('QPAccountsDB.dbo.UserAgent')->insert($ua);
  78. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->insert($gs);
  79. GlobalUserInfo::insert($guser);
  80. $GlobalUID=$guser['GlobalUID'];
  81. $UserID=$guser['UserID'];
  82. AgentService::SetUserAgent($GlobalUID, $UserID);
  83. return apiReturnSuc();
  84. }
  85. public function newAgentLink(Request $request)
  86. {
  87. AgentLinks::insert(json_decode($request->al,true));
  88. return apiReturnSuc();
  89. }
  90. public function getAgentLinkCode(Request $request)
  91. {
  92. return AgentLinks::getByCode($request->code);
  93. }
  94. public function getAgentLinks(Request $request)
  95. {
  96. $GlobalUID=$request->GlobalUID;
  97. return AgentLinks::where('GlobalUID',$GlobalUID)->get()->toArray();
  98. }
  99. public function getAgentPlayers(Request $request)
  100. {
  101. $GlobalUID=$request->GlobalUID;
  102. $date=$request->date;
  103. $sql=AgentUser::where('Higher1GUID',$GlobalUID)->select(['UserID','GlobalUID','LinkCode']);
  104. $datas=[];
  105. if($sql->exists()) {
  106. $users = $sql->get();
  107. $userids=$users->pluck('UserID')->toArray();
  108. $gusers=GlobalUserInfo::whereIn('UserID', $userids)->select(['GlobalUID','UserID','GameID','NickName','Phone','Email','RegisterDate','LastLogonDate'])->get()->toArray();
  109. $stats=DB::table('QPRecordDB.dbo.RecordUserTotalStatistics')->whereIn('UserID', $userids)->get()->toArray();
  110. $useridsToCode=$users->pluck('LinkCode','UserID')->toArray();
  111. foreach ($gusers as $guser){
  112. $guser=(array)$guser;
  113. $guser['contact_info']=$guser['Phone'].'/'.$guser['Email'];
  114. $guser['link_code']=$useridsToCode[$guser['UserID']];
  115. unset($guser['Phone'],$guser['Email']);
  116. $datas[$guser['UserID']]=$guser;
  117. }
  118. foreach ($stats as $stat){
  119. $stat=(array)$stat;
  120. $guser=&$datas[$stat['UserID']];
  121. $guser['deposits']=$stat['Recharge'];
  122. $guser['withdrawal']=$stat['Withdraw']/100;
  123. $guser['casino_bet']=$stat['TotalBet']/100??($stat['WinScore']+abs($stat['LostScore']))/100;
  124. $guser['casino_win']=($stat['WinScore']+$stat['LostScore'])/100;
  125. $guser['sport_bet']=0;
  126. $guser['sport_win']=0;
  127. }
  128. }
  129. return $datas;
  130. // 'GameID',
  131. // 'NickName',
  132. // 'Subsite',
  133. // 'contact_info',
  134. // 'deposits',
  135. // 'casino_bet',
  136. // 'casino_win',
  137. // 'sport_bet',
  138. // 'sport_win',
  139. // 'withdrawal',
  140. // 'RegisterDate',
  141. // 'LastLoginDate',
  142. // 'created_at',
  143. // 'updated_at',
  144. }
  145. public function createAccount(Request $request)
  146. {
  147. $getData = $request->query(); // 获取 GET 数据
  148. $postData = $request->post(); // 获取 POST 数据
  149. $postData['bfp']=md5(random_bytes(20));
  150. $postData['type']='guest';
  151. $response = $this->client->post( $this->url. '/game/register', [
  152. 'query' => $getData, // 传递 GET 数据
  153. 'form_params' => $postData, // 传递 POST 数据
  154. ]);
  155. $res=json_decode($response->getBody(),true);
  156. return $res['data'];
  157. }
  158. public function getAccount(Request $request)
  159. {
  160. $uids=$request->uids;
  161. return GameScoreInfo::whereIn('UserID',$uids)->select(['UserID','Score'])->pluck('Score','UserID')->toArray();
  162. }
  163. public function updateAccountScore(Request $request){
  164. $GlobalUID=$request->GlobalUID;
  165. $addScore=intval($request->addScore);
  166. $UserID=GlobalUserInfo::GlobalToUserID($GlobalUID);
  167. $nowScore=GlobalUserInfo::getScoreByUserID($UserID)*NumConfig::NUM_VALUE;
  168. if($addScore+$nowScore<0){
  169. return ['error'=>1,'NowScore'=>$nowScore,'UserID'=>$UserID,'GlobalUID'=>$GlobalUID];
  170. }
  171. [$OrgScore,$NowScore]=OuroGameService::AddScore($UserID,$addScore,OuroGameService::REASON_updateAccount);
  172. return compact('OrgScore','NowScore','UserID','GlobalUID');
  173. }
  174. public function userPay(Request $request)
  175. {
  176. $sn=$request->sn;
  177. $GlobalUID=$request->GlobalUID;
  178. $Score=$request->Score;
  179. // 获取数据
  180. $userId = ServerService::GlobalToUserID($GlobalUID);
  181. $OldScore=GlobalUserInfo::getScoreByUserID($userId);
  182. //自动识别首冲
  183. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  184. ->where('UserID', $userId)
  185. ->value('Recharge') ?: 0;
  186. $service = new OrderServices();
  187. // 生成订单信息
  188. $logic = new OrderLogic();
  189. $giftid=0;
  190. $give=0;
  191. $OrgScore=$Score;
  192. if(!$user_recharge) {
  193. // 首冲赠送直接加上
  194. if($Score>=$service->FirstCharge){
  195. $give+=$service->FirstChargeGive;
  196. $giftid=$service->FirstGiftID;
  197. $Score-=$service->FirstCharge;
  198. // [$gear_give, $gear_total, $gear_price, $czReason, $cjReason] =
  199. $service->getPayInfo($giftid, $userId, $service->FirstCharge);
  200. }else{
  201. //最小充值起跳
  202. return ['error'=>1,'MinScore'=>$service->FirstCharge,'msg'=>'You need recharge at least '.$service->FirstCharge.''];
  203. }
  204. }
  205. //确定对应的梯度
  206. $gear = DB::table('agent.dbo.recharge_gear')
  207. ->where('favorable_price', '<=',$Score)
  208. ->where('status', 1)
  209. ->where('gift_id', 0)
  210. ->orderByDesc('favorable_price')->first();
  211. if($gear){
  212. // [$gear_give, $gear_total, $gear_price, $czReason, $cjReason] = $service->getPayInfo($giftid, $userId, $service->FirstCharge);
  213. $give+=$gear->give;
  214. }else if(!$giftid){
  215. //啥也没有
  216. $gear = DB::table('agent.dbo.recharge_gear')
  217. ->where('status', 1)
  218. ->where('gift_id', 0)
  219. ->orderBy('favorable_price')->first();
  220. //最小充值起跳
  221. return ['error'=>1,'MinScore'=>$gear->favorable_price,'msg'=>'You need recharge at least '.$gear->favorable_price.''];
  222. }
  223. $amount = $OrgScore * NumConfig::NUM_VALUE;
  224. $logic->orderCreate($sn, $amount, 'AgentSystem', $userId, '', $giftid,'','');
  225. $Recharge = $OrgScore;
  226. $favorable_price = $Recharge + $give;
  227. $czReason = 1;
  228. $cjReason = 45;
  229. // 增加充值记录
  230. [$NewScore] = $service->addRecord($userId, $OrgScore, $favorable_price, $sn, $giftid, $Recharge, $czReason, $give, $cjReason, '', '');
  231. // 成功处理回调
  232. Order::dispatch([$userId, $OrgScore, $NewScore, $favorable_price, $giftid, $sn]);
  233. // 修改订单状态
  234. $body = [
  235. 'pay_status' => 1,
  236. 'finished_at' => date('Y-m-d H:i:s'),
  237. 'updated_at' => date('Y-m-d H:i:s'),
  238. 'pay_at' => date('Y-m-d H:i:s')
  239. ];
  240. DB::connection('write')->table('agent.dbo.order')
  241. ->where('order_sn', $sn)
  242. ->update($body);
  243. return ['success'=>1,'Score'=>$NewScore,'GlobalUID'=>$GlobalUID,'UserID'=>$userId];
  244. }
  245. public function userPayout(Request $request)
  246. {
  247. $sn=$request->sn;
  248. $GlobalUID=$request->GlobalUID;
  249. $score=$request->Score;
  250. $agentID=$request->agentID;
  251. $UserID=ServerService::GlobalToUserID($GlobalUID);
  252. if(!$score||is_float($score)||$score<=0){
  253. return apiReturnFail(['web.withdraw.score_fail', 'Amount must be an integer value.']);
  254. }
  255. $winfo=AccountWithDrawInfo::query()->where('UserID', $UserID)->first();
  256. if(!$winfo){
  257. $data = [
  258. "UserID" => $UserID,
  259. "BankNO" => "$agentID",
  260. "AccountsBank" => "$agentID",
  261. "BankUserName" => "$agentID",
  262. "PhoneNumber" => "$agentID",
  263. "IFSCNumber" => "$agentID",
  264. "EmailAddress" => "$agentID",
  265. "Achieves" => $agentID,
  266. "PANNumber" => "$agentID",
  267. "AdhaarNumber" => "$agentID",
  268. "HistoryWithDraw" => 0,
  269. "BranchBank" => "$agentID",
  270. "Win" => 0,
  271. "Lost" => 0,
  272. "Switch" => 1,
  273. "PixNum" => "$agentID",
  274. "PixType" => 66
  275. ];
  276. AccountWithDrawInfo::insert($data);
  277. }
  278. $dbh = DB::connection()->getPdo();
  279. $score=$score*NumConfig::NUM_VALUE;
  280. $sql="DECLARE @return_value int
  281. EXEC @return_value = QPAccountsDB.dbo.GSP_GR_GetWithDraw '$UserID','$score'
  282. SELECT 'ReturnValue' = @return_value";
  283. // echo $sql;die;
  284. $stmt = $dbh->prepare($sql);
  285. $stmt->execute();
  286. $retval = $stmt->fetch(\PDO::FETCH_ASSOC);
  287. try {
  288. // set @ret = 1 --可提额度不足
  289. // set @ret = 2 --低于最低可提现金额
  290. // set @ret = 3 --高于最高可提现金额
  291. // set @ret = 4 --超过每天提现次数上限
  292. // set @ret = 5 --身上钱不够
  293. // set @ret = 6 --开在游戏里面
  294. // set @ret = 7 --未充值的用户TX额度
  295. if (isset($retval['ReturnValue'])) {
  296. $ReturnValue = $retval['ReturnValue'];
  297. // set @ret = 1 -- Insufficient withdrawal amount
  298. // set @ret = 2 -- Lower than the minimum withdrawal amount
  299. // set @ret = 3 -- Higher than the maximum withdrawal amount
  300. // set @ret = 4 -- Exceeded the daily withdrawal limit
  301. // set @ret = 5 -- Not enough money on hand
  302. // set @ret = 6 -- Opened in the game
  303. // set @ret = 7 -- Undeposited user TX amount
  304. $errors = [
  305. [],
  306. ['web.withdraw.no_withdraw_value', "The withdrawable amount is not enough,you need play more games"],
  307. ['web.withdraw.too_low', 'Lower than the minimum withdrawal amount'],
  308. ['web.withdraw.too_high', 'Higher than the maximum withdrawal amount'],
  309. ['web.withdraw.day_max', 'Exceeded the daily withdrawal limit'],
  310. ['web.withdraw.no_enouth_score', 'Not enough money on hand'],
  311. ['web.withdraw.in_game', 'Sorry, You\'re in game for now'],
  312. ['web.withdraw.no_deposit', ' You need deposit first!'],
  313. ];
  314. return apiReturnFail($errors[$ReturnValue], [], $ReturnValue == 7 ? 777 : 301);
  315. }
  316. }catch (\Exception $e){
  317. TelegramBot::getDefault()->sendProgramNotify("Agent Withdraw Error:", var_export($retval,true).':'.$e->getTraceAsString());
  318. }
  319. $order = DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('UserID', $UserID)->orderByDesc('RecordID')->first();
  320. if($order) {
  321. DB::table('QPAccountsDB.dbo.OrderWithDraw')
  322. ->where('OrderId', $order->OrderId)
  323. ->update(['BranchBank' => $sn,'ServiceFee'=>0,'WithDraw'=>$order->WithDraw+$order->ServiceFee, 'PixNum' => $sn,'BankUserName'=>'Agent Order'.$agentID]);
  324. $retval['order'] = $order;
  325. }else{
  326. TelegramBot::getDefault()->sendProgramNotify("Agent Withdraw Error:", var_export($retval,true));
  327. }
  328. return apiReturnSuc($retval);
  329. }
  330. }