123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\api\controller;
- use app\common\controller\UserApi;
- use app\common\model\Area;
- use app\common\model\UserAddress;
- /**
- * 用户端地址模块
- */
- class UserAddressController extends UserApi
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = '*';
- /**
- * 列表
- * @ApiReturnParams (name=id,description=id)
- * @ApiReturnParams (name=name,description=姓名)
- * @ApiReturnParams (name=mobile,description=手机号码)
- * @ApiReturnParams (name=address,description=详细地址)
- * @ApiReturnParams (name=city,description=所在城市)
- * @ApiReturnParams (name=city_detail,description=所在城市名)
- * @ApiReturnParams (name=longitude,description=经度)
- * @ApiReturnParams (name=latitude,description=纬度)
- * @ApiReturnParams (name=location,description=所在地区)
- */
- public function list(){
- $list=$this->auth
- ->getUser()
- ->address()
- ->order('id','desc')
- ->select();
- $this->success('',$list);
- }
- /**
- * 新增或修改地址
- * @ApiParams (name=id,description="id,修改的时候必须")
- * @ApiParams (name=name,description="姓名")
- * @ApiParams (name=mobile,description="手机号")
- * @ApiParams (name=city,description="区县名字")
- * @ApiParams (name=address,description="详细地址")
- * @ApiParams (name=is_default,description="1和0,是否默认")
- */
- public function edit(){
- $user=$this->auth->getUser();
- $data=input();
- $this->validate($data,[
- 'name'=>'require|max:5',
- 'mobile'=>'require|number',
- 'city'=>'require',
- 'address'=>'require',
- //'location'=>'require',
- //'longitude'=>'require|float',
- //'latitude'=>'require|float',
- 'is_default'=>'require|in:0,1',
- ]);
- $city=Area::area()->where('name|shortname',$data['city'])->find();
- if(!$city){
- $this->error('区县不存在');
- }
- if(!empty($data['id'])){
- $address=$user->address()->findOrFail($data['id']);
- $address->save($data);
- }else{
- $user->address()->save($data);
- }
- $this->success();
- }
- /**
- * 地址详情
- * @ApiParams (name=id,description=id)
- * @ApiReturnParams (name=name,description=姓名)
- * @ApiReturnParams (name=mobile,description=手机号码)
- * @ApiReturnParams (name=address,description=详细地址)
- * @ApiReturnParams (name=city,description=所在城市)
- * @ApiReturnParams (name=city_detail,description=所在城市名)
- * @ApiReturnParams (name=longitude,description=经度)
- * @ApiReturnParams (name=latitude,description=纬度)
- * @ApiReturnParams (name=location,description=所在地区)
- *
- */
- public function detail(){
- $user=$this->auth->getUser();
- $data=input();
- $this->validate($data,[
- 'id'=>'require',
- ]);
- $addr=$user->address()->findOrFail($data['id']);
- $this->success('',$addr);
- }
- /**
- * 删除地址
- * @ApiParams (name=id,description=id)
- */
- public function delete(){
- $user=$this->auth->getUser();
- $data=input();
- $this->validate($data,[
- 'id'=>'require',
- ]);
- $user->address()->delete($data['id']);
- $this->success();
- }
- }
|