UserAddressController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 name string required 收货人姓名 Example: 张三
  72. * @bodyParam phone string required 收货人手机号 Example: 13800138000
  73. * @bodyParam province string required 省份 Example: 广东省
  74. * @bodyParam city string required 城市 Example: 深圳市
  75. * @bodyParam district string required 区县 Example: 南山区
  76. * @bodyParam address string required 详细地址 Example: 科技园南区
  77. *
  78. * @response {"code": 200,"message": "修改成功"}
  79. */
  80. public function update(Request $request, $id)
  81. {
  82. $data = $request->only(['name', 'phone', 'province', 'city', 'district', 'address']);
  83. return $this->userAddressService->update(Auth::user()->id, $id, $data);
  84. }
  85. /**
  86. * [用户地址] 删除地址
  87. *
  88. * @description 根据用户编号查询用户数据,用户状态为正常,根据地址编号查询地址数据,删除地址
  89. *
  90. * @urlParam id integer required 地址ID 默认值: 1
  91. *
  92. * @response {"code": 200,"message": "删除成功"}
  93. */
  94. public function destroy($id)
  95. {
  96. return $this->userAddressService->destroy(Auth::id(), $id);
  97. }
  98. /**
  99. * [用户地址] 设置默认地址
  100. *
  101. * @description 根据用户编号查询用户数据,用户状态为正常,根据地址编号查询地址数据,设置为默认地址
  102. *
  103. * @urlParam id integer required 地址ID 默认值: 1
  104. *
  105. * @response {"code": 200,"message": "设置成功"}
  106. */
  107. public function setDefault($id)
  108. {
  109. return $this->userAddressService->setDefault(Auth::id(), $id);
  110. }
  111. }