Commit f194dfcb authored by hezhen's avatar hezhen

修改分账

parent ed08c194
......@@ -53,10 +53,15 @@ public class BaseOrderAcceptDetailed implements Serializable {
@Column(name = "division_type")
@ApiModelProperty(value = "类型 1=>平台抽成;2-上级用户拥金;3-上级商家拥金;4-推荐入驻拥金")
@ApiModelProperty(value = "类型 1=>平台抽成;2-上级用户拥金;3-上级商家拥金;4-推荐入驻拥金;5-商家订单;6-商家定损;7-商家违章")
private Integer divisionType;
@Column(name = "entry_type")
@ApiModelProperty(value = "入账类型:1-线上;2-线下")
private Integer entryType;
@Column(name = "division_amount")
@ApiModelProperty(value = "分账金额")
......
package com.xxfc.platform.order.feign;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.order.entity.OrderInvoice;
import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.order.pojo.dto.OrderDetailDTO;
import com.xxfc.platform.order.pojo.order.OrderPageVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
......@@ -34,4 +34,8 @@ public interface OrderFeign {
@PostMapping(value = "/count/basebase/findOrdersByorderIdV2")
ObjectRestResponse<List<OrderDTO>> findOrdersByorderIdV2(@RequestBody List<Integer> orderIds);
@RequestMapping(value = "chw/orderDetail/app/unauth/getOrderDetail", method = RequestMethod.GET)
ObjectRestResponse<OrderDetailDTO> getOrderDetail(@RequestParam("orderNo")String orderNo, @RequestParam("type")Integer type);
}
package com.xxfc.platform.order.pojo.dto;
import com.xxfc.platform.order.entity.OrderRentVehicleDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* 门店收支明细DTO
* @author libin
* @version 1.0
* @description
* @data 2019/12/25 14:53
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrderDetailDTO {
public static final Integer PAY = 1; //支付
public static final Integer CANEL = 2; //取消
public static final Integer ADVANCE = 3; //提前还车
public static final Integer DELAY = 4; //延迟还车
public static final Integer FINISH = 5; //正常完成
@ApiModelProperty("租车订单详情")
private OrderRentVehicleDetail rentVehicleDetail;
@ApiModelProperty("订单号")
private String orderNo;
@ApiModelProperty("订单状态")
private Integer orderStatus = PAY;
@ApiModelProperty("商品实付金额")
private BigDecimal goodsAmount =BigDecimal.ZERO;
@ApiModelProperty("消费金额")
private BigDecimal orderAmount =BigDecimal.ZERO;
@ApiModelProperty("不计免赔费")
private BigDecimal damageSafeAmount =BigDecimal.ZERO;
@ApiModelProperty("其他费用-延迟用车不记免赔")
private BigDecimal damageSafeAmount2 =BigDecimal.ZERO;
@ApiModelProperty("定损费")
private BigDecimal lossSpecifiedAmount =BigDecimal.ZERO;
@ApiModelProperty("违章费")
private BigDecimal breakRulesRegulation =BigDecimal.ZERO;
@ApiModelProperty("违约金")
private BigDecimal violateAmount =BigDecimal.ZERO;
@ApiModelProperty("更换还车公司费用")
private BigDecimal chageAmount =BigDecimal.ZERO;
@ApiModelProperty("分账金额")
private BigDecimal acceptAmount;
public BigDecimal getAcceptAmount(){
return goodsAmount.subtract(orderAmount).subtract(violateAmount);
}
}
package com.xxfc.platform.order.biz;
import com.alibaba.fastjson.JSON;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.util.process.ResultCode;;
import com.xxfc.platform.order.contant.enumerate.DeductionTypeEnum;
import com.xxfc.platform.order.contant.enumerate.OrderStatusEnum;
import com.xxfc.platform.order.entity.*;
import com.xxfc.platform.order.pojo.account.OrderAccountDeduction;
import com.xxfc.platform.order.pojo.account.OrderAccountDetail;
import com.xxfc.platform.order.pojo.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Service
@Slf4j
public class OrderDetailBiz{
@Autowired
BaseOrderBiz orderBiz;
@Autowired
OrderRentVehicleBiz orderRentVehicleBiz;
@Autowired
OrderItemBiz orderItemBiz;
@Autowired
CompanyWalletBiz companyWalletBiz;
@Autowired
OrderAccountBiz orderAccountBiz;
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
//type1-支付;2-退款;3-完成
public OrderDetailDTO getOrderDetail(String orderNo,Integer type){
if (StringUtils.isBlank(orderNo)){
throw new BaseException("订单号不存在",ResultCode.FAILED_CODE);
}
log.info("---orderNo==="+orderNo);
//获取订单相关信息
BaseOrder baseOrder=new BaseOrder();
baseOrder.setNo(orderNo);
baseOrder=orderBiz.selectOne(baseOrder);
if (baseOrder == null ||(type == 1 && !baseOrder.getStatus() .equals(OrderStatusEnum.ORDER_TOSTART.getCode())) ||( (type == 2 || type == 3) && !baseOrder.getStatus().equals(OrderStatusEnum.ORDER_FINISH.getCode()))){
throw new BaseException("订单不存在或状态不是已完成",ResultCode.FAILED_CODE);
}
BigDecimal goodsAmount=baseOrder.getGoodsAmount().subtract(baseOrder.getCouponAmount());
List<OrderRentVehicleDetail> orderRentVehicleDetails = orderRentVehicleBiz.listByOrderId(baseOrder.getId());
if (orderRentVehicleDetails == null || orderRentVehicleDetails.size() == 0){
throw new BaseException("订单详情不存在",ResultCode.FAILED_CODE);
}
List<Integer> types=new ArrayList<>();
if (type == 2){
types.add(201);
types.add(202);
types.add(203);
}else if (type == 3) {
types.add(204);
}
OrderAccountDetail accountDetail = null;
if (types.size() > 0){
accountDetail = getAccountDetail(types, baseOrder.getId());
if (accountDetail == null ){
throw new BaseException("费用明细不存在",ResultCode.FAILED_CODE);
}
}
OrderItem orderItem=new OrderItem();
orderItem.setOrderId(baseOrder.getId());
List<OrderItem> orderItems = orderItemBiz.selectList(orderItem);
//不计免赔
BigDecimal damageSafeAmount = orderItems.stream().filter(x->x.getType()==102).map(OrderItem::getRealAmount).reduce(BigDecimal.ZERO, (x, y) -> x.add(y));
OrderRentVehicleDetail vehicleDetail=orderRentVehicleDetails.get(0);
//获取营收明细dto
OrderDetailDTO orderDetailDTO = new OrderDetailDTO();
orderDetailDTO.setRentVehicleDetail(vehicleDetail);
orderDetailDTO.setDamageSafeAmount(damageSafeAmount);
orderDetailDTO.setGoodsAmount(goodsAmount);
if (accountDetail != null){
List<OrderAccountDeduction> deductions = accountDetail.getDeductions();
if (CollectionUtils.isNotEmpty(deductions)){
setDeductionDetail(deductions,orderDetailDTO);
}
}
return orderDetailDTO;
}
public OrderAccountDetail getAccountDetail(List<Integer> types,Integer orderId) {
Example example = new Example(OrderAccount.class);
example.createCriteria().andEqualTo("orderId", orderId).andIn("accountType", types);
List<OrderAccount> orderAccounts = orderAccountBiz.selectByExample(example);
if (orderAccounts.size() > 0){
OrderAccount orderAccount = orderAccounts.get(0);
return org.springframework.util.StringUtils.hasText(orderAccount.getAccountDetail()) ? JSON.parseObject(orderAccount.getAccountDetail(), OrderAccountDetail.class) : null;
}
return null;
}
public void setDeductionDetail(List<OrderAccountDeduction> deductions, OrderDetailDTO orderDetailDTO){
Integer orderStatus=0;
for (OrderAccountDeduction orderAccountDeduction:deductions){
Integer type=orderAccountDeduction.getType() == null ? 0 : orderAccountDeduction.getType();
BigDecimal amount=orderAccountDeduction.getAmount() == null ?BigDecimal.ZERO : orderAccountDeduction.getAmount();
if (Objects.equals(DeductionTypeEnum.VIOLATE_CANCEL.getCode(),type)){
orderStatus=OrderDetailDTO.CANEL;
orderDetailDTO.setViolateAmount(amount);
}else {
if (Objects.equals(DeductionTypeEnum.VIOLATE_ADVANCE.getCode(),type)){
orderStatus=OrderDetailDTO.ADVANCE;
orderDetailDTO.setViolateAmount(amount);
}else if (Objects.equals(DeductionTypeEnum.VIOLATE_DELAY.getCode(),type)){
orderStatus=OrderDetailDTO.DELAY;
orderDetailDTO.setViolateAmount(amount);
} else if (Objects.equals(DeductionTypeEnum.VIOLATE_CHANGE_C.getCode(),type)){
orderDetailDTO.setChageAmount(amount);
}else if (Objects.equals(DeductionTypeEnum.CONSUME.getCode(),type)){
orderDetailDTO.setOrderAmount(amount);
}else if (Objects.equals(DeductionTypeEnum.DAMAGES.getCode(),type)){
orderDetailDTO.setLossSpecifiedAmount(amount);
}else if (Objects.equals(DeductionTypeEnum.VIOLATE_TRAFFIC_DEDUCT.getCode(),type)){
orderDetailDTO.setBreakRulesRegulation(amount);
}else if (Objects.equals(DeductionTypeEnum.OTHER_DELAY_SAFE.getCode(),type)){
orderDetailDTO.setDamageSafeAmount2(amount);
}
}
}
orderDetailDTO.setOrderStatus(orderStatus);
}
}
package com.xxfc.platform.order.rest;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.order.biz.OrderDetailBiz;
import com.xxfc.platform.order.pojo.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("chw/orderDetail")
@Slf4j
public class AppOrderDetailController{
@Autowired
OrderDetailBiz orderDetailBiz;
@RequestMapping(value = "app/unauth/getOrderDetail", method = RequestMethod.GET)
@IgnoreUserToken
public ObjectRestResponse<List<OrderDetailDTO>> getOrderDetail(@RequestParam("orderNo")String orderNo, @RequestParam("type")Integer type) {
return ObjectRestResponse.succ(orderDetailBiz.getOrderDetail(orderNo,type));
}
}
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