RechargeController.php 18 KB

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