AgentController.php 14 KB

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