model = new \app\admin\model\Purchaseemail; } public function index() { $this->relationSearch = false; $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->where($where) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { $row->visible(['id', 'email_addr', 'email_pass', 'createtime', 'updatetime']); } return json(['total' => $list->total(), 'rows' => $list->items()]); } return $this->view->fetch(); } /** 发件配置固定一条,不提供新增 */ public function add() { $this->error('请使用「编辑」修改发件邮箱配置'); } /** 不提供删除 */ public function del($ids = null) { $this->error('发件邮箱配置不可删除,请使用编辑修改'); } public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); 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); $addr = trim((string)($params['email_addr'] ?? '')); if ($addr === '' || !filter_var($addr, FILTER_VALIDATE_EMAIL)) { $this->error('请填写有效的发件邮箱'); } $pass = trim((string)($params['email_pass'] ?? '')); if ($pass === '') { $this->error('请填写邮箱授权码'); } $save = [ 'email_addr' => $addr, 'email_pass' => $pass, ]; try { $row->save($save); } catch (ValidateException|PDOException|Exception $e) { $this->error($e->getMessage()); } $this->success(); } }