Commit 82dece7b authored by 周健威's avatar 周健威

添加部分代码

parent f6dadefe
package com.xxfc.platform.order.contant.enumerate;
import java.util.HashMap;
import java.util.Map;
public enum AccountTypeEnum {
//账款类型 1*--入账;2*--出账
//账款类型 记帐类型 101--订单支付;201--取消订单退款;202--全部押金退款;203--部分押金退款;204--剩余押金退款
In_ORDER_PAY(101, "订单支付"),
OUT_ORDER_FUND(201, "订单款"),
OUT_DEPOSIT(202, "所有押金"),
OUT_PART_DEPOSIT(203, "部分押金(扣除该扣除的 + 保留违章预备金)"),
OUT_RESIDUE_DEPOSIT(204, "剩余押金(扣除该扣除的)"),
;
/**
* 编码
*/
private Integer code;
/**
* 类型描述
*/
private String desc;
private static Map<Integer,String> codeAndDesc = new HashMap<Integer, String>();
//Maps.newHashMap();
static{
for(AccountTypeEnum enumE : AccountTypeEnum.values()){
codeAndDesc.put(enumE.getCode(),enumE.getDesc());
}
}
AccountTypeEnum(Integer code, String desc){
this.code=code;
this.desc=desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public static Boolean exists(Integer code){
return codeAndDesc.containsKey(code);
}
}
\ No newline at end of file
package com.xxfc.platform.order.contant.enumerate;
import java.util.HashMap;
import java.util.Map;
public enum DeductionTypeEnum {
//账款类型 1--违约金;2--补扣消费款;3--赔偿金(定损);4--违章扣款
VIOLATE(1, "违约金"),
EXTRA(2, "补扣消费款"),
DAMAGES(3, "赔偿金(定损)"),
VIOLATE_TRAFFIC(4, "违章扣款"),
;
/**
* 编码
*/
private Integer code;
/**
* 类型描述
*/
private String desc;
private static Map<Integer,String> codeAndDesc = new HashMap<Integer, String>();
//Maps.newHashMap();
static{
for(DeductionTypeEnum enumE : DeductionTypeEnum.values()){
codeAndDesc.put(enumE.getCode(),enumE.getDesc());
}
}
DeductionTypeEnum(Integer code, String desc){
this.code=code;
this.desc=desc;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public static Boolean exists(Integer code){
return codeAndDesc.containsKey(code);
}
}
\ No newline at end of file
...@@ -40,7 +40,7 @@ public class OrderAccount implements Serializable { ...@@ -40,7 +40,7 @@ public class OrderAccount implements Serializable {
*/ */
@Column(name = "trade_no") @Column(name = "trade_no")
@ApiModelProperty(value = "账款对应的流水号") @ApiModelProperty(value = "账款对应的流水号")
private Integer tradeNo; private String tradeNo;
/** /**
* 记账时间 * 记账时间
......
...@@ -6,7 +6,23 @@ import java.math.BigDecimal; ...@@ -6,7 +6,23 @@ import java.math.BigDecimal;
@Data @Data
public class OrderAccountDeduction { public class OrderAccountDeduction {
/**
* 名称
*/
String name; String name;
/**
* 类型
*/
Integer type; Integer type;
/**
* 来源
*/
Integer origin;
/**
* 金额
*/
BigDecimal amount; BigDecimal amount;
} }
package com.xxfc.platform.order.pojo.account; package com.xxfc.platform.order.pojo.account;
import lombok.Data; import lombok.Data;
import org.assertj.core.util.Lists;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
...@@ -9,5 +10,5 @@ import java.util.List; ...@@ -9,5 +10,5 @@ import java.util.List;
public class OrderAccountDetail { public class OrderAccountDetail {
BigDecimal orderAmount; BigDecimal orderAmount;
BigDecimal depositAmount; BigDecimal depositAmount;
List<OrderAccountDeduction> deductions; List<OrderAccountDeduction> deductions = Lists.newArrayList();
} }
package com.xxfc.platform.order.biz; package com.xxfc.platform.order.biz;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.IntervalUtil;
import com.xxfc.platform.order.contant.enumerate.DeductionTypeEnum;
import com.xxfc.platform.order.contant.enumerate.RefundStatusEnum;
import com.xxfc.platform.order.contant.enumerate.RefundTypeEnum;
import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.OrderItem;
import com.xxfc.platform.order.entity.OrderRefund;
import com.xxfc.platform.order.pojo.account.OrderAccountDeduction;
import com.xxfc.platform.order.pojo.account.OrderAccountDetail;
import com.xxfc.platform.universal.entity.Dictionary;
import com.xxfc.platform.universal.feign.ThirdFeign;
import com.xxfc.platform.universal.vo.OrderRefundVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.jexl2.MapContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.xxfc.platform.order.entity.OrderAccount; import com.xxfc.platform.order.entity.OrderAccount;
import com.xxfc.platform.order.mapper.OrderAccountMapper; import com.xxfc.platform.order.mapper.OrderAccountMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import javax.xml.ws.Action;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Map;
import java.util.Set;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE;
/** /**
* 订单帐目 * 订单帐目
* *
...@@ -14,6 +42,164 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz; ...@@ -14,6 +42,164 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz;
* @date 2019-09-09 15:51:16 * @date 2019-09-09 15:51:16
*/ */
@Service @Service
@Slf4j
public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> { public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> {
@Autowired
BaseOrderBiz baseOrderBiz;
@Autowired
ThirdFeign thirdFeign;
/**
* 租车(包括旅游)退款流程
* @param baseOrder
* @param mainItem 主要商品(租车费用、旅游费用等)
* @param timeLag 与开始时间的时间差
* @param dicParentKey
*/
public BigDecimal rentRefundProcessTotal(BaseOrder baseOrder, OrderItem mainItem, Long timeLag, String dicParentKey, BigDecimal depositAmount, BigDecimal originalDeductAmount) {
//计算退款金额
//商品价格 - 优惠券减免的价格
BigDecimal originalRefundAmount = BigDecimal.ZERO.add(mainItem.getRealAmount());
StringBuilder refundDescBuilder = new StringBuilder("取消订单退款:");
OrderAccountDetail oad = new OrderAccountDetail();
BigDecimal refundMainGoodsAmount = calculateRefund(originalRefundAmount, timeLag, dicParentKey, refundDescBuilder, oad);
refundMainGoodsAmount = refundMainGoodsAmount.setScale(2, RoundingMode.HALF_UP);
//退款金额 = 主要商品退款 + (其他商品退款) 即--> 主要商品退款 + (订单总商品款 - 主要商品款)
BigDecimal refundAmount = refundMainGoodsAmount.add(baseOrder.getOrderAmount().subtract(mainItem.getRealAmount()));
// 押金
BigDecimal originalRefundAmountDeposit = BigDecimal.ZERO.add(depositAmount);
BigDecimal refundAmountDeposit = BigDecimal.ZERO.add(depositAmount);
refundDescBuilder = refundDescBuilder.append(",押金退款:");
if(null != originalDeductAmount && BigDecimal.ZERO.compareTo(originalDeductAmount) < 0) {
//通过原扣除款 计算剩余款
BigDecimal residueAmount = calculateRefund(originalDeductAmount, timeLag, dicParentKey, refundDescBuilder, oad);
residueAmount = residueAmount.setScale(2, RoundingMode.HALF_UP);
//退款金额 :押金 - (原扣除款 - 剩余款) 即: 押金 - (免费天数对应的钱 - 剩余款)
refundAmountDeposit = originalRefundAmountDeposit.subtract(originalDeductAmount.subtract(residueAmount));
}
originalRefundAmount = originalRefundAmount.add(originalRefundAmountDeposit);
refundAmount = refundAmount.add(refundAmountDeposit);
//退款子流程: 订单基础,退款描述,退款金额
refundSubProcess(baseOrder, refundDescBuilder.toString(), originalRefundAmount, refundAmount, RefundTypeEnum.ORDER_FUND.getCode(), RefundStatusEnum.ALL.getCode(), oad);
return refundAmount;
}
/**
* 退款子流程
* @param baseOrder
* @param refundDesc 退款描述
* @param refundAmount 退款金额
* @param refundType 退款类型
* @param refundStatus 退款状态
*/
public void refundSubProcess(BaseOrder baseOrder, String refundDesc, BigDecimal originalRefundAmount, BigDecimal refundAmount, Integer refundType, Integer refundStatus, OrderAccountDetail oad) {
String refundTradeNo = null;
//0 小于 退款金额
if(BigDecimal.ZERO.compareTo(refundAmount) < 0) {
OrderRefundVo orv = new OrderRefundVo();
orv.setAmount(baseOrder.getRealAmount().multiply(new BigDecimal("100")).intValue());
orv.setOrderNo(baseOrder.getNo());
orv.setRefundDesc(refundDesc+ refundAmount.toString());
orv.setRefundAmount(refundAmount.multiply(new BigDecimal("100")).intValue());
ObjectRestResponse<String> result = thirdFeign.refund(orv);
refundTradeNo = result.getData();
if(null == refundTradeNo) {
log.error("退款没有refundTradeNo,订单号为:"+ baseOrder.getNo()+ ", 微服务调用结果为"+ JSONUtil.toJsonStr(result));
}
}
//记录订单退款记录
Integer flag = addOrderRefund(baseOrder.getId(), refundDesc, originalRefundAmount, refundAmount, refundTradeNo, refundType, JSONUtil.toJsonStr(oad));
//更新订单的退款状态和退款时间
BaseOrder updateBaseOrder = new BaseOrder();
updateBaseOrder.setId(baseOrder.getId());
updateBaseOrder.setRefundStatus(refundStatus);
updateBaseOrder.setRefundTime(System.currentTimeMillis());
updateBaseOrder.setVersion(baseOrder.getVersion());
if(SYS_TRUE.equals(flag) && null != refundStatus) {
BeanUtil.copyProperties(baseOrderBiz.updateSelectiveByIdReT(updateBaseOrder), baseOrder);
}
}
public BigDecimal calculateRefund(BigDecimal goodsAmount, Long timeLag, String dicParentKey, StringBuilder refundDescBuilder, OrderAccountDetail orderAccountDetail) {
BigDecimal refundGoodsAmount = goodsAmount;
if(null == orderAccountDetail) {
orderAccountDetail = new OrderAccountDetail();
}
//根据时间处理goodsAmount
//获取出发时间 到现在 距离时间
Integer hourLag = Long.valueOf(timeLag/(1000L * 60L * 60L)).intValue();
Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData();
Set<Dictionary> rentRefunds = dictionaryMap.get(dicParentKey).getChildrens();
for(com.xxfc.platform.universal.entity.Dictionary dic : rentRefunds) {
if(StrUtil.isBlank(dic.getName())) {
continue;
}
String[] names = dic.getName().split("\\|");
if(names.length < 2) {
continue;
}
//符合范围
if(IntervalUtil.staticIsInTheInterval(hourLag.toString(), names[0])){
refundGoodsAmount = new BigDecimal((IntervalUtil.evaluate(dic.getDetail(), new MapContext(){{
//ga : goodsAmount
set("ga", goodsAmount);
}})).toString());
refundDescBuilder = refundDescBuilder.insert(0, names[1]+ ",");
OrderAccountDeduction orderAccountDeduction = new OrderAccountDeduction();
orderAccountDeduction.setType(DeductionTypeEnum.VIOLATE.getCode());
orderAccountDeduction.setName(names[1]);
orderAccountDeduction.setAmount(goodsAmount.subtract(refundGoodsAmount));
orderAccountDetail.getDeductions().add(orderAccountDeduction);
break;
}
}
return refundGoodsAmount;
}
/**
* 记录订单退款记录
* @param orderId
* @param accountDesc
* @param accountAmount
* @param tradeNo
*/
private Integer addOrderRefund(Integer orderId, String accountDesc, BigDecimal originalAmount, BigDecimal accountAmount, String tradeNo, Integer accountType, String detail) {
//如果返回的流水为空,则当做失败
Integer refundStatus = SYS_TRUE;
if(StrUtil.isBlank(tradeNo)) {
refundStatus = SYS_FALSE;
}
//创建订单退款记录
OrderAccount orderAccount = new OrderAccount(){{
setOrderId(orderId);
setAccountTime(System.currentTimeMillis());
setTradeNo(tradeNo);
setAccountType(RefundTypeEnum.ORDER_FUND.getCode());
}};
orderAccount.setOriginalAmount(originalAmount);
orderAccount.setDeductAmount(originalAmount.subtract(accountAmount));
orderAccount.setAccountAmount(accountAmount);
orderAccount.setAccountDesc(accountDesc);
orderAccount.setAccountStatus(refundStatus);
orderAccount.setAccountType(accountType);
orderAccount.setAccountDetail(detail);
insertSelective(orderAccount);
return refundStatus;
}
} }
\ No newline at end of file
...@@ -259,6 +259,44 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> { ...@@ -259,6 +259,44 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> {
} }
} }
/**
* 退款子流程
* @param baseOrder
* @param refundDesc 退款描述
* @param refundAmount 退款金额
* @param refundType 退款类型
* @param refundStatus 退款状态
*/
public void refundSubProcessNew(BaseOrder baseOrder, String refundDesc, BigDecimal originalRefundAmount, BigDecimal refundAmount, Integer refundType, Integer refundStatus) {
String refundTradeNo = null;
//0 小于 退款金额
if(BigDecimal.ZERO.compareTo(refundAmount) < 0) {
OrderRefundVo orv = new OrderRefundVo();
orv.setAmount(baseOrder.getRealAmount().multiply(new BigDecimal("100")).intValue());
orv.setOrderNo(baseOrder.getNo());
orv.setRefundDesc(refundDesc+ refundAmount.toString());
orv.setRefundAmount(refundAmount.multiply(new BigDecimal("100")).intValue());
ObjectRestResponse<String> result = thirdFeign.refund(orv);
refundTradeNo = result.getData();
if(null == refundTradeNo) {
log.error("退款没有refundTradeNo,订单号为:"+ baseOrder.getNo()+ ", 微服务调用结果为"+ JSONUtil.toJsonStr(result));
}
}
//记录订单退款记录
Integer flag = addOrderRefund(baseOrder.getId(), refundDesc, originalRefundAmount, refundAmount, refundTradeNo, refundType);
//更新订单的退款状态和退款时间
BaseOrder updateBaseOrder = new BaseOrder();
updateBaseOrder.setId(baseOrder.getId());
updateBaseOrder.setRefundStatus(refundStatus);
updateBaseOrder.setRefundTime(System.currentTimeMillis());
updateBaseOrder.setVersion(baseOrder.getVersion());
if(SYS_TRUE.equals(flag) && null != refundStatus) {
BeanUtil.copyProperties(baseOrderBiz.updateSelectiveByIdReT(updateBaseOrder), baseOrder);
}
}
/** /**
* 记录订单退款记录 * 记录订单退款记录
* @param orderId * @param orderId
......
...@@ -62,6 +62,9 @@ public class OrderCancelBiz { ...@@ -62,6 +62,9 @@ public class OrderCancelBiz {
@Autowired @Autowired
OrderCalculateBiz orderCalculateBiz; OrderCalculateBiz orderCalculateBiz;
@Autowired
OrderAccountBiz orderAccountBiz;
@Autowired @Autowired
UserFeign userFeign; UserFeign userFeign;
...@@ -149,19 +152,23 @@ public class OrderCancelBiz { ...@@ -149,19 +152,23 @@ public class OrderCancelBiz {
freeDayAmount = orderItem.getUnitPrice().multiply(new BigDecimal(orvd.getFreeDays()+ "")); freeDayAmount = orderItem.getUnitPrice().multiply(new BigDecimal(orvd.getFreeDays()+ ""));
//违约金封顶 租车身份价 * 2天 //违约金封顶 租车身份价 * 2天
BigDecimal topAmount = orderItem.getUnitPrice().multiply(new BigDecimal("2")); BigDecimal topAmount = orderItem.getUnitPrice().multiply(new BigDecimal(2+ ""));
if(freeDayAmount.compareTo(topAmount) > 0) { if(freeDayAmount.compareTo(topAmount) > 0) {
freeDayAmount = freeDayAmount; freeDayAmount = freeDayAmount;
} }
} }
orderAccountBiz.rentRefundProcessTotal(hasUpdateOrder, orderItem, timeLag, APP_ORDER+ "_"+ RENT_REFUND, orvd.getDeposit(), freeDayAmount);
} }
//退款流程 //退款流程
//退订单款 //退订单款
orderRefundBiz.rentRefundProcess(hasUpdateOrder, timeLag, APP_ORDER+ "_"+ RENT_REFUND); // orderRefundBiz.rentRefundProcess(hasUpdateOrder, timeLag, APP_ORDER+ "_"+ RENT_REFUND);
//
//退押金 // //退押金
orderRefundBiz.rentRefundDepositProcess(hasUpdateOrder, orvd.getDeposit(), timeLag, APP_ORDER+ "_"+ RENT_REFUND, freeDayAmount); // orderRefundBiz.rentRefundDepositProcess(hasUpdateOrder, orvd.getDeposit(), timeLag, APP_ORDER+ "_"+ RENT_REFUND, freeDayAmount);
//
// orderAccountBiz.rentRefundProcessTotal(hasUpdateOrder, orderItem, timeLag, APP_ORDER+ "_"+ RENT_REFUND, orvd.getDeposit(), freeDayAmount);freeDayAmount
//已付款的取消订单发送消息 //已付款的取消订单发送消息
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment