123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\data\controller\api;
- use app\data\model\DataUserAddress;
- use hg\apidoc\annotation\Title;
- use hg\apidoc\annotation\Method;
- use hg\apidoc\annotation\Param;
- use hg\apidoc\annotation\Returned;
- /**
- * 用户收货地址
- * Class User
- * @package app\data\controller\api
- */
- class User extends Auth
- {
- protected $noNeedLogin=[];
- /**
- * @Title("地址列表")
- */
- public function address_list(){
- $user= $this->getUser();
- $list = DataUserAddress::mk()->where('uuid',$user['id'])->where('deleted',1)->paginate();
- $this->success('我的地址列表',$list);
- }
- /**
- * @Title ("添加收货地址")
- * @Method("post")
- * @Param ("type",desc="默认 1")
- * @Param ("name",desc="收货名称")
- * @Param ("phone",desc="手机号")
- * @Param ("province",desc="省份 传文字")
- * @Param ("city",desc="城市")
- * @Param ("area",desc="区县")
- * @Param ("address",desc="详细的地址")
- * @return void
- */
- public function add_address(){
- $user = $this->getUser();
- $type = input('type',0);
- $name = input('name','');
- $phone = input('phone','');
- $province = input('province','');
- $city = input('city','');
- $area = input('area','');
- $address = input('address','');
- if(empty($name)||empty($phone)||empty($province)||empty($city)||empty($area)||empty($address)){
- $this->error('请完善邮寄地址信息!');
- }
- $data = [
- 'uuid'=>$user['id'],
- 'type'=>$type,
- 'name'=>$name,
- 'phone'=>$phone,
- 'province'=>$province,
- 'city'=>$city,
- 'area'=>$area,
- 'address'=>$address,
- 'deleted'=>1,
- 'create_at'=>date('Y-m-d H:i:s')
- ];
- if($type==1){
- DataUserAddress::mk()->where('type',1)->save(['type'=>0]);
- }
- DataUserAddress::mk()->insert($data);
- $this->success('邮寄地址已添加');
- }
- /**
- * @Title ("编辑收货地址")
- * @Method("post")
- * @Param ("type",desc="默认 1")
- * @Param ("name",desc="收货名称")
- * @Param ("phone",desc="手机号")
- * @Param ("province",desc="省份 传文字")
- * @Param ("city",desc="城市")
- * @Param ("area",desc="区县")
- * @Param ("address",desc="详细的地址")
- * @return void
- * 编辑用户地址
- */
- public function save_address(){
- $user = $this->getUser();
- $id = input('id');
- $type = input('type',0);
- $name = input('name','');
- $phone = input('phone','');
- $province = input('province','');
- $city = input('city','');
- $area = input('area','');
- $address = input('address','');
- if(empty($name)||empty($phone)||empty($province)||empty($city)||empty($area)||empty($address)){
- $this->error('请完善邮寄地址信息!');
- }
- $data = [
- 'type'=>$type,
- 'name'=>$name,
- 'phone'=>$phone,
- 'province'=>$province,
- 'city'=>$city,
- 'area'=>$area,
- 'address'=>$address,
- 'deleted'=>1,
- 'create_at'=>date('Y-m-d H:i:s')
- ];
- if($type==1){
- DataUserAddress::mk()->where('type',1)->save(['type'=>0]);
- }
- DataUserAddress::mk()->where('id',$id)->save($data);
- $this->success('邮寄地址已修改');
- }
- /**
- * @Title ("删除啊收货地址")
- * @Method("post")
- * @Param ("id",desc="地址的id")
- * @return void
- *
- */
- public function del_address(){
- $user = $this->getUser();
- $id = input('id');
- DataUserAddress::mk()->where('id',$id)->where('uuid',$user['id'])->save(['deleted'=>0]);
- $this->success('邮寄地址已删除');
- }
- }
|