123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace app\admin\controller\auth;
- use app\common\controller\Backend;
- class Channelfunctionmanage extends Backend
- {
- protected $model = null;
- protected $relationModel = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model("ChannelSpecialManage");
- }
- /**
- * 查看
- */
- 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();
- $aWhere = ['type' => 2];
- $total = $this->model
- ->where($where)
- ->where($aWhere)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->where($aWhere)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 关联渠道
- */
- public function operate()
- {
- if ($this->request->isAjax()) {
- $id = $this->request->param('id');
- $channelIds = $this->request->param('channel_ids');
- $operate = $this->request->param('method');
- $row = $this->model->get($id);
- if ($row) {
- //更新
- $menuRow = model("ChannelMenuList")->where('id', 'eq', $row['channel_id'])->find();
- if ($menuRow) {
- $hasChannelIds = explode(',', $menuRow['channel_id']);
- if ($hasChannelIds) {
- if ($operate == 'add') {
- if ($channelIds == "*") {
- $updateChannelIds = "*";
- } else {
- $channelIds = explode(',', $channelIds);
- $updateChannelIds = implode(',', array_unique(array_merge($hasChannelIds, $channelIds)));
- }
- } else {
- if ($channelIds == "*") {
- $updateChannelIds = '';
- } else {
- $channelIds = explode(',', $channelIds);
- $updateChannelIdsArr = array_diff($hasChannelIds, $channelIds);
- $updateChannelIds = '';
- if ($updateChannelIdsArr) {
- $updateChannelIds = implode(',', $updateChannelIdsArr);
- }
- }
- }
- } else {
- $updateChannelIds = $channelIds;
- }
- model("ChannelMenuList")->update(['channel_id' => $updateChannelIds, 'updatetime' => time()], ['id' => $menuRow['id']]);
- } else {
- //新增
- $insertId = model("ChannelMenuList")->allowField(true)->insertGetId([
- 'channel_id' => $channelIds,
- 'updatetime' => time(),
- 'createtime' => time()]);
- $this->model->update(['channel_id' => $insertId, 'updatetime' => time()], ['id' => $row['id']]);
- }
- $row->removeCache($row['rule_name']);
- } else {
- //新增
- exit(json_encode(['code' => 201, 'msg' => '记录不存在']));
- }
- }
- exit(json_encode(['code' => 200]));
- }
- }
|