| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- namespace App\Http\logic\admin;
- use App\Http\logic\api\BaseApiLogic;
- use App\Models\ChannelSaveLog;
- use Illuminate\Support\Facades\DB;
- class ChannelLogic extends BaseApiLogic
- {
- public function index()
- {
- $where = [];
- $list = DB::table('agent.dbo.channel')
- ->where($where)
- ->orderByDesc('updated_at')
- ->get();
- $names = DB::table('agent.dbo.admin_configs')->where('type', 'channel')->pluck('name', 'id');
- foreach ($list as &$value) {
- $name = [];
- if (!empty($value->open_region)) {
- $open_region = \GuzzleHttp\json_decode($value->open_region, true);
- foreach ($open_region as $val) {
- if ($val['status'] == 1) {
- $name[] = isset($names[$val['id']]) ? $names[$val['id']] : '';
- }
- }
- }
- $value->open_region = implode(',', $name);
- }
- return compact('list');
- }
- public function switch_control($id, $ChannelIndex, $AndroidVersion, $type)
- {
- $where = [
- ['ChannelType', '=', $id],
- ['ChannelIndex', '=', $ChannelIndex],
- ['AndroidVersion', '=', $AndroidVersion],
- ];
- $logModel = new ChannelSaveLog();
- $first = DB::connection('read')->table('QPPlatformDB.dbo.ChannelConfig')->where($where)->first();
- $admin_id = session('admin')->id;
- switch ($type) {
- case 'off': // 关闭
- $res = DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')->where($where)->update([
- 'ReviewState' => 0,
- ]);
- // 添加日志
- $logModel->add($admin_id, $first->ChannelType, $first->ChannelIndex, 0, $first->VersionValue, $first->AndroidVersion);
- break;
- case 'on': // 开启
- $res = DB::connection('write')->table('QPPlatformDB.dbo.ChannelConfig')->where($where)->update([
- 'ReviewState' => 1,
- ]);
- // 添加日志
- $logModel->add($admin_id, $first->ChannelType, $first->ChannelIndex, 1, $first->VersionValue, $first->AndroidVersion);
- break;
- default:
- $this->error = '类型错误';
- return false;
- }
- if (isset($res) && $res) {
- return true;
- } else {
- $this->error = '操作失败';
- return false;
- }
- }
- public function update($id)
- {
- $info = DB::table('agent.dbo.channel')->where('id', $id)->first();
- $open_region = \GuzzleHttp\json_decode($info->open_region, true);
- $names = DB::table('agent.dbo.admin_configs')->where('type', 'channel')->pluck('name', 'id');
- foreach ($open_region as &$value) {
- $value['name'] = isset($names[$value['id']]) ? $names[$value['id']] : '';
- }
- $info->open_region = $open_region;
- return compact('info');
- }
- public function channel_switch($id, $config_id, $type)
- {
- $query = DB::table('agent.dbo.channel')->where('id', $id)->first();
- $open_region = \GuzzleHttp\json_decode($query->open_region, true);
- $off = 0;
- switch ($type) {
- case 'on':
- foreach ($open_region as &$value) {
- if ($value['id'] == $config_id) {
- $value['status'] = 1;
- }
- }
- break;
- case 'off':
- foreach ($open_region as &$value) {
- if ($value['id'] == $config_id) {
- $value['status'] = -1;
- }
- if ($value['status'] == 1) {
- $off += 1;
- }
- }
- if ($off < 1) {
- $this->error = '至少开启一个通道';
- return false;
- }
- break;
- default:
- $this->error = '类型错误';
- return false;
- }
- $open_region = \GuzzleHttp\json_encode($open_region);
- DB::table('agent.dbo.channel')->where('id', $id)->update(['open_region' => $open_region]);
- }
- // 渠道包配置充值和游戏
- public function rechargeGame($ChannelPackageName)
- {
- $where = [];
- !empty($ChannelPackageName) && $where[] = ['PackageName', 'like', $ChannelPackageName . '%'];
- $list = DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
- ->where($where)
- ->paginate(30);
- foreach ($list as $value) {
- // 游戏名称
- $arr = DB::connection('write')->table('QPPlatformDB.dbo.ChannelGameOpen')
- ->where('Channel', $value->Channel)
- ->where('Status', 1)
- ->pluck('KindID')->toArray();
- $KindName = DB::connection('write')->table('QPPlatformDB.dbo.GameKindItem')
- ->whereIn('KindID', $arr)
- ->pluck('KindName')->toArray();
- $value->KindName = implode(',', $KindName);
- // 充值名称
- $ConfigIDs = DB::connection('write')->table('QPPlatformDB.dbo.ChannelOpenRecharge')
- ->where('Channel', $value->Channel)
- ->where('Status', 1)
- ->pluck('ConfigID')->toArray();
- $name = DB::connection('write')->table('agent.dbo.admin_configs')
- ->whereIn('id', $ConfigIDs)
- ->pluck('name')->toArray();
- $value->rechargeName = implode(',', $name);
- }
- return compact('list','ChannelPackageName');
- }
- }
|