FeedBack.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\controller\admin\user;
  3. use ln\basic\BaseController;
  4. use think\App;
  5. use app\common\repositories\user\FeedbackRepository as repository;
  6. class FeedBack extends BaseController
  7. {
  8. /**
  9. * @var UserRepository
  10. */
  11. protected $repository;
  12. /**
  13. * User constructor.
  14. * @param App $app
  15. * @param $repository
  16. */
  17. public function __construct(App $app, repository $repository)
  18. {
  19. parent::__construct($app);
  20. $this->repository = $repository;
  21. }
  22. /**
  23. * @return mixed
  24. * @author Qinii
  25. */
  26. public function lst()
  27. {
  28. $where = $this->request->params(['keyword', 'type', 'status','realname',['is_del',0]]);
  29. [$page, $limit] = $this->getPage();
  30. return app('json')->success($this->repository->getList($where, $page, $limit));
  31. }
  32. /**
  33. * @param $id
  34. * @return mixed
  35. * @author Qinii
  36. */
  37. public function detail($id)
  38. {
  39. if (!$this->repository->fieldExists('feedback_id',$id))
  40. return app('json')->fail('数据不存在');
  41. $feedback = $this->repository->get($id)->toArray();
  42. [$feedback['category'], $feedback['type']] = explode('/', $feedback['type'], 2);
  43. return app('json')->success($feedback);
  44. }
  45. /**
  46. * @param $id
  47. * @return mixed
  48. * @throws \think\db\exception\DbException
  49. * @author Qinii
  50. */
  51. public function reply($id)
  52. {
  53. if (!$this->repository->fieldExists('feedback_id',$id))
  54. return app('json')->fail('数据不存在');
  55. $data = $this->request->params(['reply', 'remake', ['status',0]]);
  56. $this->repository->update($id,$data);
  57. return app('json')->success('回复成功');
  58. }
  59. /**
  60. * @param $id
  61. * @return mixed
  62. * @author Qinii
  63. */
  64. public function delete($id)
  65. {
  66. if (!$this->repository->fieldExists('feedback_id',$id))
  67. return app('json')->fail('数据不存在');
  68. $this->repository->update($id,['is_del' => 1]);
  69. return app('json')->success('删除成功');
  70. }
  71. public function switchStatus($id)
  72. {
  73. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  74. if (!$this->repository->merExists($id))
  75. return app('json')->fail('数据不存在');
  76. $this->repository->update($id,['status' => $status]);
  77. return app('json')->success('修改成功');
  78. }
  79. }