Преглед на файлове

1. 数据权限校验
2. 媒体消耗
3. 渠道列表
4. 公共控制器
5. 广告位

ith5 преди 6 месеца
родител
ревизия
d05ad95c73

+ 105 - 0
app/v1/controller/CommonController.php

@@ -0,0 +1,105 @@
+<?php
+namespace app\v1\controller;
+
+use app\v1\logic\advert\AgentListLogic;
+use app\v1\logic\advert\MediaListLogic;
+use app\v1\logic\center\GameLogic;
+use plugin\saiadmin\basic\BaseController;
+use app\v1\logic\center\GameMainLogic;
+use plugin\saiadmin\app\logic\system\SystemUserLogic;
+use support\Request;
+use support\Response;
+
+/**
+ * 公共接口管理控制器
+ */
+class CommonController extends BaseController
+{
+    protected $gameMainLogic;
+    protected $gameLogic;
+    protected $mediaListLogic;
+    protected $agentListLogic;
+    protected $systemUserLogic;
+
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        $this->gameMainLogic = new GameMainLogic();
+        $this->gameLogic = new GameLogic();
+        $this->mediaListLogic = new MediaListLogic();
+        $this->agentListLogic = new AgentListLogic();
+        $this->systemUserLogic = new SystemUserLogic();
+    }
+    
+    /**
+     * 获取主游戏options列表
+     * @return Response
+     */
+    public function getMainGameOptions(Request $request): Response
+    {
+        $data = $this->gameMainLogic->getMainGameOptions();
+        return $this->success($data);
+    }
+
+    /**
+     * 获取子游戏options列表
+     * @return Response
+     */
+    public function getGameOptions(Request $request): Response
+    {
+
+        $where = $request->get();
+        $data = $this->gameLogic->getGameOptions($where);
+        return $this->success($data);
+    }
+
+    /**
+     * 获取树形游戏options列表
+     * @return Response
+     */
+    public function getTreeGameOptions(Request $request): Response
+    {
+        $where = $request->get();
+        $data = $this->gameLogic->getGameListByPermission($where);
+        return $this->success($data);
+    }
+
+
+    /**
+     * 查询媒体列表Options
+     */
+    public function getMediaOptions(Request $request): Response
+    {
+        $data = $this->mediaListLogic->getMediaOptions();
+        $data = $data->toArray();
+        $data = array_map(function ($item) {
+            return [
+                'label' => $item['name'].'【' . $item['id'] . '】',
+                'value' => $item['id'],
+            ];
+        }, $data);
+
+        return $this->success($data);
+    }
+
+    /**
+     * 查询渠道列表Options
+     */
+    public function getAgentOptions(Request $request): Response
+    {
+        $data = $this->agentListLogic->getAgentOptions();
+        return $this->success($data);
+    }
+
+    /**
+     * 后台归属人列表Options
+     */
+    public function getAuthOptions(Request $request): Response
+    {
+        $data = $this->systemUserLogic->field('id as value, username as label')->select()->toArray();
+        return $this->success($data);
+    }
+}

+ 57 - 0
app/v1/controller/advert/AgentListController.php

@@ -0,0 +1,57 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\controller\advert;
+
+use plugin\saiadmin\basic\BaseController;
+use app\v1\logic\advert\AgentListLogic;
+use app\v1\validate\advert\AgentListValidate;
+use plugin\saiadmin\app\logic\system\SystemUserLogic;
+use support\Request;
+use support\Response;
+
+/**
+ * 渠道管理控制器
+ */
+class AgentListController extends BaseController
+{
+    protected $systemUserLogic;
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->logic = new AgentListLogic();
+        $this->validate = new AgentListValidate;
+        parent::__construct();
+         $this->systemUserLogic = new SystemUserLogic();
+    }
+
+    /**
+     * 数据列表
+     * @param Request $request
+     * @return Response
+     */
+    public function index(Request $request): Response
+    {
+        $where = $request->more([
+            ['auth_id', ''],
+            ['name', ''],
+        ]);
+        $query = $this->logic->search($where);
+        $data = $this->logic->getList($query);
+        $userListData = array_column($this->systemUserLogic->field('id,username')->select()->toArray(),'username','id');
+
+
+        $data['data'] = array_map(function ($item) use ($userListData) {
+            $item['auth_name'] = $userListData[$item['auth_id']] ?? '';
+            return $item;
+        }, $data['data']);
+
+        return $this->success($data);
+    }
+
+}

+ 66 - 0
app/v1/controller/advert/AgentSiteController.php

@@ -0,0 +1,66 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\controller\advert;
+
+use app\v1\logic\advert\AgentListLogic;
+use plugin\saiadmin\basic\BaseController;
+use app\v1\logic\advert\AgentSiteLogic;
+use app\v1\logic\advert\MediaListLogic;
+use app\v1\validate\advert\AgentSiteValidate;
+use plugin\saiadmin\app\logic\system\SystemUserLogic;
+use support\Request;
+use support\Response;
+
+/**
+ * 广告位列表控制器
+ */
+class AgentSiteController extends BaseController
+{
+    protected $systemUserLogic;
+    protected $agentListLogic;
+    protected $mediaListLogic;
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->logic = new AgentSiteLogic();
+        $this->validate = new AgentSiteValidate;
+        parent::__construct();
+        $this->systemUserLogic = new SystemUserLogic();
+        $this->agentListLogic = new AgentListLogic();
+        $this->mediaListLogic = new MediaListLogic();
+    }
+
+    /**
+     * 数据列表
+     * @param Request $request
+     * @return Response
+     */
+    public function index(Request $request): Response
+    {
+        $where = $request->more([
+            ['media_id', ''],
+            ['agent_id', ''],
+            ['auth_id', ''],
+            ['name', ''],
+        ]);
+        $query = $this->logic->search($where);
+        $data = $this->logic->getList($query);
+        $userListData = array_column($this->systemUserLogic->field('id,username')->select()->toArray(),'username','id');
+        $agentListData = array_column($this->agentListLogic->field('id,name')->select()->toArray(),'name','id');
+        $mediaListData = array_column($this->mediaListLogic->field('id,name')->select()->toArray(),'name','id');
+        $data['data'] = array_map(function ($item) use ($userListData, $agentListData, $mediaListData) {
+            $item['auth_name'] = $userListData[$item['auth_id']] ?? '';
+            $item['agent_name'] = $agentListData[$item['agent_id']] ?? '';
+            $item['media_name'] = $mediaListData[$item['media_id']] ?? '';
+            return $item;
+        }, $data['data']);
+        return $this->success($data);
+    }
+
+}

+ 87 - 0
app/v1/controller/advert/MediaCostController.php

@@ -0,0 +1,87 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\controller\advert;
+
+use app\v1\logic\advert\AgentListLogic;
+use app\v1\logic\advert\AgentSiteLogic;
+use plugin\saiadmin\basic\BaseController;
+use app\v1\logic\advert\MediaCostLogic;
+use app\v1\logic\center\GameLogic;
+use app\v1\validate\advert\MediaCostValidate;
+use plugin\saiadmin\app\logic\system\SystemUserLogic;
+use support\Request;
+use support\Response;
+
+/**
+ * 媒体消耗控制器
+ */
+class MediaCostController extends BaseController
+{
+    protected $agentSiteLogic;
+    protected $agentListLogic;
+    protected $gameLogic;
+    protected $systemUserLogic;
+
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->logic = new MediaCostLogic();
+        $this->validate = new MediaCostValidate;
+        parent::__construct();
+        $this->agentSiteLogic = new AgentSiteLogic();
+        $this->agentListLogic = new AgentListLogic();
+        $this->gameLogic = new GameLogic();
+        $this->systemUserLogic = new SystemUserLogic();
+    }
+
+    /**
+     * 数据列表
+     * @param Request $request
+     * @return Response
+     */
+    public function index(Request $request): Response
+    {
+        $where = $request->more([
+            ['tdate', ''],
+            ['game_id', ''],
+            ['media_id', ''],
+            ['agent_id', ''],
+            ['site_id', ''],
+            ['auth_id', ''],
+            ['add_type', ''],
+            ['remark', ''],
+            ['create_time', ''],
+        ]);
+        $query = $this->logic->search($where);
+        
+        
+        // 游戏权限过滤
+        if($request->get('auth_game_list')){
+            $gameIds = explode(',', $request->get('auth_game_list'));
+            $query->whereIn('game_id', $gameIds);
+        }
+
+        $data = $this->logic->getList($query)['data'];
+
+        $data = $this->logic->trandformListColumn($data, ['site', 'agent', 'game', 'auth']);
+      
+        return $this->success($data);
+    }
+
+    /**
+     * 保存媒体消耗
+     */
+    public function save(Request $request): Response
+    {
+        $data = $request->post();
+        $this->logic->save($data);
+        return $this->success();
+    }
+
+}

+ 47 - 0
app/v1/controller/advert/MediaListController.php

@@ -0,0 +1,47 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\controller\advert;
+
+use plugin\saiadmin\basic\BaseController;
+use app\v1\logic\advert\MediaListLogic;
+use app\v1\validate\advert\MediaListValidate;
+use support\Request;
+use support\Response;
+
+/**
+ * 广告媒体表控制器
+ */
+class MediaListController extends BaseController
+{
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->logic = new MediaListLogic();
+        $this->validate = new MediaListValidate;
+        parent::__construct();
+    }
+
+    /**
+     * 数据列表
+     * @param Request $request
+     * @return Response
+     */
+    public function index(Request $request): Response
+    {
+        $where = $request->more([
+            ['id', ''],
+            ['name', ''],
+            ['channel_name', ''],
+        ]);
+        $query = $this->logic->search($where);
+        $data = $this->logic->getList($query);
+        return $this->success($data);
+    }
+
+}

+ 0 - 57
app/v1/controller/center/CommonController.php

@@ -1,57 +0,0 @@
-<?php
-namespace app\v1\controller\center;
-
-use app\v1\logic\center\GameLogic;
-use plugin\saiadmin\basic\BaseController;
-use app\v1\logic\center\GameMainLogic;
-use support\Request;
-use support\Response;
-
-/**
- * 公共接口管理控制器
- */
-class CommonController extends BaseController
-{
-    protected $gameMainLogic;
-    protected $gameLogic;
-
-    /**
-     * 构造函数
-     */
-    public function __construct()
-    {
-        parent::__construct();
-        $this->gameMainLogic = new GameMainLogic();
-        $this->gameLogic = new GameLogic();
-    }
-    
-    /**
-     * 获取主游戏options列表
-     * @return Response
-     */
-    public function getMainGameOptions(Request $request): Response
-    {
-        $data = $this->gameMainLogic->getMainGameOptions();
-        return $this->success($data);
-    }
-
-    /**
-     * 获取子游戏options列表
-     * @return Response
-     */
-    public function getGameOptions(Request $request): Response
-    {
-        $data = $this->gameLogic->getGameOptions();
-        return $this->success($data);
-    }
-
-    /**
-     * 获取树形游戏options列表
-     * @return Response
-     */
-    public function getTreeGameOptions(Request $request): Response
-    {
-        $data = $this->gameLogic->getGameListByPermission();
-        return $this->success($data);
-    }
-}

+ 2 - 2
app/v1/controller/center/GameController.php

@@ -41,7 +41,6 @@ class GameController extends BaseController
     public function index(Request $request): Response
     {
         $where = $request->more([
-            ['id', ''],
             ['main_id', ''],
             ['name', ''],
             ['os', ''],
@@ -126,7 +125,8 @@ class GameController extends BaseController
      */
     public function getAllGameData(Request $request): Response
     {
-        $list = $this->logic->getAllGameData();
+        $where = $request->get();
+        $list = $this->logic->getAllGameData($where);
         return $this->success($list);
     }
 

+ 41 - 0
app/v1/logic/advert/AgentListLogic.php

@@ -0,0 +1,41 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\logic\advert;
+
+use plugin\saiadmin\basic\BaseLogic;
+use plugin\saiadmin\exception\ApiException;
+use plugin\saiadmin\utils\Helper;
+use app\v1\model\advert\AgentList;
+
+/**
+ * 渠道管理逻辑层
+ */
+class AgentListLogic extends BaseLogic
+{
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->model = new AgentList();
+    }
+
+    /**
+     * 查询渠道列表Options
+     */
+    public function getAgentOptions()
+    {
+        $data = $this->model->field('id as value,name as label')->select()->toArray();
+        $data = array_map(function ($item) {
+            return [
+                'label' => $item['label'].'【' . $item['value'] . '】' ,
+                'value' => $item['value'],
+            ];
+        }, $data);
+        return $data;
+    }
+}

+ 27 - 0
app/v1/logic/advert/AgentSiteLogic.php

@@ -0,0 +1,27 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\logic\advert;
+
+use plugin\saiadmin\basic\BaseLogic;
+use plugin\saiadmin\exception\ApiException;
+use plugin\saiadmin\utils\Helper;
+use app\v1\model\advert\AgentSite;
+
+/**
+ * 广告位列表逻辑层
+ */
+class AgentSiteLogic extends BaseLogic
+{
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->model = new AgentSite();
+    }
+
+}

+ 74 - 0
app/v1/logic/advert/MediaCostLogic.php

@@ -0,0 +1,74 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\logic\advert;
+
+use app\v1\logic\center\GameLogic;
+use plugin\saiadmin\basic\BaseLogic;
+use plugin\saiadmin\exception\ApiException;
+use plugin\saiadmin\utils\Helper;
+use app\v1\model\advert\MediaCost;
+use plugin\saiadmin\app\logic\system\SystemUserLogic;
+
+/**
+ * 媒体消耗逻辑层
+ */
+class MediaCostLogic extends BaseLogic
+{
+    protected $agentSiteLogic;
+    protected $agentListLogic;
+    protected $gameLogic;
+    protected $systemUserLogic;
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->model = new MediaCost();
+        $this->agentSiteLogic = new AgentSiteLogic();
+        $this->agentListLogic = new AgentListLogic();
+        $this->gameLogic = new GameLogic();
+        $this->systemUserLogic = new SystemUserLogic();
+    }
+
+
+
+    /**
+     * 保存媒体消耗
+     */
+    public function save($data)
+    {
+        $site_id = $data['site_id'];
+        $site_info = $this->agentSiteLogic->read($site_id);
+        $auth_id = $site_info['auth_id'];
+        $data['auth_id'] = $auth_id;
+        $this->model->save($data);
+    }
+
+    public function trandformListColumn($data, $fields=['site', 'agent', 'game', 'auth']){
+
+        if(in_array('site', $fields)){
+            $agentSiteList = $this->agentSiteLogic->field('id,name')->column('name', 'id');
+        }
+        if(in_array('agent', $fields)){
+            $agentList = $this->agentListLogic->field('id,name')->column('name', 'id');
+        }
+        if(in_array('game', $fields)){
+            $gameList = $this->gameLogic->field('id,name')->select()->column('name', 'id');
+        }
+        if(in_array('auth', $fields)){
+            $authList = $this->systemUserLogic->field('id,username')->column('username', 'id');
+        }
+
+        foreach ($data as $key => $value) {
+            $data[$key]['site_name'] = $agentSiteList ? $agentSiteList[$value['site_id']] ?? '':'';
+            $data[$key]['agent_name'] = $agentList ? $agentList[$value['agent_id']] ?? '':'';
+            $data[$key]['game_name'] = $gameList ? $gameList[$value['game_id']] ?? '':'';
+            $data[$key]['auth_name'] = $authList ? $authList[$value['auth_id']] ?? '':'';
+        }
+        return $data;
+    }
+}

+ 35 - 0
app/v1/logic/advert/MediaListLogic.php

@@ -0,0 +1,35 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\logic\advert;
+
+use plugin\saiadmin\basic\BaseLogic;
+use plugin\saiadmin\exception\ApiException;
+use plugin\saiadmin\utils\Helper;
+use app\v1\model\advert\MediaList;
+
+/**
+ * 广告媒体表逻辑层
+ */
+class MediaListLogic extends BaseLogic
+{
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->model = new MediaList();
+    }
+
+    /**
+     * 查询媒体列表Options
+     */
+    public function getMediaOptions()
+    {
+        $data = $this->model->select();
+        return $data;
+    }
+}

+ 33 - 14
app/v1/logic/center/GameLogic.php

@@ -36,7 +36,12 @@ class GameLogic extends BaseLogic
      */
     public function getIndex($where)
     {
+        $auth_game_list = request()->header('auth_game_list');
         $query = $this->search($where);
+        if(!empty($auth_game_list)) {
+            $authGameList = explode(',', $auth_game_list);
+            $query->where('id', 'in', $authGameList);
+        }
         $query->order('sort', 'desc');
 
         $data = $this->getList($query);
@@ -52,24 +57,32 @@ class GameLogic extends BaseLogic
      * 获取游戏options列表
      * @return array
      */
-    public function getGameOptions()
+    public function getGameOptions($where)
     {
-        $list = $this->model->field('id,name')->where('status', 1)->order('sort', 'desc')->select()->toArray();
-        $list = array_map(function ($item) {
-            return [
-                'label' => $item['name'],
-                'value' => $item['id']
-            ];
-        }, $list);
+        $auth_game_list = request()->header('auth_game_list');
+        $query = $this->field('id as value,name as label');
+        if(!empty($auth_game_list)) {
+            $authGameList = explode(',', $auth_game_list);
+            $query->where('id', 'in', $authGameList);
+        }
+        $list = $query->select()->toArray();
         return $list;
     }
     
     /**
      * 获取所有的游戏数据
      */
-    public function getAllGameData()
+    public function getAllGameData($where)
     {
-        $game_list = $this->model->where('status', 1)->order('sort', 'desc')->select()->toArray();
+        $auth_game_list = request()->header('auth_game_list');
+        $query = $this->search($where);
+        if(!empty($auth_game_list)) {
+            $authGameList = explode(',', $auth_game_list);
+            $query->where('id', 'in', $authGameList);
+        }
+        $query->where('status', 1);
+        $query->order('sort', 'desc');
+        $game_list = $this->getList($query);
 
         $mainGameMap = $this->gameMainLogic->getMainGameMap();
         
@@ -89,10 +102,17 @@ class GameLogic extends BaseLogic
     /**
      * 根据权限获取游戏列表
      */
-    public function getGameListByPermission()
+    public function getGameListByPermission($where)
     {
-        $game_list = $this->getAllGameData();
-        return $game_list;
+        $auth_game_list = request()->header('auth_game_list');
+        $query = $this->search($where);
+        if(!empty($auth_game_list)) {
+            $authGameList = explode(',', $auth_game_list);
+            $query->where('id', 'in', $authGameList);
+        }
+        $query->where('status', 1);
+        $query->order('sort', 'desc');
+        return $query->select()->toArray();
     }
 
     /**
@@ -136,5 +156,4 @@ class GameLogic extends BaseLogic
         $this->systemDeptLogic->setGameListByDeptId($dept_id, $game_list);
     }
 
-   
 }

+ 10 - 9
app/v1/middleware/FilterPermission.php

@@ -11,6 +11,8 @@ use Webman\MiddlewareInterface;
  */
 class FilterPermission implements MiddlewareInterface
 {
+   
+
     public function process(Request $request, callable $handler) : Response
     {
 
@@ -23,14 +25,16 @@ class FilterPermission implements MiddlewareInterface
         $userAuthCache = new UserInfoCache($token['id']);
         $user_info = $userAuthCache->getUserInfo();
 
+        // $user_info = $this->systemUserLogic->read($token['id']);
+
         // 获取游戏数据权限
-        $auth_game_list = $user_info['game_list'] ?? -1;
+        $auth_game_list = $user_info['game_list'] ?? '';
 
         // 获取游戏自然量数据权限
-        $auth_normal_game_list = $user_info['normal_game_list'] ?? -1;
+        $auth_normal_game_list = $user_info['normal_game_list'] ?? '';
 
-        // 获取游戏自然量数据权限
-        $auth_ad_permission = $user_info['ad_permission'] ?? -1;
+        // 获取广告投放数据权限
+        $auth_ad_permission = $user_info['ad_permission'] ?? '';
 
         // 追加参数逻辑
         $extraParams = [
@@ -40,11 +44,8 @@ class FilterPermission implements MiddlewareInterface
         ];
        
         // 合并并设置回 request
-        if ($method === 'GET') {
-            $request->setGet(array_merge($request->get(), $extraParams));
-        } elseif ($method === 'POST') {
-            $request->setPost(array_merge($request->post(), $extraParams));
-        }
+        $origin_header = $request->header();
+        $request->setHeader(array_merge($origin_header, $extraParams));
 
         return $handler($request);
     }

+ 42 - 0
app/v1/model/advert/AgentList.php

@@ -0,0 +1,42 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\model\advert;
+
+use plugin\saiadmin\basic\BaseNormalModel;
+
+/**
+ * 渠道管理模型
+ */
+class AgentList extends BaseNormalModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 数据库表名称
+     * @var string
+     */
+    protected $table = 'agent_list';
+
+    /**
+     * 数据库连接
+     * @var string
+     */
+    protected $connection = 'db_advert';
+
+    /**
+     * 渠道名称 搜索
+     */
+    public function searchNameAttr($query, $value)
+    {
+        $query->where('name', 'like', '%'.$value.'%');
+    }
+
+}

+ 42 - 0
app/v1/model/advert/AgentSite.php

@@ -0,0 +1,42 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\model\advert;
+
+use plugin\saiadmin\basic\BaseNormalModel;
+
+/**
+ * 广告位列表模型
+ */
+class AgentSite extends BaseNormalModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 数据库表名称
+     * @var string
+     */
+    protected $table = 'agent_site';
+
+    /**
+     * 数据库连接
+     * @var string
+     */
+    protected $connection = 'db_advert';
+
+    /**
+     * 广告位名称 搜索
+     */
+    public function searchNameAttr($query, $value)
+    {
+        $query->where('name', 'like', '%'.$value.'%');
+    }
+
+}

+ 50 - 0
app/v1/model/advert/MediaCost.php

@@ -0,0 +1,50 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\model\advert;
+
+use plugin\saiadmin\basic\BaseNormalModel;
+
+/**
+ * 媒体消耗模型
+ */
+class MediaCost extends BaseNormalModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 数据库表名称
+     * @var string
+     */
+    protected $table = 'media_cost';
+
+    /**
+     * 数据库连接
+     * @var string
+     */
+    protected $connection = 'db_advert';
+
+    /**
+     * 结算日期 搜索
+     */
+    public function searchTdateAttr($query, $value)
+    {
+        $query->whereTime('tdate', 'between', $value);
+    }
+
+    /**
+     * 录入时间 搜索
+     */
+    public function searchCreateTimeAttr($query, $value)
+    {
+        $query->whereTime('create_time', 'between', $value);
+    }
+
+}

+ 50 - 0
app/v1/model/advert/MediaList.php

@@ -0,0 +1,50 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\model\advert;
+
+use plugin\saiadmin\basic\BaseNormalModel;
+
+/**
+ * 广告媒体表模型
+ */
+class MediaList extends BaseNormalModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 数据库表名称
+     * @var string
+     */
+    protected $table = 'media_list';
+
+    /**
+     * 数据库连接
+     * @var string
+     */
+    protected $connection = 'db_advert';
+
+    /**
+     * 媒体名称 搜索
+     */
+    public function searchNameAttr($query, $value)
+    {
+        $query->where('name', 'like', '%'.$value.'%');
+    }
+
+    /**
+     * 媒体渠道简称 搜索
+     */
+    public function searchChannelNameAttr($query, $value)
+    {
+        $query->where('channel_name', 'like', '%'.$value.'%');
+    }
+
+}

+ 50 - 0
app/v1/validate/advert/AgentListValidate.php

@@ -0,0 +1,50 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\validate\advert;
+
+use think\Validate;
+
+/**
+ * 渠道管理验证器
+ */
+class AgentListValidate extends Validate
+{
+    /**
+     * 定义验证规则
+     */
+    protected $rule =   [
+        'auth_id' => 'require',
+        'name' => 'require',
+        'media_id' => 'require',
+    ];
+
+    /**
+     * 定义错误信息
+     */
+    protected $message  =   [
+        'auth_id' => '后台归属人必须填写',
+        'name' => '渠道名称必须填写',
+        'media_id' => '媒体ID必须填写',
+    ];
+
+    /**
+     * 定义场景
+     */
+    protected $scene = [
+        'save' => [
+            'auth_id',
+            'name',
+            'media_id',
+        ],
+        'update' => [
+            'auth_id',
+            'name',
+            'media_id',
+        ],
+    ];
+
+}

+ 54 - 0
app/v1/validate/advert/AgentSiteValidate.php

@@ -0,0 +1,54 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\validate\advert;
+
+use think\Validate;
+
+/**
+ * 广告位列表验证器
+ */
+class AgentSiteValidate extends Validate
+{
+    /**
+     * 定义验证规则
+     */
+    protected $rule =   [
+        'media_id' => 'require',
+        'agent_id' => 'require',
+        'auth_id' => 'require',
+        'name' => 'require',
+    ];
+
+    /**
+     * 定义错误信息
+     */
+    protected $message  =   [
+        'media_id' => '媒体ID必须填写',
+        'agent_id' => '渠道ID必须填写',
+        'auth_id' => '负责人ID必须填写',
+        'name' => '广告位名称必须填写',
+    ];
+
+    /**
+     * 定义场景
+     */
+    protected $scene = [
+        'save' => [
+            'media_id',
+            'agent_id',
+            'auth_id',
+            'name',
+        ],
+        'update' => [
+            'media_id',
+            'agent_id',
+            'auth_id',
+            'name',
+        ],
+    ];
+
+}

+ 54 - 0
app/v1/validate/advert/MediaCostValidate.php

@@ -0,0 +1,54 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\validate\advert;
+
+use think\Validate;
+
+/**
+ * 媒体消耗验证器
+ */
+class MediaCostValidate extends Validate
+{
+    /**
+     * 定义验证规则
+     */
+    protected $rule =   [
+        'tdate' => 'require',
+        'game_id' => 'require',
+        'site_id' => 'require',
+        'money' => 'require',
+    ];
+
+    /**
+     * 定义错误信息
+     */
+    protected $message  =   [
+        'tdate' => '结算日期必须填写',
+        'game_id' => '投放游戏必须填写',
+        'site_id' => '广告位ID必须填写',
+        'money' => '消耗金额必须填写',
+    ];
+
+    /**
+     * 定义场景
+     */
+    protected $scene = [
+        'save' => [
+            'tdate',
+            'game_id',
+            'site_id',
+            'money',
+        ],
+        'update' => [
+            'tdate',
+            'game_id',
+            'site_id',
+            'money',
+        ],
+    ];
+
+}

+ 66 - 0
app/v1/validate/advert/MediaListValidate.php

@@ -0,0 +1,66 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\validate\advert;
+
+use think\Validate;
+
+/**
+ * 广告媒体表验证器
+ */
+class MediaListValidate extends Validate
+{
+    /**
+     * 定义验证规则
+     */
+    protected $rule =   [
+        'name' => 'require',
+        'channel_name' => 'require',
+        'andurl' => 'require',
+        'iosurl' => 'require',
+        'xyxurl' => 'require',
+        'appleturl' => 'require',
+        'state' => 'require',
+    ];
+
+    /**
+     * 定义错误信息
+     */
+    protected $message  =   [
+        'name' => '媒体名称必须填写',
+        'channel_name' => '媒体渠道简称必须填写',
+        'andurl' => '安卓监测链接必须填写',
+        'iosurl' => 'ios监测链接必须填写',
+        'xyxurl' => '小游戏监测链接必须填写',
+        'appleturl' => '小游戏路径参数补充必须填写',
+        'state' => '状态必须填写',
+    ];
+
+    /**
+     * 定义场景
+     */
+    protected $scene = [
+        'save' => [
+            'name',
+            'channel_name',
+            'andurl',
+            'iosurl',
+            'xyxurl',
+            'appleturl',
+            'state',
+        ],
+        'update' => [
+            'name',
+            'channel_name',
+            'andurl',
+            'iosurl',
+            'xyxurl',
+            'appleturl',
+            'state',
+        ],
+    ];
+
+}

+ 65 - 0
plugin/saiadmin/basic/BaseLogic.php

@@ -160,6 +160,71 @@ class BaseLogic
         return $this->model->withSearch($withSearch, $data);
     }
 
+    /**
+     * 根据权限搜索器
+     * @param array $searchWhere
+     * @param array $withSearch 搜索器
+     * @return mixed
+     */
+     public function searchByAuth(array $searchWhere = []): mixed
+    {
+        $withSearch = array_keys($searchWhere);
+        $data = $searchWhere;
+       
+        $auth_game_list = request()->header('auth_game_list');
+        $auth_normal_game_list = request()->header('auth_normal_game_list');
+        $auth_ad_permission = request()->header('auth_ad_permission');
+
+
+        foreach ($withSearch as $k => $v) {
+            if ($data[$v] === '') {
+                unset($data[$v]);
+                unset($withSearch[$k]);
+            }
+        }
+        
+        // 游戏权限
+        if(!empty($auth_game_list)){
+            // 如果传入的game_id存在,则取交集
+            if(!empty($data['game_id'])){
+                $data['game_id'] = array_values(array_intersect(explode(',', $data['game_id']), explode(',', $auth_game_list)));
+            }else{
+                // 如果传入的game_id不存在,则取权限中的game_id
+                $data['game_id'] =  $auth_game_list?explode(',', $auth_game_list) : '';
+            }
+        }
+           
+        // 自然量游戏权限
+        if(!empty($auth_normal_game_list)){
+            // 如果传入的game_id存在,则取交集
+            if(!empty($data['nomal_game_id'])){
+                $data['nomal_game_id'] = array_values(array_intersect(explode(',', $data['nomal_game_id']), explode(',', $auth_normal_game_list)));
+            }else{
+                // 如果传入的game_id不存在,则取权限中的game_id
+                $data['nomal_game_id'] =  $auth_normal_game_list?explode(',', $auth_normal_game_list) : '';
+            }
+        }
+            
+        // 广告数据权限
+        // 全部
+        if($auth_ad_permission==1){
+            $data['auth_id'] = '';
+        }
+        // 自己以及下面组员
+        if($auth_ad_permission==2){
+            $current_user_id = $this->adminInfo['id'];
+            $result = Db::connect('db_system')->table('sa_system_user')->field('dept_id')->where('id', $current_user_id)->select()->toArray();
+            $dept_ids = array_column($result, 'dept_id');
+            $under_user_ids = Db::connect('db_system')->table('sa_system_user')->field('id')->where('dept_id', 'in', $dept_ids)->select()->toArray();
+            $under_user_ids = array_column($under_user_ids, 'id');
+            $data['auth_id'] =  $under_user_ids;
+        }
+        
+        return $this->model->withSearch($withSearch, $data);
+    }
+
+
+    
     /**
      * 分页查询数据
      * @param $query

+ 36 - 0
plugin/saiadmin/basic/BaseModel.php

@@ -53,4 +53,40 @@ class BaseModel extends Model
         $info && $model->setAttr('updated_by', $info['id']);
     }
 
+    /**
+     * 游戏ID搜索
+     */
+    public function searchGameIdAttr($query, $value)
+    {
+        if (is_array($value)) {
+            $query->whereIn('game_id', $value);
+        } else if($value!='') {
+            $query->where('game_id', $value);
+        }
+    }
+
+    /**
+     * 负责人ID搜索
+     */
+    public function searchAuthIdAttr($query, $value)
+    {
+        if(is_array($value)){
+            $query->whereIn('auth_id', $value);
+        }else if($value!=''){
+            $query->where('auth_id', $value);
+        }
+    }
+
+    /**
+     * ID搜索
+     */
+    public function searchIdAttr($query, $value)
+    {
+        if (is_array($value)) {
+            $query->whereIn('id', $value);
+        } else if($value!=''){
+            $query->where('id', $value);
+        }
+    }
+
 }