zhijiezhao %!s(int64=2) %!d(string=hai) anos
pai
achega
9bcb3f79fa

+ 2 - 0
src/main/java/com/caimei/modules/order/dao/PayShopDao.java

@@ -90,4 +90,6 @@ public interface PayShopDao {
     void updateShopPost(Integer shopOrderId, Double shopPostFee);
 
     List<NewShopOrder> findPayshOpOrderWaitPay(Integer payShopId);
+
+    Double findShopPostFee(Integer shopOrderId);
 }

+ 2 - 2
src/main/java/com/caimei/modules/order/entity/CmReturnedPurchaseProduct.java

@@ -34,7 +34,7 @@ public class CmReturnedPurchaseProduct implements Serializable {
 
 	@ApiModelProperty("申请退货数量")
 	private Integer applicationReturnedNum;
-	@ApiModelProperty("申请取消数量")
+	@ApiModelProperty("本次取消数量")
 	private Integer applicationCancelNum;
 
 	@ApiModelProperty("本次退货数量")
@@ -63,6 +63,6 @@ public class CmReturnedPurchaseProduct implements Serializable {
 	private String unit;
 	@ApiModelProperty("该订单商品是否是首次退货退款")
 	private Boolean firstReturn;
-	@ApiModelProperty("商品未出库数量")
+	@ApiModelProperty("待发货")
 	private Integer notOutStore;
 }

+ 19 - 2
src/main/java/com/caimei/modules/order/service/impl/PayShopServiceImpl.java

@@ -59,26 +59,36 @@ public class PayShopServiceImpl implements PayShopService {
     public OrderPayShopDetail getPayShopDetail(Integer id) {
         OrderPayShopDetail detail = payShopDao.findPayShopDetail(id);
         List<NewShopOrder> shopOrders = new ArrayList<>();
+        double totalPayShop = 0d;
+        double totalPayCm = 0d;
         if (1 == detail.getStatus()) {
             // 已付款待付金额活动计算
             shopOrders = payShopDao.findPayShopOrders(detail.getPayShopId());
             shopOrders.forEach(s -> {
                 orderUtils.getShouldPay(s);
             });
+             totalPayShop = shopOrders.stream().mapToDouble(NewShopOrder::getPayedShopAmount).sum();
+             totalPayCm = shopOrders.stream().mapToDouble(NewShopOrder::getPayCmAmount).sum();
         } else {
             // 未付款待付显示为本次申请金额
             shopOrders = payShopDao.findPayshOpOrderWaitPay(detail.getPayShopId());
             shopOrders.forEach(s -> {
+                if (s.getShopPostFee() > 0) {
+                    s.setWaitPayShop(s.getWaitPayShop() + s.getShopPostFee());
+                    s.setShouldPayShopAmount(s.getShouldPayShopAmount() + s.getShopPostFee());
+                }
                 List<NewOrderProduct> products = payShopDao.findPayOrderProducts(s.getShopOrderId());
                 s.setNewOrderProducts(products);
             });
+            // 待审核总付 = 本次申请
+            totalPayShop = shopOrders.stream().mapToDouble(NewShopOrder::getWaitPayShop).sum();
+            // 待审核总付 =  本次申请
+            totalPayCm = shopOrders.stream().mapToDouble(NewShopOrder::getWaitPayCmAmount).sum();
         }
         detail.setShopOrders(shopOrders);
         orderUtils.setPayShopPostInfo(detail);
-        Double totalPayShop = shopOrders.stream().mapToDouble(NewShopOrder::getPayedShopAmount).sum();
         // 付供应商
         detail.setTotalAmount(totalPayShop);
-        Double totalPayCm = shopOrders.stream().mapToDouble(NewShopOrder::getPayCmAmount).sum();
         // 付采美
         detail.setPayCmTotalAmount(totalPayCm);
         return detail;
@@ -193,6 +203,13 @@ public class PayShopServiceImpl implements PayShopService {
                     payShop.setStatus(0);
                 }
                 shopOrders.forEach(s -> {
+                    if (s.getShopPostFee() > 0) {
+                        // 修改时,以数据库中的应付为准,应付 - 上一次的
+                        Double shopPostFee = payShopDao.findShopPostFee(s.getShopOrderId());
+                        // 应付为+了供应商运费的金额,应付 - 数据库应付 = 上一次的供应商运费
+                        // 待付 = 待付 - 上一次的供应商运费
+                        s.setWaitPayShop(s.getWaitPayShop() - shopPostFee);
+                    }
                     payShopDao.updateRecordById(s.getShopOrderId(), s.getWaitPayShop(), s.getWaitPayCmAmount(), payShop.getPayShopId());
                 });
             }

+ 0 - 1
src/main/resources/mapper/CmReturnedPurchaseMapper.xml

@@ -202,7 +202,6 @@
         left join cm_returned_purchase_product crpp on cso.shopOrderId = crpp.shopOrderId
         left join cm_returned_purchase crp on crp.id = crpp.returnedId
         where crp.id = #{id}
-        and crp.status = 2
         and crp.delFlag = 0
     </select>
 

+ 91 - 54
src/main/resources/mapper/CmReturnedPurchaseProductMapper.xml

@@ -4,7 +4,7 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.modules.order.dao.CmReturnedPurchaseProductDao">
     <sql id="cmReturnedPurchaseProductColumns">
-		a.id AS "id",
+        a.id AS "id",
 		a.returnedId AS "returnedId",
 		a.productId AS "productId",
 		a.orderProductId AS "orderProductId",
@@ -14,28 +14,65 @@
 		a.applicationCancelNum AS "applicationCancelNum",
 		a.actualReturnedNum AS "actualReturnedNum",
 		a.actualCancelNum AS "actualCancelNum"
-	</sql>
+    </sql>
 
     <select id="findList" resultType="com.caimei.modules.order.entity.CmReturnedPurchaseProduct">
-        SELECT
-        <include refid="cmReturnedPurchaseProductColumns"/>,
-        b.price as price,b.discount as discount,b.discountPrice as discountPrice,b.num as num,b.presentNum as presentNum,
-        b.totalFee as totalFee,b.totalAddedValueTax as totalAddedValueTax,
-        b.taxRate as taxRate,b.addedValueTax as addedValueTax,c.mainImage as mainImage,
-        c.name as name,d.name as shopName,
-        c.unit as unit
+        SELECT a.id                                          AS "id",
+               a.returnedId                                  AS "returnedId",
+               a.productId                                   AS "productId",
+               a.orderProductId                              AS "orderProductId",
+               a.shopId                                      AS "shopId",
+               a.shopOrderId                                 as "shopOrderId",
+               a.applicationReturnedNum                      AS "applicationReturnedNum",
+               a.applicationCancelNum                        AS "applicationCancelNum",
+               a.actualReturnedNum                           AS "actualReturnedNum",
+               a.actualCancelNum                             AS "actualCancelNum",
+               b.price                                       as price,
+               b.discount                                    as discount,
+               b.discountPrice                               as discountPrice,
+               b.num                                         as num,
+               b.presentNum                                  as presentNum,
+               b.totalFee                                    as totalFee,
+               b.totalAddedValueTax                          as totalAddedValueTax,
+               b.taxRate                                     as taxRate,
+               b.addedValueTax                               as addedValueTax,
+               c.mainImage                                   as mainImage,
+               c.name                                        as name,
+               d.name                                        as shopName,
+               b.totalAmount,
+               (select IFNULL(SUM(clr.num), 0)
+                from cm_logistics_record clr
+                where clr.orderProductID = b.orderProductID) as
+                                                                sendOutNum,
+               (b.num - (select IFNULL(SUM(clr.num), 0)
+                         from cm_logistics_record clr
+                         where clr.orderProductID =
+                               a.orderProductID))            as waitSendOutNum,
+               ifnull((select sum(ca.actualReturnedNum)
+                       from cm_returned_purchase_product ca
+                                left join cm_returned_purchase cb
+                                          on ca.returnedId = cb.id
+                       where ca.orderProductId = a.orderProductId
+                         and cb.status = 2
+                         and cb.delFlag = 0), 0)             as returnedPurchaseProductNum,
+               ifnull((select sum(da.actualCancelNum)
+                       from cm_returned_purchase_product da
+                                left join cm_returned_purchase db
+                                          on da.returnedId = db.id
+                       where da.orderProductId = a.orderProductId
+                         and db.status = 2
+                         and db.delFlag = 0), 0)
+                                                             as cancelProductNum,
+               b.productUnit                                 as unit
         FROM cm_returned_purchase_product a
-        left join cm_order_product b on a.orderProductId = b.orderProductId
-        left join product c on c.productId = a.productId
-        left join shop d on d.shopId = a.shopId
-        <where>
-            <if test="returnedId != null">
-                AND a.returnedId = #{returnedId}
-            </if>
-        </where>
+                 left join cm_order_product b on a.orderProductId = b.orderProductId
+                 left join product c on c.productId = a.productId
+                 left join shop d on d.shopId = a.shopId
+        where a.returnedId = #{returnedId}
     </select>
 
-    <select id="getCmReturnedPurchaseProductList" resultType="com.caimei.modules.order.entity.CmReturnedPurchaseProduct">
+    <select id="getCmReturnedPurchaseProductList"
+            resultType="com.caimei.modules.order.entity.CmReturnedPurchaseProduct">
         SELECT
         <include refid="cmReturnedPurchaseProductColumns"/>,
         b.status as status
@@ -77,43 +114,43 @@
     </select>
 
     <select id="findProductByShopOrder" resultType="com.caimei.modules.order.entity.NewOrderProduct">
-        SELECT
-            a.orderProductId AS "orderProductId",
-            a.shopId AS "shopId",
-            a.shopOrderId as "shopOrderId",
-            a.actualReturnedNum AS "actualReturnedNum",
-            a.actualCancelNum AS "actualCancelNum",
-            b.status as status,
-            cop.productImage,
-            cop.name,
-            cop.productUnit as unit,
-            cop.num,
-            cop.totalAmount,
-            cop.
-            cop.price,
-            (select sum(ca.actualReturnedNum)
-                from cm_returned_purchase_product ca
-                left join cm_returned_purchase cb
-                 on ca.returnedId = cb.id
-             where ca.orderProductId = a.orderProductId
-              and cb.status=2
-               and cb.delFlag=0) as returnedPurchaseProductNum,
-            (select sum(da.actualCancelNum)
-            from cm_returned_purchase_product da
-             left join cm_returned_purchase db
-                 on da.returnedId = db.id
-             where da.orderProductId = a.orderProductId
-               and db.status=2
-               and db.delFlag=0)
-                as cancelProductNum,
-            (select IFNULL(SUM(clr.num),0) from cm_logistics_record clr where clr.orderProductID = a.orderProductID) as sendOutNum,
-               (cop.num-(select IFNULL(SUM(clr.num),0) from cm_logistics_record clr where clr.orderProductID = a.orderProductID)) as notOutStore
+        SELECT a.orderProductId                                                          AS "orderProductId",
+               a.shopId                                                                  AS "shopId",
+               a.shopOrderId                                                             as "shopOrderId",
+               ifnull(if(b.status != 2, a.applicationReturnedNum, a.actualReturnedNum), 0) AS "actualReturnedNum",
+               ifnull(if(b.status != 2, a.applicationCancelNum, a.actualCancelNum), 0)   AS "actualCancelNum",
+               b.status                                                                  as status,
+               cop.productImage,
+               cop.name,
+               cop.productUnit                                                           as unit,
+               cop.num,
+               cop.totalAmount,
+               cop.price,
+               ifnull((select sum(ca.actualReturnedNum)
+                       from cm_returned_purchase_product ca
+                                left join cm_returned_purchase cb
+                                          on ca.returnedId = cb.id
+                       where ca.orderProductId = a.orderProductId
+                         and cb.status = 2
+                         and cb.delFlag = 0), 0)                                         as returnedPurchaseProductNum,
+               ifnull((select sum(da.actualCancelNum)
+                       from cm_returned_purchase_product da
+                                left join cm_returned_purchase db
+                                          on da.returnedId = db.id
+                       where da.orderProductId = a.orderProductId
+                         and db.status = 2
+                         and db.delFlag = 0), 0)                                         as cancelProductNum,
+               (select IFNULL(SUM(clr.num), 0)
+                from cm_logistics_record clr
+                where clr.orderProductID = a.orderProductID)                             as sendOutNum,
+               (cop.num - (select IFNULL(SUM(clr.num), 0)
+                           from cm_logistics_record clr
+                           where clr.orderProductID = a.orderProductID))                 as notOutStore
         FROM cm_returned_purchase_product a
-        left join cm_returned_purchase b on a.returnedId = b.id
-        left join cm_order_product cop on a.orderProductId = cop.orderProductId
+                 left join cm_returned_purchase b on a.returnedId = b.id
+                 left join cm_order_product cop on a.orderProductId = cop.orderProductId
         where a.shopOrderId = #{shopOrderId}
-            AND a.returnedID = #{returnId}
-            AND b.status = 2
-            AND b.delFlag = 0
+          AND a.returnedID = #{returnId}
+          AND b.delFlag = 0
     </select>
 </mapper>

+ 1 - 1
src/main/resources/mapper/NewOrderMapper.xml

@@ -716,7 +716,7 @@
     </select>
 
     <select id="findCountDeliver" resultType="java.lang.Integer">
-        SELECT COUNT(num) - ifnull((SELECT COUNT(num) FROM cm_logistics_record WHERE orderId = #{orderId}),0)
+        SELECT SUM(num) - ifnull((SELECT sum(num) FROM cm_logistics_record WHERE orderId = #{orderId}),0)
         FROM cm_order_product
         WHERE orderid = #{orderId}
         and shopId != 998

+ 1 - 1
src/main/resources/mapper/NewShopOrderMapper.xml

@@ -88,7 +88,7 @@
             <if test="sendOutStatus != null and sendOutStatus != ''">
                 sendOutStatus = #{sendOutStatus},
             </if>
-            <if test="paying != null and paying != ''">
+            <if test="paying != null">
                 paying = #{paying},
             </if>
             <if test="shopProductAmount != null">

+ 8 - 3
src/main/resources/mapper/PayShopDao.xml

@@ -465,9 +465,10 @@
     </select>
 
     <select id="findShouldPayShopAmount" resultType="java.lang.Double">
-        select shouldPayShopAmount
-        from cm_shop_order
-        where shopOrderID = #{shopOrderId}
+        SELECT ROUND(SUM(totalAmount*shopPercent/100),2)
+        FROM cm_order_product
+        WHERE shoporderId = #{shopOrderId}
+          AND shopId != 998
     </select>
 
     <select id="findSettleSum" resultType="java.lang.Double">
@@ -661,4 +662,8 @@
             and cps.delFlag = 0
             and cpsr.delFlag = 0
     </select>
+
+    <select id="findShopPostFee" resultType="java.lang.Double">
+        select ifnull(shopPostFee,0) from cm_shop_order where shopOrderId = #{shopOrderId}
+    </select>
 </mapper>