|
|
|
@ -151,6 +151,14 @@ public class ServiceManageServiceImpl implements IServiceManageService { |
|
|
|
|
setCache(config); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 剩余次数减n */ |
|
|
|
|
private void subNumSurplus(ServiceManage config,int num ) { |
|
|
|
|
config.setSurplus(config.getSurplus() - num); |
|
|
|
|
// 更新记录
|
|
|
|
|
serviceManageMapper.updateSurplus(config); |
|
|
|
|
setCache(config); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 清空缓存 |
|
|
|
|
*/ |
|
|
|
@ -249,6 +257,53 @@ public class ServiceManageServiceImpl implements IServiceManageService { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 扣费,根据传入的次数决定扣几次 */ |
|
|
|
|
@Override |
|
|
|
|
public AjaxResult companyConsume(String serviceKey, Long companyid,int num) { |
|
|
|
|
ServiceManage serviceManage = selectServiceManageByCompanyIdAndServiceKey(serviceKey, companyid); |
|
|
|
|
if (serviceManage == null) { |
|
|
|
|
throw new JianshuiNoServiceException("此销方未配置应用服务", serviceKey, companyid); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 处理扣费逻辑
|
|
|
|
|
// 如果过期时间不为Null
|
|
|
|
|
Date expireTime = serviceManage.getExpireTime(); |
|
|
|
|
Date now = DateUtils.getNowDate(); |
|
|
|
|
|
|
|
|
|
// 如果过期了
|
|
|
|
|
if (expireTime != null) { |
|
|
|
|
if (expireTime.getTime() < now.getTime()) { |
|
|
|
|
throw new JianshuiServiceExpireException("服务已过期", serviceKey, companyid); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 免费
|
|
|
|
|
if (StringUtils.equals("0", serviceManage.getServiceMode())) { |
|
|
|
|
// 调用次数 -n
|
|
|
|
|
subNumSurplus(serviceManage,num); |
|
|
|
|
return AjaxResult.success("消费成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 预付费
|
|
|
|
|
if (StringUtils.equals("1", serviceManage.getServiceMode())) { |
|
|
|
|
// 调用次数 -n
|
|
|
|
|
if (serviceManage.getSurplus() <= 0) { |
|
|
|
|
throw new JianshuiServiceNoSurplusException("服务次数不足", serviceKey, companyid); |
|
|
|
|
} |
|
|
|
|
subNumSurplus(serviceManage,num); |
|
|
|
|
return AjaxResult.success("消费成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 定期结算
|
|
|
|
|
if (StringUtils.equals("2", serviceManage.getServiceMode())) { |
|
|
|
|
subNumSurplus(serviceManage,num); |
|
|
|
|
return AjaxResult.success("消费成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return AjaxResult.error("未知的消费模式"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获得入口请求适配器 |
|
|
|
|
* |
|
|
|
|