Переглянути джерело

调整定时推送erp,改价后无法推送问题
调整赠品错误问题

yfh 5 днів тому
батько
коміт
55537e6f8a

+ 0 - 9
fs-framework/src/main/java/com/fs/framework/web/exception/GlobalExceptionHandler.java

@@ -80,15 +80,6 @@ public class GlobalExceptionHandler
         log.error("请求地址'{}',发生未知异常.", requestURI, e);
         return AjaxResult.error(e.getMessage());
     }
-
-    @ExceptionHandler(CustomException.class)
-    public AjaxResult handleCustomException(CustomException e, HttpServletRequest request)
-    {
-        String requestURI = request.getRequestURI();
-        log.error("请求地址'{}',发生未知异常.", requestURI, e);
-        return AjaxResult.error(e.getMessage());
-    }
-
     /**
      * 系统异常
      */

+ 27 - 58
fs-service/src/main/java/com/fs/erp/service/impl/WdtErpOrderServiceImpl.java

@@ -284,52 +284,24 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
     }
 
     private ErpOrderResponse getErpOrderResponseScrm(ErpOrder order) {
-        FsSysConfig sysConfig = configUtil.getSysConfig();
-        String shopCode = sysConfig.getErpWdShopCode();
-
         //测试环境sid、appkey、密钥请到旺店通开放平台-自助对接-申请测试环境内查看,测试环境url=https://sandbox.wangdian.cn/openapi2/
         //调用正式环境时请将sid、appkey、appsecret切换为实际参数,参数在旺店通开放平台-自助对接-应用管理内应用状态为已上线的应用中查看,调用正式环境注意切换正式环境url=https://api.wangdian.cn/openapi2/
 
+        FsSysConfig erpconfig = configUtil.getSysConfig();
         ErpWdtBusinessRequestParams erpWdtBusinessRequestParams = new ErpWdtBusinessRequestParams();
-        erpWdtBusinessRequestParams.setShopNo(shopCode);
+        erpWdtBusinessRequestParams.setShopNo(erpconfig.getErpWdShopCode());
         erpWdtBusinessRequestParams.setSwitchMode(0);
         ErpWdtTrade erpWdtTrade = new ErpWdtTrade();
-        FsStoreOrderScrm fsStoreOrder = fsStoreOrderScrmService.selectFsStoreOrderByOrderCode(order.getPlatform_code());
-        BigDecimal couponPrice = fsStoreOrder.getCouponPrice();
-        if (couponPrice == null) {
-            couponPrice = BigDecimal.ZERO;
-        }
-
-        // 平台状态
-        erpWdtTrade.setTradeStatus(TradeStatus.PAID_WAITING_FOR_SHIPMENT.getValue());
 
         // 订单id
         erpWdtTrade.setTid(order.getPlatform_code());
+        // 平台状态
+        erpWdtTrade.setTradeStatus(TradeStatus.REFUNDED.getValue());
 
-
-        // 如果是货到付款
-        if("2".equals(fsStoreOrder.getPayType())){
-            // 支付状态
-            erpWdtTrade.setPayStatus(PaymentStatus.PARTIALLY_PAID.getValue());
-            // 发货条件
-            erpWdtTrade.setDeliveryTerm(DeliveryTerm.CASH_ON_DELIVERY.getValue());
-            // 货到付款金额 = 物流代收金额-优惠金额
-            erpWdtTrade.setCodAmount(fsStoreOrder.getPayDelivery().subtract(couponPrice));
-
-        } else if("3".equals(fsStoreOrder.getPayType())){
-            // 支付状态
-            erpWdtTrade.setPayStatus(PaymentStatus.UNPAID.getValue());
-            // 发货条件
-            erpWdtTrade.setDeliveryTerm(DeliveryTerm.CASH_ON_DELIVERY.getValue());
-            // 货到付款金额 = 物流代收金额-优惠金额
-            erpWdtTrade.setCodAmount(fsStoreOrder.getPayDelivery().subtract(couponPrice));
-        } else { // 如果是线上付款
-            // 支付状态
-            erpWdtTrade.setPayStatus(PaymentStatus.FULLY_PAID.getValue());
-            // 发货条件
-            erpWdtTrade.setDeliveryTerm(DeliveryTerm.PAYMENT_BEFORE_DELIVERY.getValue());
-        }
-
+        // 支付状态
+        erpWdtTrade.setPayStatus(PaymentStatus.FULLY_PAID.getValue());
+        // 发货条件
+        erpWdtTrade.setDeliveryTerm(DeliveryTerm.PAYMENT_BEFORE_DELIVERY.getValue());
         // 下单时间
         erpWdtTrade.setTradeTime(order.getDeal_datetime());
         // 支付时间
@@ -358,42 +330,41 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
         erpWdtTrade.setSellerMemo(order.getSeller_memo());
         erpWdtTrade.setWarehouseNo(order.getWarehouse_code());
 
+        // 已付金额
+        FsStoreOrderScrm fsStoreOrder = fsStoreOrderScrmService.selectFsStoreOrderByOrderCode(order.getPlatform_code());
         // 运费金额
         erpWdtTrade.setPostAmount(fsStoreOrder.getFreightPrice());
-        // 已付金额
         if(ObjectUtils.isNotNull(fsStoreOrder)){
             erpWdtTrade.setPaid(fsStoreOrder.getPayMoney());
         }
 
-        List<com.fs.hisStore.vo.FsStoreOrderItemVO> fsStoreOrderItemVOS = fsStoreOrderItemScrmService.selectFsStoreOrderItemListByOrderId(fsStoreOrder.getId());
+        List<FsStoreOrderItemScrm> fsStoreOrderItemVOS = fsStoreOrderScrmService.selectFsStoreOrderItemList(String.valueOf(fsStoreOrder.getId()));
         List<ErpWdtOrder> erpWdtOrderList = new ArrayList<>();
-        // 商品总价
-        BigDecimal totalPrice = fsStoreOrder.getTotalPrice();
 
-        // 总折扣金额 = 优惠券金额 + 折扣金额
-        BigDecimal totalDiscountPrice = BigDecimal.ZERO;
-        // 折扣金额
-        BigDecimal discountPrice = totalPrice.subtract(fsStoreOrder.getPayPrice());
-        totalDiscountPrice = couponPrice.add(discountPrice);
 
-        // 防止除零错误
-        if (totalPrice.compareTo(BigDecimal.ZERO) == 0) {
-            totalPrice = BigDecimal.ONE;
+        // 优惠券金额
+        BigDecimal couponPrice = fsStoreOrder.getCouponPrice();
+        if (fsStoreOrder.getCouponPrice().compareTo(BigDecimal.ZERO) == 0
+                && fsStoreOrder.getTotalPrice().compareTo(fsStoreOrder.getPayMoney()) > 0) {
+            couponPrice = fsStoreOrder.getTotalPrice().subtract(fsStoreOrder.getPayMoney());
         }
+        // 商品总价
+        BigDecimal totalPrice = fsStoreOrder.getTotalPrice();
 
-        for (com.fs.hisStore.vo.FsStoreOrderItemVO fsStoreOrderItem : fsStoreOrderItemVOS) {
+        for (FsStoreOrderItemScrm fsStoreOrderItem : fsStoreOrderItemVOS) {
             ErpWdtOrder erpWdtOrder = new ErpWdtOrder();
             //平台订单货品表主键
-            erpWdtOrder.setOid(String.format("%s%s",fsStoreOrder.getOrderCode(),fsStoreOrderItem.getItemId()));
+            erpWdtOrder.setOid(String.format("%s%s",fsStoreOrderItem.getOrderCode(),fsStoreOrderItem.getItemId()));
             erpWdtOrder.setNum(BigDecimal.valueOf(fsStoreOrderItem.getNum()));
             FsStoreProductScrm fsStoreProduct = fsStoreProductScrmService.selectFsStoreProductById(fsStoreOrderItem.getProductId());
             Asserts.check(ObjectUtils.isNotNull(fsStoreProduct),"该产品不存在! 产品id: {} ",fsStoreOrderItem.getProductId());
             // 单价
             erpWdtOrder.setPrice(fsStoreProduct.getPrice());
             // 状态
-            erpWdtOrder.setStatus(TradeStatus.PAID_WAITING_FOR_SHIPMENT.getValue());
+
+            erpWdtOrder.setStatus(TradeStatus.REFUNDED.getValue());
             // 退款状态
-            erpWdtOrder.setRefundStatus(RefundStatus.NO_REFUND.getValue());
+            erpWdtOrder.setRefundStatus(RefundStatus.REFUND_SUCCESSFUL.getValue());
 
             // 平台货品ID
             erpWdtOrder.setGoodsId(String.valueOf(fsStoreProduct.getProductId()));
@@ -411,7 +382,7 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
             // 分摊比例
             BigDecimal price = fsStoreProduct.getPrice().multiply(BigDecimal.valueOf(fsStoreOrderItem.getNum()));
             BigDecimal divide = price.divide(totalPrice, RoundingMode.HALF_UP);
-            erpWdtOrder.setShareDiscount(divide.multiply(totalDiscountPrice));
+            erpWdtOrder.setShareDiscount(divide.multiply(couponPrice));
 
             erpWdtOrderList.add(erpWdtOrder);
         }
@@ -421,7 +392,7 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
         long size = erpWdtOrderList.size();
         if(size > 1) {
             ErpWdtOrder erpWdtOrder = erpWdtOrderList.get(erpWdtOrderList.size() - 1);
-            erpWdtOrder.setShareDiscount(totalDiscountPrice.subtract(erpWdtOrderList.stream()
+            erpWdtOrder.setShareDiscount(couponPrice.subtract(erpWdtOrderList.stream()
                     .limit(size - 1L)
                     .map(item -> Optional.ofNullable(item.getShareDiscount()).orElse(BigDecimal.ZERO))
                     .reduce(BigDecimal.ZERO, BigDecimal::add)));
@@ -440,17 +411,15 @@ public class WdtErpOrderServiceImpl implements IErpOrderService {
             String response = client.execute("trade_push.php", map);
             ParserConfig config = new ParserConfig();
             config.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
+            log.info("Erp推送传参: {}", map);
             ErpWdtApiResponse erpWdtApiResponse = JSON.parseObject(response, ErpWdtApiResponse.class,config);
             if(ObjectUtil.equal(0,erpWdtApiResponse.getCode())){
                 log.info("订单推送成功: {}", response);
                 ErpOrderResponse erpOrderResponse = new ErpOrderResponse();
                 erpOrderResponse.setCode(order.getPlatform_code());
-                erpOrderResponse.setSuccess(true);
-                erpOrderResponse.setRequestRawData(JSON.toJSONString(map));
-                erpOrderResponse.setResponseRawData(response);
                 return erpOrderResponse;
             } else {
-                throw new RuntimeException(String.format("订单推送失败,原因: %s",erpWdtApiResponse.getMessage()));
+                // throw new RuntimeException(String.format("订单推送失败,原因: %s",erpWdtApiResponse.getMessage()));
             }
         } catch (IOException e) {
             e.printStackTrace();

+ 2 - 2
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreCartScrmMapper.java

@@ -81,7 +81,7 @@ public interface FsStoreCartScrmMapper
 
     @Select("select ifnull(sum(c.cart_num),0) from fs_store_cart_scrm c inner join fs_store_product_scrm p on p.product_id=c.product_id inner join fs_store_product_attr_value_scrm v on v.id=c.product_attr_value_id where c.is_pay=0 and c.is_del=0 and c.is_buy=0 and p.is_show=1 and p.is_del=0 and c.user_id= #{userId}")
     Integer selectFsStoreCartCountByUserId(long userId);
-    @Select({"<script> " +
+    /*@Select({"<script> " +
             "select ifnull(sum(c.cart_num),0) from fs_store_cart_scrm c  " +
             "where c.is_pay=0 and c.is_del=0 and c.is_buy=0 " +
             "<if test = 'maps.userId != null     '> " +
@@ -90,7 +90,7 @@ public interface FsStoreCartScrmMapper
             "<if test = 'maps.productId != null    '> " +
             "and c.product_id =#{maps.productId} " +
             "</if>" +
-            "</script>"})
+            "</script>"})*/
     Integer selectFsStoreCartCount(@Param("maps") FsStoreCartCountParam param);
     @Select("select c.*,p.cate_id,p.product_name,p.image as product_image,p.temp_id,p.product_type,v.price,v.sku as product_attr_name,v.image as product_attr_image,v.stock,v.cost,v.integral,v.weight,v.volume,v.bar_code,v.group_bar_code,v.brokerage,v.brokerage_two,v.brokerage_three from fs_store_cart_scrm c left join fs_store_product_scrm p on p.product_id=c.product_id left join fs_store_product_attr_value_scrm v on v.id=c.product_attr_value_id where c.is_gift = 1 AND user_id = #{userId}")
     List<FsStoreCartQueryVO> selectFsStoreGiftCartList(@Param("userId") Long userId);

+ 1 - 1
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreCartScrmServiceImpl.java

@@ -238,7 +238,7 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
                 ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
                 if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
 
-                    int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
+                    int stocks = Double.valueOf(goodsStock.getStocks().get(0).getSalable_qty()).intValue();
 
                     if(stocks<=0){
                         productAttrValue.setStock(0);

+ 17 - 1
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -3079,11 +3079,27 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService
             //计算总价
             totalMoney=totalMoney.add(price.multiply(new BigDecimal(vo.getCartNum().toString())));
         }
+        List<FsStoreCartQueryVO> giftCarts = param.getGiftCarts();
+        if (giftCarts != null && !giftCarts.isEmpty()) {
+            for(FsStoreCartQueryVO vo:giftCarts){
+                BigDecimal price = vo.getPrice();
+                if (price==null || price.compareTo(BigDecimal.ZERO)<0){
+                    return R.error("商品单价不能小于0");
+                }
+                //更新购物车表
+                FsStoreCartScrm storeCart = new FsStoreCartScrm();
+                storeCart.setId(vo.getId());
+                storeCart.setChangePrice(price);
+                cartMapper.updateFsStoreCart(storeCart);
+                //计算总价
+                totalMoney=totalMoney.add(price.multiply(new BigDecimal(vo.getCartNum().toString())));
+            }
+        }
 
         redisCache.setCacheObject("createOrderMoney:"+createOrderKey, totalMoney, 24, TimeUnit.HOURS);
         //更新redis的购物车明细
         redisCache.setCacheObject("orderCarts:" + createOrderKey,carts,24, TimeUnit.HOURS);
-
+        redisCache.setCacheObject("orderGiftCarts:" + createOrderKey,giftCarts,24, TimeUnit.HOURS);
         return R.ok();
     }
 

+ 16 - 1
fs-service/src/main/resources/mapper/hisStore/FsStoreCartScrmMapper.xml

@@ -43,7 +43,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectFsStoreCartVo"/>
         where id = #{id}
     </select>
-
+    <select id="selectFsStoreCartCount" resultType="java.lang.Integer">
+        select ifnull(sum(c.cart_num),0)
+        from fs_store_cart c
+        inner join fs_store_product p on p.product_id=c.product_id
+        inner join fs_store_product_attr_value v on v.id=c.product_attr_value_id
+        where c.is_pay=0 and c.is_del=0 and c.is_buy=0 and c.is_gift = 0 and p.is_show=1 and p.is_del=0
+        <if test = 'maps.userId != null     '>
+            and c.user_id =#{maps.userId}
+        </if>
+        <if test = 'maps.productId != null    '>
+            and c.product_id =#{maps.productId}
+        </if>
+    </select>
     <insert id="insertFsStoreCart" parameterType="FsStoreCartScrm" useGeneratedKeys="true" keyProperty="id">
         insert into fs_store_cart_scrm
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -58,6 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isDel != null">is_del,</if>
             <if test="isBuy != null">is_buy,</if>
             <if test="changePrice != null">change_price,</if>
+            <if test="isGift != null">is_gift,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="userId != null">#{userId},</if>
@@ -71,6 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isDel != null">#{isDel},</if>
             <if test="isBuy != null">#{isBuy},</if>
             <if test="changePrice != null">#{changePrice},</if>
+            <if test="isGift != null">#{isGift},</if>
          </trim>
     </insert>
 
@@ -88,6 +102,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isDel != null">is_del = #{isDel},</if>
             <if test="isBuy != null">is_buy = #{isBuy},</if>
             <if test="changePrice != null">change_price = #{changePrice},</if>
+            <if test="isGift != null">is_gift = #{isGift},</if>
         </trim>
         where id = #{id}
     </update>