Authored by mingdan.ge

扣税计算

... ... @@ -78,6 +78,7 @@
<value>/UnionClickCountDayRest/delete</value>
<value>/UnionClickCountDayRest/count</value>
<value>/UnionShareRest/getShareInfoByUid</value>
<value>/UnionShareRest/checkSettlement</value>
<value>/UnionShareRest/addSettlement</value>
<value>/UnionShareRest/queryUnionShareOrder</value>
<value>/UnionShareRest/queryUnionTypeByUid</value>
... ...
... ... @@ -67,6 +67,17 @@ public class UnionShareRest {
}
/**
* 提现确认
* */
@RequestMapping("/checkSettlement")
@ResponseBody
public UnionResponse checkSettlement(@RequestBody int uid){
log.info("checkSettlement,uid is {}",uid);
ShareSettlementRspBo result = unionShareService.checkSettlement(uid);
return new UnionResponse(200, "checkSettlement success", result);
}
/**
* 提现
* */
@RequestMapping("/addSettlement")
... ...
... ... @@ -44,6 +44,10 @@ public interface IUnionShareService {
void updateSettlementStatus(ShareSettlementBo bo);
/**
* 提现确认
*/
ShareSettlementRspBo checkSettlement(Integer uid);
/**
* 提现
*/
BigDecimal addSettlement(Integer uid);
... ...
... ... @@ -2977,23 +2977,33 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
/**
* 提现
* 提现确认
*/
@Override
@Database(ForceMaster = true)
public BigDecimal addSettlement(Integer uid) {
settlementLog.info("addSettlement enter,uid is {}",uid);
public ShareSettlementRspBo checkSettlement(Integer uid){
//提现条件判断,不可提现时会throw错误码
JSONObject jsonObject=canSettlement(uid);
BigDecimal preamount=(BigDecimal) jsonObject.get("preamount");
ShareSettlementRspBo rspBo = new ShareSettlementRspBo();
rspBo.setSettlementAmount(preamount);
rspBo.setTaxAmount(getTaxAmount(preamount));
rspBo.setAfterTaxAmount(preamount.subtract(rspBo.getTaxAmount()));
return rspBo;
}
/**
* 提现条件判断,可提现返回银行卡
*/
public JSONObject canSettlement(Integer uid){
logger.info("canSettlement enter,uid is {}",uid);
if (uid == null ) {
throw new ServiceException(ServiceError.USER_ID_ERROR);
}
//提现开关是否关闭
// boolean settlementSwitch=configReader.getBoolean(settlementSwitch,)
//查询该用户是否为特邀用户
int count = unionShareUserMapper.selectCountByUid(uid);
if (count == 0) {
//不是特邀用户
settlementLog.info("addSettlement end,can not find unionType,uid is {}",uid);
settlementLog.info("canSettlement end,can not find unionType,uid is {}",uid);
throw new ServiceException(ServiceError.USER_ID_ERROR);
}
... ... @@ -3003,14 +3013,14 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
req.setStatus((byte)1);
List<UnionShareUserBank> bankCardList = unionShareUserBankMapper.selectByUid(req);
if (CollectionUtils.isEmpty(bankCardList) || null == bankCardList.get(0)) {
settlementLog.info("addSettlement end,can not find available bank card,uid is {}",uid);
settlementLog.info("canSettlement end,can not find available bank card,uid is {}",uid);
throw new ServiceException(ServiceError.UNION_HASNOT_AVAILABLE_CARD);
}
//查询是否有处理中的提现
if (hasSettlement(uid)) {
//有处理中的提现单,不可提现
settlementLog.info("addSettlement end,hasSettlement,uid is {}",uid);
settlementLog.info("canSettlement end,hasSettlement,uid is {}",uid);
throw new ServiceException(ServiceError.UNION_HASSETTLEMENT_ERROR);
}
... ... @@ -3018,7 +3028,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
int orderCount = unionShareOrdersMapper.selectCountByCondition(uid,ShareOrdersStatusEnum.CAN_SETTLE.getCode());
if (orderCount == 0 ) {
//没有可以提现的订单
settlementLog.info("addSettlement end,has not remaining settlement,uid is {}",uid);
settlementLog.info("canSettlement end,has not remaining settlement,uid is {}",uid);
throw new ServiceException(ServiceError.UNION_HASNOT_REMAINING_SETTLEMENT);
}
//查询当前可提现金额是否不小于50
... ... @@ -3026,13 +3036,28 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
Integer minimumAmount=configReader.getInt(UNION_CPS_SETTLEMENT_AMOUNT_MIN, 50);
if (preamount.compareTo(new BigDecimal(minimumAmount))<0 ) {
//没有可以提现的订单
settlementLog.info("addSettlement end,settlement lower than {},uid is {},preamount is {}",minimumAmount,uid,preamount);
settlementLog.info("canSettlement end,settlement lower than {},uid is {},preamount is {}",minimumAmount,uid,preamount);
ServiceException serviceException = new ServiceException(ServiceError.UNION_HASNOT_ENOUGH_SETTLEMENT,false,minimumAmount);
serviceException.setParams(minimumAmount.toString());
throw serviceException;
}
JSONObject result = new JSONObject();
result.put("bankcard", bankCardList.get(0));
result.put("preamount", preamount);
return result;
}
/**
* 提现
*/
@Override
@Database(ForceMaster = true)
public BigDecimal addSettlement(Integer uid) {
settlementLog.info("addSettlement enter,uid is {}",uid);
//提现条件判断,可提现返回银行卡
JSONObject jsonObject=canSettlement(uid);
UnionShareUserBank bankCard=(UnionShareUserBank) jsonObject.get("bankcard");
// 生成取现单,绑定订单
BigDecimal amount = relateSettlementAndOrder(uid,bankCardList.get(0));
BigDecimal amount = relateSettlementAndOrder(uid,bankCard);
settlementLog.info("addSettlement end,remaining settlement is {},uid is {}",amount,uid);
return amount;
}
... ... @@ -3206,7 +3231,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return totalAmount;
}
//扣税金额计算
//扣税金额计算,保留两位小数,多余位舍弃
private BigDecimal getTaxAmount(BigDecimal amount) {
// 假设佣金为X
// 增值税(B) 城建税 教育费 地方教育 个人所得税 到手佣金
... ... @@ -3222,18 +3247,18 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return new BigDecimal(0);
}
if (amount.compareTo(new BigDecimal(824))<1) {
return amount.multiply(new BigDecimal("336")).divide(new BigDecimal("10300")).setScale(2,BigDecimal.ROUND_DOWN);
return amount.multiply(new BigDecimal("336")).divide(new BigDecimal("10300"),2,BigDecimal.ROUND_DOWN);
}
if (amount.compareTo(new BigDecimal(4120))<1) {
return amount.multiply(new BigDecimal("2336")).divide(new BigDecimal("10300")).setScale(2,BigDecimal.ROUND_DOWN).subtract(new BigDecimal("160"));
return amount.multiply(new BigDecimal("2336")).divide(new BigDecimal("10300"),2,BigDecimal.ROUND_DOWN).subtract(new BigDecimal("160"));
}
if (amount.compareTo(new BigDecimal(20600))<1) {
return amount.multiply(new BigDecimal("1936")).divide(new BigDecimal("10300")).setScale(2,BigDecimal.ROUND_DOWN);
return amount.multiply(new BigDecimal("1936")).divide(new BigDecimal("10300"),2,BigDecimal.ROUND_DOWN);
}
if (amount.compareTo(new BigDecimal(51500))<1) {
return amount.multiply(new BigDecimal("2736")).divide(new BigDecimal("10300")).setScale(2,BigDecimal.ROUND_DOWN).subtract(new BigDecimal("2000"));
return amount.multiply(new BigDecimal("2736")).divide(new BigDecimal("10300"),2,BigDecimal.ROUND_DOWN).subtract(new BigDecimal("2000"));
}
return amount.multiply(new BigDecimal("3536")).divide(new BigDecimal("10300")).setScale(2,BigDecimal.ROUND_DOWN).subtract(new BigDecimal("7000"));
return amount.multiply(new BigDecimal("3536")).divide(new BigDecimal("10300"),2,BigDecimal.ROUND_DOWN).subtract(new BigDecimal("7000"));
}
/**
... ...