|
|
|
@ -17,7 +17,10 @@ import com.cyl.h5.domain.form.OrderPayForm;
|
|
|
|
import com.cyl.h5.domain.vo.OrderPayVO;
|
|
|
|
import com.cyl.h5.domain.vo.OrderPayVO;
|
|
|
|
import com.cyl.h5.domain.vo.*;
|
|
|
|
import com.cyl.h5.domain.vo.*;
|
|
|
|
import com.cyl.h5.domain.form.OrderSubmitForm;
|
|
|
|
import com.cyl.h5.domain.form.OrderSubmitForm;
|
|
|
|
|
|
|
|
import com.cyl.manager.act.domain.entity.MemberCoupon;
|
|
|
|
|
|
|
|
import com.cyl.manager.act.mapper.MemberCouponMapper;
|
|
|
|
import com.cyl.manager.act.service.IntegralHistoryService;
|
|
|
|
import com.cyl.manager.act.service.IntegralHistoryService;
|
|
|
|
|
|
|
|
import com.cyl.manager.act.service.MemberCouponService;
|
|
|
|
import com.cyl.manager.oms.convert.AftersaleItemConvert;
|
|
|
|
import com.cyl.manager.oms.convert.AftersaleItemConvert;
|
|
|
|
import com.cyl.manager.oms.convert.OrderItemConvert;
|
|
|
|
import com.cyl.manager.oms.convert.OrderItemConvert;
|
|
|
|
import com.cyl.manager.oms.mapper.*;
|
|
|
|
import com.cyl.manager.oms.mapper.*;
|
|
|
|
@ -54,8 +57,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
|
|
|
import org.springframework.security.core.parameters.P;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
@ -124,6 +129,9 @@ public class H5OrderService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IntegralHistoryService integralHistoryService;
|
|
|
|
private IntegralHistoryService integralHistoryService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MemberCouponService memberCouponService;
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Long submit(OrderSubmitForm form) {
|
|
|
|
public Long submit(OrderSubmitForm form) {
|
|
|
|
Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
|
|
|
|
Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
|
|
|
|
@ -147,6 +155,35 @@ public class H5OrderService {
|
|
|
|
Map<Long, Sku> querySkuMap = skuMapper
|
|
|
|
Map<Long, Sku> querySkuMap = skuMapper
|
|
|
|
.selectBatchIds(skuList.stream().map(OrderProductListDTO::getSkuId).collect(Collectors.toList()))
|
|
|
|
.selectBatchIds(skuList.stream().map(OrderProductListDTO::getSkuId).collect(Collectors.toList()))
|
|
|
|
.stream().collect(Collectors.toMap(Sku::getId, it -> it));
|
|
|
|
.stream().collect(Collectors.toMap(Sku::getId, it -> it));
|
|
|
|
|
|
|
|
//校验优惠券
|
|
|
|
|
|
|
|
BigDecimal couponAmount = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
if (form.getMemberCouponId() != null) {
|
|
|
|
|
|
|
|
MemberCoupon coupon = memberCouponService.selectValidCoupon(form.getMemberCouponId());
|
|
|
|
|
|
|
|
if (coupon == null) {
|
|
|
|
|
|
|
|
throw new RuntimeException("优惠券未找到");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//将sku转换成products
|
|
|
|
|
|
|
|
Map<Long, Product> products = new HashMap<>();
|
|
|
|
|
|
|
|
querySkuMap.forEach((k, v) -> {
|
|
|
|
|
|
|
|
Integer count = skuQuantityMap.get(k);
|
|
|
|
|
|
|
|
Long productId = v.getProductId();
|
|
|
|
|
|
|
|
Product product;
|
|
|
|
|
|
|
|
BigDecimal amount = v.getPrice().multiply(BigDecimal.valueOf(count));
|
|
|
|
|
|
|
|
if (products.containsKey(k)) {
|
|
|
|
|
|
|
|
product = products.get(k);
|
|
|
|
|
|
|
|
product.setPrice(amount.add(product.getPrice()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
product = new Product();
|
|
|
|
|
|
|
|
product.setId(productId);
|
|
|
|
|
|
|
|
product.setPrice(amount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
products.put(k, product);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!memberCouponService.judgeCouponCanUse(coupon, products.values())) {
|
|
|
|
|
|
|
|
throw new RuntimeException("优惠券未达到使用条件");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
couponAmount = coupon.getCouponAmount();
|
|
|
|
|
|
|
|
}
|
|
|
|
//计算商品总额、订单总额(订单总金额=商品总金额,因为暂时没有运费等概念)
|
|
|
|
//计算商品总额、订单总额(订单总金额=商品总金额,因为暂时没有运费等概念)
|
|
|
|
BigDecimal productTotalAmount = BigDecimal.ZERO;
|
|
|
|
BigDecimal productTotalAmount = BigDecimal.ZERO;
|
|
|
|
BigDecimal orderTotalAmount = BigDecimal.ZERO;
|
|
|
|
BigDecimal orderTotalAmount = BigDecimal.ZERO;
|
|
|
|
@ -184,11 +221,18 @@ public class H5OrderService {
|
|
|
|
order.setMemberId(member.getId());
|
|
|
|
order.setMemberId(member.getId());
|
|
|
|
order.setMemberUsername(member.getNickname());
|
|
|
|
order.setMemberUsername(member.getNickname());
|
|
|
|
order.setPayType(Constants.PayType.WECHAT);
|
|
|
|
order.setPayType(Constants.PayType.WECHAT);
|
|
|
|
|
|
|
|
order.setCouponAmount(couponAmount);
|
|
|
|
|
|
|
|
order.setMemberCouponId(form.getMemberCouponId());
|
|
|
|
order.setTotalAmount(orderTotalAmount);
|
|
|
|
order.setTotalAmount(orderTotalAmount);
|
|
|
|
order.setPurchasePrice(BigDecimal.ZERO);
|
|
|
|
order.setPurchasePrice(BigDecimal.ZERO);
|
|
|
|
order.setFreightAmount(BigDecimal.ZERO);
|
|
|
|
order.setFreightAmount(BigDecimal.ZERO);
|
|
|
|
order.setPayAmount(orderTotalAmount);
|
|
|
|
BigDecimal subtract = orderTotalAmount.subtract(couponAmount);
|
|
|
|
|
|
|
|
order.setPayAmount(subtract.compareTo(BigDecimal.ZERO) > 0 ? subtract : BigDecimal.ZERO);
|
|
|
|
|
|
|
|
if (order.getPayAmount().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
|
|
|
order.setStatus(Constants.OrderStatus.SEND);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
order.setStatus(Constants.OrderStatus.NOTPAID);
|
|
|
|
order.setStatus(Constants.OrderStatus.NOTPAID);
|
|
|
|
|
|
|
|
}
|
|
|
|
order.setAftersaleStatus(1);
|
|
|
|
order.setAftersaleStatus(1);
|
|
|
|
order.setReceiverName(memberAddress.getName());
|
|
|
|
order.setReceiverName(memberAddress.getName());
|
|
|
|
order.setReceiverPhone(memberAddress.getPhoneHidden());
|
|
|
|
order.setReceiverPhone(memberAddress.getPhoneHidden());
|
|
|
|
@ -241,6 +285,10 @@ public class H5OrderService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//当前订单id,接入支付后可返回payId
|
|
|
|
//当前订单id,接入支付后可返回payId
|
|
|
|
|
|
|
|
//如果是使用了优惠券,更新优惠券状态
|
|
|
|
|
|
|
|
if (form.getMemberCouponId() != null) {
|
|
|
|
|
|
|
|
memberCouponService.updateCouponStatus(form.getMemberCouponId(), orderId);
|
|
|
|
|
|
|
|
}
|
|
|
|
return payId;
|
|
|
|
return payId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -294,6 +342,24 @@ public class H5OrderService {
|
|
|
|
res.setSkuList(skuList);
|
|
|
|
res.setSkuList(skuList);
|
|
|
|
res.setOrderTotalAmount(orderTotalAmount);
|
|
|
|
res.setOrderTotalAmount(orderTotalAmount);
|
|
|
|
res.setProductTotalAmount(productTotalAmount);
|
|
|
|
res.setProductTotalAmount(productTotalAmount);
|
|
|
|
|
|
|
|
//获取能使用的优惠券列表
|
|
|
|
|
|
|
|
Map<Long, Product> products = new HashMap<>();
|
|
|
|
|
|
|
|
querySkuMap.forEach((k, v) -> {
|
|
|
|
|
|
|
|
Integer count = quantityMap.get(k);
|
|
|
|
|
|
|
|
Long productId = v.getProductId();
|
|
|
|
|
|
|
|
Product product;
|
|
|
|
|
|
|
|
BigDecimal amount = v.getPrice().multiply(BigDecimal.valueOf(count));
|
|
|
|
|
|
|
|
if (products.containsKey(k)) {
|
|
|
|
|
|
|
|
product = products.get(k);
|
|
|
|
|
|
|
|
product.setPrice(amount.add(product.getPrice()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
product = new Product();
|
|
|
|
|
|
|
|
product.setId(productId);
|
|
|
|
|
|
|
|
product.setPrice(amount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
products.put(k, product);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
res.setCouponList(memberCouponService.getCanUseList(products.values()));
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -305,6 +371,7 @@ public class H5OrderService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* h5订单分页查询
|
|
|
|
* h5订单分页查询
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param status 订单状态 -1->全部;0->待付款;1->待发货;2->待收货;-2->售后单
|
|
|
|
* @param status 订单状态 -1->全部;0->待付款;1->待发货;2->待收货;-2->售后单
|
|
|
|
* @param memberId 会员id
|
|
|
|
* @param memberId 会员id
|
|
|
|
* @param pageable 分页
|
|
|
|
* @param pageable 分页
|
|
|
|
@ -391,6 +458,7 @@ public class H5OrderService {
|
|
|
|
orderOperateHistoryMapper.insert(optHistory);
|
|
|
|
orderOperateHistoryMapper.insert(optHistory);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public String orderComplete(Long orderId) {
|
|
|
|
public String orderComplete(Long orderId) {
|
|
|
|
LocalDateTime optDate = LocalDateTime.now();
|
|
|
|
LocalDateTime optDate = LocalDateTime.now();
|
|
|
|
@ -427,6 +495,7 @@ public class H5OrderService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 统计待付款、待发货、待收货和售后订单数量
|
|
|
|
* 统计待付款、待发货、待收货和售后订单数量
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param memberId
|
|
|
|
* @param memberId
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -490,11 +559,17 @@ public class H5OrderService {
|
|
|
|
if (!flag) {
|
|
|
|
if (!flag) {
|
|
|
|
throw new RuntimeException("创建订单操作记录失败");
|
|
|
|
throw new RuntimeException("创建订单操作记录失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//判断是否使用优惠券,有的话,把优惠券还回去
|
|
|
|
|
|
|
|
List<Long> couponIdList = orderList.stream().filter(it -> it.getMemberCouponId() != null).map(Order::getMemberCouponId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(couponIdList)) {
|
|
|
|
|
|
|
|
memberCouponService.backCoupon(couponIdList);
|
|
|
|
|
|
|
|
}
|
|
|
|
return "取消订单成功";
|
|
|
|
return "取消订单成功";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 订单支付
|
|
|
|
* 订单支付
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param req 支付请求
|
|
|
|
* @param req 支付请求
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -582,6 +657,7 @@ public class H5OrderService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 支付回调方法
|
|
|
|
* 支付回调方法
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param messageDTO
|
|
|
|
* @param messageDTO
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -648,6 +724,7 @@ public class H5OrderService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 申请售后
|
|
|
|
* 申请售后
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param applyRefundForm
|
|
|
|
* @param applyRefundForm
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -730,6 +807,7 @@ public class H5OrderService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* check是否能售后 可售后的状态为:待发货、待收货、已完成
|
|
|
|
* check是否能售后 可售后的状态为:待发货、待收货、已完成
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param order 订单
|
|
|
|
* @param order 订单
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void checkIfCanApplyRefund(Order order) {
|
|
|
|
private void checkIfCanApplyRefund(Order order) {
|
|
|
|
@ -754,6 +832,7 @@ public class H5OrderService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 取消售后
|
|
|
|
* 取消售后
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param orderId 订单id
|
|
|
|
* @param orderId 订单id
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -801,6 +880,7 @@ public class H5OrderService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 售后订单详情
|
|
|
|
* 售后订单详情
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param orderId 订单id
|
|
|
|
* @param orderId 订单id
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|