123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <?php
- namespace app\admin\controller\booklistch;
- use app\admin\service\ExclusiveService;
- use app\common\controller\Backend;
- use think\Collection;
- use think\Controller;
- use think\Request;
- use app\main\constants\AdminConstants;
- /**
- * 书单素材库
- *
- * @icon fa fa-circle-o
- */
- class Media extends Backend
- {
-
- /**
- * BookListMedia模型对象
- */
- protected $model = null;
- protected $vipAdminBindModel = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->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();
- }
- }
|