FeedBack.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\user;
  12. use crmeb\basic\BaseController;
  13. use think\App;
  14. use app\common\repositories\user\FeedbackRepository as repository;
  15. class FeedBack extends BaseController
  16. {
  17. /**
  18. * @var UserRepository
  19. */
  20. protected $repository;
  21. /**
  22. * User constructor.
  23. * @param App $app
  24. * @param $repository
  25. */
  26. public function __construct(App $app, repository $repository)
  27. {
  28. parent::__construct($app);
  29. $this->repository = $repository;
  30. }
  31. /**
  32. * @return mixed
  33. * @author Qinii
  34. */
  35. public function lst()
  36. {
  37. $where = $this->request->params(['keyword', 'type', 'status','realname',['is_del',0]]);
  38. [$page, $limit] = $this->getPage();
  39. return app('json')->success($this->repository->getList($where, $page, $limit));
  40. }
  41. /**
  42. * @param $id
  43. * @return mixed
  44. * @author Qinii
  45. */
  46. public function detail($id)
  47. {
  48. if (!$this->repository->fieldExists('feedback_id',$id))
  49. return app('json')->fail('数据不存在');
  50. $feedback = $this->repository->get($id)->toArray();
  51. [$feedback['category'], $feedback['type']] = explode('/', $feedback['type'], 2);
  52. return app('json')->success($feedback);
  53. }
  54. public function replyForm($id)
  55. {
  56. return app('json')->success(formToData($this->repository->replyForm($id)));
  57. }
  58. /**
  59. * @param $id
  60. * @return mixed
  61. * @throws \think\db\exception\DbException
  62. * @author Qinii
  63. */
  64. public function reply($id)
  65. {
  66. if (!$this->repository->fieldExists('feedback_id',$id))
  67. return app('json')->fail('数据不存在');
  68. $data = $this->request->params(['reply', 'remake']);
  69. if (!empty($data['reply'])) {
  70. $data['status'] = 1;
  71. $data['update_time'] = date('Y-m-d H:i:s');
  72. }
  73. $this->repository->update($id,$data);
  74. if (!empty($data['reply'])) event('user.feedbackReply',compact('id','data'));
  75. return app('json')->success('回复成功');
  76. }
  77. /**
  78. * @param $id
  79. * @return mixed
  80. * @author Qinii
  81. */
  82. public function delete($id)
  83. {
  84. if (!$this->repository->fieldExists('feedback_id',$id))
  85. return app('json')->fail('数据不存在');
  86. $this->repository->update($id,['is_del' => 1]);
  87. return app('json')->success('删除成功');
  88. }
  89. }