UserHistory.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\controller\api\user;
  3. use ln\basic\BaseController;
  4. use app\common\repositories\user\UserHistoryRepository as repository;
  5. use think\App;
  6. class UserHistory extends BaseController
  7. {
  8. /**
  9. * @var repository
  10. */
  11. protected $repository;
  12. /**
  13. * UserHistory constructor.
  14. * @param App $app
  15. * @param repository $repository
  16. */
  17. public function __construct(App $app, repository $repository)
  18. {
  19. parent::__construct($app);
  20. $this->repository = $repository;
  21. }
  22. public function lst()
  23. {
  24. [$page, $limit] = $this->getPage();
  25. $type = $this->request->param('type',1);
  26. $uid = $this->request->uid();
  27. $data = $this->repository->getApiList($page,$limit,$uid,$type);
  28. return app('json')->success($data);
  29. }
  30. /**
  31. * @return mixed
  32. * @author Qinii
  33. */
  34. public function deleteHistory($id)
  35. {
  36. if(!$this->repository->getSearch(['uid' => $this->request->uid(),'history_id' => $id]))
  37. return app('json')->fail('信息不存在');
  38. $this->repository->delete($id);
  39. return app('json')->success('浏览记录已删除');
  40. }
  41. /**
  42. * @return mixed
  43. * @author Qinii
  44. */
  45. public function deleteHistoryBatch()
  46. {
  47. $params = $this->request->param('history_id');
  48. if(!$params) return app('json')->fail('参数不能为空');
  49. $this->repository->deleteBatch($this->request->uid(),$params);
  50. return app('json')->success('浏览记录已删除');
  51. }
  52. }