|
@@ -97,6 +97,8 @@ public class OrderFlowService {
|
|
|
|
|
|
private Map<ProductType, InitRecord> initRecordCallback = new HashMap<>();
|
|
|
|
|
|
+ private Map<ProductType, InitRecord> initRecordFinishCallback = new HashMap<>();
|
|
|
+
|
|
|
private Map<ProductType, UseRecord> useRecordCallback = new HashMap<>();
|
|
|
|
|
|
private Map<ProductType, StopRecord> stopRecordCallback = new HashMap<>();
|
|
@@ -505,7 +507,60 @@ public class OrderFlowService {
|
|
|
CoursePackage coursePackage = coursePackageService.get(record.getProductId());
|
|
|
|
|
|
// 记录销售数量
|
|
|
- coursePackageService.accumulation(coursePackage.getId(), 1);
|
|
|
+ coursePackageService.accumulation(record.getProductId(), 1);
|
|
|
+
|
|
|
+ return record;
|
|
|
+ }));
|
|
|
+ initRecordCallback.put(ProductType.DATA, ((order, record)->{
|
|
|
+ // 资料无需开启,也没有有效期
|
|
|
+ record.setIsUsed(1);
|
|
|
+ record.setIsSubscribe(1);
|
|
|
+ Date time = new Date();
|
|
|
+ record.setUseTime(time);
|
|
|
+
|
|
|
+ // 电子资料自动订阅
|
|
|
+ UserDataSubscribe subscribe = userDataSubscribeService.getByData(record.getUserId(), record.getProductId());
|
|
|
+
|
|
|
+ if (subscribe == null){
|
|
|
+ userDataSubscribeService.add(UserDataSubscribe.builder()
|
|
|
+ .userId(record.getUserId())
|
|
|
+ .dataId(record.getProductId())
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 记录销售数量
|
|
|
+ courseDataService.accumulation(record.getProductId(), 1, 0);
|
|
|
+ return record;
|
|
|
+ }));
|
|
|
+ initRecordCallback.put(ProductType.SERVICE, ((order, record)->{
|
|
|
+ if(record.getService().equals(ServiceKey.VIP.key)){
|
|
|
+ // VIP直接开通
|
|
|
+ record = useRecordCallback.get(ProductType.SERVICE).callback(record);
|
|
|
+ record.setProductType(ProductType.SERVICE.key);
|
|
|
+ }else{
|
|
|
+ ServiceKey serviceKey = ServiceKey.ValueOf(record.getService());
|
|
|
+ Date startTime = new Date();
|
|
|
+ Date endTime = Tools.addDate(startTime, record.getExpireDays());
|
|
|
+ record.setStartTime(startTime);
|
|
|
+ record.setEndTime(endTime);
|
|
|
+ // 如果使用半价优惠券,则扣除
|
|
|
+ if (serviceKey == ServiceKey.TEXTBOOK){
|
|
|
+ User user = usersService.get(record.getUserId());
|
|
|
+ if (user.getTextbookHalf() == 0) {
|
|
|
+ // todo 支付存在问题
|
|
|
+ }else if (record.getSource().equals(RecordSource.GIFT_COURSE.key)){
|
|
|
+ // 礼物不考虑
|
|
|
+ }else{
|
|
|
+ usersService.edit(User.builder().id(user.getId()).textbookHalf(user.getTextbookHalf() - 1).build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return record;
|
|
|
+ }));
|
|
|
+
|
|
|
+ initRecordFinishCallback.put(ProductType.COURSE_PACKAGE, ((order, record)->{
|
|
|
+ // 处理套餐赠送
|
|
|
+ CoursePackage coursePackage = coursePackageService.get(record.getProductId());
|
|
|
|
|
|
InitRecord callback = initRecordCallback.get(ProductType.SERVICE);
|
|
|
JSONObject gift = coursePackage.getGift();
|
|
@@ -515,6 +570,7 @@ public class OrderFlowService {
|
|
|
UserOrderRecord giftRecord = UserOrderRecord.builder()
|
|
|
.orderId(order.getId())
|
|
|
.userId(order.getUserId())
|
|
|
+ .parentId(record.getId())
|
|
|
.productType(ProductType.SERVICE.key)
|
|
|
.service(ServiceKey.QX_CAT.key)
|
|
|
.source(RecordSource.GIFT_COURSE.key)
|
|
@@ -530,6 +586,7 @@ public class OrderFlowService {
|
|
|
UserOrderRecord giftRecord = UserOrderRecord.builder()
|
|
|
.orderId(order.getId())
|
|
|
.userId(order.getUserId())
|
|
|
+ .parentId(record.getId())
|
|
|
.productType(ProductType.SERVICE.key)
|
|
|
.service(ServiceKey.TEXTBOOK.key)
|
|
|
.source(RecordSource.GIFT_COURSE.key)
|
|
@@ -546,6 +603,7 @@ public class OrderFlowService {
|
|
|
UserOrderRecord giftRecord = UserOrderRecord.builder()
|
|
|
.orderId(order.getId())
|
|
|
.userId(order.getUserId())
|
|
|
+ .parentId(record.getId())
|
|
|
.productType(ProductType.SERVICE.key)
|
|
|
.service(ServiceKey.VIP.key)
|
|
|
.param(vipKey.key)
|
|
@@ -557,52 +615,6 @@ public class OrderFlowService {
|
|
|
}
|
|
|
return record;
|
|
|
}));
|
|
|
- initRecordCallback.put(ProductType.DATA, ((order, record)->{
|
|
|
- // 资料无需开启,也没有有效期
|
|
|
- record.setIsUsed(1);
|
|
|
- record.setIsSubscribe(1);
|
|
|
- Date time = new Date();
|
|
|
- record.setUseTime(time);
|
|
|
-
|
|
|
- // 电子资料自动订阅
|
|
|
- UserDataSubscribe subscribe = userDataSubscribeService.getByData(record.getUserId(), record.getProductId());
|
|
|
-
|
|
|
- if (subscribe == null){
|
|
|
- userDataSubscribeService.add(UserDataSubscribe.builder()
|
|
|
- .userId(record.getUserId())
|
|
|
- .dataId(record.getProductId())
|
|
|
- .build());
|
|
|
- }
|
|
|
-
|
|
|
- // 记录销售数量
|
|
|
- courseDataService.accumulation(record.getProductId(), 1, 0);
|
|
|
- return record;
|
|
|
- }));
|
|
|
- initRecordCallback.put(ProductType.SERVICE, ((order, record)->{
|
|
|
- if(record.getService().equals(ServiceKey.VIP.key)){
|
|
|
- // VIP直接开通
|
|
|
- record = useRecordCallback.get(ProductType.SERVICE).callback(record);
|
|
|
- record.setProductType(ProductType.SERVICE.key);
|
|
|
- }else{
|
|
|
- ServiceKey serviceKey = ServiceKey.ValueOf(record.getService());
|
|
|
- Date startTime = new Date();
|
|
|
- Date endTime = Tools.addDate(startTime, record.getExpireDays());
|
|
|
- record.setStartTime(startTime);
|
|
|
- record.setEndTime(endTime);
|
|
|
- // 如果使用半价优惠券,则扣除
|
|
|
- if (serviceKey == ServiceKey.TEXTBOOK){
|
|
|
- User user = usersService.get(record.getUserId());
|
|
|
- if (user.getTextbookHalf() == 0) {
|
|
|
- // todo 支付存在问题
|
|
|
- }else if (record.getSource().equals(RecordSource.GIFT_COURSE.key)){
|
|
|
- // 礼物不考虑
|
|
|
- }else{
|
|
|
- usersService.edit(User.builder().id(user.getId()).textbookHalf(user.getTextbookHalf() - 1).build());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return record;
|
|
|
- }));
|
|
|
|
|
|
useRecordCallback.put(ProductType.COURSE, (record->{
|
|
|
User user = usersService.get(record.getUserId());
|
|
@@ -687,6 +699,9 @@ public class OrderFlowService {
|
|
|
.expireTime(endTime)
|
|
|
.build();
|
|
|
userService = userServiceService.add(userService);
|
|
|
+ if (serviceKey == ServiceKey.QX_CAT){
|
|
|
+ examinationService.resetCat(record.getUserId(), true);
|
|
|
+ }
|
|
|
}else{
|
|
|
if (serviceKey == ServiceKey.QX_CAT){
|
|
|
// cat逻辑独立
|
|
@@ -694,7 +709,7 @@ public class OrderFlowService {
|
|
|
// 有效期内
|
|
|
if (userService.getIsReset() == 0) throw new ParameterException("已开通当前服务");
|
|
|
// 第二次还未做完
|
|
|
- if (userService.getIsReset() == 1 && examinationService.isFinishCat(record.getUserId())) throw new ParameterException("已开通当前服务");
|
|
|
+ if (userService.getIsReset() == 1 && examinationService.isFinishQxCat(record.getUserId())) throw new ParameterException("已开通当前服务");
|
|
|
}
|
|
|
// 重置
|
|
|
examinationService.resetCat(record.getUserId(), true);
|
|
@@ -804,6 +819,11 @@ public class OrderFlowService {
|
|
|
record = userOrderRecordService.add(record);
|
|
|
// 建立新旧id关系
|
|
|
pMap.put(checkout.getId(), record.getId());
|
|
|
+
|
|
|
+ InitRecord finishCallback = initRecordFinishCallback.get(ProductType.ValueOf(record.getProductType()));
|
|
|
+ if (finishCallback != null){
|
|
|
+ callback.callback(userOrder, record);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
for(UserOrderCheckout checkout : cList){
|
|
@@ -814,6 +834,11 @@ public class OrderFlowService {
|
|
|
InitRecord callback = initRecordCallback.get(ProductType.ValueOf(record.getProductType()));
|
|
|
callback.callback(userOrder, record);
|
|
|
userOrderRecordService.add(record);
|
|
|
+
|
|
|
+ InitRecord finishCallback = initRecordFinishCallback.get(ProductType.ValueOf(record.getProductType()));
|
|
|
+ if (finishCallback != null){
|
|
|
+ callback.callback(userOrder, record);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
JSONArray gift = userOrder.getGift();
|
|
@@ -823,6 +848,7 @@ public class OrderFlowService {
|
|
|
if(info.get("key").equals("vs")){
|
|
|
// 添加赠送课时
|
|
|
Integer courseId = info.getInteger("courseId");
|
|
|
+ Course course = courseService.get(courseId);
|
|
|
if(courseId != null){
|
|
|
UserOrderRecord record = UserOrderRecord.builder()
|
|
|
.orderId(userOrder.getId())
|
|
@@ -833,6 +859,8 @@ public class OrderFlowService {
|
|
|
.productId(courseId)
|
|
|
.number(info.getIntValue("number"))
|
|
|
.source(RecordSource.GIFT_COURSE.key)
|
|
|
+ .expireDays(course.getExpireDays())
|
|
|
+ .useExpireDays(course.getExpirePreDays() / 10)
|
|
|
.build();
|
|
|
|
|
|
InitRecord callback = initRecordCallback.get(ProductType.ValueOf(record.getProductType()));
|
|
@@ -867,6 +895,8 @@ public class OrderFlowService {
|
|
|
*/
|
|
|
@Transactional
|
|
|
public int addCheckout(Integer userId, UserOrderCheckout checkout){
|
|
|
+ // 默认选中
|
|
|
+ checkout.setIsSelect(1);
|
|
|
List<UserOrderCheckout> list = userOrderCheckoutService.allByUser(userId, 0);
|
|
|
InitCheckout callback = initCheckoutCallback.get(ProductType.ValueOf(checkout.getProductType()));
|
|
|
checkout = callback.callback(checkout, list);
|
|
@@ -906,7 +936,30 @@ public class OrderFlowService {
|
|
|
return userOrderCheckoutService.allByUserBase(userId, 0).size();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 选中购物车
|
|
|
+ * @param userId
|
|
|
+ * @param checkoutId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public int selectCheckout(Integer userId, Integer checkoutId, Boolean select){
|
|
|
+ UserOrderCheckout in = userOrderCheckoutService.get(checkoutId);
|
|
|
+ if (in == null){
|
|
|
+ throw new ParameterException("记录不存在");
|
|
|
+ }
|
|
|
+ if (!in.getUserId().equals(userId)){
|
|
|
+ throw new ParameterException("记录不存在");
|
|
|
+ }
|
|
|
+ if (in.getParentId() != null && in.getParentId() > 0){
|
|
|
+ // 如果能删除子项目,要处理删除父项目,转移其他子项目
|
|
|
+ throw new ParameterException("套餐内,不允许单独选中");
|
|
|
+ }
|
|
|
+ userOrderCheckoutService.edit(UserOrderCheckout.builder().id(checkoutId).isSelect(select ? 1 : 0).build());
|
|
|
|
|
|
+ // 计算购物车数量
|
|
|
+ return userOrderCheckoutService.allByUserBase(userId, 0).size();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 删除购物车
|
|
@@ -950,6 +1003,8 @@ public class OrderFlowService {
|
|
|
* @return
|
|
|
*/
|
|
|
public UserOrder preOrderWithCheckout(Integer userId, List<UserOrderCheckout> list){
|
|
|
+ // 计算选中
|
|
|
+ list = list.stream().filter((checkout)->checkout.getIsSelect() > 0).collect(Collectors.toList());
|
|
|
UserOrder order = UserOrder.builder()
|
|
|
.userId(userId)
|
|
|
.originMoney(BigDecimal.valueOf(0))
|