2
0

RechargeController.php 18 KB

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