소스 검색

修改可使用优惠bug

liu 2 년 전
부모
커밋
625199efcd

+ 31 - 3
mhotel/src/com/happy/action/AppHotelCouponAction.java

@@ -14,6 +14,7 @@ import com.opensymphony.xwork2.ActionSupport;
 import net.sf.json.JSONObject;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.interceptor.ServletRequestAware;
+import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -139,6 +140,16 @@ public class AppHotelCouponAction extends ActionSupport implements ServletReques
         this.bookingId = bookingId;
     }
 
+    public Double totalPrice;
+
+    public Double getTotalPrice() {
+        return totalPrice;
+    }
+
+    public void setTotalPrice(Double totalPrice) {
+        this.totalPrice = totalPrice;
+    }
+
     @Resource
     BookService bookService;
 
@@ -296,10 +307,10 @@ public class AppHotelCouponAction extends ActionSupport implements ServletReques
     public JSONObject usefulCoupon() {
         JSONObject jsonObject = new JSONObject();
 
-        if (Func.checkNull(hotelId) && Func.checkNull(userId)) {
+        if (Func.checkNull(hotelId) && Func.checkNull(userId)&&totalPrice==null) {
             jsonObject.put("code", 400);
             jsonObject.put("success", false);
-            jsonObject.put("message", "缺少数据hotelId或userId---usefulCoupon");
+            jsonObject.put("message", "缺少数据hotelId,userId,totalPrice---usefulCoupon");
             ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
@@ -312,7 +323,7 @@ public class AppHotelCouponAction extends ActionSupport implements ServletReques
             return null;
         }
 
-        IPage<UsefulCouponVo> iPage = hotelCoupomService.usefulCoupon(hotelId, userId, page, rows);
+        IPage<UsefulCouponVo> iPage = hotelCoupomService.usefulCoupon(hotelId, userId, page, rows,totalPrice);
 
         jsonObject.put("code", 200);
         jsonObject.put("success", true);
@@ -404,6 +415,23 @@ public class AppHotelCouponAction extends ActionSupport implements ServletReques
             useCouponsVo.setDiscountAmount(deductionPrice);
 
         } else if (2 == type1) {
+            //            满减金额
+            Double meetPrice = hotelCoupon.getMeetPrice();
+            if (meetPrice==null||meetPrice<0) {
+                meetPrice=0.0;
+            }
+            BigDecimal meetPriceBigDecimal = new BigDecimal(meetPrice);
+
+            if (meetPrice > totalPrice) {
+                BigDecimal subtract = meetPriceBigDecimal.subtract(houseTotalPriceBigDecimal);
+                double v = subtract.doubleValue();
+                jsonObject.put("code", 400);
+                jsonObject.put("success", false);
+                jsonObject.put("message", "还差" + v + "元可使用");
+                ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+                return null;
+            }
+
 //            享受的折扣
             Double rebatePrice = hotelCoupon.getRebatePrice();
             BigDecimal rebatePriceBigDecimal = new BigDecimal(rebatePrice/10);

+ 2 - 2
mhotel/src/com/happy/dao/HotelCouponDao.java

@@ -78,8 +78,8 @@ public interface HotelCouponDao {
 
     int cardCouponPageTotal(String types, String userId);
 
-    List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows);
+    List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice);
 
-    int usefulCouponTotal(String hotelId, String userId);
+    int usefulCouponTotal(String hotelId, String userId,Double totalPrice);
 
 }

+ 6 - 5
mhotel/src/com/happy/dao/impl/HotelCouponImplDao.java

@@ -356,7 +356,7 @@ public class HotelCouponImplDao implements HotelCouponDao {
     }
 
     @Override
-    public List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows) {
+    public List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice) {
         int start = (page - 1) * rows;// 每页的起始下标
         String sql="SELECT\n" +
                 "\t hcs.id as id , hcs.complaint_id AS complaintId,\n" +
@@ -370,7 +370,7 @@ public class HotelCouponImplDao implements HotelCouponDao {
                 "\thc.effective_end_date as effectiveEndDate \n" +
                 "FROM\n" +
                 "\thotel_coupon_status hcs\n" +
-                "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id where (FIND_IN_SET(:hotelId, hc.hotelIds) or hc.hotelIds=-1 ) and hcs.user_id=:userId and hcs.status=1 \n" +
+                "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id where (FIND_IN_SET(:hotelId, hc.hotelIds) or hc.hotelIds=-1 ) and hcs.user_id=:userId and hcs.status=1 and hc.meet_price<= :totalPrice \n" +
                 "\t ORDER BY hc.effective_start_date DESC limit :start,:rows";
 
 
@@ -379,6 +379,7 @@ public class HotelCouponImplDao implements HotelCouponDao {
         sps.addValue("userId", userId);
         sps.addValue("start", start);
         sps.addValue("rows", rows);
+        sps.addValue("totalPrice",totalPrice);
         List<UsefulCouponVo> list = null;
         try{
             list = namedParameterJdbcTemplate.query(sql, sps,new BeanPropertyRowMapper<>(UsefulCouponVo.class));
@@ -390,7 +391,7 @@ public class HotelCouponImplDao implements HotelCouponDao {
     }
 
     @Override
-    public int usefulCouponTotal(String hotelId, String userId) {
+    public int usefulCouponTotal(String hotelId, String userId,Double totalPrice) {
         String sql="SELECT\n" +
                 "\tCOUNT(*) \n" +
                 "FROM\n" +
@@ -399,12 +400,12 @@ public class HotelCouponImplDao implements HotelCouponDao {
                 "WHERE\n" +
                 "\t(FIND_IN_SET(:hotelId, hc.hotelIds) or hc.hotelIds=-1 ) \n" +
                 "\tAND hcs.user_id = :userId \n" +
-                "\tAND hcs.`status` = 1";
+                "\tAND hcs.`status` = 1 and hc.meet_price<= :totalPrice ";
 
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("hotelId", hotelId);
         sps.addValue("userId", userId);
-
+        sps.addValue("totalPrice",totalPrice);
         return namedParameterJdbcTemplate.queryForInt(sql, sps);
     }
     private void appendValue(HotelCoupon hotelCoupon, StringBuffer stringBuffer, MapSqlParameterSource sps){

+ 1 - 1
mhotel/src/com/happy/service/HotelCoupomService.java

@@ -89,7 +89,7 @@ public interface HotelCoupomService {
      * @param rows
      * @return
      */
-    IPage<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows);
+    IPage<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice);
 
 
     int useCoupons(HotelCoupon hotelCoupon, HotelCouponStatus hotelCouponStatus);

+ 3 - 3
mhotel/src/com/happy/service/impl/HotelCoupomImplService.java

@@ -220,10 +220,10 @@ public class HotelCoupomImplService implements HotelCoupomService {
     }
 
     @Override
-    public IPage<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows) {
+    public IPage<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice) {
         IPage<UsefulCouponVo> iPage = new IPage();
-        List<UsefulCouponVo> hotelCouponList = hotelCouponDao.usefulCoupon(hotelId, userId, page, rows);
-        int total = hotelCouponDao.usefulCouponTotal(hotelId, userId);
+        List<UsefulCouponVo> hotelCouponList = hotelCouponDao.usefulCoupon(hotelId, userId, page, rows,totalPrice);
+        int total = hotelCouponDao.usefulCouponTotal(hotelId, userId,totalPrice);
         iPage.setPageList(hotelCouponList);
         iPage.setPage(page);
         iPage.setTotalPage((int) Math.ceil((double) total / rows));