| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?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-commenting-o
- */
- class Procuremensms extends Backend
- {
- /**
- * @var \app\admin\model\Purchasesmstemplate
- */
- protected $model = null;
- protected $searchFields = 'title,content,remark';
- public function _initialize()
- {
- parent::_initialize();
- $this->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();
- }
- }
|