model = model('BookListMediaCh'); $this->vipAdminBindModel = model('VipAdminBind'); $this->view->assign("statusList", $this->model->getStatusList()); } /** * 查看 */ 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(); $maps = []; $maps['admin_id'] = $this->auth->id; //判断角色 if (in_array($this->group, [7, 8])) { //vip 或 vip运营只显示自己 $maps['admin_id'] = $this->auth->id; } else { //找账号绑定信息 $bindModel = $this->vipAdminBindModel ->where('admin_id_slave', 'eq', $this->auth->id) ->select(); if ($bindModel) { $vipAdminIds = array_column($bindModel, 'admin_id_master'); $vipAdminIds[] = $this->auth->id; $maps['admin_id'] = ['in', $vipAdminIds]; } } $total = $this->model ->where($where) ->where($maps) ->order($sort, $order) ->count(); $list = $this->model ->where($where) ->where($maps) ->order($sort, $order) ->limit($offset, $limit) ->select(); foreach ($list as &$row) { $row['self'] = $row['admin_id'] == $this->auth->id ? 1: 0; } $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 素材选择列表 */ public function select() { if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } $maps = []; $maps['status'] = ['EQ', 'normal']; $maps['admin_id'] = $this->auth->id; list($where, $sort, $order, $offset, $limit) = $this->buildparams(); //判断角色 if (in_array($this->group, [7, 8])) { //vip 或 vip运营只显示自己 $maps['admin_id'] = $this->auth->id; } else { //找账号绑定信息 $bindModel = $this->vipAdminBindModel ->where('admin_id_slave', 'eq', $this->auth->id) ->select(); if ($bindModel) { $vipAdminIds = array_column($bindModel, 'admin_id_master'); $vipAdminIds[] = $this->auth->id; $maps['admin_id'] = ['in', $vipAdminIds]; } } $total = $this->model ->where($where) ->where($maps) ->order($sort, $order) ->count(); $list = $this->model ->where($where) ->where($maps) ->order($sort, $order) ->limit($offset, $limit) ->select(); if ($list) { foreach ($list as &$row) { $row['self'] = $row['admin_id'] == $this->auth->id ? 1: 0; } } $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 添加 */ public function add() { $from = $this->request->get('from_window', 'list'); if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $params['admin_id'] = $this->auth->id; /* * 已经弃用,如果为了兼容老版可取消注释 foreach ($params as $k => &$v) { $v = is_array($v) ? implode(',', $v) : $v; } */ if ($this->dataLimit) { $params[$this->dataLimitField] = $this->auth->id; } 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)->save($params); if ($result !== false) { $res = $this->model->getData(); $res['self'] = 1; $this->success('', null, $res); } else { $this->error($this->model->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $this->assignconfig('from_window', $from); return $this->view->fetch(); } /** * 编辑 */ public function edit($ids = NULL) { $from = $this->request->get('from_window', 'list'); $row = $this->model->get($ids); if (!$row) $this->error(__('No Results were found')); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { if ($row['admin_id'] != $this->auth->id) { $this->error(__('您没有权限进行修改')); } /* * 已经弃用,如果为了兼容老版可取消注释 foreach ($params as $k => &$v) { $v = is_array($v) ? implode(',', $v) : $v; } */ try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate; $row->validate($validate); } $result = $row->allowField(true)->save($params); if ($result !== false) { $res = $row->getData(); $res['self'] = 1; $this->success('', null, $res); } else { $this->error($row->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $this->view->assign("row", $row); //获取独家书籍id $bnotin= []; ExclusiveService::instance()->getExclusiveNotidsWithoutWhere($this->group, $this->auth->id,$bnotin); $this->assignconfig('bnotin', $bnotin); $this->assignconfig('from_window', $from); return $this->view->fetch(); } }