Response.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\admin\controller\wechat;
  3. use app\common\controller\Backend;
  4. use addons\wechat\library\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. $params = $this->request->post("row/a");
  33. $params['eventkey'] = isset($params['eventkey']) && $params['eventkey'] ? $params['eventkey'] : uniqid();
  34. $params['content'] = json_encode($params['content']);
  35. $params['createtime'] = time();
  36. if ($params) {
  37. $this->model->save($params);
  38. $this->success();
  39. $this->content = $params;
  40. }
  41. $this->error();
  42. }
  43. $appConfig = Wechat::appConfig();
  44. $this->view->applist = $appConfig;
  45. return $this->view->fetch();
  46. }
  47. /**
  48. * 编辑
  49. */
  50. public function edit($ids = NULL)
  51. {
  52. $row = $this->model->get($ids);
  53. if (!$row)
  54. $this->error(__('No Results were found'));
  55. if ($this->request->isPost()) {
  56. $params = $this->request->post("row/a");
  57. $params['eventkey'] = isset($params['eventkey']) && $params['eventkey'] ? $params['eventkey'] : uniqid();
  58. $params['content'] = json_encode($params['content']);
  59. if ($params) {
  60. $row->save($params);
  61. $this->success();
  62. }
  63. $this->error();
  64. }
  65. $this->view->assign("row", $row);
  66. $appConfig = Wechat::appConfig();
  67. $this->view->applist = $appConfig;
  68. return $this->view->fetch();
  69. }
  70. }