123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\main\constants\AdminConstants;
- use think\Controller;
- use think\Request;
- use app\common\model\Postbackrules;
- /**
- * 管理员管理
- *
- * @icon fa fa-circle-o
- */
- class Postbackchannel extends Backend
- {
- /**
- * @var \app\common\model\Admin
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('admin');
- $ruleId = $this->request->get('rule_id');
- $this->assignconfig('rule_id', $ruleId);
- $action = $this->request->get('action', 'relation');
- $this->assignconfig('action', $action);
- $this->view->assign('action', $action);
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- $ruleId = $this->request->get('rule_id');
- $mPostbackrules = new Postbackrules();
- $sChannelIds = $mPostbackrules->where('id', $ruleId)->value('channel_ids');
- if ($sChannelIds == '*') {
- $this->assignconfig('channels', '*');
- $this->view->assign('channels', '*');
- } else {
- $this->view->assign('channels', '');
- }
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $action = $this->request->get('action', 'relation');
- $channelIds = explode(',', $sChannelIds);
- if (!$channelIds) {
- array_push($channelIds, 0);
- }
- $aWhere = [
- 'aga.group_id' => AdminConstants::ADMIN_GROUP_ID_CHANNEL
- ];
- $all = 0;
- if ($action == 'relation') {
- if ($sChannelIds == '*') {
- $aWhere['id'] = '-1';
- } else {
- $aWhere['id'] = ['not in', $channelIds];
- }
- } else {
- if ($sChannelIds != '*') {
- $aWhere['id'] = ['in', $channelIds];
- } else {
- $all = 1;
- }
- }
- $total = $this->model
- ->alias('a')
- ->where($aWhere)
- ->where($where)
- ->join('auth_group_access aga', 'aga.uid=a.id')
- ->join('admin_extend ae', 'ae.admin_id=a.id')
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->alias('a')
- ->where($aWhere)
- ->where($where)
- ->join('auth_group_access aga', 'aga.uid=a.id')
- ->join('admin_extend ae', 'ae.admin_id=a.id')
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list, 'all'=>$all);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 批量修改渠道
- */
- public function batch_relation()
- {
- $channelids = $this->request->param('channel_ids');
- $rule_id = $this->request->param('rule_id');
- $action = $this->request->param('action');
- $mRule = new Postbackrules();
- $ruleData = $mRule->where(['id' => $rule_id])->find();
- $origin_array = explode(',', $ruleData['channel_ids']);
- $admin_ids = explode(',', $channelids);
- $updateData = [];
- if ($action == 'add') {
- //添加全部渠道
- if ($channelids == '-1') {
- $updateData['channel_ids'] = ['*'];
- } else {
- $updateData['channel_ids'] = array_unique(array_merge($origin_array, $admin_ids));;
- }
- } else {
- //清空所有渠道
- if ($channelids == '-1') {
- $updateData = ['channel_ids' => []];
- model('Postbackklreferral')
- ->where('rule_id', $rule_id)
- ->delete();
- } else {
- $updateData['channel_ids'] = array_unique(array_diff($origin_array, $admin_ids));
- model('Postbackklreferral')
- ->where('rule_id', $rule_id)
- ->whereIn('admin_id', $admin_ids)
- ->delete();
- }
- }
- //清空空值
- $updateData['channel_ids'] = array_filter($updateData['channel_ids'], function ($value) {
- return $value;
- });
- $updateData['channel_ids'] = implode(',', $updateData['channel_ids']);
- $mRule->update($updateData, ['id' => $rule_id]);
- $this->success();
- }
- }
|