huangzhiguo 1 tahun lalu
induk
melakukan
a8a3a17dfc

+ 4 - 0
src/main/java/com/caimei/modules/order/dao/CmDiscernReceiptDao.java

@@ -18,6 +18,8 @@ import java.util.Map;
 @MyBatisDao
 public interface CmDiscernReceiptDao extends CrudDao<CmDiscernReceipt> {
 
+    List<Map<String, Object>> getShopOrderIDStr(@Param("id") String id);
+
     List<Map<String, Object>> getOrderIDStr(@Param("id") String id);
 
     ReceiptDetailVo getInfos(@Param("receiptID") String receiptID);
@@ -52,6 +54,8 @@ public interface CmDiscernReceiptDao extends CrudDao<CmDiscernReceipt> {
 
     CmDiscernReceipt findSmoothoutshopInfo(@Param("shopOrderId") Integer shopOrderId);
 
+    List<CmReceiptOrderRelation> getPaidAmountByOrderId(@Param("shopOrderId") Integer shopOrderId);
+
     double getAssociateAmount(@Param("orderID") String orderID);
 
     double getShopAssociateAmount(@Param("shopOrderId") String shopOrderId);

+ 9 - 0
src/main/java/com/caimei/modules/order/entity/ReceiptDetailVo.java

@@ -26,6 +26,7 @@ public class ReceiptDetailVo {
     private String confirmType;// 确认订单类型:1小额抹平确认,2大额抹平确认,3大额退款余额,4确认关联
     private String smsContent;     //短信内容
     private String cancelReason;//撤销原因
+    private Double needAmount;  // 子订单应该总金额
     /**
      * 返佣关联备注
      */
@@ -60,6 +61,14 @@ public class ReceiptDetailVo {
         this.vipInfo = vipInfo;
     }
 
+    public Double getNeedAmount() {
+        return needAmount;
+    }
+
+    public void setNeedAmount(Double needAmount) {
+        this.needAmount = needAmount;
+    }
+
     public String getRebateRemarks() {
         return rebateRemarks;
     }

+ 19 - 4
src/main/java/com/caimei/modules/order/service/CmDiscernReceiptService.java

@@ -78,7 +78,10 @@ public class CmDiscernReceiptService extends CrudService<CmDiscernReceiptDao, Cm
             String type = "";
             String no = "";
             if ("1".equals(bean.getReceiptType()) || "3".equals(bean.getReceiptType()) || "5".equals(bean.getReceiptType())) {
-                List<Map<String, Object>> orderIDs = cmDiscernReceiptDao.getOrderIDStr(bean.getId());
+                List<Map<String, Object>> orderIDs = cmDiscernReceiptDao.getShopOrderIDStr(bean.getId());
+                if (orderIDs.size()<=0 || (orderIDs != null && null == orderIDs.get(0).get("shopOrderId"))) {
+                    orderIDs = cmDiscernReceiptDao.getOrderIDStr(bean.getId());
+                }
                 for (Map<String, Object> map : orderIDs) {
                     if (!ObjectUtils.isEmpty(map)) {
                         if ("".equals(type)) {
@@ -101,9 +104,11 @@ public class CmDiscernReceiptService extends CrudService<CmDiscernReceiptDao, Cm
                             type += ("<br>" + (map.get("orderType").toString().equals("0") ? "协销" : "自主"));
                         }
                         if ("".equals(no)) {
-                            no += "<a href='/a/order/detail?id=" + map.get("orderID") + "'>" + map.get("orderNo") + "</a>";
+                            // no += "<a href='/a/order/detail?id=" + map.get("orderID") + "'>" + map.get("shopOrderNo") + "</a>";
+                            no += "<a href='/a/order/detail?id=" + map.get("orderID") + "&shopOrderID=" + map.get("shopOrderId") + "'>" + "子订单" + map.get("shopOrderNo") + "("+map.get("shopOrderId")+")" + "</a>";
                         } else {
-                            no += ("<br><a href='/a/order/detail?id=" + map.get("orderID") + "'>" + map.get("orderNo")) + "</a>";
+                            // no += ("<br><a href='/a/order/detail?id=" + map.get("orderID") + "'>" + map.get("shopOrderNo")) + "</a>";
+                            no += ("<br><a href='/a/order/detail?id=" + map.get("orderID") + "&shopOrderID=" + map.get("shopOrderId") + "'>" + "子订单" + map.get("shopOrderNo") + "("+map.get("shopOrderId")+")") + "</a>";
                         }
                     }
                 }
@@ -145,11 +150,21 @@ public class CmDiscernReceiptService extends CrudService<CmDiscernReceiptDao, Cm
 //        vo.setReceiptOrderFlag(receiptOrderFlag);//设置一款多单状态
         List<ReceiptOrderInfoVo> orderInfos = new ArrayList<>(); //一个收款可能会关联了一个或多个订单
         ReceiptOrderInfoVo receiptOrderInfoVo = null;
+        double needAmount = 0d;
         for(CmReceiptOrderRelation relation : relations) {
             if (null != relation.getShopOrderId()) {
                 receiptOrderInfoVo = cmDiscernReceiptDao.getOrderInfoByShopOrderID(relation.getShopOrderId().toString());
                 BigDecimal add = MathUtil.add(receiptOrderInfoVo.getReceiptAmount(), cmDiscernReceiptService.findShoOrderIDReceipt(relation.getShopOrderId()));
                 receiptOrderInfoVo.setReceiptAmount(add.toString());
+                List<CmReceiptOrderRelation> amountByOrderId = cmDiscernReceiptDao.getPaidAmountByOrderId(relation.getShopOrderId());
+                // 子订单应付金额
+                needAmount += Double.parseDouble(receiptOrderInfoVo.getShopOrderAmount());
+                // 收款金额
+                for (CmReceiptOrderRelation receiptOrderRelation : amountByOrderId) {
+                    if (!receiptOrderRelation.getReceiptID().equals(cmDiscernReceipt.getId())) {
+                        needAmount -= Double.parseDouble(receiptOrderRelation.getAssociateAmount());
+                    }
+                }
                 orderInfos.add(receiptOrderInfoVo);
                 //是否抹平支付过(抹平最多只允许存在一次)
                 CmDiscernReceipt cmDiscernReceiptInfo = cmDiscernReceiptDao.findSmoothoutshopInfo(Integer.parseInt(receiptOrderInfoVo.getShopOrderID()));
@@ -228,7 +243,7 @@ public class CmDiscernReceiptService extends CrudService<CmDiscernReceiptDao, Cm
                 receiptOrderInfoVo.setReceiptRecordVo(receiptRecordByOrderID);
             }
         }
-
+        vo.setNeedAmount(needAmount);
         /*for (CmReceiptOrderRelation relation : relations) {
             ReceiptOrderInfoVo roi = null; //这是通过订单列表上的一条收款记录对应的多个订单中的一个订单
             if ("1".equals(relation.getRelationType())) { // relation.orderID 指的是子订单id

+ 6 - 3
src/main/java/com/caimei/modules/order/service/NewOrderService.java

@@ -1665,7 +1665,7 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
             //已付金额
             double v = balancePayFee + order.getNewShopOrders().get(0).getReceiptAmount();
             order.getNewShopOrders().get(0).setReceiptAmount(v);
-            saveDiscernReceipt(balancePayFee, orderID);
+            saveDiscernReceipt(balancePayFee, orderID, shopOrderID);
             //针对商品productId:6898,做兑换券操作(couponId:15)
 //            if ("3".equals(order.getReceiptStatus())) {
             if ("3".equals(order.getNewShopOrders().get(0).getReceiptStatus())) {
@@ -1702,7 +1702,7 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
      *
      * @param balancePayFee 余额抵扣金额
      */
-    private void saveDiscernReceipt(Double balancePayFee, Integer orderId) {
+    private void saveDiscernReceipt(Double balancePayFee, Integer orderId, Integer shopOrderId) {
         String curDateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
         //保存余额到收款记录
         CmDiscernReceipt discernReceipt = new CmDiscernReceipt();
@@ -1720,6 +1720,7 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
         CmReceiptOrderRelation relation = new CmReceiptOrderRelation();
         relation.setReceiptID(discernReceipt.getId());
         relation.setOrderID(orderId.toString());
+        relation.setShopOrderId(shopOrderId);
         relation.setAssociateAmount(balancePayFee.toString());
         relation.setRelationType("2");
         relation.setDelFlag("0");
@@ -2738,7 +2739,9 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
             //修改账户余额
             user.setUserMoney(MathUtil.sub(user.getUserMoney(), balancePayFee).doubleValue());
             //保存收款记录
-            saveDiscernReceipt(balancePayFee.doubleValue(), orderID);
+            // todo 订单改版,收款记录需添加子订单id,退款以及其余子订单金额计算使用子订单Id
+            // todo 版本 暂时启用,后续启用余额抵扣,加入子订单Id
+            // saveDiscernReceipt(balancePayFee.doubleValue(), orderID);
             user.setAbleUserMoney(MathUtil.sub(user.getAbleUserMoney(), balancePayFee).doubleValue());
             cmUserDao.updateMoney(user);
             //保存余额收支记录

+ 40 - 20
src/main/resources/mappings/modules/order/CmDiscernReceiptMapper.xml

@@ -812,28 +812,45 @@
 		WHERE id = #{id}
 	</delete>
 
-    <select id="getOrderIDStr" parameterType="string" resultType="map">
-		-- 	relationType值为1是为子订单ID,为2时为主订单ID)
-		select
-		(case when cror.relationType = '1'
-		then concat('子订单',cso.shopOrderNo,'(', cso.shopOrderID,')')
-		else concat(cou.orderNo,'(', cou.orderID,')')
-		end)  AS orderNo,
-		(CASE WHEN cror.relationType = '1'
-		THEN co.orderID
-		ELSE cou.orderID
-		END) AS orderID ,
-		(case when cror.relationType = '1'
-		then (select b.orderType from cm_shop_order b where cso.shopOrderID =  b.shopOrderID)
-		else (select  c.orderType from cm_order c where cou.orderID = c.orderID)
-		end) AS orderType
-		from cm_receipt_order_relation cror
-        left join cm_shop_order cso on cror.orderID = cso.shopOrderID
-		left join cm_order co on cso.orderID = co.orderID
-		LEFT JOIN cm_order cou ON cror.orderID = cou.orderID
-		where cror.receiptID = #{id} and cror.delFlag = '0'
+    <select id="getShopOrderIDStr" parameterType="string" resultType="map">
+        SELECT
+            cso.shopOrderId,
+            cso.shopOrderNo,
+            cso.orderId AS orderID,
+            (case when cror.relationType = '1'
+                      then (select b.orderType from cm_shop_order b where cso.shopOrderID =  b.shopOrderID)
+                  else (select  c.orderType from cm_order c where cou.orderID = c.orderID)
+                end) AS orderType
+        FROM cm_receipt_order_relation cror
+                 LEFT JOIN cm_shop_order cso ON cror.shopOrderId = cso.shopOrderID
+                 LEFT JOIN cm_order co ON cso.orderID = co.orderID
+                 LEFT JOIN cm_order cou ON cror.orderID = cou.orderID
+        WHERE cror.receiptID = #{id} AND cror.delFlag = '0'
 	</select>
 
+    <select id="getOrderIDStr" parameterType="string" resultType="map">
+        -- 	relationType值为1是为子订单ID,为2时为主订单ID)
+        select
+            cso.shopOrderId,
+            cso.shopOrderNo,
+            (case when cror.relationType = '1'
+                      then concat('子订单',cso.shopOrderNo,'(', cso.shopOrderID,')')
+                  else concat(cou.orderNo,'(', cou.orderID,')')
+                end)  AS orderNo,
+            (CASE WHEN cror.relationType = '1'
+                      THEN co.orderID
+                  ELSE cou.orderID
+                END) AS orderID ,
+            (case when cror.relationType = '1'
+                      then (select b.orderType from cm_shop_order b where cso.shopOrderID =  b.shopOrderID)
+                  else (select  c.orderType from cm_order c where cou.orderID = c.orderID)
+                end) AS orderType
+        from cm_receipt_order_relation cror
+                 left join cm_shop_order cso on cror.orderID = cso.shopOrderID
+                 left join cm_order co on cso.orderID = co.orderID
+                 LEFT JOIN cm_order cou ON cror.orderID = cou.orderID
+        where cror.receiptID = #{id} and cror.delFlag = '0'
+    </select>
     <select id="getInfos" parameterType="CmDiscernReceipt" resultType="com.caimei.modules.order.entity.ReceiptDetailVo">
 		select
 	    cdr.id AS receiptID,
@@ -1104,6 +1121,9 @@
           and  cror.shopOrderId = #{shopOrderId} LIMIT 1;
     </select>
 
+    <select id="getPaidAmountByOrderId" resultType="com.caimei.modules.order.entity.CmReceiptOrderRelation">
+        SELECT receiptID, associateAmount FROM cm_receipt_order_relation WHERE shopOrderId = #{shopOrderId}
+    </select>
 
     <select id="findOrderReceipt" resultType="double">
 		select sum(associateAmount) from cm_receipt_order_relation cror

+ 2 - 0
src/main/resources/mappings/modules/order/CmReceiptOrderRelationMapper.xml

@@ -56,11 +56,13 @@
                                               receiptID,
                                               associateAmount,
                                               orderID,
+                                              shopOrderId,
                                               delFlag)
         VALUES (#{relationType},
                 #{receiptID},
                 #{associateAmount},
                 #{orderID},
+                #{shopOrderId},
                 #{delFlag})
     </insert>
 

+ 1 - 0
src/main/resources/mappings/modules/user/CmSpMapper.xml

@@ -125,6 +125,7 @@
 	<update id="update">
 		UPDATE serviceprovider SET
 		userID = #{userID},
+		organizeID = 0,
 		name = #{name},
 		contractPhone = #{contractPhone},
 		contractMobile = #{contractMobile},

+ 30 - 4
src/main/webapp/WEB-INF/views/modules/order/cmDiscernReceiptForm.jsp

@@ -205,6 +205,32 @@
                 </c:if>
             </span>
             <span><label>收款金额:</label>${vo.receiptAmount}</span>
+            <span>
+                <c:if test="${vo.confirmType eq 1 || vo.confirmType eq  2 || vo.confirmType eq 3}">
+                    <label>抹平明细:</label>
+                    <c:if test="${vo.confirmType eq 1}">
+                            <font color="red">(少收抹平:
+                                ¥<fmt:formatNumber
+                                        value="${vo.needAmount - vo.receiptAmount}"
+                                        pattern="#0.00"/>)
+                            </font>
+                    </c:if>
+                    <c:if test="${vo.confirmType eq 2}">
+                            <font color="red">(多收抹平:
+                                ¥<fmt:formatNumber
+                                        value="${vo.receiptAmount - vo.needAmount}"
+                                        pattern="#0.00"/>)
+                            </font>
+                    </c:if>
+                    <c:if test="${vo.confirmType eq 3}">
+                            <font color="red">(多收退余额&nbsp;&nbsp;:
+                                ¥<fmt:formatNumber
+                                        value="${vo.receiptAmount - vo.needAmount}"
+                                        pattern="#0.00"/>)
+                            </font>
+                    </c:if>
+                </c:if>
+            </span>
             <span><label>收款时间:</label>${vo.receiptDate}</span>
             <span><label>收款状态:</label>
                 <c:if test="${vo.payWay ne 3}">
@@ -352,7 +378,7 @@
                                                 <c:if test="${!orderInfo.receiptOrderFlag}">
                                                 <font color="red">(少收抹平:
                                                     ¥<fmt:formatNumber
-                                                            value="${orderInfo.needPayAmount - (empty orderInfo.orderReceivedAmount ? 0 : orderInfo.orderReceivedAmount)}"
+                                                            value="${orderInfo.shopOrderAmount - (empty orderInfo.orderReceivedAmount ? 0 : orderInfo.orderReceivedAmount)}"
                                                             pattern="#0.00"/>)
                                                 </font>
                                                 </c:if>
@@ -364,7 +390,7 @@
                                                 <c:if test="${!orderInfo.receiptOrderFlag}">
                                                 <font color="red">(多收抹平:
                                                     ¥<fmt:formatNumber
-                                                            value="${(empty orderInfo.receiptAmount ? 0 : orderInfo.orderReceivedAmount) - orderInfo.payableAmount}"
+                                                            value="${(empty orderInfo.receiptAmount ? 0 : orderInfo.orderReceivedAmount) - orderInfo.shopOrderAmount}"
                                                             pattern="#0.00"/>)
                                                 </font>
                                                 </c:if>
@@ -464,7 +490,7 @@
                                         </c:if>
                                         <span>
                     <%--                        一款多单的时候直接显示再订单上即可,无需收款记录显示--%>
-                                                <c:if test="${!vo.receiptOrderFlag}">
+                                                <%--<c:if test="${!vo.receiptOrderFlag}">
                                                     <c:if test="${receiptRecord.confirmType eq 1 || receiptRecord.confirmType eq  2 || receiptRecord.confirmType eq 3}">
                                                         <label>抹平明细:</label>
                                                         <c:if test="${order.confirmType eq 1}">
@@ -504,7 +530,7 @@
                                                             </c:if>
                                                         </c:if>
                                                     </c:if>
-                                                </c:if>
+                                                </c:if>--%>
                                             </span>
                                     </div>
                                 </c:forEach>