UserAddressController.php 4.6 KB

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