ChannelLogic.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace App\Http\logic\admin;
  3. use App\Http\logic\api\BaseApiLogic;
  4. use App\Models\ChannelSaveLog;
  5. use Illuminate\Support\Facades\DB;
  6. class ChannelLogic extends BaseApiLogic
  7. {
  8. public function index()
  9. {
  10. $where = [];
  11. $list = DB::table('agent.dbo.channel')
  12. ->where($where)
  13. ->orderByDesc('updated_at')
  14. ->get();
  15. $names = DB::table('agent.dbo.admin_configs')->where('type', 'channel')->pluck('name', 'id');
  16. foreach ($list as &$value) {
  17. $name = [];
  18. if (!empty($value->open_region)) {
  19. $open_region = \GuzzleHttp\json_decode($value->open_region, true);
  20. foreach ($open_region as $val) {
  21. if ($val['status'] == 1) {
  22. $name[] = isset($names[$val['id']]) ? $names[$val['id']] : '';
  23. }
  24. }
  25. }
  26. $value->open_region = implode(',', $name);
  27. }
  28. return compact('list');
  29. }
  30. public function switch_control($id, $ChannelIndex, $AndroidVersion, $type)
  31. {
  32. $where = [
  33. ['ChannelType', '=', $id],
  34. ['ChannelIndex', '=', $ChannelIndex],
  35. ['AndroidVersion', '=', $AndroidVersion],
  36. ];
  37. $logModel = new ChannelSaveLog();
  38. $first = DB::connection('read')->table('QPPlatformDB.dbo.ChannelConfig')->where($where)->first();
  39. $admin_id = session('admin')->id;
  40. switch ($type) {
  41. case 'off': // 关闭
  42. $res = DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')->where($where)->update([
  43. 'ReviewState' => 0,
  44. ]);
  45. // 添加日志
  46. $logModel->add($admin_id, $first->ChannelType, $first->ChannelIndex, 0, $first->VersionValue, $first->AndroidVersion);
  47. break;
  48. case 'on': // 开启
  49. $res = DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')->where($where)->update([
  50. 'ReviewState' => 1,
  51. ]);
  52. // 添加日志
  53. $logModel->add($admin_id, $first->ChannelType, $first->ChannelIndex, 1, $first->VersionValue, $first->AndroidVersion);
  54. break;
  55. default:
  56. $this->error = '类型错误';
  57. return false;
  58. }
  59. if (isset($res) && $res) {
  60. return true;
  61. } else {
  62. $this->error = '操作失败';
  63. return false;
  64. }
  65. }
  66. public function update($id)
  67. {
  68. $info = DB::table('agent.dbo.channel')->where('id', $id)->first();
  69. $open_region = \GuzzleHttp\json_decode($info->open_region, true);
  70. $names = DB::table('agent.dbo.admin_configs')->where('type', 'channel')->pluck('name', 'id');
  71. foreach ($open_region as &$value) {
  72. $value['name'] = isset($names[$value['id']]) ? $names[$value['id']] : '';
  73. }
  74. $info->open_region = $open_region;
  75. return compact('info');
  76. }
  77. public function channel_switch($id, $config_id, $type)
  78. {
  79. $query = DB::table('agent.dbo.channel')->where('id', $id)->first();
  80. $open_region = \GuzzleHttp\json_decode($query->open_region, true);
  81. $off = 0;
  82. switch ($type) {
  83. case 'on':
  84. foreach ($open_region as &$value) {
  85. if ($value['id'] == $config_id) {
  86. $value['status'] = 1;
  87. }
  88. }
  89. break;
  90. case 'off':
  91. foreach ($open_region as &$value) {
  92. if ($value['id'] == $config_id) {
  93. $value['status'] = -1;
  94. }
  95. if ($value['status'] == 1) {
  96. $off += 1;
  97. }
  98. }
  99. if ($off < 1) {
  100. $this->error = '至少开启一个通道';
  101. return false;
  102. }
  103. break;
  104. default:
  105. $this->error = '类型错误';
  106. return false;
  107. }
  108. $open_region = \GuzzleHttp\json_encode($open_region);
  109. DB::table('agent.dbo.channel')->where('id', $id)->update(['open_region' => $open_region]);
  110. }
  111. // 渠道包配置充值和游戏
  112. public function rechargeGame($ChannelPackageName)
  113. {
  114. $where = [];
  115. !empty($ChannelPackageName) && $where[] = ['PackageName', 'like', $ChannelPackageName . '%'];
  116. $list = DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  117. ->where($where)
  118. ->paginate(30);
  119. foreach ($list as $value) {
  120. // 游戏名称
  121. $arr = DB::connection('write')->table('QPPlatformDB.dbo.ChannelGameOpen')
  122. ->where('Channel', $value->Channel)
  123. ->where('Status', 1)
  124. ->pluck('KindID')->toArray();
  125. $KindName = DB::connection('write')->table('QPPlatformDB.dbo.GameKindItem')
  126. ->whereIn('KindID', $arr)
  127. ->pluck('KindName')->toArray();
  128. $value->KindName = implode(',', $KindName);
  129. // 充值名称
  130. $ConfigIDs = DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge')
  131. ->where('Channel', $value->Channel)
  132. ->where('Status', 1)
  133. ->pluck('ConfigID')->toArray();
  134. $name = DB::connection('write')->table('agent.dbo.admin_configs')
  135. ->whereIn('id', $ConfigIDs)
  136. ->pluck('name')->toArray();
  137. $value->rechargeName = implode(',', $name);
  138. }
  139. return compact('list','ChannelPackageName');
  140. }
  141. }