|
@@ -7,7 +7,9 @@ import java.util.Arrays;
|
|
|
import java.util.Random;
|
|
|
|
|
|
import com.miaxis.common.core.domain.entity.SysUser;
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
+import com.miaxis.system.service.ISysUserService;
|
|
|
import com.miaxis.vip.dto.QueryVipCodeListDTO;
|
|
|
import io.swagger.annotations.*;
|
|
|
import com.miaxis.common.core.domain.Response;
|
|
@@ -43,6 +45,9 @@ public class VipCodeController extends BaseController{
|
|
|
@Autowired
|
|
|
private IVipCodeService vipCodeService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询激活码列表
|
|
|
*/
|
|
@@ -95,6 +100,16 @@ public class VipCodeController extends BaseController{
|
|
|
@PostMapping
|
|
|
@ApiOperation("新增激活码")
|
|
|
public Response<String> add(){
|
|
|
+ SysUser sysUser = SecurityUtils.getLoginUser().getUser();
|
|
|
+ if (sysUser.getAgentType() == null) {
|
|
|
+ throw new CustomException("用户还未成为会员");
|
|
|
+ }
|
|
|
+ if ( "1".equals(sysUser.getAgentType()) && sysUser.getAgentRemainingNumber() <= 0){
|
|
|
+ throw new CustomException("剩余券码已不足");
|
|
|
+ }
|
|
|
+ if ( "2".equals(sysUser.getAgentType()) && sysUser.getAgentExpireTime().getTime()< System.currentTimeMillis()){
|
|
|
+ throw new CustomException("代理权限已过期");
|
|
|
+ }
|
|
|
VipCode vipCode = new VipCode();
|
|
|
String rVipCode = null ;
|
|
|
do {
|
|
@@ -102,6 +117,10 @@ public class VipCodeController extends BaseController{
|
|
|
}while (isRepeat(rVipCode));
|
|
|
vipCode.setVipCode(rVipCode);
|
|
|
vipCodeService.save(vipCode);
|
|
|
+ if ( "1".equals(sysUser.getAgentType()) ){
|
|
|
+ sysUser.setAgentRemainingNumber(sysUser.getAgentRemainingNumber()-1);
|
|
|
+ }
|
|
|
+ userService.updateUser(sysUser);
|
|
|
return Response.success(rVipCode);
|
|
|
}
|
|
|
|