RechargeController.php 19 KB

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