User.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\data\controller\api;
  3. use app\data\model\DataUserAddress;
  4. use hg\apidoc\annotation\Title;
  5. use hg\apidoc\annotation\Method;
  6. use hg\apidoc\annotation\Param;
  7. use hg\apidoc\annotation\Returned;
  8. /**
  9. * 用户收货地址
  10. * Class User
  11. * @package app\data\controller\api
  12. */
  13. class User extends Auth
  14. {
  15. protected $noNeedLogin=[];
  16. /**
  17. * @Title("地址列表")
  18. */
  19. public function address_list(){
  20. $user= $this->getUser();
  21. $list = DataUserAddress::mk()->where('uuid',$user['id'])->where('deleted',1)->paginate();
  22. $this->success('我的地址列表',$list);
  23. }
  24. /**
  25. * @Title ("添加收货地址")
  26. * @Method("post")
  27. * @Param ("type",desc="默认 1")
  28. * @Param ("name",desc="收货名称")
  29. * @Param ("phone",desc="手机号")
  30. * @Param ("province",desc="省份 传文字")
  31. * @Param ("city",desc="城市")
  32. * @Param ("area",desc="区县")
  33. * @Param ("address",desc="详细的地址")
  34. * @return void
  35. */
  36. public function add_address(){
  37. $user = $this->getUser();
  38. $type = input('type',0);
  39. $name = input('name','');
  40. $phone = input('phone','');
  41. $province = input('province','');
  42. $city = input('city','');
  43. $area = input('area','');
  44. $address = input('address','');
  45. if(empty($name)||empty($phone)||empty($province)||empty($city)||empty($area)||empty($address)){
  46. $this->error('请完善邮寄地址信息!');
  47. }
  48. $data = [
  49. 'uuid'=>$user['id'],
  50. 'type'=>$type,
  51. 'name'=>$name,
  52. 'phone'=>$phone,
  53. 'province'=>$province,
  54. 'city'=>$city,
  55. 'area'=>$area,
  56. 'address'=>$address,
  57. 'deleted'=>1,
  58. 'create_at'=>date('Y-m-d H:i:s')
  59. ];
  60. if($type==1){
  61. DataUserAddress::mk()->where('type',1)->save(['type'=>0]);
  62. }
  63. DataUserAddress::mk()->insert($data);
  64. $this->success('邮寄地址已添加');
  65. }
  66. /**
  67. * @Title ("编辑收货地址")
  68. * @Method("post")
  69. * @Param ("type",desc="默认 1")
  70. * @Param ("name",desc="收货名称")
  71. * @Param ("phone",desc="手机号")
  72. * @Param ("province",desc="省份 传文字")
  73. * @Param ("city",desc="城市")
  74. * @Param ("area",desc="区县")
  75. * @Param ("address",desc="详细的地址")
  76. * @return void
  77. * 编辑用户地址
  78. */
  79. public function save_address(){
  80. $user = $this->getUser();
  81. $id = input('id');
  82. $type = input('type',0);
  83. $name = input('name','');
  84. $phone = input('phone','');
  85. $province = input('province','');
  86. $city = input('city','');
  87. $area = input('area','');
  88. $address = input('address','');
  89. if(empty($name)||empty($phone)||empty($province)||empty($city)||empty($area)||empty($address)){
  90. $this->error('请完善邮寄地址信息!');
  91. }
  92. $data = [
  93. 'type'=>$type,
  94. 'name'=>$name,
  95. 'phone'=>$phone,
  96. 'province'=>$province,
  97. 'city'=>$city,
  98. 'area'=>$area,
  99. 'address'=>$address,
  100. 'deleted'=>1,
  101. 'create_at'=>date('Y-m-d H:i:s')
  102. ];
  103. if($type==1){
  104. DataUserAddress::mk()->where('type',1)->save(['type'=>0]);
  105. }
  106. DataUserAddress::mk()->where('id',$id)->save($data);
  107. $this->success('邮寄地址已修改');
  108. }
  109. /**
  110. * @Title ("删除啊收货地址")
  111. * @Method("post")
  112. * @Param ("id",desc="地址的id")
  113. * @return void
  114. *
  115. */
  116. public function del_address(){
  117. $user = $this->getUser();
  118. $id = input('id');
  119. DataUserAddress::mk()->where('id',$id)->where('uuid',$user['id'])->save(['deleted'=>0]);
  120. $this->success('邮寄地址已删除');
  121. }
  122. }