1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\Mobile;
- use app\common\model\MobileUserHistory;
- /**
- * 号码浏览记录接口
- */
- class HistoryApi extends Api
- {
- protected $noNeedRight='*';
- /**
- * 浏览记录列表
- * @ApiParams (name=page,description=第几页)
- * @ApiParams (name=limit,description=每页数量)
- * @ApiReturnParams (name=no,description=手机号)
- * @ApiReturnParams (name=province,description=省份)
- * @ApiReturnParams (name=city,description=城市)
- * @ApiReturnParams (name=amount,description=价格)
- * @ApiReturnParams (name=network,description=网络类型)
- * @ApiReturnParams (name=mobile_id,description=手机号id)
- * @ApiReturnParams (name=mobile_user_history_id,description=记录id)
- */
- public function index(){
- $user=$this->auth->getUser();
- $list=$user->mobileHistory()
- ->order('mobile_user_history_id','desc')
- ->paginate(input('limit',20));
- $this->success('',$list);
- }
- /**
- * 删除
- * @ApiParams (name=id,description="传mobile_user_history_id")
- */
- public function delete(){
- $data=$this->_validate([
- 'id'=>['require'],
- ]);
- $user=$this->auth->getUser();
- $user->mobileHistory()->where('mobile_user_history_id',$data['id'])->delete();
- $this->success();
- }
- /**
- * 添加到足迹
- * @ApiParams (name=id,description="号码ID")
- */
- public function add(){
- $data=$this->_validate([
- 'id|号码'=>['require','integer','gt:0'],
- ]);
- $user=$this->auth->getUser();
- $mobile=Mobile::beauti()->find($data['id']);
- if(!$mobile){
- $this->error('号码不存在');
- }
- $history=$user->mobileHistory()->where('mobile_id',$mobile['id'])->find();
- if($history){
- $this->error('该号码已添加到我的足迹');
- }
- MobileUserHistory::add($user,$mobile);
- $this->success();
- }
- }
|