zhijiezhao 2 年之前
父節點
當前提交
61fdfab54d

+ 2 - 1
src/main/java/com/caimei/modules/groupbuy/entity/BuyerDto.java

@@ -54,7 +54,8 @@ public class BuyerDto {
     @ApiModelProperty("手机号")
     private String mobile;
 
-
+    @ApiModelProperty("总需求数量")
+    private Integer needNum;
 
     @ApiModelProperty("参与机构数")
     private Integer clubCount;

+ 10 - 4
src/main/java/com/caimei/modules/groupbuy/service/ProcureService.java

@@ -20,16 +20,13 @@ import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.stereotype.Service;
 import org.springframework.data.mongodb.core.query.Query;
-import sun.util.calendar.BaseCalendar;
 
 import javax.annotation.Resource;
-import javax.xml.ws.Response;
-import java.text.DateFormat;
-import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.regex.Pattern;
 
 @Slf4j
@@ -154,6 +151,7 @@ public class ProcureService {
         List<BuyerDto> buyerDtos = new ArrayList<>();
         // 定义格式化字符串
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
         procurePos.forEach(p -> {
             BuyerDto buyerDto = new BuyerDto();
             String format = dateFormat.format(new Date(p.getSaveTime()));
@@ -168,6 +166,14 @@ public class ProcureService {
             status = !"0".equals(p.getDelFlag()) ? 3 : status;
             buyerDto.setStatus(status);
             BeanUtils.copyProperties(p, buyerDto);
+            AtomicReference<Integer> totalCount = new AtomicReference<>(0);
+            totalCount.set(Integer.valueOf(p.getNumber()));
+            List<AdditionalPo> procureById = additionalService.findProcureById(p.getId());
+            procureById.forEach(b -> {
+                ProcurePo byId1 = findById(b.getAdditionalId());
+                totalCount.set(totalCount.get() + Integer.parseInt(byId1.getNumber()));
+            });
+            buyerDto.setNeedNum(totalCount.get());
             buyerDtos.add(buyerDto);
         });
         long count = mongoTemplate.count(query, ProcurePo.class);

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

@@ -94,4 +94,6 @@ public interface PayShopDao {
     Double findShopPostFee(Integer shopOrderId);
 
     NewShopOrder findShopOrderByPayShop(Integer payShopId);
+
+    Integer getSplitTime(Integer shopOrderId);
 }

+ 33 - 11
src/main/java/com/caimei/modules/order/service/impl/PayShopServiceImpl.java

@@ -21,6 +21,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
 
@@ -142,7 +143,6 @@ public class PayShopServiceImpl implements PayShopService {
 
             orderPayShop.setPayTime(DateUtils.getDateTime());
             orderPayShop.setStatus(1);
-            log.info("orderPayShop--------------------"+orderPayShop);
             payShopDao.updatePayShop(orderPayShop);
             return ResponseJson.success();
         } else {
@@ -256,6 +256,7 @@ public class PayShopServiceImpl implements PayShopService {
                     log.info("【分账】>>>>>>>>>>子订单id:" + s + "进入分账");
                     // 收款对应的订单信息
                     NewShopOrder shopOrder = newOrderDao.getShopOrderListByOrderId(orderRelation.getShopOrderId());
+                    orderUtils.getShouldPay(shopOrder);
                     PayParamBo payParam = new PayParamBo();
                     //支付金额
                     payParam.setAllPay(orderRelation.getAssociateAmount());
@@ -327,11 +328,12 @@ public class PayShopServiceImpl implements PayShopService {
                                             Double paidAmount = newOrderDao.getPaidShopAmount(shopOrderId);
                                             Double paidShop = MathUtil.add(paidAmount, splitAmount).doubleValue();
                                             shopOrder.setPayedShopAmount(paidShop);
-                                            if (MathUtil.compare(shopOrder.getShouldPayShopAmount(), paidShop) == 0) {
+                                            //todo
+//                                            if (MathUtil.compare(shopOrder.getShouldPayShopAmount(), paidShop) == 0) {
                                                 shopOrder.setPayStatus(3);
-                                            } else {
-                                                shopOrder.setPayStatus(2);
-                                            }
+//                                            } else {
+//                                                shopOrder.setPayStatus(2);
+//                                            }
                                             // 修改子订单付款状态及付款金额
                                             newOrderDao.updateShopOrderByPayStatus(shopOrderId, paidShop, shopOrder.getPayStatus());
                                         }
@@ -390,6 +392,27 @@ public class PayShopServiceImpl implements PayShopService {
     @Override
     public ResponseJson settleShopOrders(OrderPayShopDetail payShop) {
         List<NewShopOrder> shopOrders = payShop.getShopOrders();
+        AtomicInteger flag = new AtomicInteger();
+        shopOrders.forEach(o -> {
+            Calendar instance = Calendar.getInstance();
+            int weekIdx = instance.get(Calendar.DAY_OF_WEEK) - 1;
+            String form = new SimpleDateFormat("HH:mm:ss").format(new Date());
+            Integer sub = Integer.valueOf(form.substring(0, 2));
+            //当前时间周五下午到周日都返回1不能结算,其他时间看够不够24小时
+            if ((5 == weekIdx && sub > 14) || 6 == weekIdx || 7 == weekIdx) {
+                flag.set(1);
+                return;
+            } else {
+                Integer val = payShopDao.getSplitTime(o.getShopOrderId());
+                if (val <= 0) {
+                    flag.set(1);
+                    return;
+                }
+            }
+        });
+        if (1 == flag.get()) {
+            return ResponseJson.error("当前时间为周五下午到周日,或分账完成时间不足24小时,无法结算!");
+        }
         String format = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS").format(new Date());
         String substring = format.substring(20);
         shopOrders.forEach(s -> {
@@ -403,9 +426,9 @@ public class PayShopServiceImpl implements PayShopService {
         });
         NewShopOrder shopOrder = newShopOrderDao.findColdChainShopOrder(shopOrders.get(0).getOrderId());
         // 联合丽格冷链费
-        if (null != shopOrder && 1 == shopOrder.getIsColdChina() && shopOrder.getShopPostFee() >= 700) {
+        if (null != shopOrder && 1 == shopOrder.getIsColdChina() && shopOrder.getShopPostFee() >= 0) {
             try {
-                orderUtils.settleOrder("JSLLF" + shopOrder.getShopOrderId() + substring, 700d, Constant.LHLGCUSTOMERNUM, shopOrder.getShopOrderId(), 6);
+                orderUtils.settleOrder("JSLLF" + shopOrder.getShopOrderId() + substring, shopOrder.getShopPostFee(), Constant.LHLGCUSTOMERNUM, shopOrder.getShopOrderId(), 6);
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -533,10 +556,8 @@ public class PayShopServiceImpl implements PayShopService {
         // 子订单商品成本
         AtomicReference<BigDecimal> totalCostPrice = new AtomicReference<>();
         for (NewOrderProduct orderProduct : orderProductList) {
-            // 售价 * 数量 = 总价
-            BigDecimal total = MathUtil.mul(orderProduct.getPrice(), orderProduct.getNum());
             // 总价 * 供应商百分比 = 成本分账金额
-            double costPrice = MathUtil.mul(total, MathUtil.div(orderProduct.getShopPercent(), 100)).doubleValue();
+            double costPrice = MathUtil.mul(orderProduct.getTotalAmount(), MathUtil.div(orderProduct.getShopPercent(), 100)).doubleValue();
             // 供应商承担手续费 ,减去手续费
             String payType = payParam.getPayType();
             double charge = 0d;
@@ -560,8 +581,9 @@ public class PayShopServiceImpl implements PayShopService {
                 charge = Math.max(MathUtil.mul(splitAmount, 0.006, 2).doubleValue(), 0.1);
             }
             costPrice = costPrice - charge;
+            splitAmount = splitAmount - charge;
             totalCostPrice.set(MathUtil.add(costPrice, totalCostPrice.get()));
-            double organize = MathUtil.mul(total, MathUtil.div(orderProduct.getOrganizePercent(), 100), 2).doubleValue();
+            double organize = MathUtil.mul(orderProduct.getTotalAmount(), MathUtil.div(orderProduct.getOrganizePercent(), 100), 2).doubleValue();
             totalOrganize.set(MathUtil.add(organize, totalOrganize.get()));
             /**
              * todo

+ 6 - 1
src/main/java/com/caimei/modules/order/util/OrderUtils.java

@@ -146,6 +146,10 @@ public class OrderUtils {
             waitSettleCm = MathUtil.sub(cmFee, settleCm).doubleValue();
             settleOrganize = payShopDao.findSettleSum(shopOrder.getShopOrderId(), 3);
             waitSettleOrganize = MathUtil.sub(organizeFee.get(), settleOrganize).doubleValue();
+            // 减0.1%分账手续费
+            cmFee = MathUtil.div(cmFee, 1.001, 2).doubleValue();
+            v = MathUtil.div(v, 1.001, 2).doubleValue();
+
             shouldSettleShop = v;
             shouldSettleCm = cmFee;
             shouldSettleOrganize = organizeFee.get().doubleValue();
@@ -171,7 +175,8 @@ public class OrderUtils {
         shopOrder.setBrokerage(organizeFee.get().doubleValue());
         shopOrder.setWaitPayCmAmount(MathUtil.sub(cmFee, paidCm).doubleValue());
         // 待付不加供应商运费
-        shopOrder.setWaitPayShop(v - paidShop - shopPostFee);
+        shopOrder.setWaitPayShop(MathUtil.sub(v, MathUtil.add(paidShop, shopPostFee)).doubleValue());
+
         shopOrder.setShouldPayCmAmount(cmFee);
         shopOrder.setShouldPayShopAmount(v);
         shopOrder.setReceiptTotalFee(receiptTotal.get());

+ 7 - 3
src/main/resources/mapper/NewShopOrderMapper.xml

@@ -484,10 +484,10 @@
         LEFT JOIN cm_split_account csa on csa.shopOrderId = a.shopOrderID
         <where>
             <if test="orderStartTime != null and orderStartTime != ''">
-                AND (a.orderTime &gt; #{startTime} OR a.orderTime = #{startTime})
+                AND (a.orderTime &gt; #{orderStartTime} OR a.orderTime = #{orderStartTime})
             </if>
             <if test="orderEndTime != null and orderEndTime != ''">
-                AND (a.orderTime &lt; #{endTime} OR a.orderTime = #{endTime})
+                AND (a.orderTime &lt; #{orderEndTime} OR a.orderTime = #{orderEndTime})
             </if>
             <if test="orderId != null">
                 AND a.orderID = #{orderId}
@@ -527,9 +527,13 @@
                 AND cror.mbOrderId IS NOT NULL
                 AND cror.splitStatus = 1
             </if>
+            <if test="listType == 1">
+                AND (cdr.payWay != 1 OR cdr.payWay is NULL)
+                and a.payStatus != 3
+            </if>
             AND co.organizeID = #{organizeId}
             and (co.confirmFlag = '1' or co.confirmFlag = '2')
-            and a.payStatus != 3 and co.status NOT IN (6,7)
+            and co.status NOT IN (6,7)
             and co.delFlag = 0
             and a.delFlag = 0
             and a.shopID != 998

+ 10 - 1
src/main/resources/mapper/PayShopDao.xml

@@ -327,9 +327,11 @@
                a.shopId,
                (select bankAccount from cm_shop_account where id = 1)     as cmBankAccount,
                (select bankAccountName from cm_shop_account where id = 1) as cmbankAccountName,
-               (select bankName from cm_shop_account where id = 1)        as cmbankName
+               (select bankName from cm_shop_account where id = 1)        as cmbankName,
+               coc.bankAccount as bankNameType
         FROM cm_pay_shop a
         left join cm_mall_admin_user u1 on u1.id = a.applicant
+        left join cm_offline_collection coc on coc.TYPE = a.payType
         left join cm_mall_admin_user u2 on u2.id = a.reviewer
         left join shop s on s.shopID = a.shopID
         where a.id = #{id}
@@ -706,4 +708,11 @@
         where cps.id = #{payShopId}
           and cso.shopId != 998
     </select>
+
+    <select id="getSplitTime" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM cm_split_account
+        WHERE shopOrderId=#{shopOrderId}
+        AND DATE_ADD(splitTime,INTERVAL 1 DAY) <![CDATA[  <  ]]> now()
+    </select>
 </mapper>