123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace App\Http\Controllers\Client;
- use App\Http\Controllers\Controller;
- use App\Services\Client\UserAddressService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- /**
- * @group 用户端-地址管理
- *
- * 用户地址相关的API接口
- */
- class UserAddressController extends Controller
- {
- protected $userAddressService;
- public function __construct(UserAddressService $userAddressService)
- {
- $this->userAddressService = $userAddressService;
- }
- /**
- * 获取默认地址2
- *
- * @description 根据用户编号查询用户数据,用户状态为正常,查询用户地址列表,返回用户默认地址
- *
- * @response {
- * "code": 200,
- * "message": "success",
- * "data": {
- * "id": 1,
- * "user_id": 1,
- * "name": "张三",
- * "phone": "13800138000",
- * "province": "广东省",
- * "city": "深圳市",
- * "district": "南山区",
- * "address": "科技园",
- * "is_default": 1,
- * "created_at": "2024-01-01 00:00:00",
- * "updated_at": "2024-01-01 00:00:00"
- * }
- * }
- */
- public function getDefault()
- {
- return $this->userAddressService->getDefault(Auth::user()->id);
- }
- /**
- * 添加地址
- *
- * @description 根据用户编号查询用户数据,用户状态为正常,保存用户地址,如果用户只有一个地址则设置为默认地址
- *
- * @bodyParam phone string required 手机号 Example: 13800138000
- * @bodyParam province string required 省份 Example: 广东省
- * @bodyParam city string required 城市 Example: 深圳市
- * @bodyParam district string required 区县 Example: 南山区
- * @bodyParam longitude string required 经度 Example: 113.93041
- * @bodyParam latitude string required 纬度 Example: 22.53332
- * @bodyParam area_code string required 区划代码 Example: 440305
- * @bodyParam is_default boolean required 是否默认地址 Example: true
- * @bodyParam location string required 定位地址 Example: 科技园
- * @bodyParam detail string required 详细地址 Example: 科技园南区
- *
- * @response {"code": 200,"message": "添加成功"}
- */
- public function store(Request $request)
- {
- $data = $request->only(['phone', 'province', 'city', 'district', 'longitude', 'latitude', 'area_code', 'is_default', 'location', 'detail']);
- return $this->userAddressService->store(Auth::user()->id, $data);
- }
- /**
- * 修改地址
- *
- * @description 根据用户编号查询用户数据,用户状态为正常,根据地址编号查询地址数据,修改地址信息
- *
- * @urlParam id integer required 地址ID Example: 1
- *
- * @bodyParam phone string required 手机号 Example: 13800138000
- * @bodyParam province string required 省份 Example: 广东省
- * @bodyParam city string required 城市 Example: 深圳市
- * @bodyParam district string required 区县 Example: 南山区
- * @bodyParam longitude string required 经度 Example: 113.93041
- * @bodyParam latitude string required 纬度 Example: 22.53332
- * @bodyParam area_code string required 区划代码 Example: 440305
- * @bodyParam is_default boolean required 是否默认地址 Example: true
- * @bodyParam location string required 定位地址 Example: 科技园
- * @bodyParam detail string required 详细地址 Example: 科技园南区
- *
- * @response {"code": 200,"message": "修改成功"}
- */
- public function update(Request $request, $id)
- {
- $data = $request->only(['phone', 'province', 'city', 'district', 'longitude', 'latitude', 'area_code', 'is_default', 'location', 'detail']);
- return $this->userAddressService->update(Auth::user()->id, $id, $data);
- }
- /**
- * 删除地址
- *
- * @description 根据用户编号查询用户数据,用户状态为正常,根据地址编号查询地址数据,删除地址
- *
- * @urlParam id integer required 地址ID Example: 1
- *
- * @response {"code": 200,"message": "删除成功"}
- */
- public function destroy($id)
- {
- return $this->userAddressService->destroy(Auth::user()->id, $id);
- }
- /**
- * 设置默认地址
- *
- * @description 根据用户编号查询用户数据,用户状态为正常,根据地址编号查询地址数据,设置为默认地址
- *
- * @urlParam id integer required 地址ID Example: 1
- *
- * @response {"code": 200,"message": "设置成功"}
- */
- public function setDefault($id)
- {
- return $this->userAddressService->setDefault(Auth::user()->id, $id);
- }
- }
|