Procuremensms.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\PDOException;
  6. use think\exception\ValidateException;
  7. use Exception;
  8. /**
  9. * 外发采购 — 短信模版维护
  10. *
  11. * @icon fa fa-commenting-o
  12. */
  13. class Procuremensms extends Backend
  14. {
  15. /**
  16. * @var \app\admin\model\Purchasesmstemplate
  17. */
  18. protected $model = null;
  19. protected $searchFields = 'title,content,remark';
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\Purchasesmstemplate;
  24. $this->view->assign('sceneList', $this->model->getSceneList());
  25. $this->view->assign('statusList', $this->model->getStatusList());
  26. }
  27. public function index()
  28. {
  29. $this->relationSearch = false;
  30. $this->request->filter(['strip_tags', 'trim']);
  31. if ($this->request->isAjax()) {
  32. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  33. $list = $this->model
  34. ->where($where)
  35. ->order($sort, $order)
  36. ->paginate($limit);
  37. return json(['total' => $list->total(), 'rows' => $list->items()]);
  38. }
  39. return $this->view->fetch();
  40. }
  41. public function edit($ids = null)
  42. {
  43. $row = $this->model->get($ids);
  44. if (!$row) {
  45. $this->error(__('No Results were found'));
  46. }
  47. if (false === $this->request->isPost()) {
  48. $sceneList = $this->model->getSceneList();
  49. $sc = (string)($row['scene'] ?? '');
  50. $this->view->assign('row', $row);
  51. $this->view->assign('sceneText', $sceneList[$sc] ?? $sc);
  52. $this->view->assign('isEmailScene', \app\admin\model\Purchasesmstemplate::isEmailScene($sc));
  53. $this->view->assign('smsVarGuide', \app\admin\model\Purchasesmstemplate::getVariableGuideForScene($sc));
  54. return $this->view->fetch();
  55. }
  56. $params = $this->request->post('row/a');
  57. if (empty($params)) {
  58. $this->error(__('Parameter %s can not be empty', ''));
  59. }
  60. $params = $this->preExcludeFields($params);
  61. $content = trim((string)($params['content'] ?? ''));
  62. if ($content === '') {
  63. $this->error('请填写模版正文');
  64. }
  65. $params['content'] = $content;
  66. $params['title'] = trim((string)($params['title'] ?? ''));
  67. $params['remark'] = trim((string)($params['remark'] ?? ''));
  68. if (!isset($params['status']) || $params['status'] === '') {
  69. $params['status'] = '1';
  70. }
  71. if ($params['status'] === 'normal') {
  72. $params['status'] = '1';
  73. }
  74. if ($params['status'] === 'hidden') {
  75. $params['status'] = '0';
  76. }
  77. $params['updatetime'] = date('Y-m-d H:i:s');
  78. try {
  79. $row->allowField(true)->save($params);
  80. } catch (ValidateException|PDOException|Exception $e) {
  81. $this->error($e->getMessage());
  82. }
  83. $this->success();
  84. }
  85. }