Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
online-edu-backend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
online-edu
online-edu-backend
Commits
d38cdb01
Commit
d38cdb01
authored
Jun 03, 2021
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
订单完成的逻辑处理
parent
ec0f209c
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
148 additions
and
21 deletions
+148
-21
OrgSurplusPO.java
...n/java/com/qkdata/biz/management/entity/OrgSurplusPO.java
+9
-3
UserCourseAuthPO.java
...va/com/qkdata/biz/management/entity/UserCourseAuthPO.java
+9
-9
OrgSurplusService.java
.../com/qkdata/biz/management/service/OrgSurplusService.java
+29
-0
OrganizationService.java
...om/qkdata/biz/management/service/OrganizationService.java
+2
-0
ProductOrderService.java
...om/qkdata/biz/management/service/ProductOrderService.java
+18
-7
UserCourseAuthService.java
.../qkdata/biz/management/service/UserCourseAuthService.java
+45
-1
SysUserService.java
src/main/java/com/qkdata/biz/sys/service/SysUserService.java
+36
-0
V1.0.7__update.sql
src/main/resources/db/migration/V1.0.7__update.sql
+0
-1
No files found.
src/main/java/com/qkdata/biz/management/entity/OrgSurplusPO.java
View file @
d38cdb01
package
com
.
qkdata
.
biz
.
management
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.qkdata.biz.enums.ProductTypeEnum
;
import
com.qkdata.common.base.entity.BasePO
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
...
...
@@ -14,12 +16,16 @@ import lombok.EqualsAndHashCode;
* @since 2021-06-03
*/
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@TableName
(
"org_surplus"
)
public
class
OrgSurplusPO
extends
BasePO
{
public
class
OrgSurplusPO
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 主键ID
*/
@TableId
private
Long
id
;
/**
* 企业ID
*/
...
...
@@ -33,7 +39,7 @@ public class OrgSurplusPO extends BasePO {
/**
* 产品类型
*/
private
String
productType
;
private
ProductTypeEnum
productType
;
/**
* 剩余数量
...
...
src/main/java/com/qkdata/biz/management/entity/UserCourseAuthPO.java
View file @
d38cdb01
package
com
.
qkdata
.
biz
.
management
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.qkdata.common.base.entity.BasePO
;
import
java.time.LocalDateTime
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.time.LocalDateTime
;
/**
* <p>
...
...
@@ -15,12 +15,16 @@ import lombok.EqualsAndHashCode;
* @since 2021-06-03
*/
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@TableName
(
"user_course_auth"
)
public
class
UserCourseAuthPO
extends
BasePO
{
public
class
UserCourseAuthPO
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 主键ID
*/
@TableId
private
Long
id
;
/**
* 用户ID
*/
...
...
@@ -41,10 +45,6 @@ public class UserCourseAuthPO extends BasePO {
*/
private
LocalDateTime
endTime
;
/**
* 购买或领用
*/
private
String
type
;
}
src/main/java/com/qkdata/biz/management/service/OrgSurplusService.java
View file @
d38cdb01
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.mapper.OrgSurplusMapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
...
@@ -16,4 +18,30 @@ import org.springframework.stereotype.Service;
@Service
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
src/main/java/com/qkdata/biz/management/service/OrganizationService.java
View file @
d38cdb01
...
...
@@ -8,6 +8,7 @@ import com.qkdata.biz.common.BizConstants;
import
com.qkdata.biz.enums.AccountStatusEnum
;
import
com.qkdata.biz.enums.AccountTypeEnum
;
import
com.qkdata.biz.enums.OrgTypeEnum
;
import
com.qkdata.biz.enums.VipReceiveEnum
;
import
com.qkdata.biz.management.entity.OrganizationPO
;
import
com.qkdata.biz.management.mapper.OrganizationMapper
;
import
com.qkdata.biz.management.vo.*
;
...
...
@@ -131,6 +132,7 @@ public class OrganizationService extends BaseServiceImpl<OrganizationMapper, Org
po
.
setProvince
(
model
.
getProvince
());
po
.
setCity
(
model
.
getCity
());
po
.
setAddress
(
model
.
getAddress
());
po
.
setVipReceive
(
VipReceiveEnum
.
CLOSE
);
save
(
po
);
return
po
.
getId
();
}
...
...
src/main/java/com/qkdata/biz/management/service/ProductOrderService.java
View file @
d38cdb01
...
...
@@ -17,6 +17,7 @@ import com.qkdata.biz.common.BizConstants;
import
com.qkdata.biz.enums.*
;
import
com.qkdata.biz.management.entity.CoursePO
;
import
com.qkdata.biz.management.entity.ProductOrderPO
;
import
com.qkdata.biz.management.entity.UserCourseAuthPO
;
import
com.qkdata.biz.management.mapper.ProductOrderMapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.qkdata.biz.management.vo.ProductOrderModel
;
...
...
@@ -68,6 +69,10 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
private
String
frontendDomain
;
@Autowired
private
SysRoleService
roleService
;
@Autowired
private
UserCourseAuthService
userCourseAuthService
;
@Autowired
private
OrgSurplusService
orgSurplusService
;
public
void
createOrder
(
UserBuyVIPModel
model
)
{
...
...
@@ -231,18 +236,24 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
updateStatus
(
orderNo
,
ProductOrderStatusEnum
.
PAY_COMPLETE
);
ProductOrderPO
orderPO
=
getByOrderNo
(
orderNo
);
if
(
orderPO
.
getProductType
()
==
ProductTypeEnum
.
USER_VIP
){
//TODO 更新用户VIP时间,用户从普通用户变为会员
LocalDateTime
payCompleteTime
=
orderPO
.
getUpdateTime
();
//支付完成时间
int
count
=
orderPO
.
getProductCount
();
//购买的几个月VIP
LocalDateTime
payCompleteTime
=
orderPO
.
getUpdateTime
();
//支付完成时间,即生效时间
int
month
=
orderPO
.
getProductCount
();
//购买的几个月VIP
Long
userId
=
orderPO
.
getUserId
();
sysUserService
.
updateVIPTimeLimit
(
userId
,
payCompleteTime
,
month
);
}
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
){
//TODO 添加课程购买记录
userCourseAuthService
.
updateAuth
(
orderPO
.
getUserId
(),
orderPO
.
getCourseId
(),
orderPO
.
getUpdateTime
());
}
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
());
}
}
}
...
...
src/main/java/com/qkdata/biz/management/service/UserCourseAuthService.java
View file @
d38cdb01
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.mapper.UserCourseAuthMapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.time.LocalDateTime
;
/**
* <p>
* 用户课程授权 服务类
...
...
@@ -16,4 +21,42 @@ import org.springframework.stereotype.Service;
@Service
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
src/main/java/com/qkdata/biz/sys/service/SysUserService.java
View file @
d38cdb01
...
...
@@ -143,4 +143,40 @@ public class SysUserService extends BaseServiceImpl<SysUserMapper, SysUserPO> {
Long
enterpriesId
=
userInfo
.
getId
();
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
;
}
}
src/main/resources/db/migration/V1.0.7__update.sql
View file @
d38cdb01
...
...
@@ -12,7 +12,6 @@ CREATE TABLE `user_course_auth` (
`course_id`
bigint
(
20
)
NULL
COMMENT
'课程ID'
,
`start_time`
datetime
(
0
)
NULL
COMMENT
'开始时间'
,
`end_time`
datetime
(
0
)
NULL
COMMENT
'结束时间'
,
`type`
varchar
(
10
)
NULL
COMMENT
'购买或领用'
,
PRIMARY
KEY
(
`id`
)
)
COMMENT
=
'用户课程授权表'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment