UserAddressController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Client\UserAddressService;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. /**
  8. * @group 用户端-地址管理
  9. *
  10. * 用户地址相关的API接口
  11. */
  12. class UserAddressController extends Controller
  13. {
  14. protected $userAddressService;
  15. public function __construct(UserAddressService $userAddressService)
  16. {
  17. $this->userAddressService = $userAddressService;
  18. }
  19. /**
  20. * 获取默认地址2
  21. *
  22. * @description 根据用户编号查询用户数据,用户状态为正常,查询用户地址列表,返回用户默认地址
  23. *
  24. * @response {
  25. * "code": 200,
  26. * "message": "success",
  27. * "data": {
  28. * "id": 1,
  29. * "user_id": 1,
  30. * "name": "张三",
  31. * "phone": "13800138000",
  32. * "province": "广东省",
  33. * "city": "深圳市",
  34. * "district": "南山区",
  35. * "address": "科技园",
  36. * "is_default": 1,
  37. * "created_at": "2024-01-01 00:00:00",
  38. * "updated_at": "2024-01-01 00:00:00"
  39. * }
  40. * }
  41. */
  42. public function getDefault()
  43. {
  44. return $this->userAddressService->getDefault(Auth::user()->id);
  45. }
  46. /**
  47. * 添加地址
  48. *
  49. * @description 根据用户编号查询用户数据,用户状态为正常,保存用户地址,如果用户只有一个地址则设置为默认地址
  50. *
  51. * @bodyParam phone string required 手机号 Example: 13800138000
  52. * @bodyParam province string required 省份 Example: 广东省
  53. * @bodyParam city string required 城市 Example: 深圳市
  54. * @bodyParam district string required 区县 Example: 南山区
  55. * @bodyParam longitude string required 经度 Example: 113.93041
  56. * @bodyParam latitude string required 纬度 Example: 22.53332
  57. * @bodyParam area_code string required 区划代码 Example: 440305
  58. * @bodyParam is_default boolean required 是否默认地址 Example: true
  59. * @bodyParam location string required 定位地址 Example: 科技园
  60. * @bodyParam detail string required 详细地址 Example: 科技园南区
  61. *
  62. * @response {"code": 200,"message": "添加成功"}
  63. */
  64. public function store(Request $request)
  65. {
  66. $data = $request->only(['phone', 'province', 'city', 'district', 'longitude', 'latitude', 'area_code', 'is_default', 'location', 'detail']);
  67. return $this->userAddressService->store(Auth::user()->id, $data);
  68. }
  69. /**
  70. * 修改地址
  71. *
  72. * @description 根据用户编号查询用户数据,用户状态为正常,根据地址编号查询地址数据,修改地址信息
  73. *
  74. * @urlParam id integer required 地址ID Example: 1
  75. *
  76. * @bodyParam phone string required 手机号 Example: 13800138000
  77. * @bodyParam province string required 省份 Example: 广东省
  78. * @bodyParam city string required 城市 Example: 深圳市
  79. * @bodyParam district string required 区县 Example: 南山区
  80. * @bodyParam longitude string required 经度 Example: 113.93041
  81. * @bodyParam latitude string required 纬度 Example: 22.53332
  82. * @bodyParam area_code string required 区划代码 Example: 440305
  83. * @bodyParam is_default boolean required 是否默认地址 Example: true
  84. * @bodyParam location string required 定位地址 Example: 科技园
  85. * @bodyParam detail string required 详细地址 Example: 科技园南区
  86. *
  87. * @response {"code": 200,"message": "修改成功"}
  88. */
  89. public function update(Request $request, $id)
  90. {
  91. $data = $request->only(['phone', 'province', 'city', 'district', 'longitude', 'latitude', 'area_code', 'is_default', 'location', 'detail']);
  92. return $this->userAddressService->update(Auth::user()->id, $id, $data);
  93. }
  94. /**
  95. * 删除地址
  96. *
  97. * @description 根据用户编号查询用户数据,用户状态为正常,根据地址编号查询地址数据,删除地址
  98. *
  99. * @urlParam id integer required 地址ID Example: 1
  100. *
  101. * @response {"code": 200,"message": "删除成功"}
  102. */
  103. public function destroy($id)
  104. {
  105. return $this->userAddressService->destroy(Auth::user()->id, $id);
  106. }
  107. /**
  108. * 设置默认地址
  109. *
  110. * @description 根据用户编号查询用户数据,用户状态为正常,根据地址编号查询地址数据,设置为默认地址
  111. *
  112. * @urlParam id integer required 地址ID Example: 1
  113. *
  114. * @response {"code": 200,"message": "设置成功"}
  115. */
  116. public function setDefault($id)
  117. {
  118. return $this->userAddressService->setDefault(Auth::user()->id, $id);
  119. }
  120. }