|
@@ -3,10 +3,7 @@ package com.caimei365.user.service.impl;
|
|
import com.caimei365.user.components.CommonService;
|
|
import com.caimei365.user.components.CommonService;
|
|
import com.caimei365.user.components.RedisService;
|
|
import com.caimei365.user.components.RedisService;
|
|
import com.caimei365.user.components.WeChatService;
|
|
import com.caimei365.user.components.WeChatService;
|
|
-import com.caimei365.user.mapper.BaseMapper;
|
|
|
|
-import com.caimei365.user.mapper.LoginMapper;
|
|
|
|
-import com.caimei365.user.mapper.RegisterMapper;
|
|
|
|
-import com.caimei365.user.mapper.SellerMapper;
|
|
|
|
|
|
+import com.caimei365.user.mapper.*;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.model.dto.*;
|
|
import com.caimei365.user.model.dto.*;
|
|
import com.caimei365.user.model.po.*;
|
|
import com.caimei365.user.model.po.*;
|
|
@@ -23,7 +20,9 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -37,6 +36,8 @@ import java.util.Map;
|
|
@Service
|
|
@Service
|
|
public class RegisterServiceImpl implements RegisterService {
|
|
public class RegisterServiceImpl implements RegisterService {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private SuperVipMapper vipMapper;
|
|
@Resource
|
|
@Resource
|
|
private RedisService redisService;
|
|
private RedisService redisService;
|
|
@Resource
|
|
@Resource
|
|
@@ -944,5 +945,106 @@ public class RegisterServiceImpl implements RegisterService {
|
|
}
|
|
}
|
|
return ResponseJson.success(clubTemporary);
|
|
return ResponseJson.success(clubTemporary);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 现金买超级会员
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson superVipUpgrade(SuperVipDto superVipDto, HttpHeaders headers) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 采美豆买超级会员
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson superVipUpByBeans(SuperVipDto vipDto, HttpHeaders headers) {
|
|
|
|
+ Integer userId = vipDto.getUserId();
|
|
|
|
+ SuperVipPo superVip = vipMapper.findSuperVip(userId);
|
|
|
|
+ //库里没有则新增
|
|
|
|
+ if (null == superVip) {
|
|
|
|
+ //1.查用户采美豆,够就用采美豆下单,不够就返回信息
|
|
|
|
+ Integer userBeans = vipMapper.findUserBeans(userId);
|
|
|
|
+ Integer userPackage = vipDto.getUserPackage();
|
|
|
|
+ Double price = vipMapper.findUserPackage(userPackage);
|
|
|
|
+ if (Double.valueOf(userBeans) >= (price * 100)) {
|
|
|
|
+ //用户采美豆>=套餐需要的采美豆,调用采美豆支付方法
|
|
|
|
+ //传空表示新客户
|
|
|
|
+ beanPay(vipDto, null, 0);
|
|
|
|
+ return ResponseJson.success("支付采美豆购买成功");
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.error("用户采美豆不足,请确认后再支付", null);
|
|
|
|
+ }
|
|
|
|
+ if (superVip.getDelFlag() != 0) {
|
|
|
|
+ return ResponseJson.error("用户信息已删除,请确认后重试", null);
|
|
|
|
+ }
|
|
|
|
+ //库里有用户信息,查是否过期,没过期续费,过期重买
|
|
|
|
+ // 设置日期时间格式
|
|
|
|
+ Long current = System.currentTimeMillis();
|
|
|
|
+ Long endTime = superVip.getEndTime().getTime();
|
|
|
|
+ //现在时间大于过期时间则重买,重买begintime=now,不是重买的话begintime=supervip.getendtime否则续费
|
|
|
|
+ if (current >= endTime) {
|
|
|
|
+ beanPay(vipDto, null, 0);
|
|
|
|
+ } else {
|
|
|
|
+ beanPay(vipDto, superVip.getEndTime(), 1);
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success("支付采美豆购买成功", null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 超级会员支付采美豆买会员
|
|
|
|
+ *
|
|
|
|
+ * @param vipDto
|
|
|
|
+ * @param beginTime
|
|
|
|
+ */
|
|
|
|
+ private void beanPay(SuperVipDto vipDto, Date beginTime, Integer repayFlag) {
|
|
|
|
+ //1.user表扣豆子
|
|
|
|
+ Integer userId = vipDto.getUserId();
|
|
|
|
+ Integer userPackageId = vipDto.getUserPackage();
|
|
|
|
+ Double price = vipMapper.findUserPackage(userPackageId);
|
|
|
|
+ Integer userBeans = vipMapper.findUserBeans(userId);
|
|
|
|
+ vipMapper.updateUserBeans(vipDto.getUserId(), Integer.valueOf(String.valueOf(userBeans - price * 100)));
|
|
|
|
+ //2.改user权限
|
|
|
|
+ vipMapper.updateUserPermission(userId, 7);
|
|
|
|
+ vipMapper.updateUserIdentity(userId, 7);
|
|
|
|
+ //3.超级会员表更改
|
|
|
|
+ SuperVipPo superVip = vipMapper.findSuperVip(userId);
|
|
|
|
+ //重买标记是0生效时间就是now
|
|
|
|
+ if (repayFlag == 0) {
|
|
|
|
+ beginTime = new Date();
|
|
|
|
+ superVip.setBeginTime(beginTime);
|
|
|
|
+ }
|
|
|
|
+ superVip.setDelFlag(0);
|
|
|
|
+ superVip.setUserId(userId);
|
|
|
|
+ superVip.setUpdateTime(beginTime);
|
|
|
|
+ //4.改采美豆历史表和会员购买记录
|
|
|
|
+ VipPayHistoryPo payHistory = new VipPayHistoryPo();
|
|
|
|
+ payHistory.setUserId(userId);
|
|
|
|
+ payHistory.setUserBeans(price * 100);
|
|
|
|
+ payHistory.setPayTime(new Date());
|
|
|
|
+ payHistory.setPayWay(4);
|
|
|
|
+ payHistory.setPackageId(userPackageId);
|
|
|
|
+ payHistory.setPrice(0.00);
|
|
|
|
+ payHistory.setBeginTime(beginTime);
|
|
|
|
+ //给begintime加上套餐的时间变成到期时间
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ cal.setTime(beginTime);
|
|
|
|
+ Integer userPackageTime = vipMapper.findUserPackageTime(userPackageId);
|
|
|
|
+ cal.add(Calendar.MONTH, userPackageTime);
|
|
|
|
+ payHistory.setEndTime(beginTime);
|
|
|
|
+ superVip.setEndTime(beginTime);
|
|
|
|
+ //加入超级会员表,重买标记是1,修改表
|
|
|
|
+ if (repayFlag == 1) {
|
|
|
|
+ vipMapper.updateVip(superVip);
|
|
|
|
+ }
|
|
|
|
+ vipMapper.addVip(superVip);
|
|
|
|
+ //加入会员购买记录
|
|
|
|
+ vipMapper.addPayHistory(payHistory);
|
|
|
|
+ //采美豆变更加入采美豆历史表
|
|
|
|
+ vipMapper.updateUserBeansHistory(userId, Integer.valueOf((int) (price * 100)));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|