|
@@ -0,0 +1,132 @@
|
|
|
+package com.caimei365.order.controller;
|
|
|
+
|
|
|
+import com.caimei365.order.model.ResponseJson;
|
|
|
+import com.caimei365.order.model.dto.AddressDto;
|
|
|
+import com.caimei365.order.model.dto.CartDto;
|
|
|
+import com.caimei365.order.model.vo.AddressSelectVo;
|
|
|
+import com.caimei365.order.model.vo.AddressVo;
|
|
|
+import com.caimei365.order.service.AddressService;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 收货地址Api
|
|
|
+ *
|
|
|
+ * @author : Charles
|
|
|
+ * @date : 2021/7/2
|
|
|
+ */
|
|
|
+@Api(tags="收货地址API")
|
|
|
+@RestController
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RequestMapping("/order/address")
|
|
|
+public class AddressApi {
|
|
|
+
|
|
|
+ private final AddressService addressService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收货地址列表
|
|
|
+ */
|
|
|
+ @ApiOperation("收货地址列表(旧:/personalCenter/findAddress)")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(required = true, name = "userId", value = "用户Id"),
|
|
|
+ @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
|
|
|
+ @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
|
|
|
+ })
|
|
|
+ @GetMapping("/list")
|
|
|
+ public ResponseJson<PageInfo<AddressVo>> getUserAddressList(Integer userId,
|
|
|
+ @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
|
|
|
+ if (null == userId) {
|
|
|
+ return ResponseJson.error("用户Id不能为空!", null);
|
|
|
+ }
|
|
|
+ return addressService.getUserAddressList(userId, pageNum, pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收货地址下拉选项列表
|
|
|
+ */
|
|
|
+ @ApiOperation("收货地址下拉选项列表(旧:/club/province(city)(town))")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(required = false, name = "type", value = "选项类型:0省(默认),1市,2区"),
|
|
|
+ @ApiImplicitParam(required = false, name = "parentId", value = "父级地址Id")
|
|
|
+ })
|
|
|
+ @GetMapping("/select")
|
|
|
+ public ResponseJson<List<AddressSelectVo>> getSelectAddress(Integer type, Integer parentId) {
|
|
|
+ if (null == type) {
|
|
|
+ type = 0;
|
|
|
+ } else {
|
|
|
+ if (null == parentId) {
|
|
|
+ return ResponseJson.error("父级地址Id不能为空!", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return addressService.getSelectAddress(type, parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存收货地址
|
|
|
+ *
|
|
|
+ * @param addressDto {
|
|
|
+ * userId 用户ID
|
|
|
+ * addressId 用户地址Id
|
|
|
+ * townId 区ID
|
|
|
+ * address 详细地址
|
|
|
+ * name 收货人
|
|
|
+ * mobile 手机
|
|
|
+ * defaultFlag 是否默认收货地址(0 不是默认,1 默认)
|
|
|
+ */
|
|
|
+ @ApiOperation("保存收货地址(旧:/personalCenter/saveAddress)")
|
|
|
+ @PostMapping("/save")
|
|
|
+ public ResponseJson<Integer> addUserAddress(AddressDto addressDto){
|
|
|
+ if (null == addressDto.getUserId()) {
|
|
|
+ return ResponseJson.error("用户Id不能为空!", null);
|
|
|
+ }
|
|
|
+ if (null == addressDto.getTownId()) {
|
|
|
+ return ResponseJson.error("地区ID不能为空!", null);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(addressDto.getAddress())) {
|
|
|
+ return ResponseJson.error("详细地址不能为空!", null);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(addressDto.getName())) {
|
|
|
+ return ResponseJson.error("收货人不能为空!", null);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(addressDto.getMobile())) {
|
|
|
+ return ResponseJson.error("手机号码不能为空!", null);
|
|
|
+ }
|
|
|
+ return addressService.addUserAddress(addressDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除收货地址
|
|
|
+ *
|
|
|
+ * @param addressDto {
|
|
|
+ * userId 用户ID
|
|
|
+ * addressId 用户地址Id
|
|
|
+ */
|
|
|
+ @ApiOperation("删除购物车(旧:/personalCenter/deleteAddress)")
|
|
|
+ @PostMapping("/cart/delete")
|
|
|
+ public ResponseJson<Integer> deleteUserAddress(AddressDto addressDto){
|
|
|
+ if (null == addressDto.getUserId()) {
|
|
|
+ return ResponseJson.error("用户Id不能为空!", null);
|
|
|
+ }
|
|
|
+ if (null == addressDto.getTownId()) {
|
|
|
+ return ResponseJson.error("地区ID不能为空!", null);
|
|
|
+ }
|
|
|
+ return addressService.deleteUserAddress(addressDto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|