ChannelController.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. // 渠道管理
  4. use App\Facade\TableName;
  5. use App\Game\WebChannelConfig;
  6. use App\Http\helper\Helper;
  7. use App\Http\logic\admin\ChannelLogic;
  8. use App\Http\logic\admin\RechargeLogic;
  9. use App\Jobs\ClearCache;
  10. use App\Models\AppSwitch;
  11. use App\Models\SystemStatusInfo;
  12. use App\Models\WithdrawalAgentRatioConfig;
  13. use App\Models\WithdrawalChannelPositionConfig;
  14. use App\Models\WithdrawalPositionConfig;
  15. use App\Services\GameRoomInfo;
  16. use App\Services\PayConfig;
  17. use App\Util;
  18. use Illuminate\Http\Request;
  19. use Illuminate\Support\Facades\DB;
  20. use Illuminate\Support\Facades\Redis;
  21. use Illuminate\Support\Facades\Validator;
  22. class ChannelController
  23. {
  24. public function index(Request $request)
  25. {
  26. $where = [];
  27. $name = $request->Name ?: '';
  28. !empty($name) && $where[] = ['Name', 'like', $name . '%'];
  29. // $notIn = [1, 2, 3, 4, 5, 7, 10, 13, 14, 15, 16, 17];
  30. $list = DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')
  31. // ->whereNotIn('ChannelIndex', $notIn)
  32. ->where($where)
  33. ->paginate(10);
  34. return view('admin.channel.index', ['list' => $list, 'Name' => $name]);
  35. }
  36. public function channelAdd(Request $request)
  37. {
  38. if ($request->isMethod('post')) {
  39. $post = $request->post();
  40. $Channel = $post['Channel'];
  41. $post['ChannelType'] = 100;
  42. $post['ChannelIndex'] = $Channel - $post['ChannelType'];
  43. $post['ReviewState'] = 1;
  44. unset($post['Channel']);
  45. DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')
  46. ->insert($post);
  47. // 同步添加渠道包
  48. DB::connection('write')->table('QPPlatformDB.dbo.ChannelRechargeGameOpen')
  49. ->insert(['ChannelPackageName' => $post['Name'], 'Channel' => $Channel]);
  50. return apiReturnSuc();
  51. } else {
  52. return view('admin.channel.channel_add');
  53. }
  54. }
  55. public function channelNew(Request $request)
  56. {
  57. if ($request->isMethod('post')) {
  58. $post = $request->post();
  59. $post['Remarks'] = $post['AliasName'];
  60. $post['AppKey']= Util::generateRandomString();
  61. while(DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')->where('AppKey', $post['AppKey'])->exists()) {
  62. $post['AppKey'] = Util::generateRandomString();
  63. }
  64. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  65. ->insert($post);
  66. $channel = @$post['Channel'];
  67. if($channel){
  68. $createConfig = function () use($channel) {
  69. $config = new WithdrawalChannelPositionConfig();
  70. $config->channel = $channel;
  71. return $config;
  72. };
  73. $config = WithdrawalChannelPositionConfig::query()->where('channel', $channel)->first() ?: $createConfig();
  74. $config->save();
  75. }
  76. return apiReturnSuc();
  77. } else {
  78. return view('admin.channel.channel_new');
  79. }
  80. }
  81. public function channelEdit(Request $request, $id)
  82. {
  83. $ChannelIndex = $request->ChannelIndex;
  84. $AndroidVersion = $request->AndroidVersion;
  85. $where = [
  86. ['ChannelType', '=', $id],
  87. ['ChannelIndex', '=', $ChannelIndex],
  88. ['AndroidVersion', '=', $AndroidVersion],
  89. ];
  90. if ($request->isMethod('post')) {
  91. $post = $request->post();
  92. //$post['ChannelIndex'] = $post['Channel'] - $post['ChannelType'];
  93. unset($post['Channel']);
  94. DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')
  95. ->where($where)
  96. ->update($post);
  97. // 同步修改渠道包
  98. DB::connection('write')->table('QPPlatformDB.dbo.ChannelRechargeGameOpen')
  99. ->where('Channel', ($id + $ChannelIndex))
  100. ->update(['ChannelPackageName' => $post['Name']]);
  101. return apiReturnSuc();
  102. } else {
  103. $info = DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')
  104. ->where($where)
  105. ->first();
  106. return view('admin.channel.channel_edit', compact('info', 'id', 'ChannelIndex', 'AndroidVersion'));
  107. }
  108. }
  109. public function switch_control(Request $request, $id)
  110. {
  111. $type = $request->type;
  112. $ChannelIndex = $request->ChannelIndex;
  113. $AndroidVersion = $request->AndroidVersion;
  114. $logic = new ChannelLogic();
  115. $res = $logic->switch_control($id, $ChannelIndex, $AndroidVersion, $type);
  116. if ($res === false) {
  117. return apiReturnFail($logic->getError());
  118. }
  119. return apiReturnSuc();
  120. }
  121. public function update(Request $request, $ChannelType)
  122. {
  123. $ChannelIndex = $request->ChannelIndex ?: '';
  124. $ChannelName = $request->ChannelName ?: '';
  125. $AndroidVersion = $request->AndroidVersion;
  126. $data = $request->data ?: '';
  127. $where[] = ['ChannelIndex', '=', $ChannelIndex];
  128. $where[] = ['ChannelType', '=', $ChannelType];
  129. $where[] = ['AndroidVersion', '=', $AndroidVersion];
  130. if ($request->isMethod('POST')) {
  131. DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')
  132. ->where($where)
  133. ->updateOrInsert($where, $data);
  134. return apiReturnSuc();
  135. } else {
  136. $info = DB::connection('read')->table('QPPlatformDB.dbo.ChannelConfig')
  137. ->where($where)
  138. ->first();
  139. return view('admin.channel.update', [
  140. 'info' => $info,
  141. 'ChannelName' => $ChannelName
  142. ]);
  143. }
  144. }
  145. public function ChannelSaveLog()
  146. {
  147. $list = DB::connection('read')->table('agent.dbo.ChannelSaveLog as log')
  148. ->join('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  149. ->select('au.account', 'log.*')
  150. ->paginate(10);
  151. foreach ($list as &$val) {
  152. $ChannelName = '';
  153. switch ($val->channel) {
  154. case 0:
  155. $ChannelName = '官方';
  156. break;
  157. case 100: // 谷歌渠道
  158. switch ($val->ChannelIndex) {
  159. case 0:
  160. $ChannelName = '谷歌渠道';
  161. break;
  162. case 1:
  163. $ChannelName = 'Teenpatti Royal';
  164. break;
  165. case 2:
  166. $ChannelName = 'teenpatti club';
  167. break;
  168. case 3:
  169. $ChannelName = 'Teenpatti.Champion';
  170. break;
  171. case 4:
  172. $ChannelName = 'com.teempatti.Victory';
  173. break;
  174. case 5:
  175. $ChannelName = 'com.teempatti.fun';
  176. break;
  177. case 6:
  178. $ChannelName = 'teenpatti Exceed';
  179. break;
  180. case 7:
  181. $ChannelName = 'com.teempatti.reward';
  182. break;
  183. case 8:
  184. $ChannelName = 'com.teempatti.qplayer';
  185. break;
  186. case 9:
  187. $ChannelName = 'com.teempatti.q3acard';
  188. break;
  189. case 10:
  190. $ChannelName = 'com.teempatti.qnobles';
  191. break;
  192. case 11:
  193. $ChannelName = 'com.teempatti.qgrandparty';
  194. break;
  195. case 12:
  196. $ChannelName = 'com.teempatti.queen';
  197. break;
  198. case 13:
  199. $ChannelName = 'com.teempatti.royalclub';
  200. break;
  201. case 14:
  202. $ChannelName = 'com.teempatti.queencard';
  203. break;
  204. case 15:
  205. $ChannelName = 'com.teempatti.queensnice';
  206. break;
  207. case 16:
  208. $ChannelName = 'com.teempatti.queensplay';
  209. break;
  210. case 17:
  211. $ChannelName = 'com.teempatti.queensclub';
  212. break;
  213. }
  214. }
  215. $val->ChannelName = $ChannelName;
  216. }
  217. return view('admin.channel.ChannelSaveLog', ['list' => $list]);
  218. }
  219. // 渠道审核屏蔽ID白名单
  220. public function ChannelShieldIDWhite()
  221. {
  222. // $list = DB::connection('write')->table('QPPlatformDB.dbo.ChannelShieldIDWhite')->paginate(10);
  223. $list = DB::connection('read')->table('QPAccountsDB.dbo.IDWhiteUser as white')
  224. ->join('QPAccountsDB.dbo.AccountsInfo as acc', 'acc.UserID', '=', 'white.UserID')
  225. ->select('acc.GameID', 'acc.UserID','white.Remarks')
  226. ->paginate(100);
  227. // print_r($list);die;
  228. return view('admin.channel.channel_shield_id_white', compact('list'));
  229. }
  230. // 渠道审核屏蔽ID白名单 -- 添加ID
  231. public function add(Request $request)
  232. {
  233. if ($request->isMethod('post')) {
  234. $post = $request->post();
  235. $userid = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')
  236. ->where('GameID', $post['GameID'])
  237. ->select('UserID')
  238. ->first()->UserID;
  239. if (!$userid) {
  240. return apiReturnFail('用户ID不存在');
  241. }
  242. $first = DB::connection('write')->table('QPAccountsDB.dbo.IDWhiteUser')
  243. ->where('UserID', $userid)
  244. ->first();
  245. if ($first) {
  246. return apiReturnFail('用户已经存在');
  247. }
  248. DB::connection('write')->table('QPAccountsDB.dbo.IDWhiteUser')
  249. ->insert(['UserID'=>$userid,'Remarks'=>$post['Remarks']]);
  250. return apiReturnSuc();
  251. }
  252. return view('admin.channel.channel_shield_id_white_add');
  253. }
  254. // 渠道审核屏蔽ID白名单 -- 修改ID
  255. public function edit(Request $request, $ID)
  256. {
  257. if ($request->isMethod('post')) {
  258. $post = $request->post();
  259. DB::connection('write')->table('QPAccountsDB.dbo.IDWhiteUser')
  260. ->where('UserID', $ID)
  261. ->update($post);
  262. return apiReturnSuc();
  263. }
  264. $info = DB::connection('write')->table('QPAccountsDB.dbo.IDWhiteUser')
  265. ->where('UserID', $ID)
  266. ->first();
  267. return view('admin.channel.channel_shield_id_white_add', compact('info'));
  268. }
  269. // 渠道审核屏蔽ID白名单 -- 删除ID
  270. public function del($ID)
  271. {
  272. DB::connection('write')->table('QPAccountsDB.dbo.IDWhiteUser')
  273. ->where('UserID', $ID)
  274. ->delete();
  275. return apiReturnSuc();
  276. }
  277. // 渠道审核屏蔽ID白名单 -- 修改状态
  278. public function updateState(Request $request)
  279. {
  280. $State = (int)$request->State;
  281. $State = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  282. ->where('StatusName', 'ChannelShieldIDWhite')
  283. ->update(['StatusValue' => $State]);
  284. return apiReturnSuc();
  285. }
  286. // 渠道包配置充值和游戏
  287. public function rechargeGame(Request $request)
  288. {
  289. $ChannelPackageName = $request->ChannelPackageName ?: '';
  290. $list = (new ChannelLogic())->rechargeGame($ChannelPackageName);
  291. return view('admin.channel.recharge_game', compact('list'));
  292. }
  293. // 开放游戏配置修改 $Channel == -1 默认游戏配置
  294. // 开放游戏配置修改 $Channel == -1 默认游戏配置
  295. public function OpenGames(Request $request, $Channel)
  296. {
  297. $ChannelPackageName = $request->ChannelPackageName ?: '';
  298. if ($request->isMethod('post')) {
  299. $post = $request->all();
  300. $GameShareUrl = $post['ShareUrl'] ?? '';
  301. unset($post['ShareUrl']);
  302. $arr = [];
  303. if (isset($post['KindID'])) {
  304. for ($i = 0; $i < count($post['KindID']); $i++) {
  305. if (isset($post['KindID'][$i]) && $post['KindID'][$i] >= 0) {
  306. $arr[$i]['KindID'] = $post['KindID'][$i];
  307. $arr[$i]['Status'] = $post['Status'][$i] ?? 1;
  308. $arr[$i]['Sort'] = $post['Sort'][$i] ?? 0;
  309. $arr[$i]['SecondStageStatus'] = $post['SecondStageStatus'][$i] ?? 0;
  310. $arr[$i]['SecondStageSort'] = $post['SecondStageSort'][$i] ?? 0;
  311. $arr[$i]['IconType'] = $post['IconType'][$i] ?? 1;
  312. $arr[$i]['Channel'] = $Channel;
  313. $arr[$i]['LimitCV'] = $post['LimitCV'][$i]??0;
  314. $arr[$i]['VIP'] = $post['VIP'][$i]??0;
  315. }
  316. }
  317. }
  318. DB::connection('write')->table('QPPlatformDB.dbo.ChannelGameOpen')
  319. ->where('Channel', $Channel)
  320. ->delete();
  321. DB::connection('write')->table('QPPlatformDB.dbo.ChannelGameOpen')
  322. ->insert($arr);
  323. // 修改默认游戏分享链接
  324. if (!empty($GameShareUrl)) {
  325. DB::table(TableName::QPAccountsDB() . 'SystemStatusInfo')
  326. ->where('StatusName', 'GameShareUrl')
  327. ->update(['StatusString' => $GameShareUrl]);
  328. }
  329. // ted提现开关
  330. if ($request->input('ted_switch', null) !== null) {
  331. $tedSwitch = AppSwitch::query()->firstOrNew(['name' => 'ted', 'scene' => 1, 'channel' => $Channel]);
  332. $tedSwitch->status = $request->input('ted_switch');
  333. $tedSwitch->save();
  334. }
  335. return apiReturnSuc();
  336. }
  337. $openGames = config('games.openKGame');
  338. $list = DB::connection('write')->table('QPPlatformDB.dbo.GameKindItem as gi')
  339. ->leftJoin('QPPlatformDB.dbo.ChannelGameOpen as cg', function ($join) use ($Channel) {
  340. $join->on('gi.KindID', 'cg.KindID');
  341. $join->where('Channel', $Channel);
  342. })
  343. ->whereIn('gi.KindID', $openGames)
  344. ->selectRaw('IsNull(Status,2) Status,KindName,gi.KindID,cg.Sort,SecondStageStatus,SecondStageSort,IconType,LimitCV,VIP')
  345. ->orderByDesc('Sort')
  346. ->get();
  347. // 游戏默认分享链接
  348. $GameShareUrl = DB::table(TableName::QPAccountsDB() . 'SystemStatusInfo')
  349. ->where('StatusName', 'GameShareUrl')
  350. ->value('StatusString');
  351. $tedSwitch = AppSwitch::query()->where([
  352. 'name' => 'ted',
  353. 'channel' => $Channel
  354. ])->first();
  355. return view(
  356. 'admin.channel.open_games',
  357. compact('list', 'ChannelPackageName', 'Channel', 'GameShareUrl', 'tedSwitch')
  358. );
  359. }
  360. public function payMethods($channel, Request $request)
  361. {
  362. $list = DB::connection('write')->table('agent.dbo.admin_configs as ac')
  363. ->leftJoin('QPPlatformDB.dbo.ChannelOpenRecharge as oc', function ($join) use ($channel) {
  364. $join->on('ac.id', '=', 'oc.ConfigID');
  365. $join->where('Channel', $channel);
  366. })
  367. ->where('type', 'pay_method')
  368. ->selectRaw('IsNull(oc.Status,2) Status,name,ac.id,oc.Sort, ac.config_key')
  369. ->get();
  370. foreach ($list as $k => $v) {
  371. $channels = DB::table('agent.dbo.admin_configs as ac')->where([
  372. 'type' => 'pay',
  373. 'new_pay_type' => $v->config_key
  374. ])
  375. ->leftJoin('QPPlatformDB.dbo.ChannelOpenRecharge as oc', function ($join) use ($channel) {
  376. $join->on('ac.id', '=', 'oc.ConfigID');
  377. $join->where('Channel', $channel);
  378. })
  379. ->selectRaw('IsNull(oc.Status,2) Status,name,ac.id,oc.Sort, ac.config_key')
  380. ->get();
  381. $list[$k]->channels = $channels;
  382. }
  383. $switch = intval(Redis::get("recharge_config_switch_{$channel}"));
  384. return view('admin.channel.pay_methods', [
  385. 'list' => $list,
  386. 'channel' => $channel,
  387. 'switch' => $switch
  388. ]);
  389. }
  390. public function updatePayConfig($channel, Request $request)
  391. {
  392. $switch = $request->input('switch', 0);
  393. Redis::set("recharge_config_switch_{$channel}", $switch);
  394. $switchOpened = DB::table('agent.dbo.admin_configs')->where([
  395. 'type' => 'pay',
  396. 'status' => 1,
  397. ])->pluck('id');
  398. $payMethodOpened = DB::table('agent.dbo.admin_configs')->where([
  399. 'type' => 'pay_method',
  400. 'status' => 1,
  401. ])->pluck('id');
  402. $inserts = [];
  403. foreach ($request->input('items') as $k => $v) {
  404. if (!in_array($v['id'], $payMethodOpened->toArray()) && $v['status'] == 1) {
  405. return apiReturnFail($v['id'] . '总开关已关闭,无法开启');
  406. }
  407. $inserts[] = [
  408. 'ConfigID' => $v['id'],
  409. 'Status' => $v['status'],
  410. 'Sort' => $v['sort'],
  411. 'Channel' => $channel
  412. ];
  413. $percent = 0;
  414. foreach ($v['channels'] ?? [] as $k1 => $v1) {
  415. if (!in_array($v1['id'], $switchOpened->toArray()) && $v1['status'] == 1) {
  416. return apiReturnFail($v1['id'] . '总开关已关闭,无法开启');
  417. }
  418. $inserts[] = [
  419. 'ConfigID' => $v1['id'],
  420. 'Status' => $v1['status'],
  421. 'Sort' => $v1['sort'],
  422. 'Channel' => $channel
  423. ];
  424. $percent += $v1['sort'];
  425. }
  426. if ($percent != 100 && $v['status'] == 1) {
  427. return apiReturnFail('权重值分配不正确');
  428. }
  429. }
  430. DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge')
  431. ->where('Channel', $channel)
  432. ->delete();
  433. DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge')
  434. ->insert($inserts);
  435. ClearCache::dispatch();
  436. return apiReturnSuc();
  437. }
  438. // 充值配置修改
  439. public function OpenRecharge(Request $request, $Channel)
  440. {
  441. $ChannelPackageName = $request->ChannelPackageName ?: '';
  442. if ($request->isMethod('post')) {
  443. $post = $request->all();
  444. $arr = [];
  445. if (isset($post['id'])) {
  446. for ($i = 0; $i < count($post['id']); $i++) {
  447. $arr[$i]['ConfigID'] = $post['id'][$i] ?? 0;
  448. $arr[$i]['Status'] = $post['Status'][$i] ?? 1;
  449. $arr[$i]['Sort'] = $post['Sort'][$i] ?? 0;
  450. $arr[$i]['Channel'] = $Channel;
  451. }
  452. }
  453. DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge')
  454. ->where('Channel', $Channel)
  455. ->delete();
  456. DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge')
  457. ->insert($arr);
  458. ClearCache::dispatch();
  459. return apiReturnSuc();
  460. }
  461. $list = DB::connection('write')->table('agent.dbo.admin_configs as ac')
  462. ->leftJoin('QPPlatformDB.dbo.ChannelOpenRecharge as oc', function ($join) use ($Channel) {
  463. $join->on('ac.id', '=', 'oc.ConfigID');
  464. $join->where('Channel', $Channel);
  465. })
  466. ->where('ac.status', 1)
  467. ->where('type', 'pay')
  468. ->selectRaw('IsNull(oc.Status,2) Status,name,ac.id,oc.Sort')
  469. ->get();
  470. return view('admin.channel.open_recharge', compact('list', 'ChannelPackageName', 'Channel'));
  471. }
  472. // 修改备注
  473. public function appkey(Request $request, $id)
  474. {
  475. $app=DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  476. ->where('ID', $id)->first();
  477. if(empty($app->AppKey)) {
  478. $AppKey=Util::generateRandomString(random_int(6,12));
  479. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  480. ->where('ID', $id)
  481. ->update(['AppKey' => $AppKey]);
  482. }else{
  483. $AppKey=$app->AppKey;
  484. }
  485. return apiReturnSuc($AppKey);
  486. }
  487. // 修改备注
  488. public function app_key_set(Request $request, $id)
  489. {
  490. $config = DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('ID', $id)->first();
  491. if ($request->method() == 'GET') {
  492. return view('admin.channel.app_key_set', [
  493. 'config' => $config,
  494. ]);
  495. }
  496. $data=$request->all();
  497. $data['AdjustConfig']=$data['AdjustConfig']??"";
  498. DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('ID', $id)->update($data);
  499. return apiReturnSuc();
  500. }
  501. // 修改备注
  502. public function review(Request $request, $id)
  503. {
  504. $review=$request->status?:0;
  505. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  506. ->where('ID', $id)
  507. ->update(['InReview' => $review]);
  508. $app=DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  509. ->where('ID', $id)->first();
  510. Redis::del("InReview_{$id}");
  511. Redis::del("InReview_{$app->PackageName}");
  512. return apiReturnSuc($review);
  513. }
  514. // 修改备注
  515. public function remarks(Request $request, $id)
  516. {
  517. $remarks = $request->remark ?: '';
  518. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  519. ->where('ID', $id)
  520. ->update(['Remarks' => $remarks,'AliasName'=>$remarks]);
  521. $cp=DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  522. ->where('ID', $id)->select('Channel','PackageName')->first();
  523. $Channel=$cp->Channel;
  524. $PackageName=$cp->PackageName;
  525. if(WebChannelConfig::where('Channel', $Channel)->exists()) {
  526. WebChannelConfig::where('Channel', $Channel)->update(['Remarks' => $remarks]);
  527. }else{
  528. $config=WebChannelConfig::getByChannel(50)->toArray();
  529. $config['Remarks']=$remarks;
  530. $config['Channel']=$Channel;
  531. $config['PackageName']=$PackageName;
  532. unset($config['ID']);
  533. WebChannelConfig::insert($config);
  534. }
  535. $dcatChannel=DB::connection('mysql')->table('dcat-admin.channel')->where('channel',$Channel);
  536. if($dcatChannel->exists()){
  537. $dcatChannel->update(['channel_name'=>$remarks]);
  538. }else{
  539. DB::connection('mysql')->table('dcat-admin.channel')->insert(['channel'=>$Channel,'channel_name'=>$remarks,'package_name'=>'','remark'=>'']);
  540. }
  541. $dcatChannel=DB::connection('mysql')->table('dcat-admin.channel_ownership')->where('channel',$Channel);
  542. if($dcatChannel->exists()){
  543. $dcatChannel->update(['name'=>$remarks]);
  544. }else{
  545. DB::connection('mysql')->table('dcat-admin.channel_ownership')->insert(['channel'=>$Channel,'name'=>$remarks]);
  546. }
  547. return apiReturnSuc();
  548. }
  549. // 分享url
  550. public function shareUrl(Request $request, $id, $field)
  551. {
  552. $ShareUrl = $request->ShareUrl ?: '';
  553. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  554. ->where('ID', $id)
  555. ->update([$field => $ShareUrl]);
  556. return apiReturnSuc();
  557. }
  558. // 修改minScore
  559. public function minScore(Request $request, $id)
  560. {
  561. $MinScore = $request->MinScore ?: 0;
  562. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  563. ->where('ID', $id)
  564. ->update(['MinScore' => $MinScore]);
  565. return apiReturnSuc();
  566. }
  567. // 修改ContrlScore
  568. public function contrlScore(Request $request, $id)
  569. {
  570. $ContrlScore = $request->ContrlScore ?: 0;
  571. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  572. ->where('ID', $id)
  573. ->update(['ContrlScore' => $ContrlScore]);
  574. return apiReturnSuc();
  575. }
  576. // 修改Rate
  577. public function rateN(Request $request, $id)
  578. {
  579. $Rate = $request->Rate ?: 0;
  580. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  581. ->where('ID', $id)
  582. ->update(['Rate' => $Rate]);
  583. return apiReturnSuc();
  584. }
  585. public function shareConfig(Request $request, $id)
  586. {
  587. $config = DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('ID', $id)->first();
  588. if ($request->method() == 'GET') {
  589. return view('admin.channel.share_config', [
  590. 'config' => $config,
  591. ]);
  592. }
  593. $validator = Validator::make($request->all(), [
  594. 'UrlStatus' => 'required|in:0,1',
  595. 'UrlSelect' => 'required|in:1,2',
  596. 'ShareUrl' => 'nullable|url',
  597. 'SpreadShareUrl' => 'nullable|url',
  598. ]);
  599. if ($validator->fails()) {
  600. return apiReturnFail($validator->errors()->first());
  601. }
  602. $data = $request->only(['UrlStatus', 'UrlSelect']);
  603. $data['ShareUrl'] = strval($request->input('ShareUrl'));
  604. $data['SpreadShareUrl'] = strval($request->input('SpreadShareUrl'));
  605. DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('ID', $id)->update($data);
  606. return apiReturnSuc();
  607. }
  608. // 提现免审配置
  609. public function withdrawalConfigAll(Request $request)
  610. {
  611. $createConfig = function () {
  612. $config = new WithdrawalChannelPositionConfig();
  613. $config->channel = 100;
  614. return $config;
  615. };
  616. $config = WithdrawalChannelPositionConfig::query()->where('channel', 100)->first() ?: $createConfig();
  617. if ($request->method() == 'GET') {
  618. $agent = DB::table('agent.dbo.admin_configs')
  619. ->where('type', 'cash')
  620. ->where('status', 1)
  621. ->get();
  622. $this->markWithdrawalAgentFee($agent);
  623. return view('admin.channel.channel_withdrawal_configall', [
  624. 'config' => $config,
  625. 'agent' => $agent,
  626. 'ratioConfig' => WithdrawalAgentRatioConfig::getGlobal(),
  627. 'pixTypeOptions' => WithdrawalAgentRatioConfig::pixTypeOptions(),
  628. ]);
  629. }
  630. list($ratioValid, $ratioRules) = $this->withdrawalAgentRatioRules($request);
  631. if (!$ratioValid) {
  632. return apiReturnFail($ratioRules);
  633. }
  634. WithdrawalAgentRatioConfig::saveGlobal($ratioRules);
  635. return apiReturnSuc();
  636. }
  637. // 提现免审配置
  638. public function withdrawalSwitch(Request $request)
  639. {
  640. $key="WithDrawSwitch";
  641. if ($request->method() == 'GET') {
  642. $info=SystemStatusInfo::CacheValue($key);
  643. return view('admin.channel.channel_withdrawal_switch', [
  644. 'State' => $info->StatusValue,
  645. ]);
  646. }
  647. $State = (int)$request->State;
  648. SystemStatusInfo::CacheValue($key,$State);
  649. return apiReturnSuc();
  650. }
  651. // 提现免审配置
  652. public function withdrawalConfig($channel, Request $request)
  653. {
  654. $createConfig = function () use($channel) {
  655. $config = new WithdrawalChannelPositionConfig();
  656. $config->channel = $channel;
  657. return $config;
  658. };
  659. $config = WithdrawalChannelPositionConfig::query()->where('channel', $channel)->first() ?: $createConfig();
  660. if ($request->method() == 'GET') {
  661. $agent = DB::table('agent.dbo.admin_configs')
  662. ->where('type', 'cash')
  663. ->where('status', 1)
  664. ->get();
  665. $this->markWithdrawalAgentFee($agent);
  666. return view('admin.channel.channel_withdrawal_config', [
  667. 'config' => $config,
  668. 'agent' => $agent,
  669. 'ratioConfig' => WithdrawalAgentRatioConfig::getGlobal(),
  670. 'pixTypeOptions' => WithdrawalAgentRatioConfig::pixTypeOptions(),
  671. ]);
  672. }
  673. list($ratioValid, $ratioRules) = $this->withdrawalAgentRatioRules($request);
  674. if (!$ratioValid) {
  675. return apiReturnFail($ratioRules);
  676. }
  677. WithdrawalAgentRatioConfig::saveGlobal($ratioRules);
  678. return apiReturnSuc();
  679. }
  680. private function withdrawalAgentRatioRules(Request $request)
  681. {
  682. $input = $request->input('agent_ratio', []);
  683. $rules = [];
  684. $pixTypeNames = WithdrawalAgentRatioConfig::pixTypeOptions();
  685. foreach ($pixTypeNames as $pixType => $pixTypeName) {
  686. $total = 0;
  687. foreach (($input[$pixType] ?? []) as $agent => $ratio) {
  688. if ($ratio === null || $ratio === '') {
  689. $ratio = 0;
  690. }
  691. if (!is_numeric($ratio)) {
  692. return [false, $pixTypeName . '比例必须是数字'];
  693. }
  694. $ratio = (int)$ratio;
  695. if ($ratio < 0 || $ratio > 100) {
  696. return [false, $pixTypeName . '比例必须在0-100之间'];
  697. }
  698. $total += $ratio;
  699. if ($ratio > 0) {
  700. $rules[$pixType][(int)$agent] = $ratio;
  701. }
  702. }
  703. if ($total != 100) {
  704. return [false, $pixTypeName . '比例总和必须为100'];
  705. }
  706. }
  707. return [true, $rules];
  708. }
  709. private function markWithdrawalAgentFee($agent)
  710. {
  711. foreach ($agent as $item) {
  712. $item->withdraw_fee_texts = $this->withdrawalAgentFeeTexts($item->config_value);
  713. }
  714. }
  715. private function withdrawalAgentFeeTexts($agent)
  716. {
  717. $configKey = $this->withdrawalPayConfigKey($agent);
  718. $empty = [
  719. 1 => '-',
  720. 2 => '-',
  721. WithdrawalAgentRatioConfig::PIX_TYPE_CASH_SMALL => '-',
  722. ];
  723. if (!$configKey) {
  724. return $empty;
  725. }
  726. $config = (new PayConfig())->getConfig($configKey);
  727. $payRates = $config['pay_rate'] ?? null;
  728. if (empty($payRates) || !is_array($payRates)) {
  729. return $empty;
  730. }
  731. if (is_array(reset($payRates))) {
  732. return [
  733. 1 => isset($payRates[1]) ? $this->formatWithdrawalPayRate($payRates[1]) : '-',
  734. 2 => isset($payRates[2]) ? $this->formatWithdrawalPayRate($payRates[2]) : '-',
  735. WithdrawalAgentRatioConfig::PIX_TYPE_CASH_SMALL => isset($payRates[1]) ? $this->formatWithdrawalPayRate($payRates[1]) : '-',
  736. ];
  737. }
  738. $feeText = $this->formatWithdrawalPayRate($payRates);
  739. return [
  740. 1 => $feeText,
  741. 2 => $feeText,
  742. WithdrawalAgentRatioConfig::PIX_TYPE_CASH_SMALL => $feeText,
  743. ];
  744. }
  745. private function withdrawalPayConfigKey($agent)
  746. {
  747. $map = [
  748. 99 => 'WiwiPayOut',
  749. 100 => 'WDPayOut',
  750. 103 => 'PagYeepPayOut',
  751. 105 => 'AiNewPayOut',
  752. 106 => 'SafePayOut',
  753. 107 => 'BotImPayOut',
  754. ];
  755. return $map[(int)$agent] ?? null;
  756. }
  757. private function formatWithdrawalPayRate($rate)
  758. {
  759. if (!is_array($rate)) {
  760. return '-';
  761. }
  762. $percent = $rate[0] ?? 0;
  763. $fixed = $rate[1] ?? 0;
  764. return $percent . '%+$' . $fixed;
  765. }
  766. public function quickCreateChannel(Request $request)
  767. {
  768. if ($request->isMethod('post')) {
  769. $packageName = $request->input('packageName');
  770. $channelName = $request->input('channelName');
  771. $adminSign = $request->input('adminSign', 'dk');
  772. // 检查包名是否已存在
  773. $exists = DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  774. ->where('PackageName', $packageName)
  775. ->exists();
  776. if ($exists) {
  777. return apiReturnFail('包名已存在');
  778. }
  779. try {
  780. // 调用自动创建渠道方法
  781. $autoApkController = new \App\Http\Controllers\Api\AutoApkController();
  782. $packageConfig = $autoApkController->autoCreateChannel($packageName, $channelName, $adminSign);
  783. $autoApkController->modifyRights($packageConfig, $adminSign);
  784. return apiReturnSuc(['message' => '渠道创建成功', 'channel' => $packageConfig['Channel']]);
  785. } catch (\Exception $e) {
  786. Util::WriteLog('quick_create_channel', $e->getMessage());
  787. return apiReturnFail('创建失败:' . $e->getMessage());
  788. }
  789. } else {
  790. // 获取最后一个包名和渠道名,用于生成默认值
  791. $lastPackage = DB::connection('read')->table('QPPlatformDB.dbo.ChannelPackageName')
  792. ->orderByDesc('ID')
  793. ->first();
  794. $defaultPackageName = '';
  795. $defaultChannelName = '';
  796. if ($lastPackage) {
  797. // 提取包名中的数字并+1
  798. if (preg_match('/^(.+?)(\d+)$/', $lastPackage->PackageName, $matches)) {
  799. $defaultPackageName = $matches[1] . ($matches[2] + 1);
  800. } else {
  801. $defaultPackageName = $lastPackage->PackageName . '1';
  802. }
  803. // 提取渠道名中的数字并+1
  804. $aliasName = $lastPackage->AliasName ?? $lastPackage->Remarks ?? '';
  805. // 去掉前缀(USA_、NEW_等),只保留下划线后面的部分
  806. if (strpos($aliasName, '_') !== false) {
  807. $aliasName = substr($aliasName, strrpos($aliasName, '_') + 1);
  808. }
  809. if (preg_match('/^(.+?)(\d+)$/', $aliasName, $matches)) {
  810. $defaultChannelName = $matches[1] . ($matches[2] + 1);
  811. } else {
  812. $defaultChannelName = $aliasName . '1';
  813. }
  814. }
  815. return view('admin.channel.quick_create_channel', [
  816. 'defaultPackageName' => $defaultPackageName,
  817. 'defaultChannelName' => $defaultChannelName,
  818. ]);
  819. }
  820. }
  821. }