123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\common\library\Redis;
- use think\Controller;
- use think\Request;
- /**
- * 倒粉域名与渠道关联管理
- *
- * @icon fa fa-circle-o
- */
- class Guideagent extends Backend
- {
-
- /**
- * GuideRelation模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('GuideRelation');
- }
- /**
- * 查看
- *
- * @author liues@dianzhong.com
- * @date 2018-08-16 11:44:18
- * @return html|json
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams(null, true);
- $total = $this->model->alias('gr')
- ->join('admin a','a.id=gr.admin_id', 'LEFT')
- ->join('admin_extend ae','ae.admin_id=a.id', "LEFT")
- ->join('auth_group_access ag','ag.uid= a.id', "LEFT")
- ->join('admin a2','a2.id=ae.create_by', "LEFT")
- ->join('guide_domain gd','gd.id=gr.domain_id', 'LEFT')
- ->where(['ag.group_id' => 4])
- ->where($where)
- ->order($sort, $order)
- ->group('gr.admin_id')
- ->count();
- $fields = implode(',', [
- 'gr.*',
- 'GROUP_CONCAT(gr.id) AS id',
- 'a.username as username',
- 'a.nickname as nickname',
- 'ae.create_by',
- 'a2.username as create_username',
- 'a2.nickname as create_nickname',
- 'GROUP_CONCAT(gd.id) AS hostid_concat',
- 'GROUP_CONCAT(gd.host) AS host_concat',
- 'GROUP_CONCAT(FROM_UNIXTIME(gr.createtime)) AS createtime_concat',
- 'GROUP_CONCAT(FROM_UNIXTIME(gr.updatetime)) AS updatetime_concat'
- ]);
- $list = $this->model->alias('gr')
- ->field($fields)
- ->join('admin a','a.id=gr.admin_id', 'LEFT')
- ->join('admin_extend ae','ae.admin_id=a.id', "LEFT")
- ->join('auth_group_access ag','ag.uid= a.id', "LEFT")
- ->join('admin a2','a2.id=ae.create_by', "LEFT")
- ->join('guide_domain gd','gd.id=gr.domain_id', 'LEFT')
- ->where(['ag.group_id' => 4])
- ->where($where)
- ->order($sort, $order)
- ->group('gr.admin_id')
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 添加/批量添加
- *
- * @author liues@dianzhong.com
- * @date 2018-08-16 13:30:34
- * @return html|json
- */
- public function add()
- {
- if ($this->request->isPost())
- {
- $hostIds = array_filter($this->request->post('host_ids/a'));
- $channelIds = array_filter($this->request->post('channel_ids/a'));
- if(!empty($hostIds) && !empty($channelIds))
- {
- $params = array();
- foreach ($hostIds as $hostId)
- {
- foreach($channelIds as $channelId)
- {
- $exists = model('GuideRelation')->where(['admin_id'=>$channelId,'domain_id'=>$hostId])->find();
- if(empty($exists))
- {
- $params[] = ['admin_id' => $channelId, 'domain_id' => $hostId];
- }
- }
- }
- try
- {
- //是否采用模型验证
- if ($this->modelValidate)
- {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
- $this->model->validate($validate);
- }
- $result = $this->model->allowField(true)->saveAll($params);
- if ($result !== false)
- {
- $this->success();
- }
- else
- {
- $this->error($this->model->getError());
- }
- }
- catch (\think\exception\PDOException $e)
- {
- $this->error($e->getMessage());
- }
- }
- $this->error('请选择相应的关联关系');
- }
- else
- {
- $rows = $this->request->get('rows/a');
- //域名列表
- $where = ['status'=>'1'];
- if($rows['host']){
- $where['host'] = ['LIKE', sprintf('%%%s%%', $rows['host'])];
- }
- $hosts = model('GuideDomain')
- ->field('id,host,status')
- ->where($where)
- ->order('id', 'desc')
- ->select();
- $this->assign('hosts', $hosts);
- //渠道商列表
- $where = ['admin.status'=>'normal','ae.distribute'=>'1','ag.group_id' => 4];
- if($rows['channel_id']){
- $where['admin.id'] = ['=', $rows['channel_id']];
- }
- if($rows['channel_username']){
- $where['admin.username'] = ['LIKE', sprintf('%%%s%%', $rows['channel_username'])];
- }
- if($rows['channel_nickname']){
- $where['admin.nickname'] = ['LIKE', sprintf('%%%s%%', $rows['channel_nickname'])];
- }
- if($rows['create_id']){
- $where['ae.create_by'] = ['=', $rows['create_id']];
- }
- if($rows['create_username']){
- $where['a2.username'] = ['LIKE', sprintf('%%%s%%', $rows['create_username'])];
- }
- if($rows['create_nickname']){
- $where['a2.nickname'] = ['LIKE', sprintf('%%%s%%', $rows['create_nickname'])];
- }
- $channels = model('Admin')
- ->field('admin.id,admin.username,admin.nickname,admin.status,ae.create_by,a2.username as create_username,a2.nickname as create_nickname')
- ->join('admin_extend ae','ae.admin_id=admin.id', "LEFT")
- ->join('admin a2','a2.id=ae.create_by', "LEFT")
- ->join('auth_group_access ag','ag.uid= admin.id', "LEFT")
- ->where($where) //3渠道商
- ->order('admin.id', 'desc')
- ->select();
- $this->assign('channels', $channels);
- $this->assign('rows', $rows);
- return $this->view->fetch();
- }
- }
- /**
- * 编辑
- *
- * @author liues@dianzhong.com
- * @date 2018-08-16 13:30:53
- * @return html|json
- */
- public function edit($ids = NULL)
- {
- $this->error('请删除对应项,重新绑定');
- }
- /**
- * 删除
- */
- public function del($ids = "")
- {
- if ($ids)
- {
- $pk = $this->model->getPk();
- // $adminIds = $this->getDataLimitAdminIds();
- // if (is_array($adminIds))
- // {
- // $count = $this->model->where($this->dataLimitField, 'in', $adminIds);
- // }
- $list = $this->model->where($pk, 'in', $ids)->select();
- $count = 0;
- // 组合一个admin_id为key的二维数组,value为domain_id一维数组
- $guideRelationAdmin = [];
- foreach ($list as $k => $v) {
- $guideRelationAdmin[$v['admin_id']][] = $v['domain_id'];
- }
- foreach ($guideRelationAdmin as $k => $v) {
- if (!model('GuideRelation')->where(['admin_id' => $k])->where('domain_id', 'not in', $v)->find()) { //除此短链外,没有任何其他短链了
- model('AdminConfig')->where(['admin_id' => $k])->update(['guide_domain' => '0']);
- model('AdminConfig')->delAdminInfoAllCache($k);
- }
- }
- foreach ($list as $k => $v)
- {
- $count += $v->delete();
- }
- if ($count)
- {
- $this->success();
- }
- else
- {
- $this->error(__('No rows were deleted'));
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- }
|