AgentController.php 14 KB

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