Response.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\admin\controller\wechat;
  3. use app\common\controller\Backend;
  4. use fast\service\Wechat;
  5. /**
  6. * 资源管理
  7. *
  8. * @icon fa fa-list-alt
  9. */
  10. class Response extends Backend
  11. {
  12. protected $model = null;
  13. protected $searchFields = 'id,title';
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. $this->model = model('WechatResponse');
  18. }
  19. /**
  20. * 选择素材
  21. */
  22. public function select()
  23. {
  24. return $this->view->fetch();
  25. }
  26. /**
  27. * 添加
  28. */
  29. public function add()
  30. {
  31. if ($this->request->isPost())
  32. {
  33. $this->code = -1;
  34. $params = $this->request->post("row/a");
  35. $params['eventkey'] = isset($params['eventkey']) && $params['eventkey'] ? $params['eventkey'] : uniqid();
  36. $params['content'] = json_encode($params['content']);
  37. $params['createtime'] = time();
  38. if ($params)
  39. {
  40. $this->model->save($params);
  41. $this->code = 1;
  42. $this->content = $params;
  43. }
  44. return;
  45. }
  46. $appConfig = Wechat::appConfig();
  47. $this->view->applist = $appConfig;
  48. return $this->view->fetch();
  49. }
  50. /**
  51. * 编辑
  52. */
  53. public function edit($ids = NULL)
  54. {
  55. $row = $this->model->get($ids);
  56. if (!$row)
  57. $this->error(__('No Results were found'));
  58. if ($this->request->isPost())
  59. {
  60. $this->code = -1;
  61. $params = $this->request->post("row/a");
  62. $params['eventkey'] = isset($params['eventkey']) && $params['eventkey'] ? $params['eventkey'] : uniqid();
  63. $params['content'] = json_encode($params['content']);
  64. if ($params)
  65. {
  66. $row->save($params);
  67. $this->code = 1;
  68. }
  69. return;
  70. }
  71. $this->view->assign("row", $row);
  72. $appConfig = Wechat::appConfig();
  73. $this->view->applist = $appConfig;
  74. return $this->view->fetch();
  75. }
  76. }