| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Db;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- use Exception;
- /**
- * 外发发件邮箱配置(仅维护编辑,不增删)
- *
- * @icon fa fa-envelope
- */
- class Purchaseemail extends Backend
- {
- /** @var \app\admin\model\Purchaseemail */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->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();
- }
- }
|