NoticeTemplate.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\admin\controller\qingdong\general;
  3. use app\common\controller\Backend;
  4. use addons\qingdong\model\Field;
  5. use think\Db;
  6. use think\Exception;
  7. /**
  8. * 通知模板
  9. */
  10. class NoticeTemplate extends Backend {
  11. protected $relationSearch = true;
  12. /**
  13. * @var \addons\qingdong\model\NoticeTemplate
  14. */
  15. protected $model = null;
  16. public function _initialize() {
  17. parent::_initialize();
  18. $this->model =new \addons\qingdong\model\NoticeTemplate;
  19. }
  20. /**
  21. * 查看
  22. */
  23. public function index() {
  24. //设置过滤方法
  25. $this->request->filter(['strip_tags', 'trim']);
  26. if ($this->request->isAjax()) {
  27. $list = $this->model->where([])->paginate();
  28. $result = array("total" => $list->total(), "rows" => $list->items());
  29. return json($result);
  30. }
  31. return $this->view->fetch();
  32. }
  33. /**
  34. * 修改通知模板
  35. */
  36. public function edit($id = null) {
  37. if ($this->request->isPost()) {
  38. $data = input('row/a');
  39. if (empty($id) || empty($data)) {
  40. $this->error('参数错误');
  41. }
  42. Db::startTrans();
  43. try {
  44. $newdata = [
  45. 'template_id'=>$data['template_id'],
  46. 'first'=>$data['first'],
  47. 'remark'=>$data['remark'],
  48. 'remark_color'=>$data['remark_color'],
  49. ];
  50. foreach($data as $k=>$v){
  51. if($k=='keyword1_key' && $data['keyword1_key'] && $data['keyword1']){
  52. $newdata[$data['keyword1_key']] =$data['keyword1'];
  53. }
  54. if($k=='keyword2_key' && $data['keyword2_key'] && $data['keyword2']){
  55. $newdata[$data['keyword2_key']] =$data['keyword2'];
  56. }
  57. if($k=='keyword3_key' && $data['keyword3_key'] && $data['keyword3']){
  58. $newdata[$data['keyword3_key']] =$data['keyword3'];
  59. }
  60. if($k=='keyword4_key' && $data['keyword4_key'] && $data['keyword4']){
  61. $newdata[$data['keyword4_key']] =$data['keyword4'];
  62. }
  63. if($k=='keyword5_key' && $data['keyword5_key'] && $data['keyword5']){
  64. $newdata[$data['keyword5_key']] =$data['keyword5'];
  65. }
  66. }
  67. $this->model->save(['data' => json_encode($newdata,JSON_UNESCAPED_UNICODE)], ['id' => $id]);
  68. Db::commit();
  69. } catch (Exception $e) {
  70. Db::rollback();
  71. $this->error($e->getMessage());
  72. }
  73. $this->success('设置成功');
  74. }
  75. $row=$this->model->get($id);
  76. if(empty($row)){
  77. $this->error('数据不存在');
  78. }
  79. $this->view->assign('variable',$this->model->getVariable($row['type']));
  80. $this->view->assign('row',$row);
  81. return $this->view->fetch();
  82. }
  83. /**
  84. * 修改通知模板
  85. */
  86. public function edit_enterprise($id = null) {
  87. if ($this->request->isPost()) {
  88. $data = input('row/a');
  89. if (empty($id) || empty($data)) {
  90. $this->error('参数错误');
  91. }
  92. Db::startTrans();
  93. try {
  94. $this->model->save(['enterprise_data' => json_encode($data,JSON_UNESCAPED_UNICODE)], ['id' => $id]);
  95. Db::commit();
  96. } catch (Exception $e) {
  97. Db::rollback();
  98. $this->error($e->getMessage());
  99. }
  100. $this->success('设置成功');
  101. }
  102. $row=$this->model->get($id);
  103. if(empty($row)){
  104. $this->error('数据不存在');
  105. }
  106. $this->view->assign('variable',$this->model->getVariable($row['type']));
  107. $this->view->assign('row',$row);
  108. return $this->view->fetch();
  109. }
  110. }