Browse Source

Merge remote-tracking branch 'origin/master'

Longlin 5 years ago
parent
commit
08f542e288

+ 10 - 6
whepi-ui/templates/home/buy.ftl

@@ -22,7 +22,9 @@
                         <div style="width: 33%; text-align: center;color: #0a001f">订单状态</div>
                     </div>
                 </div>
-                <div id="MyBuyAll">
+                <div class="container">
+                    <div id="MyBuyAll">
+                    </div>
                 </div>
             </div>
         </div>
@@ -35,8 +37,9 @@
                 <div style="width: 15%; text-align: center;color: #0a001f">状态</div>
             </div>
         </div>
-        <div id="buyAll" class="weui-panel__bd">
-        <#--   <a href="javascript:void(0);" style="color: grey;font-size: large">
+        <div class="container">
+            <div id="buyAll" class="weui-panel__bd">
+            <#--   <a href="javascript:void(0);" style="color: grey;font-size: large">
                 <div style="display: flex; flex-direction: row; text-align: center; font-size: x-small; line-height: 5vh;"
                      onclick=" myBuyClick()">
                     <div style="width: 40%; overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size: 12px">
@@ -53,6 +56,7 @@
                     </div>
                 </div>
             </a>-->
+            </div>
         </div>
     </div>
 
@@ -138,13 +142,13 @@
             if (v.buyStatus != 1) {
                 return $.alert("该订单已经取消");
             }
-            window.location.href = "/home/buytc.html?userId=" + $('#userId').val() + "&jmId=" + v.jmId + "&type=" + 2 + "&tgStatus=" + v.tgStatus+"&buyId="+v.buyId;
+            window.location.href = "/home/buytc.html?userId=" + $('#userId').val() + "&jmId=" + v.jmId + "&type=" + 2 + "&tgStatus=" + v.tgStatus + "&buyId=" + v.buyId;
         }
 
 
         /*居民求助信息*/
         function myBuyClick(v) {
-            window.location.href = "/home/buytc.html?userId=" + $('#userId').val() + "&jmId=" + v.jmId + "&type=" + 1 + "&tgStatus=" + v.tgStatus+"&buyId="+1;
+            window.location.href = "/home/buytc.html?userId=" + $('#userId').val() + "&jmId=" + v.jmId + "&type=" + 1 + "&tgStatus=" + v.tgStatus + "&buyId=" + 1;
         }
 
 
@@ -179,6 +183,6 @@
             var h = (date.getHours() < 10) ? ('0' + date.getHours() + ':') : (date.getHours() + ':');
             var m = (date.getMinutes() < 10) ? ('0' + date.getMinutes() + ':') : (date.getMinutes() + ':');
             var s = (date.getSeconds() < 10) ? ('0' + date.getSeconds()) : (date.getSeconds());
-            return  M + D + h + m + s;
+            return M + D + h + m + s;
         }
     </script>

+ 1 - 1
whepi-ui/templates/home/buyClient.ftl

@@ -17,7 +17,7 @@
             <div style="display: inline;">
                 <input type="text" id="buyCount"
                        style="border: 1px solid rgba(0,0,0,.2);box-sizing:border-box; border-radius: 5px; height: 5vh; width: 50%;font-size: 16px;margin-top: 1vh;"
-                       maxlength="6" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" min="1"
+                       maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" min="1"
                        onchange="changeBuy()">
             </div>
         </div>

+ 2 - 0
whepi-web/src/main/java/com/bofeng/dao/BuyMapper.java

@@ -22,4 +22,6 @@ public interface BuyMapper extends BaseMapper<Buy> {
   JmTuangou selectGroup(@Param("userId") Long userId, @Param("jmId") Long jmId);
 
   Buy status(@Param("jmId") Long jmId);
+
+  List<Buy> selectCountNum(@Param("jmId") Long jmId);
 }

+ 12 - 8
whepi-web/src/main/java/com/bofeng/dao/JmTuangouDao.java

@@ -12,19 +12,23 @@ import java.util.List;
 @Repository
 public interface JmTuangouDao extends BaseMapper<JmTuangou> {
 
-    List<JmTuangou> queryTuangouListByUptownId (@Param("uptownId") Long uptownId);
+  List<JmTuangou> queryTuangouListByUptownId(@Param("uptownId") Long uptownId);
 
-    List<JmTuangou> queryTuangouListByUptownIdAndTitle (@Param("uptownId") Long uptownId, @Param("title") String title);
+  List<JmTuangou> queryTuangouListByUptownIdAndTitle(@Param("uptownId") Long uptownId, @Param("title") String title);
 
-    List<JmTuangou> queryTuangouListByUserId (@Param("userId") Long userId);
+  List<JmTuangou> queryTuangouListByUserId(@Param("userId") Long userId);
 
-    List<JmTuangou> queryTuangouListByUserIdAndTitle (@Param("userId") Long userId, @Param("title") String title);
+  List<JmTuangou> queryTuangouListByUserIdAndTitle(@Param("userId") Long userId, @Param("title") String title);
 
-    JmTuangou selectJmTuangouByJmId(@Param("JmId") Long JmId);
+  JmTuangou selectJmTuangouByJmId(@Param("JmId") Long JmId);
 
-    Integer updateRemarkByJmId(@Param("JmId") Long JmId, @Param("remark") String remark);
+  Integer updateRemarkByJmId(@Param("JmId") Long JmId, @Param("remark") String remark);
 
-    Integer updateStatusByJmId(@Param("JmId") Long JmId, @Param("status") Long status);
+  Integer updateStatusByJmId(@Param("JmId") Long JmId, @Param("status") Long status);
 
-    Integer updateStatusRemarkByJmId(@Param("JmId") Long JmId, @Param("status") Long status, @Param("remark") String remark);
+  Integer updateStatusRemarkByJmId(@Param("JmId") Long JmId, @Param("status") Long status, @Param("remark") String remark);
+
+  List<JmTuangou> selectAll();
+
+  int updateAll(@Param("tg") List<JmTuangou> tg);
 }

+ 39 - 1
whepi-web/src/main/java/com/bofeng/service/BuyService.java

@@ -2,6 +2,7 @@ package com.bofeng.service;
 
 import com.baomidou.mybatisplus.toolkit.IdWorker;
 import com.bofeng.dao.BuyMapper;
+import com.bofeng.dao.JmTuangouDao;
 import com.bofeng.entity.Buy;
 import com.bofeng.entity.JmTuangou;
 import org.joda.time.DateTime;
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -19,6 +21,9 @@ public class BuyService {
   @Autowired
   private BuyMapper buyMapper;
 
+  @Autowired
+  private JmTuangouDao jmTuangouDao;
+
   @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
   public int buyGroup(Buy buy) {
     Buy buy1 = buyMapper.selectBuyOne(buy.getUserId(), buy.getJmId());
@@ -33,11 +38,15 @@ public class BuyService {
     return buyMapper.insert(buy);
   }
 
+  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
   public List<JmTuangou> group(Long userId) {
+    updateStatus();
     return buyMapper.group(userId);
   }
 
+  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
   public List<Buy> MyGroup(Long userId) {
+    updateStatus();
     return buyMapper.MyGroup(userId);
   }
 
@@ -54,7 +63,7 @@ public class BuyService {
   public int buyBack(Buy buy) {
     //在该套餐截止日期之前 并且是在团状态的才能撤单
     JmTuangou jmTuangou = buyMapper.selectGroup(buy.getUserId(), buy.getJmId());
-    if (jmTuangou.getTgEndTime().getTime() >= new DateTime().getMillis() && jmTuangou.getTgStatus() == 1) {
+    if (jmTuangou.getTgEndTime().getTime() > new DateTime().getMillis() && jmTuangou.getTgStatus() == 1) {
       Buy buy1 = buyMapper.selectBuyOne(buy.getUserId(), buy.getJmId());
       buy.setBuyId(buy1.getBuyId());
       buy.setBuyStatus(2);//撤单
@@ -67,4 +76,33 @@ public class BuyService {
   public Buy status(Buy buy) {
     return buyMapper.status(buy.getJmId());
   }
+
+  //截止日期状态的更改
+  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
+  public int updateStatus() {
+    List<JmTuangou> jmTuangous = jmTuangouDao.selectAll();
+    if (jmTuangous != null && jmTuangous.size() > 0) {
+      //已经到截止时间
+      for (JmTuangou list : jmTuangous)
+        if (list.getTgEndTime().getTime() < new DateTime().getMillis()) {
+
+          // 团购数量  最小起订量
+          List<Buy> buys = buyMapper.selectCountNum(list.getJmId());
+          if (buys != null && buys.size() > 0) {
+            for (Buy v : buys) {                //最小起订量
+              if (v.getCount().intValue() < list.getTgMinNum().intValue()) {
+                jmTuangouDao.updateStatusByJmId(list.getJmId(), 4L);//取消
+              } else {
+                jmTuangouDao.updateStatusByJmId(list.getJmId(), 2L);//发货
+              }
+            }
+          } else {
+            jmTuangouDao.updateStatusByJmId(list.getJmId(), 4L);//取消
+          }
+
+        }
+    }
+    return 1;
+  }
+
 }

+ 1 - 0
whepi-web/src/main/java/com/bofeng/wx/controller/BuyController.java

@@ -35,6 +35,7 @@ public class BuyController {
     model.put("type", type);
     model.put("tgStatus", tgStatus);
     model.put("buyId", buyId);
+    buyService.updateStatus();
     return new ModelAndView("/home/buytc.ftl", model);
   }
 

+ 4 - 0
whepi-web/src/main/resources/mapper/BuyMapper.xml

@@ -39,4 +39,8 @@
       WHERE a.jm_id = #{jmId} limit 1
     </select>
 
+    <select id="selectCountNum" resultType="com.bofeng.entity.Buy">
+        select sum(buy_count) as count,buy_id from jm_buy where jm_id=#{jmId} GROUP BY buy_id
+    </select>
+
 </mapper>

+ 10 - 0
whepi-web/src/main/resources/mapper/JmTuangouMapper.xml

@@ -43,4 +43,14 @@
     <update id="updateStatusRemarkByJmId">
         update jm_tuangou set tg_status=#{status},remark=#{remark} where jm_id=#{JmId}
     </update>
+
+    <select id="selectAll" resultType="com.bofeng.entity.JmTuangou">
+        select * from jm_tuangou where tg_status=1
+    </select>
+
+    <update id="updateAll">
+        <foreach collection="tg" item="item" index="index" separator=";">
+            update jm_tuangou set tg_status=#{item.tgStatus} where jm_id=#{item.jmId}
+        </foreach>
+    </update>
 </mapper>