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' => 1]; $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'); if (!preg_match('/^(\*)?[-,0-9]*$/', $channelIds)) { exit(json_encode(['code' => 201, 'msg' => '渠道id输入有误,渠道id使用逗号分隔,第一个字符可以为*'])); } $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])); } }