Response.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\admin\controller\wechat;
  3. use app\admin\model\AdminLog;
  4. use app\common\controller\Backend;
  5. use fast\service\Wechat;
  6. /**
  7. * 资源管理
  8. *
  9. * @icon fa fa-list-alt
  10. */
  11. class Response extends Backend
  12. {
  13. protected $model = null;
  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'] = $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. AdminLog::record(__('Add'), $this->model->getLastInsID());
  42. $this->code = 1;
  43. $this->content = $params;
  44. }
  45. return;
  46. }
  47. $appConfig = Wechat::appConfig();
  48. $this->view->applist = $appConfig;
  49. return $this->view->fetch();
  50. }
  51. /**
  52. * 编辑
  53. */
  54. public function edit($ids = NULL)
  55. {
  56. $row = $this->model->get($ids);
  57. if (!$row)
  58. $this->error(__('No Results were found'));
  59. if ($this->request->isPost())
  60. {
  61. $this->code = -1;
  62. $params = $this->request->post("row/a");
  63. $params['eventkey'] = $params['eventkey'] ? $params['eventkey'] : uniqid();
  64. $params['content'] = json_encode($params['content']);
  65. if ($params)
  66. {
  67. $row->save($params);
  68. AdminLog::record(__('Edit'), $ids);
  69. $this->code = 1;
  70. }
  71. return;
  72. }
  73. $this->view->assign("row", $row);
  74. $appConfig = Wechat::appConfig();
  75. $this->view->applist = $appConfig;
  76. return $this->view->fetch();
  77. }
  78. }