model = new \app\admin\model\Purchasesmstemplate; $this->view->assign('sceneList', $this->model->getSceneList()); $this->view->assign('statusList', $this->model->getStatusList()); } public function index() { $this->relationSearch = false; $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->where($where) ->order($sort, $order) ->paginate($limit); return json(['total' => $list->total(), 'rows' => $list->items()]); } return $this->view->fetch(); } public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } if (false === $this->request->isPost()) { $sceneList = $this->model->getSceneList(); $sc = (string)($row['scene'] ?? ''); $this->view->assign('row', $row); $this->view->assign('sceneText', $sceneList[$sc] ?? $sc); $this->view->assign('isEmailScene', \app\admin\model\Purchasesmstemplate::isEmailScene($sc)); $this->view->assign('smsVarGuide', \app\admin\model\Purchasesmstemplate::getVariableGuideForScene($sc)); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $content = trim((string)($params['content'] ?? '')); if ($content === '') { $this->error('请填写模版正文'); } $params['content'] = $content; $params['title'] = trim((string)($params['title'] ?? '')); $params['remark'] = trim((string)($params['remark'] ?? '')); if (!isset($params['status']) || $params['status'] === '') { $params['status'] = '1'; } if ($params['status'] === 'normal') { $params['status'] = '1'; } if ($params['status'] === 'hidden') { $params['status'] = '0'; } $params['updatetime'] = date('Y-m-d H:i:s'); try { $row->allowField(true)->save($params); } catch (ValidateException|PDOException|Exception $e) { $this->error($e->getMessage()); } $this->success(); } }