Kefu.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\controller\adminapi\kefu;
  3. use app\extra\basic\Base;
  4. use app\extra\service\service\KefuService;
  5. use app\middleware\AuthMiddleware;
  6. use app\validate\adminapi\kefu\KefuValidate;
  7. use DI\Attribute\Inject;
  8. use LinFly\Annotation\Route\Controller;
  9. use LinFly\Annotation\Route\Middleware;
  10. use LinFly\Annotation\Route\Route;
  11. use support\Request;
  12. use support\Response;
  13. #[Controller(prefix: "/adminapi/kefu/"),Middleware(AuthMiddleware::class)]
  14. class Kefu extends Base
  15. {
  16. #[Inject]
  17. protected KefuService $service;
  18. #[Inject]
  19. protected KefuValidate $validate;
  20. #[Route(path: "list",methods: "get")]
  21. public function getList(Request $request): Response
  22. {
  23. try {
  24. $param = $request->get();
  25. $list = $this->service->getList($param,'*',$param['page']??0,$param['limit']??0);
  26. return successTrans("success.data",$list);
  27. } catch (\Throwable $throwable) {
  28. return error($throwable->getMessage());
  29. }
  30. }
  31. #[Route(path: "save",methods: "post")]
  32. public function save(Request $request): Response
  33. {
  34. try {
  35. $param = $request->post();
  36. if (!$this->validate->check($param)) return error($this->validate->getError());
  37. $param = $this->validate->checked($param);
  38. $state = $this->service->save($param);
  39. if ($state->isEmpty()) return errorTrans("empty.error");
  40. return successTrans("success.data");
  41. } catch (\Throwable $throwable) {
  42. return error($throwable->getMessage());
  43. }
  44. }
  45. #[Route(path: "set_status/{id}/{status}",methods: "get")]
  46. public function set_status($id,$status): Response
  47. {
  48. try {
  49. $state = $this->service->update($id,['status'=>$status]);
  50. if (!$state) return errorTrans("empty.error");
  51. return successTrans($status?'显示成功':'关闭成功');
  52. } catch (\Throwable $throwable) {
  53. return error($throwable->getMessage());
  54. }
  55. }
  56. #[Route(path: "del/{id}",methods: "delete")]
  57. public function delete($id): Response
  58. {
  59. try {
  60. $state = $this->service->update($id,['is_del'=>1]);
  61. if (!$state) return errorTrans("empty.error");
  62. return successTrans('删除成功');
  63. } catch (\Throwable $throwable) {
  64. return error($throwable->getMessage());
  65. }
  66. }
  67. }