zhijiezhao 1 سال پیش
والد
کامیت
8c1f05966e

+ 11 - 5
src/main/java/com/caimei/modules/order/dao/NewOrderDao.java

@@ -265,7 +265,7 @@ public interface NewOrderDao extends CrudDao<NewOrder> {
 
     List<SplitAccountPo> getSplitRecord(Integer orderID);
 
-    Integer getSplitTime(Integer shopOrderId);
+    Integer getSplitTime(String shopOrderId);
 
     /**
      * 查询用户模块重构-主订单
@@ -273,7 +273,7 @@ public interface NewOrderDao extends CrudDao<NewOrder> {
      * @param orderID 用户模块重构-主订单主键
      * @return 用户模块重构-主订单
      */
-    public NewOrder getCmOrderByOrderID(String orderID);
+    NewOrder getCmOrderByOrderID(String orderID);
 
     /**
      * 查询用户模块重构-主订单Id
@@ -344,7 +344,7 @@ public interface NewOrderDao extends CrudDao<NewOrder> {
      * @param orderIDs 需要删除的数据主键集合
      * @return 结果
      */
-    public int delCmOrderByOrderIDs(@Param("orderIDs") String[] orderIDs);
+    int delCmOrderByOrderIDs(@Param("orderIDs") String[] orderIDs);
 
     /**
      * 修改批量删除用户模块重构-主订单
@@ -352,7 +352,7 @@ public interface NewOrderDao extends CrudDao<NewOrder> {
      * @param orderIDs 需要删除的数据主键集合
      * @return 结果
      */
-    public int updateDelCmOrderByOrderIDs(@Param("orderIDs") String[] orderIDs,@Param("delFlag") Integer delFlag);
+    int updateDelCmOrderByOrderIDs(@Param("orderIDs") String[] orderIDs,@Param("delFlag") Integer delFlag);
 
     Double getPaidOrganizePrice(Integer shopOrderId);
 
@@ -362,5 +362,11 @@ public interface NewOrderDao extends CrudDao<NewOrder> {
 
     Double getShopOrderPaidAmount(Integer shopOrderId);
 
-    Double getOtherPaid(Integer shopOrderId);
+    Double getOtherPaid(String shopOrderId);
+
+    Double findShopCost(String shopOrderId);
+
+    Double findPayOrganize(String shopOrderId);
+
+    String findOrganizeSplitByShopOrder(String shopOrderId);
 }

+ 24 - 22
src/main/java/com/caimei/modules/order/service/CmPayShopService.java

@@ -15,10 +15,8 @@ import com.caimei.modules.product.entity.Product;
 import com.caimei.modules.sys.utils.UploadImageUtils;
 import com.caimei.modules.user.dao.NewCmShopDao;
 import com.caimei.modules.user.entity.NewCmShop;
-import com.caimei.redis.RedisService;
 import com.caimei.utils.MathUtil;
 import com.caimei.utils.StringUtil;
-import com.opensymphony.module.sitemesh.html.CustomTag;
 import com.thinkgem.jeesite.common.config.Global;
 import com.thinkgem.jeesite.common.persistence.Page;
 import com.thinkgem.jeesite.common.service.CrudService;
@@ -32,8 +30,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.beans.IntrospectionException;
-import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -75,8 +71,6 @@ public class CmPayShopService extends CrudService<CmPayShopDao, CmPayShop> {
     private HeHeNewOrderDao heHeNewOrderDao;
     @Resource
     private CmRefundShopDao cmRefundShopDao;
-    @Resource
-    private RedisService redisService;
 
 
     public List<CmPayShop> exports(Page<CmPayShop> cmPayShopPage, CmPayShop cmPayShop) {
@@ -976,7 +970,7 @@ public class CmPayShopService extends CrudService<CmPayShopDao, CmPayShop> {
             payShop.setBankAccount(payShopOther.getBankAccount());
             payShop.setBankName(payShopOther.getBankName());
             payShop.setType(payShopOther.getType().toString());
-        }else{
+        } else {
             String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
             payShop.setApplyTime(format);
             payShop.setReviewTime(format);
@@ -987,7 +981,7 @@ public class CmPayShopService extends CrudService<CmPayShopDao, CmPayShop> {
         payShop.setWipePayment(0d);
         payShop.setApplicant(currentUser.getId());
         payShop.setApplyTime(time);
-        String status = 2 == payShopOther.getPayType()?"1":"0";
+        String status = 2 == payShopOther.getPayType() ? "1" : "0";
         payShop.setStatus(status);
         payShop.setDelFlag("0");
         if (payShopOther.getPayShopId() == null) {
@@ -1299,18 +1293,28 @@ public class CmPayShopService extends CrudService<CmPayShopDao, CmPayShop> {
     }
 
     @Transactional(readOnly = false, rollbackFor = Exception.class)
-    public void settlement(String shopOrderId, Double settleAmount) throws Exception {
+    public void settlement(String shopOrderId) throws Exception {
         // 结算付供应商
         String format = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS").format(new Date());
         String substring = format.substring(20);
         String P3_customerNumber = newOrderDao.findSplitCode(shopOrderId);
-        redisService.set("SDJSS", 1, 120L);
-        settleOrder("JSCB" + shopOrderId + substring, settleAmount, P3_customerNumber, shopOrderId, 1);
+        Double shopCost = newOrderDao.findShopCost(shopOrderId);
+        settleOrder("JSCB" + shopOrderId + substring, shopCost, P3_customerNumber, shopOrderId, 1);
         // 结算佣金 佣金目前分到网络
         Double payAmount = newOrderDao.findPayAmount(shopOrderId);
         if (null != payAmount && payAmount > 0) {
             settleOrder("JSYJ" + shopOrderId + substring, payAmount, Constant.CUSTOMERNUM2, shopOrderId, 2);
         }
+        // 有组织佣金/付第三方的情况下,还需要结算组织佣金,付第三方
+        Double payOrganize = newOrderDao.findPayOrganize(shopOrderId);
+        if (null != payOrganize && payOrganize > 0) {
+            String split = newOrderDao.findOrganizeSplitByShopOrder(shopOrderId);
+            settleOrder("JSZZ" + shopOrderId + substring, payOrganize, split, shopOrderId, 3);
+        }
+        Double payOther = newOrderDao.getOtherPaid(shopOrderId);
+        if (null != payOther && payOther > 0) {
+            settleOrder("JSDSF" + shopOrderId + substring, payOther, Constant.CUSTOMERNUM3, shopOrderId, 4);
+        }
     }
 
     @Transactional(readOnly = false, rollbackFor = Exception.class)
@@ -1354,17 +1358,17 @@ public class CmPayShopService extends CrudService<CmPayShopDao, CmPayShop> {
                     newOrderDao.insertSettleRecord(settleRecord);
                     // 修改cm_split_account settlestatus
                     newOrderDao.updateSettleStatus(shopOrderId, 1);
-                    //计算供应商成本,结算金额,修改结算状态
-                    Double shouldPayShopAmount = newOrderDao.findShouldPayShopAmount(shopOrderId);
-                    Double settleSum = newOrderDao.findSettleSum(shopOrderId);
-                    if (shouldPayShopAmount > settleSum) {
-                        //成本>结算金额,部分结算
-                        newOrderDao.updateShopOrderSettleStatus(shopOrderId, 2);
-                    } else {
+//                    //计算供应商成本,结算金额,修改结算状态
+//                    Double shouldPayShopAmount = newOrderDao.findShouldPayShopAmount(shopOrderId);
+//                    Double settleSum = newOrderDao.findSettleSum(shopOrderId);
+//                    if (shouldPayShopAmount > settleSum) {
+//                        //成本>结算金额,部分结算
+//                        newOrderDao.updateShopOrderSettleStatus(shopOrderId, 2);
+//                    } else {
                         //成本=结算金额 全部结算
                         newOrderDao.updateShopOrderSettleStatus(shopOrderId, 3);
-                    }
-                } else {
+//                    }
+                } else  {
                     //佣金结算
                     settleRecord.setSettleType(settleFlag);
                     settleRecord.setSettleAmount(settleAmount);
@@ -1374,8 +1378,6 @@ public class CmPayShopService extends CrudService<CmPayShopDao, CmPayShop> {
                     // 修改cm_split_account settlestatus
                     newOrderDao.updateSettleStatus(shopOrderId, 3);
                 }
-                //解锁
-                redisService.remove("SDJSS");
             }
         }
     }

+ 26 - 34
src/main/java/com/caimei/modules/order/web/CmPayShopController.java

@@ -8,19 +8,15 @@ import com.caimei.modules.order.dao.NewOrderDao;
 import com.caimei.modules.order.dao.NewOrderProductDao;
 import com.caimei.modules.order.entity.*;
 import com.caimei.modules.order.service.*;
-import com.caimei.modules.order.utils.OrderUtil;
 import com.caimei.modules.sys.utils.UploadImageUtils;
 import com.caimei.modules.user.entity.CmUserOrganize;
 import com.caimei.modules.user.service.CmUserOrganizeService;
-import com.caimei.redis.RedisService;
-import com.caimei.utils.MathUtil;
 import com.thinkgem.jeesite.common.config.Global;
 import com.thinkgem.jeesite.common.persistence.Page;
 import com.thinkgem.jeesite.common.utils.Encodes;
 import com.thinkgem.jeesite.common.utils.StringUtils;
 import com.thinkgem.jeesite.common.web.BaseController;
 import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -33,12 +29,12 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
-import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
 
 /**
  * 付款单表Controller
@@ -49,9 +45,6 @@ import java.util.concurrent.atomic.AtomicReference;
 @Controller
 @RequestMapping(value = "${adminPath}/order/cmPayShop")
 public class CmPayShopController extends BaseController {
-
-    @Resource
-    private RedisService redisService;
     @Resource
     private CmPayShopService cmPayShopService;
     @Resource
@@ -673,23 +666,26 @@ public class CmPayShopController extends BaseController {
 
     @RequestMapping("settleTime")
     @ResponseBody
-    public Map<String, Object> settleTime(@RequestParam("shopOrderId") Integer shopOrderId) {
+    public Map<String, Object> settleTime(@RequestParam("shopOrderIds") String[] shopOrderIds) {
+        List<String> ids = Arrays.stream(shopOrderIds).collect(Collectors.toList());
         Map<String, Object> map = new HashMap<>();
         Calendar instance = Calendar.getInstance();
-        int flag = 0;
+        AtomicInteger flag = new AtomicInteger(0);
         int weekIdx = instance.get(Calendar.DAY_OF_WEEK) - 1;
         String format = new SimpleDateFormat("HH:mm:ss").format(new Date());
         Integer substring = Integer.valueOf(format.substring(0, 2));
-        //当前时间周五下午到周日都返回1不能结算,其他时间看够不够24小时
-        if ((5 == weekIdx && substring > 14) || 6 == weekIdx || 7 == weekIdx) {
-            flag = 1;
-        } else {
-            Integer val = newOrderDao.getSplitTime(shopOrderId);
-            if (val <= 0) {
-                flag = 1;
+        ids.forEach(i->{
+            //当前时间周五下午到周日都返回1不能结算,其他时间看够不够24小时
+            if ((5 == weekIdx && substring > 14) || 6 == weekIdx || 7 == weekIdx) {
+                flag.set(1);
+            } else {
+                Integer val = newOrderDao.getSplitTime(i);
+                if (val <= 0) {
+                    flag.set(1);
+                }
             }
-        }
-        map.put("flag", flag);
+        });
+        map.put("flag", flag.get());
         map.put("msg", "添加成功");
         return map;
     }
@@ -875,25 +871,21 @@ public class CmPayShopController extends BaseController {
      * @return
      */
     @RequestMapping("settlement")
-    public String settlement(Double settleAmount, String shopOrderId, RedirectAttributes redirectAttributes) throws Exception {
-        Double shouldPayShopAmount = newOrderDao.findShouldPayShopAmount(shopOrderId);
-        Double settleSum = newOrderDao.findSettleSum(shopOrderId);
-        if (settleSum >= shouldPayShopAmount) {
-            addMessage(redirectAttributes, "此订单已结算完毕!");
-            return "redirect:" + Global.getAdminPath() + "/shopOrder/settlement";
-        }
-        Integer SDJSS = (Integer) redisService.get("SDJSS");
-        //验锁
-        if (null != SDJSS && SDJSS > 0) {
-            addMessage(redirectAttributes, "请勿短时间内重复结算,等待支付公司返回结算结果!");
-            return "redirect:" + Global.getAdminPath() + "/shopOrder/splitList/?repage";
+    public String settlement(String[] shopOrderIds, RedirectAttributes redirectAttributes) throws Exception {
+        List<String> ids = Arrays.stream(shopOrderIds).collect(Collectors.toList());
+        for (String shopOrderId : ids) {
+            Double shouldPayShopAmount = newOrderDao.findShouldPayShopAmount(shopOrderId);
+            Double settleSum = newOrderDao.findSettleSum(shopOrderId);
+            if (settleSum >= shouldPayShopAmount) {
+                addMessage(redirectAttributes, "此订单已结算完毕!");
+                return "redirect:" + Global.getAdminPath() + "/shopOrder/settlement";
+            }
+            cmPayShopService.settlement(shopOrderId);
         }
-        cmPayShopService.settlement(shopOrderId, settleAmount);
         return "redirect:" + Global.getAdminPath() + "/shopOrder/settlement";
     }
 
 
-    ////applyPayWipe
     @RequiresPermissions("order:cmPayShop:edit")
     @RequestMapping("applyPayWipe")
     public String applyPayWipe(CmPayShop cmPayShop, Model model, RedirectAttributes redirectAttributes) {

+ 23 - 0
src/main/resources/mappings/modules/order/OrderMapper.xml

@@ -2056,6 +2056,29 @@
           AND type = 6
     </select>
 
+    <select id="findShopCost" resultType="java.lang.Double">
+        SELECT ifnull(SUM(splitAccount),0)
+        FROM cm_split_account
+        WHERE shopOrderId = #{shopOrderId}
+          AND payStatus = 1
+          AND productType = 1
+    </select>
+
+    <select id="findPayOrganize" resultType="java.lang.Double">
+        SELECT ifnull(SUM(splitAccount),0)
+        FROM cm_split_account
+        WHERE shopOrderId = #{shopOrderId}
+          AND payStatus = 1
+          AND productType = 5
+    </select>
+
+    <select id="findOrganizeSplitByShopOrder" resultType="java.lang.String">
+        select cmo.splitCode
+        from cm_mall_organize cmo
+        left join cm_shop_order cso on cmo.id = cso.organizeID
+        where cso.shopOrderID = #{shopOrderId}
+    </select>
+
     <insert id="addCmOrder" parameterType="com.caimei.modules.order.entity.NewOrder" useGeneratedKeys="true" keyProperty="orderID">
         insert into cm_order
         <trim prefix="(" suffix=")" suffixOverrides=",">

+ 2 - 5
src/main/resources/mappings/modules/order/ShopOrderMapper.xml

@@ -1209,14 +1209,13 @@
         LEFT JOIN cm_split_account csa on csa.shopOrderId = a.shopOrderID
         LEFT JOIN shop s ON s.shopID = a.shopID
         LEFT JOIN club c ON c.userID = a.userID
-        LEFT JOIN cm_order_product cop ON a.shopOrderID = cop.shopOrderID
-        LEFT JOIN product p ON cop.productID = p.productID
         WHERE co.organizeID = 0
         AND co.refundType != 2
         AND co.delFlag = 0
         AND co.orderType != 2
         AND co.receiptStatus = 3
         AND a.delFlag = 0
+        AND a.refundStatus = 1
         AND a.shopID != 998
         AND (a.organizeID!=4 or a.organizeID is null)
         AND cdr.payWay = 1
@@ -1226,9 +1225,7 @@
         AND cror.delFlag = 0
         AND cror.mbOrderId IS NOT NULL
         AND cror.splitStatus = 1
-        -- AND p.splitCode != 'E1807059160'
-        AND co.orderID NOT IN (SELECT orderID FROM cm_order_product cops LEFT JOIN product ps ON cops.productID =
-        ps.productID WHERE ps.splitCode = 'E1807059160' AND cops.orderID = cop.orderID)
+        AND a.splitCode != 'E1807059160'
         <if test="startTime != null and startTime != ''">
             AND (a.orderTime &gt; #{startTime} OR a.orderTime = #{startTime})
         </if>

+ 18 - 17
src/main/webapp/WEB-INF/views/modules/order/cmSettlementList.jsp

@@ -324,13 +324,13 @@
         <form:input path="endTime" type="text" maxlength="10" class="input-medium Wdate" value="${endTime}"
                     onclick="WdatePicker({dateFmt:'yyyy-MM-dd ',isShowClear:false});"/>
         <div class="pay-status">
-            <form>
-                <label>结算状态:</label>
-                <label><input name="payStatus" type="checkbox" class="pay-other-status pay-checkbox" value="1"/>未结算
-                </label>
-                <label><input name="payStatus" type="checkbox" class="pay-other-status pay-checkbox" value="2"/>部分结算
-                </label>
-            </form>
+<%--            <form>--%>
+<%--                <label>结算状态:</label>--%>
+<%--                <label><input name="payStatus" type="checkbox" class="pay-other-status pay-checkbox" value="1"/>未结算--%>
+<%--                </label>--%>
+<%--                <label><input name="payStatus" type="checkbox" class="pay-other-status pay-checkbox" value="2"/>部分结算--%>
+<%--                </label>--%>
+<%--            </form>--%>
             <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
         </div>
         <div class="clearfix"></div>
@@ -535,9 +535,9 @@
                     </tr>
                 </c:forEach>
             </table>
-            <div class="pay-more-func">
-                <a href="${ctx}/shopOrder/settleRecord?shopOrderID=${s.shopOrderID}">结算记录</a>
-            </div>
+<%--            <div class="pay-more-func">--%>
+<%--                <a href="${ctx}/shopOrder/settleRecord?shopOrderID=${s.shopOrderID}">结算记录</a>--%>
+<%--            </div>--%>
         </div>
     </c:forEach>
 </div>
@@ -824,21 +824,21 @@
             var checked = $('.pay-wrapper input[type=checkbox]:checked'), params = '?';
             for (var i = 0; i < checked.length; i++) {
                 shopOrderId = $(checked[i]).attr('data-shoporderid');
-                params += ('&shopOrderIDs=' + shopOrderId);
+                params += ('&shopOrderIds=' + shopOrderId);
             }
             if (checked.length < 1 || params == '?') {
                 alertx('请至少选择一个订单');
                 return false;
             }
-            if (checked.length > 1) {
-                alertx('每次只能选择一个子订单进行结算申请');
-                return false;
-            }
+            // if (checked.length > 1) {
+            //     alertx('每次只能选择一个子订单进行结算申请');
+            //     return false;
+            // }
             var flag=0;
             debugger;
             $.ajax({
                 url: "${ctx}/order/cmPayShop/settleTime",
-                data: {"shopOrderId":shopOrderId},
+                data: {"shopOrderIds":shopOrderId},
                 type: "POST",
                 async: false,
                 success: function(data){
@@ -849,7 +849,8 @@
                 alertx('该子订单暂未到结算时间,请于T+1后的工作日再申请结算(T指子订单分账时间)');
                 return false;
             }
-            window.location.href = '${ctx}/order/cmPayShop/settleEdit' + params;
+            window.location.href = '${ctx}/order/cmPayShop/settlement'+ params;
+            <%--window.location.href = '${ctx}/order/cmPayShop/settleEdit' + params;--%>
         });
 
         //付第三方