Commit d38cdb01 authored by liuyang's avatar liuyang

订单完成的逻辑处理

parent ec0f209c
package com.qkdata.biz.management.entity; package com.qkdata.biz.management.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.qkdata.biz.enums.ProductTypeEnum;
import com.qkdata.common.base.entity.BasePO; import com.qkdata.common.base.entity.BasePO;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
...@@ -14,12 +16,16 @@ import lombok.EqualsAndHashCode; ...@@ -14,12 +16,16 @@ import lombok.EqualsAndHashCode;
* @since 2021-06-03 * @since 2021-06-03
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true)
@TableName("org_surplus") @TableName("org_surplus")
public class OrgSurplusPO extends BasePO { public class OrgSurplusPO {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId
private Long id;
/** /**
* 企业ID * 企业ID
*/ */
...@@ -33,7 +39,7 @@ public class OrgSurplusPO extends BasePO { ...@@ -33,7 +39,7 @@ public class OrgSurplusPO extends BasePO {
/** /**
* 产品类型 * 产品类型
*/ */
private String productType; private ProductTypeEnum productType;
/** /**
* 剩余数量 * 剩余数量
......
package com.qkdata.biz.management.entity; package com.qkdata.biz.management.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.qkdata.common.base.entity.BasePO;
import java.time.LocalDateTime;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/** /**
* <p> * <p>
...@@ -15,12 +15,16 @@ import lombok.EqualsAndHashCode; ...@@ -15,12 +15,16 @@ import lombok.EqualsAndHashCode;
* @since 2021-06-03 * @since 2021-06-03
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true)
@TableName("user_course_auth") @TableName("user_course_auth")
public class UserCourseAuthPO extends BasePO { public class UserCourseAuthPO {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId
private Long id;
/** /**
* 用户ID * 用户ID
*/ */
...@@ -41,10 +45,6 @@ public class UserCourseAuthPO extends BasePO { ...@@ -41,10 +45,6 @@ public class UserCourseAuthPO extends BasePO {
*/ */
private LocalDateTime endTime; private LocalDateTime endTime;
/**
* 购买或领用
*/
private String type;
} }
package com.qkdata.biz.management.service; package com.qkdata.biz.management.service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qkdata.biz.enums.ProductTypeEnum;
import com.qkdata.biz.management.entity.OrgSurplusPO; import com.qkdata.biz.management.entity.OrgSurplusPO;
import com.qkdata.biz.management.mapper.OrgSurplusMapper; import com.qkdata.biz.management.mapper.OrgSurplusMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -16,4 +18,30 @@ import org.springframework.stereotype.Service; ...@@ -16,4 +18,30 @@ import org.springframework.stereotype.Service;
@Service @Service
public class OrgSurplusService extends ServiceImpl<OrgSurplusMapper, OrgSurplusPO> { public class OrgSurplusService extends ServiceImpl<OrgSurplusMapper, OrgSurplusPO> {
/**
* 更新企业VIP或课程余额
* @param orgId
* @param courseId
* @param productType
* @param count
*/
public void updateSurplus(Long orgId, Long courseId, ProductTypeEnum productType,Integer count) {
OrgSurplusPO po = null;
if (productType == ProductTypeEnum.ENTERPRISE_VIP){
po = getOne(Wrappers.<OrgSurplusPO>lambdaQuery().eq(OrgSurplusPO::getOrgId,orgId).eq(OrgSurplusPO::getProductType,productType));
}else if (productType == ProductTypeEnum.ENTERPRISE_COURSE_BUY){
po = getOne(Wrappers.<OrgSurplusPO>lambdaQuery().eq(OrgSurplusPO::getOrgId,orgId).eq(OrgSurplusPO::getCourseId,courseId).eq(OrgSurplusPO::getProductType,productType));
}
if (po == null){
po = new OrgSurplusPO();
po.setOrgId(orgId);
po.setCourseId(courseId);
po.setProductType(productType);
po.setCount(count);
save(po);
}else {
po.setCount(po.getCount()+count);
updateById(po);
}
}
} }
\ No newline at end of file
...@@ -8,6 +8,7 @@ import com.qkdata.biz.common.BizConstants; ...@@ -8,6 +8,7 @@ import com.qkdata.biz.common.BizConstants;
import com.qkdata.biz.enums.AccountStatusEnum; import com.qkdata.biz.enums.AccountStatusEnum;
import com.qkdata.biz.enums.AccountTypeEnum; import com.qkdata.biz.enums.AccountTypeEnum;
import com.qkdata.biz.enums.OrgTypeEnum; import com.qkdata.biz.enums.OrgTypeEnum;
import com.qkdata.biz.enums.VipReceiveEnum;
import com.qkdata.biz.management.entity.OrganizationPO; import com.qkdata.biz.management.entity.OrganizationPO;
import com.qkdata.biz.management.mapper.OrganizationMapper; import com.qkdata.biz.management.mapper.OrganizationMapper;
import com.qkdata.biz.management.vo.*; import com.qkdata.biz.management.vo.*;
...@@ -131,6 +132,7 @@ public class OrganizationService extends BaseServiceImpl<OrganizationMapper, Org ...@@ -131,6 +132,7 @@ public class OrganizationService extends BaseServiceImpl<OrganizationMapper, Org
po.setProvince(model.getProvince()); po.setProvince(model.getProvince());
po.setCity(model.getCity()); po.setCity(model.getCity());
po.setAddress(model.getAddress()); po.setAddress(model.getAddress());
po.setVipReceive(VipReceiveEnum.CLOSE);
save(po); save(po);
return po.getId(); return po.getId();
} }
......
...@@ -17,6 +17,7 @@ import com.qkdata.biz.common.BizConstants; ...@@ -17,6 +17,7 @@ import com.qkdata.biz.common.BizConstants;
import com.qkdata.biz.enums.*; import com.qkdata.biz.enums.*;
import com.qkdata.biz.management.entity.CoursePO; import com.qkdata.biz.management.entity.CoursePO;
import com.qkdata.biz.management.entity.ProductOrderPO; import com.qkdata.biz.management.entity.ProductOrderPO;
import com.qkdata.biz.management.entity.UserCourseAuthPO;
import com.qkdata.biz.management.mapper.ProductOrderMapper; import com.qkdata.biz.management.mapper.ProductOrderMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qkdata.biz.management.vo.ProductOrderModel; import com.qkdata.biz.management.vo.ProductOrderModel;
...@@ -68,6 +69,10 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product ...@@ -68,6 +69,10 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
private String frontendDomain; private String frontendDomain;
@Autowired @Autowired
private SysRoleService roleService; private SysRoleService roleService;
@Autowired
private UserCourseAuthService userCourseAuthService;
@Autowired
private OrgSurplusService orgSurplusService;
public void createOrder(UserBuyVIPModel model) { public void createOrder(UserBuyVIPModel model) {
...@@ -231,18 +236,24 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product ...@@ -231,18 +236,24 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
updateStatus(orderNo,ProductOrderStatusEnum.PAY_COMPLETE); updateStatus(orderNo,ProductOrderStatusEnum.PAY_COMPLETE);
ProductOrderPO orderPO = getByOrderNo(orderNo); ProductOrderPO orderPO = getByOrderNo(orderNo);
if (orderPO.getProductType() == ProductTypeEnum.USER_VIP){ if (orderPO.getProductType() == ProductTypeEnum.USER_VIP){
//TODO 更新用户VIP时间,用户从普通用户变为会员 LocalDateTime payCompleteTime = orderPO.getUpdateTime();//支付完成时间,即生效时间
LocalDateTime payCompleteTime = orderPO.getUpdateTime();//支付完成时间 int month = orderPO.getProductCount();//购买的几个月VIP
int count = orderPO.getProductCount();//购买的几个月VIP
Long userId = orderPO.getUserId(); Long userId = orderPO.getUserId();
sysUserService.updateVIPTimeLimit(userId,payCompleteTime,month);
}else if (orderPO.getProductType() == ProductTypeEnum.ENTERPRISE_VIP){ }else if (orderPO.getProductType() == ProductTypeEnum.ENTERPRISE_VIP){
//TODO 添加企业VIP购买记录 Long orgId = sysUserService.getUserEnterpriesId(orderPO.getUserId());
if (orgId != null){
orgSurplusService.updateSurplus(orgId,null,orderPO.getProductType(),orderPO.getProductCount());
}
}else if (orderPO.getProductType() == ProductTypeEnum.COURSE_BUY){ }else if (orderPO.getProductType() == ProductTypeEnum.COURSE_BUY){
//TODO 添加课程购买记录 userCourseAuthService.updateAuth(orderPO.getUserId(),orderPO.getCourseId(),orderPO.getUpdateTime());
}else if (orderPO.getProductType() == ProductTypeEnum.ENTERPRISE_COURSE_BUY){ }else if (orderPO.getProductType() == ProductTypeEnum.ENTERPRISE_COURSE_BUY){
//TODO 添加企业课程购买记录 Long orgId = sysUserService.getUserEnterpriesId(orderPO.getUserId());
if (orgId != null){
orgSurplusService.updateSurplus(orgId,orderPO.getCourseId(),orderPO.getProductType(),orderPO.getProductCount());
}
} }
} }
......
package com.qkdata.biz.management.service; package com.qkdata.biz.management.service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qkdata.biz.management.entity.CoursePO;
import com.qkdata.biz.management.entity.UserCourseAuthPO; import com.qkdata.biz.management.entity.UserCourseAuthPO;
import com.qkdata.biz.management.mapper.UserCourseAuthMapper; import com.qkdata.biz.management.mapper.UserCourseAuthMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
/** /**
* <p> * <p>
* 用户课程授权 服务类 * 用户课程授权 服务类
...@@ -16,4 +21,42 @@ import org.springframework.stereotype.Service; ...@@ -16,4 +21,42 @@ import org.springframework.stereotype.Service;
@Service @Service
public class UserCourseAuthService extends ServiceImpl<UserCourseAuthMapper, UserCourseAuthPO> { public class UserCourseAuthService extends ServiceImpl<UserCourseAuthMapper, UserCourseAuthPO> {
@Autowired
private CourseService courseService;
/**
* 更新用户课程授权
* 判断用户课程的授权记录是否存在,不存在:添加,存在:更新期限
* 更新期限时,判断当前是否过期,未过期:延期处理,已过期:更新新的期限
* @param userId
* @param courseId
* @param startTime 生效时间
*/
public void updateAuth(Long userId, Long courseId, LocalDateTime startTime) {
CoursePO coursePO = courseService.getById(courseId);
if (coursePO != null){
Integer validPeriod = coursePO.getValidPeriod();
UserCourseAuthPO po = getByUserIdAndCourseId(userId,courseId);
if (po == null){
po = new UserCourseAuthPO();
po.setUserId(userId);
po.setCourseId(courseId);
po.setStartTime(startTime);
po.setEndTime(startTime.plusHours(validPeriod));
save(po);
}else {
LocalDateTime now = LocalDateTime.now();
if (now.isAfter(po.getStartTime()) && now.isBefore(po.getEndTime())){
po.setEndTime(po.getEndTime().plusHours(validPeriod));
}else {
po.setStartTime(startTime);
po.setEndTime(startTime.plusHours(validPeriod));
}
updateById(po);
}
}
}
private UserCourseAuthPO getByUserIdAndCourseId(Long userId, Long courseId) {
return getOne(Wrappers.<UserCourseAuthPO>lambdaQuery().eq(UserCourseAuthPO::getUserId,userId).eq(UserCourseAuthPO::getCourseId,courseId));
}
} }
\ No newline at end of file
...@@ -143,4 +143,40 @@ public class SysUserService extends BaseServiceImpl<SysUserMapper, SysUserPO> { ...@@ -143,4 +143,40 @@ public class SysUserService extends BaseServiceImpl<SysUserMapper, SysUserPO> {
Long enterpriesId = userInfo.getId(); Long enterpriesId = userInfo.getId();
return enterpriesId; return enterpriesId;
} }
/**
* 更新用户VIP期限
* 用户为普通用户时:更新开始结束时间,更新用户为会员
* 用户为会员或企业会员时:判断用户VIP是否过期,已过期:更新开始、结束时间,未过期:延长结束时间
* @param userId
* @param startTime
* @param month 期限(几人月)
*/
public void updateVIPTimeLimit(Long userId, LocalDateTime startTime, int month) {
SysUserExtPO userExtPO = sysUserExtMapper.selectOne(Wrappers.<SysUserExtPO>lambdaQuery().eq(SysUserExtPO::getUserId,userId));
if (userExtPO != null){
if (userExtPO.getType() == AccountTypeEnum.USER){
userExtPO.setVipStartTime(startTime);
userExtPO.setVipEndTime(startTime.plusMonths(month));
userExtPO.setType(AccountTypeEnum.VIP);
}else {
LocalDateTime now = LocalDateTime.now();
if (now.isAfter(userExtPO.getVipStartTime()) && now.isBefore(userExtPO.getVipEndTime())){
userExtPO.setVipEndTime(userExtPO.getVipEndTime().plusMonths(month));
}else {
userExtPO.setVipStartTime(startTime);
userExtPO.setVipEndTime(startTime.plusMonths(month));
}
}
sysUserExtMapper.updateById(userExtPO);
}
}
public Long getUserEnterpriesId(Long userId) {
SysUserExtPO userExtPO = sysUserExtMapper.selectOne(Wrappers.<SysUserExtPO>lambdaQuery().eq(SysUserExtPO::getUserId,userId));
if (userExtPO != null){
return userExtPO.getEnterpriseId();
}
return null;
}
} }
...@@ -12,7 +12,6 @@ CREATE TABLE `user_course_auth` ( ...@@ -12,7 +12,6 @@ CREATE TABLE `user_course_auth` (
`course_id` bigint(20) NULL COMMENT '课程ID', `course_id` bigint(20) NULL COMMENT '课程ID',
`start_time` datetime(0) NULL COMMENT '开始时间', `start_time` datetime(0) NULL COMMENT '开始时间',
`end_time` datetime(0) NULL COMMENT '结束时间', `end_time` datetime(0) NULL COMMENT '结束时间',
`type` varchar(10) NULL COMMENT '购买或领用',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) COMMENT = '用户课程授权表'; ) COMMENT = '用户课程授权表';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment