model = model('ManageBlockResource'); $typeList = $this->model->getTypeList(); $block = model('ManageBlock')->where('id', $this->request->get('block_id'))->find(); if ($block['type'] != '1') { unset($typeList[3]); } $this->view->assign("typeList", $typeList); $this->view->assign("specialList", SpecialService::instance()->getSpecialList()->data); $page_id = model('ManageBlock')->where('id','in',$this->request->get('block_id'))->find(); $blockList = collection(model('ManageBlock')->where('page_id', 'in', $page_id['page_id'])->select())->toArray(); foreach ($blockList as $k => $v) { $this->blockData[$v['id']] = $v['name']; } $this->view->assign('block_id', $this->request->get('block_id')); $this->assignconfig('block_id', $this->request->get('block_id')); $this->assignconfig('page_id', $this->request->get('page_id')); $this->view->assign('blockData', $this->blockData); } /** * 查看 */ public function index() { if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(NULL); $total = $this->model ->where($where) ->with('Book') ->order($sort, $order) ->count(); $list = $this->model ->where($where) ->with('Book') ->order($sort, $order) ->limit($offset, $limit) ->select(); $result = array("total" => $total, "rows" => $list, "extend" => ['id' => 1]); return json($result); } return $this->view->fetch(); } /* * 新增块资源 */ public function add() { if($this->request->isPost()){ $row = $this->request->post('row/a'); if($row){ try{ //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate; $this->model->validate($validate); } $this->model->startTrans(); //保存资源信息 if($this->model->allowField(true)->save($row) == false){ throw new Exception($this->model->getError()); } $row['free_stime'] = 0; $row['free_etime'] = 0; $this->model->commit(); $this->success(); }catch (Exception $e){ $this->model->rollback(); $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $this->view->assign('page_id', $this->request->get('page_id')); return $this->view->fetch(); } /** * 编辑 */ public function edit($ids = NULL) { $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) { 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); } $row->startTrans(); $result = $row->allowField(true)->save($params); if($result === false){ throw new Exception($row->getError()); } $params['free_stime'] = 0; $params['free_etime'] = 0; $row->commit(); $this->success(); }catch (Exception $e){ $row->rollback(); $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } $this->view->assign("row", $row); return $this->view->fetch(); } }