UserHistory.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\api\user;
  12. use crmeb\basic\BaseController;
  13. use app\common\repositories\user\UserHistoryRepository as repository;
  14. use think\App;
  15. class UserHistory extends BaseController
  16. {
  17. /**
  18. * @var repository
  19. */
  20. protected $repository;
  21. /**
  22. * UserHistory constructor.
  23. * @param App $app
  24. * @param repository $repository
  25. */
  26. public function __construct(App $app, repository $repository)
  27. {
  28. parent::__construct($app);
  29. $this->repository = $repository;
  30. }
  31. /**
  32. * 用户浏览记录
  33. * @return \think\response\Json
  34. * @author wuhaotian
  35. * @email 442384644@qq.com
  36. * @date 2024/7/10
  37. */
  38. public function lst()
  39. {
  40. [$page, $limit] = $this->getPage();
  41. $type = $this->request->param('type',1);
  42. $uid = $this->request->uid();
  43. $data = $this->repository->getApiList($page,$limit,$uid,$type);
  44. return app('json')->success($data);
  45. }
  46. /**
  47. * 删除浏览记录
  48. * @return mixed
  49. * @author Qinii
  50. */
  51. public function deleteHistory($id)
  52. {
  53. if(!$this->repository->getSearch(['uid' => $this->request->uid(),'history_id' => $id]))
  54. return app('json')->fail('信息不存在');
  55. $this->repository->delete($id);
  56. return app('json')->success('浏览记录已删除');
  57. }
  58. /**
  59. * 批量删除浏览记录
  60. * @return mixed
  61. * @author Qinii
  62. */
  63. public function deleteHistoryBatch()
  64. {
  65. $params = $this->request->param('history_id');
  66. if(!$params) return app('json')->fail('参数不能为空');
  67. $this->repository->deleteBatch($this->request->uid(),$params);
  68. return app('json')->success('浏览记录已删除');
  69. }
  70. }