Browse Source

下单bug

qzy 11 months ago
parent
commit
b8bb4b5d64

+ 8 - 2
sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderService.java

@@ -912,8 +912,14 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
         if (htTradeSettlement == null) {
             return false;
         }
-        Integer orderCount = htTradeSettlement.getOrderCount();
-        htTradeSettlement.setBeOrderCount((orderCount == null ? 0 : orderCount) + 1);
+        Integer orderCount=htTradeSettlement.getOrderCount();
+        Integer beOrderCount = htTradeSettlement.getBeOrderCount();
+        orderCount=  orderCount == null ? 0 : orderCount;
+        beOrderCount=  beOrderCount == null ? 0 : beOrderCount;
+        if (beOrderCount>=orderCount){
+            return false;
+        }
+        htTradeSettlement.setBeOrderCount(beOrderCount + 1);
         htTradeSettlementService.updateById(htTradeSettlement);
         return true;
     }

+ 41 - 34
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersService.java

@@ -39,6 +39,7 @@ 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.sg.AjaxError;
 import com.pj.utils.so.SoMap;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -120,7 +121,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);
@@ -154,32 +155,35 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
     /**
      * 改 收购商购买
      */
-    boolean purchaserBuy(String idStr,Long purchaserId) {
-
+    boolean purchaserBuy(String idStr, Long purchaserId) {
         // 获取收购商ID与名称
         TbPurchaser purchaser = tbPurchaserMapper.selectById(purchaserId);
         if (null == purchaser) throw new RuntimeException("当前收购商账号异常,请重新登录或联系管理员!");
+        log.info("收购商采购:{},{}",purchaser.getName(),idStr);
 
         Long[] idArr = Convert.toLongArray(idStr);
-
-        TbOrders orders = new TbOrders();
-        orders.setPurchaserId(purchaser.getId());
-        orders.setPurchaserName(purchaser.getName());
-
         for (Long id : idArr) {
-
-            orders.setId(id);
-            boolean b = updateById(orders);
+            TbOrders orderTwo = this.getById(id);
+            if (orderTwo == null) {
+                log.error(id + "订单不存在");
+                throw new AjaxError("订单不存在!");
+            }
+            if (StrUtil.isNotEmpty(orderTwo.getPurchaserName())) {
+                throw new AjaxError(orderTwo.getOrderNo() + "订单已被购买!");
+            }
+            orderTwo.setPurchaserId(purchaser.getId());
+            orderTwo.setPurchaserName(purchaser.getName());
+            boolean b = updateById(orderTwo);
             if (!b) throw new RuntimeException("购买异常,请重新登录或联系管理员!");
 
-            TbOrders orderTwo = getById(id);
             //修改对应的一级市场订单状态:BeingOrder值为已被下单
-            levelOneServerInterface.updateBeingOrder(orderTwo.getLevelOneOrderId());
+            boolean updateResult = levelOneServerInterface.updateBeingOrder(orderTwo.getLevelOneOrderId());
+            if (!updateResult) throw new AjaxError(orderTwo.getOrderNo()+"下单异常");
 
             OrderDto orderOne = levelOneServerInterface.getOrderDtoById(orderTwo.getLevelOneOrderId());
 
             //todo 接收国内采购商的货款支付申请,划扣至边民账户并给出回执 并且同步至航通
-            PaymentTwoDto paymentTwoDto = this.getPaymentData(orderTwo,orderOne);
+            PaymentTwoDto paymentTwoDto = this.getPaymentData(orderTwo, orderOne);
             paymentServerInterface.sendMKT006_NoCommission(paymentTwoDto);
 
             //给每个购买他商品的边民发一条支付成功消息,通知边民发起缴税申请以及缴费申请
@@ -198,6 +202,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
 
     /**
      * 收到采购商支付扣款回执:成功——> 边民缴税以及各服务费
+     *
      * @param orderNo 二级市场边民订单-订单编号
      */
     boolean payTax(String orderNo, Integer MKT008Status) {
@@ -210,19 +215,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、系统将服务费自动分账,将分账信息自动发送至银行进行划扣
@@ -252,19 +256,20 @@ 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);
     }
+
     /**
      * 收到边民缴税以及各服务费回执
      *
@@ -277,12 +282,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());
@@ -361,7 +365,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 -> {
@@ -443,8 +447,8 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
         orders.setCreateTime(new Date());
         orders.setVeNo(orderDto.getVeNo())
                 .setGoodsUnit(orderDto.getGoodsUnit())
-                .setNetWet(orderDto.getNetWt()+"")
-                .setTotalWeight(orderDto.getTotalWeight()+"")
+                .setNetWet(orderDto.getNetWt() + "")
+                .setTotalWeight(orderDto.getTotalWeight() + "")
                 .setSinglePrice(orders.getSinglePrice());
         this.add(orders);
 
@@ -457,8 +461,8 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
 
     public OrderFeeItemVO countPrice(SoMap so) {
         OrderDto orderDto = levelOneServerInterface.getOrderDtoById(so.getLong("id"));
-        if (null == orderDto){
-            log.error("当前一级市场订单为空,请联系管理员:{}",so.getLong("id"));
+        if (null == orderDto) {
+            log.error("当前一级市场订单为空,请联系管理员:{}", so.getLong("id"));
             throw new RuntimeException("当前一级市场订单为空,请联系管理员!");
         }
         //目前逻辑为一个边民订单只有一个商品
@@ -466,7 +470,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
         List<TbFeeItem> feeItemList = tbFeeItemService.getFeeItems();
 
         BigDecimal TotalPrice = new BigDecimal(orderDto.getTotalPrice());
-        BigDecimal GrossWt = new BigDecimal(orderDto.getNetWt()+"");
+        BigDecimal GrossWt = new BigDecimal(orderDto.getNetWt() + "");
         if (orderDto.getGoodsUnit().contains("千克") || orderDto.getGoodsUnit().contains("kg")) {
             GrossWt = GrossWt.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP);
         }
@@ -516,7 +520,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;
     }
 
@@ -589,27 +593,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);
     }