|
@@ -0,0 +1,80 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\UserApi;
|
|
|
+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=longitude,description=经度)
|
|
|
+ * @ApiReturnParams (name=latitude,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=longitude,description="经度")
|
|
|
+ * @ApiParams (name=latitude,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',
|
|
|
+ 'longitude'=>'require|float',
|
|
|
+ 'latitude'=>'require|float',
|
|
|
+ 'is_default'=>'require|in:0,1',
|
|
|
+ ]);
|
|
|
+ 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)
|
|
|
+ */
|
|
|
+ public function delete(){
|
|
|
+ $user=$this->auth->getUser();
|
|
|
+ $data=input();
|
|
|
+ $this->validate($data,[
|
|
|
+ 'id'=>'require',
|
|
|
+ ]);
|
|
|
+ $user->address()->delete($data['id']);
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+}
|