|
@@ -1,32 +1,40 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
|
import com.ym.mec.biz.dal.dto.*;
|
|
|
-import com.ym.mec.biz.dal.entity.ActivityApplyStudentType;
|
|
|
-import com.ym.mec.biz.dal.entity.Teacher;
|
|
|
-import com.ym.mec.biz.dal.entity.VipGroupActivity;
|
|
|
-import com.ym.mec.biz.dal.entity.VipGroupCategory;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
+import com.ym.mec.biz.dal.enums.*;
|
|
|
import com.ym.mec.biz.dal.page.ActivityStudentQueryInfo;
|
|
|
import com.ym.mec.biz.dal.page.DoubleEleven2021QueryInfo;
|
|
|
import com.ym.mec.biz.dal.page.VipGroupActivityQueryInfo;
|
|
|
-import com.ym.mec.biz.service.VipGroupActivityService;
|
|
|
+import com.ym.mec.biz.service.*;
|
|
|
+import com.ym.mec.common.constant.CommonConstants;
|
|
|
+import com.ym.mec.common.controller.BaseController;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
+import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
+import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
+import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
-
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
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;
|
|
|
+
|
|
|
@Service
|
|
|
public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGroupActivity> implements VipGroupActivityService {
|
|
|
|
|
@@ -39,7 +47,35 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
@Autowired
|
|
|
private VipGroupCategoryDao vipGroupCategoryDao;
|
|
|
@Autowired
|
|
|
+ private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
+ @Autowired
|
|
|
+ private ActivityUserMapperService activityUserMapperService;
|
|
|
+ @Autowired
|
|
|
+ private SysCouponCodeService sysCouponCodeService;
|
|
|
+ @Autowired
|
|
|
+ private MemberFeeSettingService memberFeeSettingService;
|
|
|
+ @Autowired
|
|
|
+ private PracticeGroupSellPriceService practiceGroupSellPriceService;
|
|
|
+ @Autowired
|
|
|
+ private VipGroupDefaultClassesUnitPriceService vipGroupDefaultClassesUnitPriceService;
|
|
|
+ @Autowired
|
|
|
+ private IdGeneratorService idGeneratorService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserCashAccountService sysUserCashAccountService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
|
+ @Autowired
|
|
|
private SysConfigDao sysConfigDao;
|
|
|
+ @Autowired
|
|
|
+ private PayService payService;
|
|
|
+ @Autowired
|
|
|
+ private StudentRegistrationDao studentRegistrationDao;
|
|
|
+ @Autowired
|
|
|
+ private SysEmployeePositionService employeePositionService;
|
|
|
+ @Autowired
|
|
|
+ private SysMessageService sysMessageService;
|
|
|
+ @Autowired
|
|
|
+ private StudentDao studentDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, VipGroupActivity> getDAO() {
|
|
@@ -62,7 +98,12 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
+ public VipGroupActivityDao getDao() {
|
|
|
+ return vipGroupActivityDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public VipGroupActivityAddDto addVipGroupActivity(VipGroupActivityAddDto vipGroupActivityAddDto) {
|
|
|
|
|
|
if(Objects.isNull(vipGroupActivityAddDto.getOrganId())){
|
|
@@ -147,19 +188,47 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
|
|
|
@Override
|
|
|
public List<VipGroupActivity> findByVipGroupCategory(ActivityQueryDto activityQueryDto) {
|
|
|
- Teacher teacher = teacherDao.get(activityQueryDto.getTeacherId());
|
|
|
- if(Objects.isNull(teacher)){
|
|
|
- throw new BizException("未找到指定教师");
|
|
|
+ if(activityQueryDto.getTeacherId() != null){
|
|
|
+ Teacher teacher = teacherDao.get(activityQueryDto.getTeacherId());
|
|
|
+ if(Objects.isNull(teacher)){
|
|
|
+ throw new BizException("未找到指定教师");
|
|
|
+ }
|
|
|
+ String organId = activityQueryDto.getOrganId();
|
|
|
+ if(StringUtils.isBlank(organId)){
|
|
|
+ organId = teacher.getTeacherOrganId().toString();
|
|
|
+ if (StringUtils.isNotEmpty(teacher.getFlowOrganRange())) {
|
|
|
+ organId += "," + teacher.getFlowOrganRange();
|
|
|
+ }
|
|
|
+ activityQueryDto.setOrganId(organId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<VipGroupActivity> activityList = vipGroupActivityDao.findByCategory(activityQueryDto);
|
|
|
+ if(!CollectionUtils.isEmpty(activityList)){
|
|
|
+ Integer organId = Integer.parseInt(activityQueryDto.getOrganId());
|
|
|
+ BigDecimal buyNum = new BigDecimal(1);
|
|
|
+ activityList.stream().forEach(e->e.setSinglePrice(this.getActivityPrice(e,organId,buyNum)));
|
|
|
}
|
|
|
- String organId = activityQueryDto.getOrganId();
|
|
|
- if(StringUtils.isBlank(organId)){
|
|
|
- organId = teacher.getTeacherOrganId().toString();
|
|
|
- if (StringUtils.isNotEmpty(teacher.getFlowOrganRange())) {
|
|
|
- organId += "," + teacher.getFlowOrganRange();
|
|
|
+ return activityList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BigDecimal getActivityPrice(VipGroupActivity vipGroupActivity, Integer organId, BigDecimal buyNum){
|
|
|
+ BigDecimal actualAmount;
|
|
|
+ if(vipGroupActivity.getActivityType().equals(1)){
|
|
|
+
|
|
|
+ actualAmount = memberFeeSettingService.getAmount(organId,1,
|
|
|
+ vipGroupActivity.getPeriodEnum(),buyNum,
|
|
|
+ MemberFeeSettingServiceImpl::getCurrentFee);
|
|
|
+ }else {
|
|
|
+ if (StringUtils.isEmpty(vipGroupActivity.getVipGroupCategoryIdList())){
|
|
|
+
|
|
|
+ actualAmount = practiceGroupSellPriceService.getAmount(organId,buyNum);
|
|
|
+ }else {
|
|
|
+
|
|
|
+ actualAmount = vipGroupDefaultClassesUnitPriceService.getAmount(organId,buyNum);
|
|
|
}
|
|
|
- activityQueryDto.setOrganId(organId);
|
|
|
}
|
|
|
- return vipGroupActivityDao.findByCategory(activityQueryDto);
|
|
|
+ return actualAmount;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -398,4 +467,185 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
|
|
|
pageInfo.setRows(dataList);
|
|
|
return pageInfo;
|
|
|
}
|
|
|
+
|
|
|
+ private VipGroupActivity checkActivityBuy(ActivityPayParamDto payParam){
|
|
|
+ VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(payParam.getVipGroupActivityId());
|
|
|
+ if (Objects.nonNull(vipGroupActivity.getStudentMaxUsedTimes()) && vipGroupActivity.getStudentMaxUsedTimes() != -1) {
|
|
|
+ int useNum = activityUserMapperService.countActivityBuyNum(vipGroupActivity.getId(), payParam.getUserId());
|
|
|
+ if (useNum >= vipGroupActivity.getStudentMaxUsedTimes()) {
|
|
|
+ throw new BizException("您已超过该活动购买限制{}次", vipGroupActivity.getStudentMaxUsedTimes());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(vipGroupActivity.getMinCourseNum())
|
|
|
+ && vipGroupActivity.getMinCourseNum() != -1 && Objects.nonNull(vipGroupActivity.getMaxCourseNum())
|
|
|
+ && vipGroupActivity.getMaxCourseNum() != -1) {
|
|
|
+ if (payParam.getBuyNum().compareTo(vipGroupActivity.getMinCourseNum()) < 0 || payParam.getBuyNum().compareTo(vipGroupActivity.getMaxCourseNum()) > 0) {
|
|
|
+ throw new BizException("该活动课时数为{}节~{}节", vipGroupActivity.getMinCourseNum(), vipGroupActivity.getMaxCourseNum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return vipGroupActivity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public HttpResponseResult buy(ActivityPayParamDto payParam) throws Exception {
|
|
|
+
|
|
|
+ VipGroupActivity vipGroupActivity = this.checkActivityBuy(payParam);
|
|
|
+
|
|
|
+ OrderTypeEnum type;
|
|
|
+ CouponDetailTypeEnum couponType;
|
|
|
+ if(vipGroupActivity.getActivityType().equals(1)){
|
|
|
+ type = OrderTypeEnum.MEMBER;
|
|
|
+ couponType = CouponDetailTypeEnum.MEMBER;
|
|
|
+ }else {
|
|
|
+ if (StringUtils.isEmpty(vipGroupActivity.getVipGroupCategoryIdList())){
|
|
|
+ type = OrderTypeEnum.PRACTICE_GROUP_BUY;
|
|
|
+ couponType = CouponDetailTypeEnum.PRACTICE;
|
|
|
+ }else {
|
|
|
+ type = OrderTypeEnum.SMALL_CLASS_TO_BUY;
|
|
|
+ couponType = CouponDetailTypeEnum.VIP;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal actualAmount = this.getActivityPrice(vipGroupActivity,payParam.getOrganId(),new BigDecimal(payParam.getBuyNum()));
|
|
|
+ actualAmount = actualAmount.multiply(vipGroupActivity.getDiscount()).divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
|
|
|
+
|
|
|
+ List<StudentPaymentOrder> list = studentPaymentOrderService
|
|
|
+ .queryByCondition(GroupType.ACTIVITY,
|
|
|
+ payParam.getVipGroupActivityId().toString(),
|
|
|
+ payParam.getUserId(),
|
|
|
+ DealStatusEnum.ING,type);
|
|
|
+
|
|
|
+ if (list.size() > 0) {
|
|
|
+ StudentPaymentOrder applyOrder = list.get(list.size() - 1);
|
|
|
+
|
|
|
+ HttpResponseResult result = studentPaymentOrderService.checkRepeatPay(applyOrder, payParam.getRepeatPay());
|
|
|
+ if (result.getCode() != 200) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String[] checkCoupon = CouponDetailTypeEnum.getAllowType(couponType);
|
|
|
+ StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(payParam.getCouponIdList(), actualAmount, true, checkCoupon);
|
|
|
+ if(payParam.getAmount().compareTo(studentPaymentOrder.getActualAmount()) != 0){
|
|
|
+ throw new BizException("非法请求");
|
|
|
+ }
|
|
|
+ studentPaymentOrder.setUserId(payParam.getUserId());
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.ACTIVITY);
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.SMALL_CLASS_TO_BUY);
|
|
|
+ studentPaymentOrder.setMusicGroupId(payParam.getVipGroupActivityId().toString());
|
|
|
+ studentPaymentOrder.setOrganId(payParam.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(payParam.getOrganId());
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+ studentPaymentOrder.setActivityBuyNum(payParam.getBuyNum());
|
|
|
+ studentPaymentOrder.setActivityId(payParam.getVipGroupActivityId().toString());
|
|
|
+ studentPaymentOrder.setMemo("学员活动购买");
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal amount = studentPaymentOrder.getActualAmount();
|
|
|
+ BigDecimal balance = BigDecimal.ZERO;
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
|
|
|
+
|
|
|
+ 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);
|
|
|
+ Map<String, Object> payMap = payService.getPayMap(
|
|
|
+ amount,
|
|
|
+ balance,
|
|
|
+ orderNo,
|
|
|
+ baseApiUrl + "/api-student/studentOrder/callback",
|
|
|
+ baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
+ "学员活动购买",
|
|
|
+ vipGroupActivity.getName(),
|
|
|
+ payParam.getOrganId(),
|
|
|
+ "activityBuy"
|
|
|
+ );
|
|
|
+
|
|
|
+ studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ return BaseController.succeed(payMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ private StudentPaymentOrder checkOrderStatus(StudentPaymentOrder studentPaymentOrder){
|
|
|
+ StudentPaymentOrder order = studentPaymentOrderService.lockOrder(studentPaymentOrder.getId());
|
|
|
+ if (!order.getStatus().equals(DealStatusEnum.ING)) {
|
|
|
+ throw new BizException("订单状态异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ int updateCount = studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ if (updateCount <= 0) {
|
|
|
+ throw new BizException("订单更新失败");
|
|
|
+ }
|
|
|
+ return order;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
+ public void orderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
+ studentPaymentOrder = this.checkOrderStatus(studentPaymentOrder);
|
|
|
+ if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
|
|
|
+
|
|
|
+ studentPaymentOrderService.activityGive(Integer.parseInt(studentPaymentOrder.getActivityId()), studentPaymentOrder,
|
|
|
+ null, null, null);
|
|
|
+
|
|
|
+ sysUserCashAccountDetailService.saveSysUserCashAccountDetail(studentPaymentOrder,studentPaymentOrder.getMemo());
|
|
|
+
|
|
|
+ this.sendSuccessMsg(studentPaymentOrder);
|
|
|
+ }else {
|
|
|
+ if (Objects.nonNull(studentPaymentOrder.getBalancePaymentAmount()) && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, studentPaymentOrder.getMemo() + "支付失败,退还余额");
|
|
|
+ }
|
|
|
+ sysCouponCodeService.quit(studentPaymentOrder.getCouponCodeId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendSuccessMsg(StudentPaymentOrder studentPaymentOrder){
|
|
|
+ Integer userId = studentPaymentOrder.getUserId();
|
|
|
+ VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(Integer.parseInt(studentPaymentOrder.getActivityId()));
|
|
|
+ String activityName = vipGroupActivity.getName();
|
|
|
+ SysUser user = teacherDao.getUser(userId);
|
|
|
+ String username = StringUtils.isEmpty(user.getUsername())?user.getRealName():user.getUsername();
|
|
|
+ Map<Integer, String> map = new HashMap<>(1);
|
|
|
+ map.put(userId, userId.toString());
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.PUSH_STUDENT_BUY_ACTIVITY, map, null, 0,null, "STUDENT",
|
|
|
+ activityName);
|
|
|
+
|
|
|
+ Map<Integer, String> eduMap = studentRegistrationDao.queryStudentEduMap(userId);
|
|
|
+ if(CollectionUtils.isEmpty(eduMap)){
|
|
|
+ Set<Integer> integers = employeePositionService.queryUserIdByRoleId(new SysUserRoleEnum[]{ORGAN_MANAGER}, studentPaymentOrder.getOrganId());
|
|
|
+ if(!CollectionUtils.isEmpty(integers)){
|
|
|
+ for (Integer integer : integers) {
|
|
|
+ eduMap.put(integer,integer.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!CollectionUtils.isEmpty(eduMap)){
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,MessageTypeEnum.PUSH_SYSTEM_ACTIVITY_COURSE,
|
|
|
+ eduMap,null,0,null,"SYSTEM",username,activityName);
|
|
|
+ }
|
|
|
+ Student student = studentDao.get(userId);
|
|
|
+ if(Objects.nonNull(student) && student.getTeacherId() != null){
|
|
|
+ Map<Integer, String> teacherMap = new HashMap<>(1);
|
|
|
+ teacherMap.put(student.getTeacherId(), student.getTeacherId().toString());
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,MessageTypeEnum.PUSH_TEACHER_ACTIVITY_COURSE,
|
|
|
+ teacherMap,null,0,null,"TEACHER",username,activityName);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|