|
@@ -1,6 +1,7 @@
|
|
|
package com.pj.tb_orders;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.IService;
|
|
@@ -31,11 +32,13 @@ import com.pj.tb_goods_demand.TbGoodsDemandService;
|
|
|
import com.pj.tb_goods_demand.vo.GoodsDemandVo;
|
|
|
import com.pj.tb_item_rules.TbItemRules;
|
|
|
import com.pj.tb_item_rules.TbItemRulesService;
|
|
|
+import com.pj.tb_orders.vo.OrderFeeItemVO;
|
|
|
import com.pj.tb_orders_cart.TbOrdersCart;
|
|
|
import com.pj.tb_orders_cart.TbOrdersCartMapper;
|
|
|
import com.pj.tb_purchaser.TbPurchaser;
|
|
|
import com.pj.tb_purchaser.TbPurchaserMapper;
|
|
|
import com.pj.utils.so.SoMap;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -54,6 +57,7 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
+@Slf4j
|
|
|
public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> implements IService<TbOrders> {
|
|
|
|
|
|
/**
|
|
@@ -114,7 +118,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
|
|
|
}
|
|
|
|
|
|
- private PaymentTwoDto getPaymentData(TbOrders t,OrderDto orderOne) {
|
|
|
+ private PaymentTwoDto getPaymentData(TbOrders t, OrderDto orderOne) {
|
|
|
TradeSettlementDto htTradeSettlement = levelOneServerInterface.getHtTradeSettlementById(orderOne.getSaleMainId());
|
|
|
PaymentTwoDto paymentTwoDto = new PaymentTwoDto();
|
|
|
BeanUtils.copyProperties(htTradeSettlement, paymentTwoDto);
|
|
@@ -176,7 +180,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
OrderDto orderOne = levelOneServerInterface.getOrderDtoById(orderTwo.getLevelOneOrderId());
|
|
|
|
|
|
//todo 接收国内采购商的货款支付申请,划扣至边民账户并给出回执 并且同步至航通
|
|
|
- PaymentTwoDto paymentTwoDto = this.getPaymentData(orderTwo,orderOne);
|
|
|
+ PaymentTwoDto paymentTwoDto = this.getPaymentData(orderTwo, orderOne);
|
|
|
paymentServerInterface.sendMKT006_NoCommission(paymentTwoDto);
|
|
|
|
|
|
//给每个购买他商品的边民发一条支付成功消息,通知边民发起缴税申请以及缴费申请
|
|
@@ -195,6 +199,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
|
|
|
/**
|
|
|
* 收到采购商支付扣款回执:成功——> 边民缴税以及各服务费
|
|
|
+ *
|
|
|
* @param orderNo 二级市场边民订单-订单编号
|
|
|
*/
|
|
|
boolean payTax(String orderNo, Integer MKT008Status) {
|
|
@@ -207,19 +212,18 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
OrderDto orderOne = levelOneServerInterface.getOrderDtoById(orderTwo.getLevelOneOrderId());
|
|
|
if (null == orderOne) new RuntimeException("收到采购商支付扣款回执:一级市场订单不存在");
|
|
|
|
|
|
- if(2==MKT008Status) {//扣款失败
|
|
|
+ if (2 == MKT008Status) {//扣款失败
|
|
|
//todo 订单状态更新
|
|
|
orderTwo.setIsPay(2);//支付失败
|
|
|
orderTwo.setPayTime(new Date());
|
|
|
- }
|
|
|
- else if(1==MKT008Status) {//扣款成功
|
|
|
+ } else if (1 == MKT008Status) {//扣款成功
|
|
|
//todo 1、订单状态更新
|
|
|
orderTwo.setIsPay(1);//支付成功
|
|
|
orderTwo.setPayTime(new Date());
|
|
|
|
|
|
//todo 2、同步订单信息,发送航通
|
|
|
OrdersDto ordersDto = new OrdersDto();
|
|
|
- BeanUtils.copyProperties(orderTwo,ordersDto);
|
|
|
+ BeanUtils.copyProperties(orderTwo, ordersDto);
|
|
|
asyncServerInterface.sendLevelTwoOrdersDto(ordersDto, DataType.DATA_TYPE_FOUR.getCode());
|
|
|
|
|
|
//todo 3、系统将服务费自动分账,将分账信息自动发送至银行进行划扣
|
|
@@ -249,21 +253,23 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
List<TbFeeItem> feeItems = feeItemList.stream().filter(feeItem -> feeItem.getId().equals(ruleItem.getItemId())).collect(Collectors.toList());
|
|
|
if (feeItems.size() > 0) {
|
|
|
TbCompany company = companyService.getById(feeItems.get(0).getCompanyId());
|
|
|
- BeanUtils.copyProperties(company,companyDto);
|
|
|
+ BeanUtils.copyProperties(company, companyDto);
|
|
|
companyDto.setChargesPrice(chargesPrice);
|
|
|
}
|
|
|
companyDtoList.add(companyDto);
|
|
|
}
|
|
|
|
|
|
- PaymentTwoDto paymentTwoDto = this.getPaymentData(orderTwo,orderOne);
|
|
|
+ PaymentTwoDto paymentTwoDto = this.getPaymentData(orderTwo, orderOne);
|
|
|
paymentTwoDto.setCompanyDtoList(companyDtoList);
|
|
|
paymentServerInterface.sendMKT006(paymentTwoDto);
|
|
|
}
|
|
|
|
|
|
return updateById(orderTwo);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 收到边民缴税以及各服务费回执
|
|
|
+ *
|
|
|
* @param orderNo 二级市场边民订单-订单编号
|
|
|
*/
|
|
|
boolean payTaxFromBank(String orderNo, Integer MKT008Status) {
|
|
@@ -273,12 +279,11 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
if (list.size() <= 0) new RuntimeException("收到边民缴税以及各服务费回执:二级市场订单不存在");
|
|
|
TbOrders orderTwo = list.get(0);
|
|
|
|
|
|
- if(2==MKT008Status) {//缴费失败
|
|
|
+ if (2 == MKT008Status) {//缴费失败
|
|
|
//todo 订单状态更新
|
|
|
orderTwo.setPayTax(2);
|
|
|
orderTwo.setPayTaxTime(new Date());
|
|
|
- }
|
|
|
- else if(1==MKT008Status) {//缴费成功
|
|
|
+ } else if (1 == MKT008Status) {//缴费成功
|
|
|
//todo 订单状态更新
|
|
|
orderTwo.setPayTax(1);
|
|
|
orderTwo.setPayTaxTime(new Date());
|
|
@@ -357,7 +362,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
List<TbOrders> levelTwoList = tbOrdersMapper.getLevelTwoList(so);
|
|
|
|
|
|
String typeCode = so.getString("typeCode");
|
|
|
- if(StringUtils.isNotEmpty(typeCode)) {
|
|
|
+ if (StringUtils.isNotEmpty(typeCode)) {
|
|
|
List<TbOrders> collect = new ArrayList<>();
|
|
|
List<Long> goodsIds = levelOneServerInterface.getGoodsIds(typeCode);
|
|
|
goodsIds.forEach(goodsId -> {
|
|
@@ -450,34 +455,56 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public Double countPrice(SoMap so) {
|
|
|
+ public OrderFeeItemVO countPrice(SoMap so) {
|
|
|
OrderDto orderDto = levelOneServerInterface.getOrderDtoById(so.getLong("id"));
|
|
|
- if (null == orderDto) throw new RuntimeException("当前一级市场订单为空,请联系管理员!");
|
|
|
-
|
|
|
- List<TbItemRules> ruleList = new ArrayList<>();
|
|
|
- List<TbFeeItem> feeItemList = tbFeeItemService.getFeeItems();
|
|
|
- feeItemList.forEach(feeItem -> {
|
|
|
- ruleList.addAll(tbItemRulesService.getList(new SoMap().set("itemId", feeItem.getId())));
|
|
|
- });
|
|
|
+ if (null == orderDto){
|
|
|
+ log.error("当前一级市场订单为空,请联系管理员:{}",so.getLong("id"));
|
|
|
+ throw new RuntimeException("当前一级市场订单为空,请联系管理员!");
|
|
|
+ }
|
|
|
//目前逻辑为一个边民订单只有一个商品
|
|
|
GoodsDto goods = levelOneServerInterface.getByGoodsId(orderDto.getGoodsId());
|
|
|
- List<TbItemRules> newRuleList = ruleList.stream().filter(rule -> rule.getGoodsCodes().contains(goods.getCode())).collect(Collectors.toList());
|
|
|
- BigDecimal chargesPrice = BigDecimal.ZERO;
|
|
|
+ List<TbFeeItem> feeItemList = tbFeeItemService.getFeeItems();
|
|
|
+
|
|
|
BigDecimal TotalPrice = new BigDecimal(orderDto.getTotalPrice());
|
|
|
- BigDecimal GrossWt = new BigDecimal(orderDto.getGrossWt());
|
|
|
- for (TbItemRules ruleItem : newRuleList) {
|
|
|
- BigDecimal Percent = new BigDecimal(ruleItem.getPercent());
|
|
|
- //类型(1=按交易额收取,2=按次收取,3=按吨)
|
|
|
- if ("1".equals(ruleItem.getFeeType())) {
|
|
|
- chargesPrice = chargesPrice.add(TotalPrice.multiply(Percent).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));//保留两位小数,四舍五入
|
|
|
- } else if ("2".equals(ruleItem.getFeeType())) {
|
|
|
- chargesPrice = chargesPrice.add(ruleItem.getFeeMoney());
|
|
|
- } else if ("3".equals(ruleItem.getFeeType())) {
|
|
|
- chargesPrice = chargesPrice.add(GrossWt.multiply(Percent).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));//保留两位小数,四舍五入
|
|
|
+ BigDecimal GrossWt = new BigDecimal(orderDto.getNetWt()+"");
|
|
|
+ if (orderDto.getGoodsUnit().contains("千克") || orderDto.getGoodsUnit().contains("kg")) {
|
|
|
+ GrossWt = GrossWt.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ //需要交的费用
|
|
|
+ BigDecimal chargesPrice = BigDecimal.ZERO;
|
|
|
+ OrderFeeItemVO vo = new OrderFeeItemVO();
|
|
|
+ List<OrderFeeItemVO.FeeDTO> feeDTOList = new ArrayList<>();
|
|
|
+ for (TbFeeItem feeItem : feeItemList) {
|
|
|
+ List<TbItemRules> ruleList = tbItemRulesService.getList(new SoMap().set("itemId", feeItem.getId()));
|
|
|
+ List<TbItemRules> newRuleList = ruleList.stream()
|
|
|
+ .filter(rule -> rule.getGoodsCodes().contains(goods.getCode()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (newRuleList.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (TbItemRules ruleItem : newRuleList) {
|
|
|
+ OrderFeeItemVO.FeeDTO feeDTO = new OrderFeeItemVO.FeeDTO();
|
|
|
+ BigDecimal Percent = new BigDecimal(ruleItem.getPercent());
|
|
|
+ BigDecimal timesPrice = BigDecimal.ZERO;
|
|
|
+ //类型(1=按交易额收取,2=按次收取,3=按吨)
|
|
|
+ if ("1".equals(ruleItem.getFeeType())) {
|
|
|
+ feeDTO.setPercent(Percent);
|
|
|
+ timesPrice = TotalPrice.multiply(Percent).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
|
|
|
+ } else if ("2".equals(ruleItem.getFeeType())) {
|
|
|
+ timesPrice = ruleItem.getFeeMoney();
|
|
|
+ } else if ("3".equals(ruleItem.getFeeType())) {
|
|
|
+ feeDTO.setPercent(Percent);
|
|
|
+ timesPrice = GrossWt.multiply(Percent).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ chargesPrice = chargesPrice.add(timesPrice);
|
|
|
+ feeDTO.setName(feeItem.getName()).setFeeType(ruleItem.getFeeType())
|
|
|
+ .setFeeMoney(timesPrice.doubleValue() + "");
|
|
|
+ vo.setCompanyName(feeItem.getCompanyName());
|
|
|
+ feeDTOList.add(feeDTO);
|
|
|
}
|
|
|
}
|
|
|
- Double sumPrice = chargesPrice.add(TotalPrice).doubleValue();
|
|
|
- return sumPrice;
|
|
|
+ vo.setTotalFee(chargesPrice).setFeeList(feeDTOList);
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -489,7 +516,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
wrapper.eq(TbOrders::getLevelOneOrderId, levelOneOrderId);
|
|
|
List<TbOrders> tbOrders = tbOrdersMapper.selectList(wrapper);
|
|
|
|
|
|
- if(tbOrders.size()>0) return tbOrders.get(0);
|
|
|
+ if (tbOrders.size() > 0) return tbOrders.get(0);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -499,6 +526,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
public boolean updateResalePrice(TbOrders tbOrders) {
|
|
|
return updateById(tbOrders);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 增 二级市场订单
|
|
|
*/
|
|
@@ -563,27 +591,30 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
|
|
|
|
|
|
/**
|
|
|
* 根据年份查询每月订单交易额和交易量统计
|
|
|
+ *
|
|
|
* @param type
|
|
|
* @param year
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Map<String, Object>> orderStatistics(String type,String year,Long tradeAreaId){
|
|
|
- return tbOrdersMapper.orderStatistics(type,year,tradeAreaId);
|
|
|
+ public List<Map<String, Object>> orderStatistics(String type, String year, Long tradeAreaId) {
|
|
|
+ return tbOrdersMapper.orderStatistics(type, year, tradeAreaId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询所有统计年份
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Map<String, Object>> selectYear(){
|
|
|
+ public List<Map<String, Object>> selectYear() {
|
|
|
return tbOrdersMapper.selectYear();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 累计交易额
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Object> totalMoney(Long tradeAreaId){
|
|
|
+ public Map<String, Object> totalMoney(Long tradeAreaId) {
|
|
|
return tbOrdersMapper.totalMoney(tradeAreaId);
|
|
|
}
|
|
|
}
|