|
@@ -33,8 +33,7 @@ import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.ym.mec.biz.dal.enums.SysUserRoleEnum.ORGAN_MANAGER;
|
|
|
-import static java.math.BigDecimal.ROUND_DOWN;
|
|
|
-import static java.math.BigDecimal.ROUND_UP;
|
|
|
+import static java.math.BigDecimal.*;
|
|
|
|
|
|
@Service
|
|
|
public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGroupActivity> implements VipGroupActivityService {
|
|
@@ -298,7 +297,7 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
}
|
|
|
Map<Long, Long> maps = MapUtil.convertIntegerMap(vipGroupActivityDao.countOrganGiveMemberNum(organIdList));
|
|
|
for (DoubleEleven2021Dto doubleEleven2021Dto : doubleEleven2021Dtos) {
|
|
|
- if(doubleEleven2021Dto.getTotalBuyAmount().compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ if(doubleEleven2021Dto.getTotalBuyAmount().compareTo(ZERO) > 0){
|
|
|
doubleEleven2021Dto.setAvgBuyAmount(
|
|
|
doubleEleven2021Dto.getTotalBuyAmount().divide(new BigDecimal(doubleEleven2021Dto.getTotalBuyNum()),2,BigDecimal.ROUND_CEILING));
|
|
|
}
|
|
@@ -419,7 +418,7 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
public Object doubleEleven2021Statis() {
|
|
|
//获取总成交数据
|
|
|
DoubleEleven2021Dto doubleEleven2021Dto = vipGroupActivityDao.countDoubleEleven2021Statis();
|
|
|
- if(doubleEleven2021Dto.getTotalBuyAmount().compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ if(doubleEleven2021Dto.getTotalBuyAmount().compareTo(ZERO) > 0){
|
|
|
doubleEleven2021Dto.setAvgBuyAmount(
|
|
|
doubleEleven2021Dto.getTotalBuyAmount().divide(new BigDecimal(doubleEleven2021Dto.getTotalBuyNum()),2,BigDecimal.ROUND_CEILING));
|
|
|
}
|
|
@@ -560,17 +559,16 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
}
|
|
|
|
|
|
BigDecimal amount = studentPaymentOrder.getActualAmount();
|
|
|
- BigDecimal balance = BigDecimal.ZERO;
|
|
|
String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
|
//分类费用 course,instrument,accessories,other
|
|
|
Map<String, BigDecimal> classFee = new HashMap<>();
|
|
|
classFee.put("course", amount);
|
|
|
- classFee.put("instrument", BigDecimal.ZERO);
|
|
|
- classFee.put("accessories", BigDecimal.ZERO);
|
|
|
- classFee.put("other", BigDecimal.ZERO);
|
|
|
+ classFee.put("instrument", ZERO);
|
|
|
+ classFee.put("accessories", ZERO);
|
|
|
+ classFee.put("other", ZERO);
|
|
|
Map<String, Object> payMap = payService.getPayMap(
|
|
|
amount,
|
|
|
- balance,
|
|
|
+ studentPaymentOrder.getBalancePaymentAmount(),
|
|
|
orderNo,
|
|
|
baseApiUrl + "/api-student/studentOrder/callback",
|
|
|
baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
@@ -605,7 +603,7 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
//发送短信
|
|
|
this.sendSuccessMsg(studentPaymentOrder);
|
|
|
}else {
|
|
|
- if (Objects.nonNull(studentPaymentOrder.getBalancePaymentAmount()) && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (Objects.nonNull(studentPaymentOrder.getBalancePaymentAmount()) && studentPaymentOrder.getBalancePaymentAmount().compareTo(ZERO) > 0) {
|
|
|
sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, studentPaymentOrder.getMemo() + "支付失败,退还余额");
|
|
|
}
|
|
|
sysCouponCodeService.quit(studentPaymentOrder.getCouponCodeId());
|
|
@@ -639,6 +637,96 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional( rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
|
|
|
+ public HttpResponseResult buyDoubleEleven2022(BuyDoubleEleven2022Dto payParam) throws Exception {
|
|
|
+ String activityIdList = payParam.getActivityIdList();
|
|
|
+ List<VipGroupActivity> vipGroupActivities = vipGroupActivityDao.queryByIds(activityIdList);
|
|
|
+ Student student = studentDao.getLocked(payParam.getUserId());
|
|
|
+ BigDecimal activityFee = ZERO;
|
|
|
+ for (int i = 0; i < vipGroupActivities.size(); i++) {
|
|
|
+ VipGroupActivity activity = vipGroupActivities.get(i);
|
|
|
+ //校验活动时间
|
|
|
+ SysConfigService.checkActivityDate(activity.getStartTime(),activity.getEndTime());
|
|
|
+ Integer studentMaxUsedTimes = activity.getStudentMaxUsedTimes();
|
|
|
+ if(studentMaxUsedTimes != -1){
|
|
|
+ //获取活动购买次数
|
|
|
+ int activityBuyNum = activityUserMapperService.countActivityBuyNum(activity.getId(), payParam.getUserId());
|
|
|
+ if(activityBuyNum >= studentMaxUsedTimes){
|
|
|
+ throw new BizException("{}活动最多课购买{}次,感谢您的参与",activity.getName(),studentMaxUsedTimes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ activityFee = activityFee.add(activity.getMarketPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断是否存在支付中的记录
|
|
|
+ List<StudentPaymentOrder> list = studentPaymentOrderService
|
|
|
+ .queryByCondition(GroupType.ACTIVITY,
|
|
|
+ payParam.getActivityIdList(),
|
|
|
+ payParam.getUserId(),
|
|
|
+ DealStatusEnum.ING,OrderTypeEnum.SMALL_CLASS_TO_BUY);
|
|
|
+
|
|
|
+ if (list.size() > 0) {
|
|
|
+ StudentPaymentOrder applyOrder = list.get(list.size() - 1);
|
|
|
+ //校验重复支付
|
|
|
+ HttpResponseResult result = studentPaymentOrderService.checkRepeatPay(applyOrder, payParam.getRepeatPay());
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算订单金额
|
|
|
+ StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(payParam.getCouponIdList(), activityFee, true);
|
|
|
+ activityFee = studentPaymentOrder.getActualAmount();
|
|
|
+
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ studentPaymentOrder.setMemo("2022双十一活动购买");
|
|
|
+ studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
+ studentPaymentOrder.setUserId(student.getUserId());
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.ACTIVITY);
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.SMALL_CLASS_TO_BUY);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setRemitFee(ZERO);
|
|
|
+ studentPaymentOrder.setCourseRemitFee(ZERO);
|
|
|
+ studentPaymentOrder.setOrganId(payParam.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(payParam.getOrganId());
|
|
|
+ studentPaymentOrder.setActivityId(activityIdList);
|
|
|
+ studentPaymentOrder.setMusicGroupId(activityIdList);
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+ studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
+
|
|
|
+
|
|
|
+ //消耗余额
|
|
|
+ Boolean success = sysUserCashAccountService.use(payParam,studentPaymentOrder);
|
|
|
+ if(success){
|
|
|
+ this.orderCallback(studentPaymentOrder);
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("orderNo", studentPaymentOrder.getOrderNo());
|
|
|
+ return BaseController.succeed(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderSubject = "2022双十一活动";
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
|
+ Map payMap = payService.getPayMap(
|
|
|
+ activityFee,
|
|
|
+ studentPaymentOrder.getBalancePaymentAmount(),
|
|
|
+ orderNo,
|
|
|
+ baseApiUrl + "/api-student/studentOrder/notify",
|
|
|
+ baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
+ orderSubject,
|
|
|
+ orderSubject,
|
|
|
+ studentPaymentOrder.getOrganId(),
|
|
|
+ "vip"
|
|
|
+ );
|
|
|
+
|
|
|
+ studentPaymentOrder.setOrganId(studentPaymentOrder.getOrganId());
|
|
|
+ studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ return BaseController.succeed(payMap);
|
|
|
+ }
|
|
|
+
|
|
|
private void sendSuccessMsg(StudentPaymentOrder studentPaymentOrder){
|
|
|
Integer userId = studentPaymentOrder.getUserId();
|
|
|
VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(Integer.parseInt(studentPaymentOrder.getActivityId()));
|