HistoryApi.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Mobile;
  5. use app\common\model\MobileUserHistory;
  6. /**
  7. * 号码浏览记录接口
  8. */
  9. class HistoryApi extends Api
  10. {
  11. protected $noNeedRight='*';
  12. /**
  13. * 浏览记录列表
  14. * @ApiParams (name=page,description=第几页)
  15. * @ApiParams (name=limit,description=每页数量)
  16. * @ApiReturnParams (name=no,description=手机号)
  17. * @ApiReturnParams (name=province,description=省份)
  18. * @ApiReturnParams (name=city,description=城市)
  19. * @ApiReturnParams (name=amount,description=价格)
  20. * @ApiReturnParams (name=network,description=网络类型)
  21. * @ApiReturnParams (name=mobile_id,description=手机号id)
  22. * @ApiReturnParams (name=mobile_user_history_id,description=记录id)
  23. */
  24. public function index(){
  25. $user=$this->auth->getUser();
  26. $list=$user->mobileHistory()
  27. ->order('mobile_user_history_id','desc')
  28. ->paginate(input('limit',20));
  29. $this->success('',$list);
  30. }
  31. /**
  32. * 删除
  33. * @ApiParams (name=id,description="传mobile_user_history_id")
  34. */
  35. public function delete(){
  36. $data=$this->_validate([
  37. 'id'=>['require'],
  38. ]);
  39. $user=$this->auth->getUser();
  40. $user->mobileHistory()->where('mobile_user_history_id',$data['id'])->delete();
  41. $this->success();
  42. }
  43. /**
  44. * 添加到足迹
  45. * @ApiParams (name=id,description="号码ID")
  46. */
  47. public function add(){
  48. $data=$this->_validate([
  49. 'id|号码'=>['require','integer','gt:0'],
  50. ]);
  51. $user=$this->auth->getUser();
  52. $mobile=Mobile::beauti()->find($data['id']);
  53. if(!$mobile){
  54. $this->error('号码不存在');
  55. }
  56. $history=$user->mobileHistory()->where('mobile_id',$mobile['id'])->find();
  57. if($history){
  58. $this->error('该号码已添加到我的足迹');
  59. }
  60. MobileUserHistory::add($user,$mobile);
  61. $this->success();
  62. }
  63. }