RechargeController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\dao\Pay\AccountPayInfo;
  4. use App\Facade\TableName;
  5. use App\Http\helper\NumConfig;
  6. use App\Http\logic\api\CashPayLogic;
  7. use App\Http\logic\api\RechargeLogic;
  8. use App\Models\AccountsInfo;
  9. use App\Models\Order;
  10. use App\Models\Platform\MonthCard;
  11. use App\Services\ApkService;
  12. use App\Util;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\Cache;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Log;
  17. use Illuminate\Support\Facades\Redis;
  18. use function GuzzleHttp\Psr7\rewind_body;
  19. class RechargeController
  20. {
  21. protected $JumpOut = [2, 4, 9, 13, 12, 14];
  22. protected $Sdk = [];
  23. // 返回支付档位
  24. public function gear(Request $request)
  25. {
  26. $origin = $_SERVER['HTTP_ORIGIN'] ??$_SERVER['HTTP_REFERER']?? '*';
  27. if (strstr($origin, "52256") ) {
  28. return apiReturnSuc();
  29. }
  30. // return apiReturnSuc(['list'=>null,'bonus_show'=>false]);
  31. $names = DB::table('agent.dbo.admin_configs')
  32. ->where([
  33. 'type' => 'pay_method',
  34. 'status' => 1,
  35. ])
  36. ->selectRaw('id, name, status, new_pay_type as type')
  37. ->orderByDesc('sort')->get()->toArray();
  38. $list = DB::table('agent.dbo.recharge_gear')
  39. ->select('id','money','favorable_price','give','first_pay','gift_id','recommend')
  40. ->where('first_pay', 0)
  41. ->orderBy('money', 'asc')->where('status', 1)->get();
  42. $p=[];
  43. $gear=\GuzzleHttp\json_encode($names);
  44. foreach ($list as &$val) {
  45. $val->favorable_price = $val->favorable_price + $val->give;
  46. if(isset($p[$val->money])){
  47. $val->activity=$p[$val->money];
  48. }
  49. $val->gear = $gear;
  50. }
  51. return apiReturnSuc(['list'=>$list,'bonus_show'=>false]);
  52. }
  53. // 根据支付档位获取渠道
  54. public function getPayChannel(Request $request)
  55. {
  56. $id = $request->id ?: '';
  57. $ChannelNumber = $request->ChannelNumber ?: '';
  58. if (empty($id)) {
  59. return apiReturnFail(['web.payment.payment_error','PayMent Error']);
  60. }
  61. $key="get_channel_{$id}_{$ChannelNumber}";
  62. // if(Redis::exists($key)) {
  63. // $result=json_decode(Redis::get($key));
  64. // }else {
  65. $first = DB::table('agent.dbo.recharge_gear')
  66. ->where('status', 1)
  67. ->where('id', $id)
  68. ->first();
  69. if (empty($first)) {
  70. return apiReturnFail(['web.payment.payment_error','PayMent Error']);
  71. }
  72. $first->favorable_price = $first->favorable_price + $first->give;
  73. $UserID=$request->UserID;
  74. if(env('MULTI_COUNTRY',0)==1){
  75. $names = DB::table('agent.dbo.admin_configs')
  76. ->where('type', 'pay_method')
  77. ->where('status', '1')
  78. ->where('country',$request->Country??AccountsInfo::select('BindCountry')->where('UserID',$UserID)->first()->BindCountry)
  79. ->select('id', 'name', 'new_pay_type')
  80. ->orderByDesc('sort')->get()
  81. ->map(function ($value) {
  82. return (array)$value;
  83. })->toArray();
  84. }else{
  85. $names = DB::table('agent.dbo.admin_configs')
  86. ->where('type', 'pay_method')
  87. ->where('status', '1')
  88. ->select('id', 'name', 'new_pay_type')
  89. ->orderByDesc('sort')->get()
  90. ->map(function ($value) {
  91. return (array)$value;
  92. })->toArray();
  93. }
  94. // 渠道
  95. if ($ChannelNumber != '') {
  96. $switch = Redis::get("recharge_config_switch_{$ChannelNumber}");
  97. if ($switch) {
  98. $list = DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge as go')
  99. ->join('agent.dbo.admin_configs as cf', 'go.ConfigID', '=', 'cf.id')
  100. ->where('go.Channel', $ChannelNumber)
  101. ->where('go.Status', 1)
  102. ->where('cf.type', 'pay_method')
  103. ->orderByDesc('go.Sort')
  104. ->select('go.Sort', 'ConfigID')
  105. ->pluck('Sort', 'ConfigID')->toArray();
  106. }
  107. }
  108. if (!isset($list) || count($list) < 1) { // 默认配置
  109. $list = DB::connection('write')->table('agent.dbo.admin_configs')
  110. ->where('type', 'pay_method')
  111. ->where('status', 1)
  112. ->select('sort as Sort', 'id as ConfigID')
  113. ->pluck('Sort', 'ConfigID')->toArray();
  114. }
  115. $data = [];
  116. foreach ($names as $k => $va) {
  117. if (isset($list[$va['id']])) {
  118. $type = $va['new_pay_type'] == 1 ? 3 : 2;
  119. if ($va['new_pay_type'] == 4) {
  120. $type = 0;
  121. }
  122. // type = 1 sdk跳转 type=2 外跳链接 type=0 默认 type=3 复制信息到APP支付
  123. $data[] = ['id' => $va['id'],
  124. 'name' => $va['name'], 'status' => 1, 'type' => $type, 'sort' => $list[$va['id']]];
  125. }
  126. }
  127. // $first->cpf_first=0;
  128. // if($ChannelNumber==103)$first->cpf_first=1;
  129. $gear = array_values($data);
  130. $gear = collect($gear)->sortByDesc('sort')->toArray();
  131. $first->kefu_switch = 1;
  132. $gear = array_values($gear);
  133. $first->gear = \GuzzleHttp\json_encode($gear);
  134. $result = apiReturnSuc($first);
  135. // Redis::set($key,json_encode($result));
  136. // Redis::expire($key,60);
  137. // }
  138. // $dir = $path = app()->basePath() . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'cache';
  139. // if (!file_exists($dir)) {
  140. // mkdir($dir, 0777);
  141. // }
  142. // $path = $dir . DIRECTORY_SEPARATOR . "get_channel_{$id}_{$ChannelNumber}.json";
  143. // file_put_contents($path, json_encode($result));
  144. return $result;
  145. }
  146. // 返回支付渠道
  147. public function payChannel()
  148. {
  149. $list = DB::table('agent.dbo.admin_configs')->where('type', 'pay_method')
  150. ->where('status', 1)
  151. ->select('id', 'name', 'status')
  152. ->orderByDesc('sort')->get();
  153. foreach ($list as &$value) {
  154. if (in_array($value->id, $this->Sdk)) {
  155. $value->type = 0;
  156. } elseif (in_array($value->id, $this->JumpOut)) {
  157. $value->type = 2;
  158. } else {
  159. $value->type = 0;
  160. }
  161. }
  162. unset($value);
  163. return apiReturnSuc("$list");
  164. }
  165. // 首充可选择渠道
  166. public function firstPayConfig(Request $request)
  167. {
  168. $origin = $_SERVER['HTTP_ORIGIN'] ??$_SERVER['HTTP_REFERER']?? '*';
  169. if (strstr($origin, "52256") ) {
  170. return apiReturnSuc(null);
  171. }
  172. $user=$request->user();
  173. if($user){
  174. $firstPayExists = DB::table(TableName::QPAccountsDB().'UserRechargeActive')->where('UserID',$user->UserID)->first();
  175. if($firstPayExists){
  176. return apiReturnSuc(null);
  177. }
  178. }
  179. // 推荐充值档位
  180. $recomendar_recharge = DB::table(TableName::QPAccountsDB() . 'SystemStatusInfo')
  181. ->where('StatusName', 'RecomendarRecharge')
  182. ->value('StatusValue');
  183. $first_pay = DB::table('agent.dbo.recharge_gear')->where('status', 1)
  184. ->where('first_pay', 1)->first();
  185. if (!$first_pay) {
  186. return apiReturnSuc(compact('first_pay', 'recomendar_recharge'));
  187. }
  188. $names = DB::table('agent.dbo.admin_configs')
  189. ->where('type', 'pay_method')
  190. ->where('status', 1)
  191. ->select('id', 'name', 'new_pay_type')->orderByDesc('sort')->get()->toArray();
  192. $first_pay->favorable_price = $first_pay->favorable_price + $first_pay->give;
  193. $data = [];
  194. foreach ($names as $k => $va) {
  195. $type = $va->new_pay_type == 1 ? 3 : 2;
  196. if($va->new_pay_type == 4){
  197. $type = 0;
  198. }
  199. // type = 1 sdk跳转 type=2 外跳链接 type=0 默认 type=3 复制信息到APP支付
  200. $data[] = ['id' => $va->id, 'name' => $va->name, 'status' => 1, 'type' => $type];
  201. }
  202. $gear = array_values($data);
  203. $first_pay->gear = \GuzzleHttp\json_encode($gear);
  204. $ChannelNumber = $request->ChannelNumber ?: '';
  205. // $first_pay->cpf_first=0;
  206. // if($ChannelNumber==103)$first_pay->cpf_first=1;
  207. return apiReturnSuc(compact('first_pay', 'recomendar_recharge'));
  208. }
  209. // 引导付费
  210. public function guidePayment(Request $request)
  211. {
  212. $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  213. // 引导付费标识
  214. // $guide_payment_exists = DB::table(TableName::agent() . 'guide_payment')->where('UserID', $UserID)->first();
  215. $flag = false;
  216. // 查看用户有没有充值过【只要充值过,引导付费就不能充值】
  217. $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  218. ->where('UserID', $UserID)
  219. ->value('Recharge') ?: 0;
  220. if ($user_recharge > 0) {
  221. $flag = true;
  222. }
  223. // 引导付费礼包列表
  224. $guidePayment = (new RechargeLogic())->guidePayment($this->JumpOut);
  225. // 日期 -- 倒计时【小时】
  226. $countdown = 24;
  227. return apiReturnSuc(['is_pay' => $flag, 'countdown' => $countdown, 'guidePayment' => $guidePayment]);
  228. }
  229. // 充值Vip等级
  230. public function vipConfig(Request $request)
  231. {
  232. $res = DB::table('QPAccountsDB.dbo.ProtectLevel')
  233. ->orderBy('Recharge')->get();
  234. $list = [];
  235. foreach ($res as $v) {
  236. $list[] = [
  237. 'id' => $v->ID,
  238. 'money' => $v->Recharge,
  239. 'num' => $v->ID - 1,
  240. 'relief_money' => $v->GrantNum/100,
  241. 'vip' => $v->ID - 1,
  242. ];
  243. }
  244. // 充值礼包
  245. $monthCards = MonthCard::query()
  246. ->select('CardID', 'CardName', 'Price', 'FirstReward', 'DayReward', 'gear', 'CardState')
  247. ->where(['CardType' => 1,])
  248. ->get();
  249. // 充值渠道过滤
  250. $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  251. $accountInfo = AccountsInfo::query()->where('UserID', $UserID)->first();
  252. $channel = $accountInfo->Channel ?? 0;
  253. $switch = Redis::get("recharge_config_switch_{$channel}");
  254. if ($channel && $switch) {
  255. $channels = DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge as go')
  256. ->join('agent.dbo.admin_configs as cf', 'go.ConfigID', '=', 'cf.id')
  257. ->where('go.Channel', $channel)
  258. ->where('go.Status', 1)
  259. ->where('cf.type', 'pay_method')
  260. ->orderByDesc('go.Sort')
  261. ->select(
  262. DB::raw('cf.id as id'),
  263. 'name',
  264. 'config_value',
  265. 'new_pay_type',
  266. DB::raw('go.Sort as sort')
  267. )
  268. ->get()
  269. ->toArray();
  270. }
  271. if (empty($channels)) {
  272. $channels = DB::table('agent.dbo.admin_configs')
  273. ->select('id', 'name', 'config_value', 'new_pay_type', 'sort')
  274. ->where([
  275. 'type' => 'pay_method',
  276. 'status' => 1
  277. ])
  278. ->orderByDesc('sort')
  279. ->get()->toArray();
  280. }
  281. foreach ($monthCards as $k => $v) {
  282. $monthCards[$k]['CardID'] = $monthCards[$k]['CardID'] + 100;
  283. $monthCards[$k]['FirstReward'] = $v['FirstReward']/100;
  284. $monthCards[$k]['DayReward'] = $v['DayReward']/100;
  285. $cardChannels = [];
  286. foreach ($channels as $channel) {
  287. $channel->type = $channel->new_pay_type == 4?0: ($channel->new_pay_type == 1 ? 3 : 2);
  288. $cardChannels[] = [
  289. 'id' => $channel->id,
  290. 'name' => $channel->name,
  291. 'pic' => $channel->config_value,
  292. 'status' => 1,
  293. 'type' => $channel->new_pay_type == 4?0: ($channel->new_pay_type == 1 ? 3 : 2),
  294. 'new_pay_type' => $channel->new_pay_type,
  295. 'sort' => $channel->sort
  296. ];
  297. }
  298. usort($cardChannels, function ($a, $b) {
  299. return $a['sort'] > $b['sort'] ? -1 : 1;
  300. });
  301. $monthCards[$k]['gear'] = json_encode($cardChannels);
  302. }
  303. return apiReturnSuc(compact('list', 'monthCards'));
  304. }
  305. // 用户总充值
  306. public function userTotalRecharge(Request $request)
  307. {
  308. $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  309. // Util::WriteLog('login_header',$request->header());
  310. try{
  311. $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  312. ->where('UserID', $UserID)
  313. ->first();
  314. if(isset($userInfo)) {
  315. //记录版本号
  316. $v = (int)$request->get('v');
  317. $cv = Util::getClientVer();
  318. // $CustomID = $v * 1000 + $cv;
  319. // DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  320. // ->where('UserID', $UserID)
  321. // ->update(['CustomID' => $CustomID]);
  322. $list = DB::connection('read')->table('QPTreasureDB.dbo.GameScoreInfo')
  323. ->where('UserID', '=', $UserID)
  324. ->first();
  325. if ($list) {
  326. //下线的包
  327. if ($list->WinCount == 0 && $list->LostCount == 0 && in_array($userInfo->Channel, [103, 104, 101, 105, 123, 109, 121, 106])) {
  328. // ApkService::ControlOldUser($UserID);
  329. }
  330. if ($list->WinCount == 0 && $list->LostCount == 0 && strtotime($list->RegisterDate) < time() - 86400 * 2) {
  331. if ($userInfo->Channel == 100 || $userInfo->Channel == 103 || $userInfo->Channel == 104) {
  332. // ApkService::ControlOldUser($UserID);
  333. }
  334. }
  335. }
  336. }
  337. }catch (\Exception $exception){
  338. Util::WriteLog('control_old_user',$exception);
  339. }
  340. $user_total_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
  341. ->where('UserID', $UserID)
  342. ->value('Recharge') ?: 0;
  343. // 引导付费标识
  344. // $guide_payment_exists = DB::table(TableName::agent() . 'guide_payment')->where('UserID', $UserID)->first();
  345. $flag = false;
  346. // 查看用户有没有充值过【只要充值过,引导付费就不能充值】
  347. if ($user_total_recharge > 0) {
  348. $flag = true;
  349. }
  350. // 引导付费礼包列表
  351. // $guidePayment = (new RechargeLogic())->guidePayment($this->JumpOut);
  352. // 日期 -- 倒计时【小时】
  353. $countdown = 24;
  354. return apiReturnSuc(['user_total_recharge'=>$user_total_recharge,'is_pay' => $flag, 'countdown' => $countdown, 'guidePayment' => []]);
  355. // $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  356. // ->lock('WITH(NOLOCK)')
  357. // ->where('UserID', $UserID)
  358. // ->first();
  359. //
  360. //
  361. // if (!$AccountWithDrawInfo) {
  362. // $cpf = $this->_getNewCpf($UserID);
  363. // if($cpf){
  364. // $dao = new AccountPayInfo();
  365. // $data = [
  366. // 'PixType' => 1,
  367. // 'BankUserName' => $dao->randUserName(0),
  368. // 'PixNum' => $cpf,
  369. // 'UserID' => $UserID,
  370. // 'Achieves' => 0,
  371. // 'HistoryWithDraw' => 0
  372. // ];
  373. //
  374. // try {
  375. // DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  376. // ->where('UserID', $UserID)
  377. // ->insert($data);
  378. //
  379. // try {
  380. // DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  381. // ->insert([
  382. // 'UserID' => $UserID,
  383. // 'BankCard' => $cpf,
  384. // 'BindDate' => now()
  385. // ]);
  386. // Util::WriteLog('update_pix',[
  387. // 'UserID' => $UserID,
  388. // 'BankCard' => $cpf,
  389. // 'BindDate' => now()
  390. // ]);
  391. // } catch (\Exception $e) {
  392. // Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  393. // }
  394. //
  395. // } catch (\Exception $e) {
  396. // Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  397. // }
  398. // }
  399. //
  400. // } else {
  401. // if(!$AccountWithDrawInfo->BankUserName || !$AccountWithDrawInfo->PixNum){
  402. //
  403. // $cpf = $this->_getNewCpf($UserID);
  404. //
  405. // if($cpf){
  406. // $dao = new AccountPayInfo();
  407. // $data = [
  408. // 'PixType' => 1,
  409. // 'BankUserName' => $dao->randUserName(0),
  410. // 'PixNum' => $cpf,
  411. // 'UserID' => $UserID,
  412. // 'Achieves' => 0,
  413. // 'HistoryWithDraw' => 0
  414. // ];
  415. //
  416. // DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  417. // ->where('UserID', $UserID)
  418. // ->update($data);
  419. // }
  420. //
  421. //
  422. // }
  423. // }
  424. }
  425. private function _getNewCpf($UserID){
  426. return 0;
  427. $where[] = ['payment_code', 'cashPay'];
  428. $where[] = ['pay_status', 1];
  429. $where[] = ['UserID', $UserID];
  430. $build_sql = DB::connection('write')->table('order')
  431. ->where($where)
  432. ->first();
  433. if($build_sql){
  434. $cashPay = new CashPayLogic();
  435. return $cashPay->search($build_sql->order_sn);
  436. }
  437. return 0;
  438. }
  439. }