|
|
@@ -10,6 +10,8 @@ import com.etotem.cfc.dto.ProductOrderDTO;
|
|
|
import com.etotem.cfc.entity.AfterSalesRequest;
|
|
|
import com.etotem.cfc.entity.AssessmentProduct;
|
|
|
import com.etotem.cfc.entity.Consignee;
|
|
|
+import com.etotem.cfc.entity.UserAddress;
|
|
|
+import com.etotem.cfc.mapper.UserAddressMapper;
|
|
|
import com.etotem.cfc.entity.Coupon;
|
|
|
import com.etotem.cfc.entity.FamilyCoupon;
|
|
|
import com.etotem.cfc.entity.Product;
|
|
|
@@ -181,6 +183,9 @@ public class ProductOrderService {
|
|
|
@Resource
|
|
|
private com.etotem.cfc.mapper.ConsigneeMapper consigneeMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private UserAddressMapper userAddressMapper;
|
|
|
+
|
|
|
@Resource
|
|
|
private ProductOrderGiftMapper productOrderGiftMapper;
|
|
|
|
|
|
@@ -256,8 +261,7 @@ public class ProductOrderService {
|
|
|
order.setCoverImage(product.getCoverImage());
|
|
|
order.setDiscountAmount(discountAmount);
|
|
|
order.setCouponId(dto.getCouponId());
|
|
|
- order.setAddressSnapshot(dto.getAddressSnapshot());
|
|
|
- order.setConsigneeId(dto.getConsigneeId());
|
|
|
+ resolveOrderAddress(order, dto, buyerId);
|
|
|
if (dto.getPurchaseInfo() != null && !dto.getPurchaseInfo().isEmpty()) {
|
|
|
order.setPurchaseInfo(JSON.toJSONString(dto.getPurchaseInfo()));
|
|
|
}
|
|
|
@@ -297,6 +301,44 @@ public class ProductOrderService {
|
|
|
* 配送方式与履约校验(设计文档十一节)
|
|
|
* 分支校验 + 生成快照 + 扣减时间段余量;返回 error!=null 表示校验失败
|
|
|
*/
|
|
|
+ /** 落库前统一整理收货地址:优先直接快照,其次 addressId(user_address),最后 consigneeId(consignees) */
|
|
|
+ private void resolveOrderAddress(ProductOrder order, CreateProductOrderDTO dto, Long buyerId) {
|
|
|
+ String snapshot = dto.getAddressSnapshot();
|
|
|
+ Long consigneeId = dto.getConsigneeId();
|
|
|
+ if ((snapshot == null || snapshot.isEmpty()) && dto.getAddressId() != null) {
|
|
|
+ UserAddress ua = userAddressMapper.selectById(dto.getAddressId());
|
|
|
+ if (ua != null && buyerId.equals(ua.getUserId())) {
|
|
|
+ Map<String, Object> snap = new HashMap<>();
|
|
|
+ snap.put("receiverName", ua.getReceiverName());
|
|
|
+ snap.put("phone", ua.getPhone());
|
|
|
+ snap.put("province", ua.getProvince());
|
|
|
+ snap.put("city", ua.getCity());
|
|
|
+ snap.put("district", ua.getDistrict());
|
|
|
+ snap.put("street", ua.getStreet());
|
|
|
+ snap.put("isDefault", ua.getIsDefault());
|
|
|
+ snap.put("source", "user_address");
|
|
|
+ snapshot = JSON.toJSONString(snap);
|
|
|
+ consigneeId = ua.getId();
|
|
|
+ }
|
|
|
+ } else if ((snapshot == null || snapshot.isEmpty()) && dto.getConsigneeId() != null) {
|
|
|
+ Consignee c = consigneeMapper.selectById(dto.getConsigneeId());
|
|
|
+ if (c != null && buyerId.equals(c.getUserId())) {
|
|
|
+ Map<String, Object> snap = new HashMap<>();
|
|
|
+ snap.put("receiverName", c.getName());
|
|
|
+ snap.put("phone", c.getPhone());
|
|
|
+ snap.put("province", c.getProvince());
|
|
|
+ snap.put("city", c.getCity());
|
|
|
+ snap.put("district", c.getDistrict());
|
|
|
+ snap.put("street", c.getStreet());
|
|
|
+ snap.put("source", "consignee");
|
|
|
+ snapshot = JSON.toJSONString(snap);
|
|
|
+ consigneeId = c.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.setAddressSnapshot(snapshot);
|
|
|
+ order.setConsigneeId(consigneeId);
|
|
|
+ }
|
|
|
+
|
|
|
private FulfillValidation validateFulfill(Product product, CreateProductOrderDTO dto, Long buyerId) {
|
|
|
FulfillValidation fv = new FulfillValidation();
|
|
|
Integer productMethod = product.getDeliveryMethod() != null ? product.getDeliveryMethod() : 1;
|
|
|
@@ -316,16 +358,25 @@ public class ProductOrderService {
|
|
|
|
|
|
switch (actualMethod) {
|
|
|
case 1:
|
|
|
- // 快递:校验收货地址存在且属于当前用户
|
|
|
- if (dto.getConsigneeId() == null) {
|
|
|
+ // 快递:收货地址三选一校验:直接快照 > addressId(user_address) > consigneeId(consignees)
|
|
|
+ if (dto.getAddressSnapshot() != null && !dto.getAddressSnapshot().isEmpty()) {
|
|
|
+ // 直接提供快照,校验通过
|
|
|
+ } else if (dto.getAddressId() != null) {
|
|
|
+ UserAddress ua = userAddressMapper.selectById(dto.getAddressId());
|
|
|
+ if (ua == null || !buyerId.equals(ua.getUserId())) {
|
|
|
+ fv.error = "收货地址不存在";
|
|
|
+ return fv;
|
|
|
+ }
|
|
|
+ } else if (dto.getConsigneeId() != null) {
|
|
|
+ Consignee consignee = consigneeMapper.selectById(dto.getConsigneeId());
|
|
|
+ if (consignee == null || !buyerId.equals(consignee.getUserId())) {
|
|
|
+ fv.error = "收货地址不存在";
|
|
|
+ return fv;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
fv.error = "请选择收货地址";
|
|
|
return fv;
|
|
|
}
|
|
|
- Consignee consignee = consigneeMapper.selectById(dto.getConsigneeId());
|
|
|
- if (consignee == null || !buyerId.equals(consignee.getUserId())) {
|
|
|
- fv.error = "收货地址不存在";
|
|
|
- return fv;
|
|
|
- }
|
|
|
break;
|
|
|
case 2: {
|
|
|
// 自提:校验自取地点 + 时间段
|
|
|
@@ -558,8 +609,7 @@ public class ProductOrderService {
|
|
|
order.setCoverImage(firstItem.getCoverImage() != null ? firstItem.getCoverImage() : firstProduct.getCoverImage());
|
|
|
order.setDiscountAmount(multiDiscountAmount);
|
|
|
order.setCouponId(dto.getCouponId());
|
|
|
- order.setAddressSnapshot(dto.getAddressSnapshot());
|
|
|
- order.setConsigneeId(dto.getConsigneeId());
|
|
|
+ resolveOrderAddress(order, dto, buyerId);
|
|
|
if (dto.getPurchaseInfo() != null && !dto.getPurchaseInfo().isEmpty()) {
|
|
|
order.setPurchaseInfo(JSON.toJSONString(dto.getPurchaseInfo()));
|
|
|
}
|