|
|
|
@ -4,10 +4,9 @@ import api.PageResult;
|
|
|
|
|
import com.luoo.user.dao.MembershipCodeDao;
|
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
|
import com.luoo.user.dto.memberShip.MembershipCodeSearchDto;
|
|
|
|
|
import com.luoo.user.dto.point.UserPointLogSearchDto;
|
|
|
|
|
import com.luoo.user.pojo.MembershipCode;
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
import com.luoo.user.pojo.UserPointLog;
|
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
|
import constants.TaskPointIdConstants;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.MembershipEnums;
|
|
|
|
@ -128,7 +127,7 @@ public class MembershipCodeService {
|
|
|
|
|
MembershipCode membershipCode = membershipCodeDao.findMembershipCodeByCodeAndStatus(code,
|
|
|
|
|
MembershipEnums.CREATED.getCode());
|
|
|
|
|
if (membershipCode == null) {
|
|
|
|
|
throw new BizException("会员码不存在");
|
|
|
|
|
throw new BizException(ErrorConstants.MEMBERSHIP_CODE_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
// 处理会员码表
|
|
|
|
|
membershipCode.setStatus(MembershipEnums.BIND.getCode());
|
|
|
|
@ -142,14 +141,14 @@ public class MembershipCodeService {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
|
|
|
|
|
|
|
|
|
|
String result = "";
|
|
|
|
|
if(userInfo.getVipStatus() == UserVipStatusEnum.INITIAL.getCode()) {
|
|
|
|
|
if (userInfo.getVipStatus() == UserVipStatusEnum.INITIAL.getCode()) {
|
|
|
|
|
// 首次开通会员
|
|
|
|
|
Integer point = userPointLogService.addByTaskNew(TaskPointIdConstants.BUY_MEMBER, token);
|
|
|
|
|
result = "首次开通会员,积分增加" + point + "分";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 永久会员码
|
|
|
|
|
if(Objects.equals(membershipCode.getLife(), PointEnums.MEMBERSHIP_LIFE.getCode())) {
|
|
|
|
|
if (Objects.equals(membershipCode.getLife(), PointEnums.MEMBERSHIP_LIFE.getCode())) {
|
|
|
|
|
userInfo.setVipStatus(UserVipStatusEnum.LIFE.getCode());
|
|
|
|
|
} else {
|
|
|
|
|
// 非永久会员码
|
|
|
|
@ -189,6 +188,28 @@ public class MembershipCodeService {
|
|
|
|
|
return membershipCodeDao.findAll(specification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除会员码
|
|
|
|
|
*
|
|
|
|
|
* @param token token
|
|
|
|
|
* @param id 会员码id
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void delMembershipCode(String token, String id) {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
|
|
MembershipCode membershipCode = membershipCodeDao.findById(id).get();
|
|
|
|
|
if (!Objects.equals(membershipCode.getStatus(), MembershipEnums.CREATED.getCode())) {
|
|
|
|
|
// 已使用,禁止删除
|
|
|
|
|
throw new BizException(ErrorConstants.MEMBERSHIP_CODE_ALREADY_USED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
membershipCode.setStatus(MembershipEnums.DISCARD.getCode());
|
|
|
|
|
membershipCode.setUpdateUser(userLoginDto.getUserId());
|
|
|
|
|
membershipCode.setUpdateUserName(userLoginDto.getNickName());
|
|
|
|
|
membershipCodeDao.save(membershipCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Specification<MembershipCode> buildSearchSpecification(MembershipCodeSearchDto param) {
|
|
|
|
|
return (Root<MembershipCode> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
@ -219,6 +240,11 @@ public class MembershipCodeService {
|
|
|
|
|
criteriaBuilder.and(criteriaBuilder.equal(root.get("duration"), param.getDuration())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (param.getEventDate() != null) {
|
|
|
|
|
predicateList.add(
|
|
|
|
|
criteriaBuilder.and(criteriaBuilder.equal(criteriaBuilder.function("DATE", LocalDate.class, root.get("createTime")), param.getEventDate())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|