Ver Fonte

2022双十一

zouxuan há 2 anos atrás
pai
commit
d48c8b5aec

+ 0 - 95
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/BuyDoubleEleven2021Dto.java

@@ -1,95 +0,0 @@
-package com.ym.mec.biz.dal.dto;
-
-import io.swagger.annotations.ApiModelProperty;
-
-import java.math.BigDecimal;
-import java.util.List;
-
-public class BuyDoubleEleven2021Dto {
-
-    @ApiModelProperty(value = "付款渠道")
-    private String paymentChannel;
-
-    @ApiModelProperty(value = "业务渠道")
-    private String paymentBusinessChannel;
-
-    @ApiModelProperty(value = "是否使用账户余额支付")
-    private boolean isUseBalancePayment;
-
-    @ApiModelProperty(value = "是否重新支付")
-    private boolean isRepeatPay;
-
-    @ApiModelProperty(value = "营销活动编号")
-    private String activityIdList;
-
-    @ApiModelProperty(value = "优惠券列表", required = false)
-    private List<Integer> couponIdList;
-
-    private Integer organId;
-
-    private Integer userId;
-
-    public String getActivityIdList() {
-        return activityIdList;
-    }
-
-    public void setActivityIdList(String activityIdList) {
-        this.activityIdList = activityIdList;
-    }
-
-    public Integer getOrganId() {
-        return organId;
-    }
-
-    public void setOrganId(Integer organId) {
-        this.organId = organId;
-    }
-
-    public List<Integer> getCouponIdList() {
-        return couponIdList;
-    }
-
-    public void setCouponIdList(List<Integer> couponIdList) {
-        this.couponIdList = couponIdList;
-    }
-
-    public boolean isRepeatPay() {
-        return isRepeatPay;
-    }
-
-    public void setRepeatPay(boolean repeatPay) {
-        isRepeatPay = repeatPay;
-    }
-
-    public boolean isUseBalancePayment() {
-        return isUseBalancePayment;
-    }
-
-    public void setUseBalancePayment(boolean useBalancePayment) {
-        isUseBalancePayment = useBalancePayment;
-    }
-
-    public Integer getUserId() {
-        return userId;
-    }
-
-    public void setUserId(Integer userId) {
-        this.userId = userId;
-    }
-
-    public String getPaymentChannel() {
-        return paymentChannel;
-    }
-
-    public void setPaymentChannel(String paymentChannel) {
-        this.paymentChannel = paymentChannel;
-    }
-
-    public String getPaymentBusinessChannel() {
-        return paymentBusinessChannel;
-    }
-
-    public void setPaymentBusinessChannel(String paymentBusinessChannel) {
-        this.paymentBusinessChannel = paymentBusinessChannel;
-    }
-}

+ 42 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/BuyDoubleEleven2022Dto.java

@@ -0,0 +1,42 @@
+package com.ym.mec.biz.dal.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class BuyDoubleEleven2022Dto extends PayParamBasicDto implements Serializable {
+
+    @ApiModelProperty(value = "营销活动编号")
+    private String activityIdList;
+
+    @ApiModelProperty(value = "分部")
+    private Integer organId;
+
+    @ApiModelProperty(value = "用户编号")
+    private Integer userId;
+
+    public Integer getOrganId() {
+        return organId;
+    }
+
+    public void setOrganId(Integer organId) {
+        this.organId = organId;
+    }
+
+    public String getActivityIdList() {
+        return activityIdList;
+    }
+
+    public void setActivityIdList(String activityIdList) {
+        this.activityIdList = activityIdList;
+    }
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+}

+ 2 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/OrderTypeEnum.java

@@ -11,8 +11,8 @@ public enum OrderTypeEnum implements BaseEnum<String, OrderTypeEnum> {
     RENEW("RENEW", "乐团续费"),
     SPORADIC("SPORADIC", "缴费"),
     OTHER("OTHER", "其他订单"),
-    SMALL_CLASS_TO_BUY("SMALL_CLASS_TO_BUY", "VIP课报名"),
-    PRACTICE_GROUP_BUY("PRACTICE_GROUP_BUY", "网管课报名"),
+    SMALL_CLASS_TO_BUY("SMALL_CLASS_TO_BUY", "VIP课购买"),
+    PRACTICE_GROUP_BUY("PRACTICE_GROUP_BUY", "网管课购买"),
     PRACTICE_GROUP_RENEW("PRACTICE_GROUP_RENEW", "网管课续费"),
     COURSE_GROUP_BUY("COURSE_GROUP_BUY", "课程购买"),
     //余额充值活动

+ 4 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/SysConfigService.java

@@ -398,12 +398,14 @@ public interface SysConfigService extends BaseService<Long, SysConfig> {
     String TENANT_CLOUD_ROOM_BALANCE_NOTICE = "tenant_cloud_room_balance_notice_";
 
     static Date checkActivityDate(String startTimeStr, String endTimeStr) {
+        return checkActivityDate(DateUtil.stringToDate(startTimeStr),DateUtil.stringToDate(endTimeStr));
+    }
+
+    static Date checkActivityDate(Date startTime, Date endTime) {
         Date now = new Date();
-        Date startTime = DateUtil.stringToDate(startTimeStr);
         if (startTime.compareTo(now) > 0) {
             throw new BizException("活动还未开始,谢谢关注");
         }
-        Date endTime = DateUtil.stringToDate(endTimeStr);
         if (endTime.compareTo(now) <= 0) {
             throw new BizException("活动已结束,谢谢关注");
         }

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/VipGroupActivityService.java

@@ -116,6 +116,8 @@ public interface VipGroupActivityService extends BaseService<Integer, VipGroupAc
     */
     HttpResponseResult buy(ActivityPayParamDto activityPayParamDto) throws Exception;
 
+    HttpResponseResult buyDoubleEleven2022(BuyDoubleEleven2022Dto buyDoubleEleven2022Dto) throws Exception;
+
     void orderCallback(StudentPaymentOrder studentPaymentOrder);
 
     void setActivityType(VipGroupActivity activity);

+ 1 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysUserCashAccountServiceImpl.java

@@ -335,12 +335,10 @@ public class SysUserCashAccountServiceImpl extends BaseServiceImpl<Integer, SysU
             if (userCashAccount.getBalance().subtract(amount).doubleValue() >= 0) {
                 studentPaymentRouteOrderService.addRouteOrder(studentPaymentOrder.getOrderNo(), studentPaymentOrder.getOrganId(),amount);
                 // 更新订单信息
-                studentPaymentOrder.setActualAmount(new BigDecimal(0));
+                studentPaymentOrder.setActualAmount(BigDecimal.ZERO);
                 studentPaymentOrder.setBalancePaymentAmount(amount);
                 studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
                 studentPaymentOrder.setRoutingOrganId(studentPaymentOrder.getOrganId());
-//                studentPaymentOrderService.orderCallback(studentPaymentOrder);
-
                 this.updateBalance(studentPaymentOrder.getUserId(), amount.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, studentPaymentOrder.getMemo());
                 return true;
             } else {

+ 98 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupActivityServiceImpl.java

@@ -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()));

+ 29 - 19
mec-student/src/main/java/com/ym/mec/student/controller/ActivityController.java

@@ -6,26 +6,20 @@ import com.ym.mec.biz.dal.dao.StudentDao;
 import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dao.VipGroupCategoryDao;
-import com.ym.mec.biz.dal.dto.ActivityPayParamDto;
-import com.ym.mec.biz.dal.dto.ActivityQueryDto;
-import com.ym.mec.biz.dal.dto.Cloud2022ActivityDto;
-import com.ym.mec.biz.dal.dto.ConditionDto;
+import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.ActivityDetailDto;
 import com.ym.mec.biz.dal.entity.SporadicChargeInfo;
 import com.ym.mec.biz.dal.entity.Student;
 import com.ym.mec.biz.dal.entity.VipGroupActivity;
-import com.ym.mec.biz.service.MarketActivityService;
-import com.ym.mec.biz.service.SporadicChargeInfoService;
-import com.ym.mec.biz.service.SysUserService;
-import com.ym.mec.biz.service.VipGroupActivityService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
+import com.ym.mec.common.exception.BizException;
 import com.yonge.log.model.AuditLogAnnotation;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
@@ -54,6 +48,32 @@ public class ActivityController extends BaseController {
     @Autowired
     private VipGroupCategoryDao vipGroupCategoryDao;
 
+    @ApiOperation("活动购买")
+    @PostMapping(value = "/buy")
+    @AuditLogAnnotation(operateName = "学生端活动购买")
+    public HttpResponseResult buy(@RequestBody ActivityPayParamDto activityPayParamDto) throws Exception {
+        SysUser user = sysUserService.getUser();
+        activityPayParamDto.setUserId(user.getId());
+        activityPayParamDto.setOrganId(user.getOrganId());
+        return vipGroupActivityService.buy(activityPayParamDto);
+    }
+
+    @ApiOperation("2022双十一活动购买")
+    @PostMapping(value = "/buyDoubleEleven2022")
+    @AuditLogAnnotation(operateName = "2022双十一活动购买")
+    public HttpResponseResult buyDoubleEleven2022(@RequestBody BuyDoubleEleven2022Dto buyDoubleEleven2022Dto) throws Exception {
+        String startTimeStr = sysConfigDao.findConfigValue(SysConfigService.START_TIME_OF_1111);
+        String endTimeStr = sysConfigDao.findConfigValue(SysConfigService.END_TIME_OF_1111);
+        SysConfigService.checkActivityDate(startTimeStr,endTimeStr);
+        if(StringUtils.isEmpty(buyDoubleEleven2022Dto.getActivityIdList())){
+            throw new BizException("请选择活动");
+        }
+        SysUser sysUser = sysUserService.getUser();
+        buyDoubleEleven2022Dto.setOrganId(sysUser.getOrganId());
+        buyDoubleEleven2022Dto.setUserId(sysUser.getId());
+        return vipGroupActivityService.buyDoubleEleven2022(buyDoubleEleven2022Dto);
+    }
+
     @ApiOperation(value = "分部双11活动信息")
     @GetMapping("/doubleEleven2020")
     public HttpResponseResult<List<SporadicChargeInfo>> doubleEleven2020(){
@@ -85,16 +105,6 @@ public class ActivityController extends BaseController {
         return succeed(resultMap);
     }
 
-    @ApiOperation("活动购买")
-    @PostMapping(value = "/buy")
-    @AuditLogAnnotation(operateName = "活动购买")
-    public HttpResponseResult buy(@RequestBody ActivityPayParamDto activityPayParamDto) throws Exception {
-        SysUser user = sysUserService.getUser();
-        activityPayParamDto.setUserId(user.getId());
-        activityPayParamDto.setOrganId(user.getOrganId());
-        return vipGroupActivityService.buy(activityPayParamDto);
-    }
-
     @ApiOperation("获取2022云教练活动列表")
     @PostMapping(value = "/queryActivity")
     @AuditLogAnnotation(operateName = "获取2022云教练活动列表")