Explorar o código

Merge branch 'master' of https://e.coding.net/chuanghaikeji/jinganxiangsu/Homestay_app_houtai

lijie %!s(int64=2) %!d(string=hai) anos
pai
achega
532229436f

+ 11 - 0
mhotel/src/com/happy/Model/Hotel.java

@@ -166,6 +166,17 @@ public class Hotel {
 
 	private String collect_hotel;
 	private boolean is_collect_hotel;
+
+	private Double score;
+
+	public Double getScore() {
+		return score;
+	}
+
+	public void setScore(Double score) {
+		this.score = score;
+	}
+
 	/**
 	 * 720全景图链接
 	 */

+ 4 - 0
mhotel/src/com/happy/Model/HotelCouponStatus.java

@@ -16,6 +16,10 @@ public class HotelCouponStatus {
 
 	private String complaintId; // 优惠卷id
 
+	private String bookingId;// 订单id
+
+	private Double discountAmount;//优惠金额
+
 	private String userId; // 用户id
 
 	private String createId; // 创建人

+ 37 - 2
mhotel/src/com/happy/action/AppBookingAction.java

@@ -31,6 +31,8 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedReader;
 import java.io.PrintWriter;
 import java.text.ParseException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 /**
@@ -52,6 +54,11 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     @Resource
     public AdminManagerService adminManagerService;
 
+    @Resource
+    public HotelCoupomService hotelCoupomService;
+    @Resource
+    public HotelCoupomStatusService hotelCoupomStatusService;
+
     public int page; // 当前页
     public int rows;// 每页显示的行数rows
     public Integer id;
@@ -84,6 +91,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         this.request = request;
     }
 
+    @Override
     public void setServletRequest(HttpServletRequest request) {
         this.request = request;
     }
@@ -129,6 +137,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     }
 
     public String complaintId;
+    public String useId;
 
     public String getComplaintId() {
         return complaintId;
@@ -138,6 +147,14 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         this.complaintId = complaintId;
     }
 
+    public String getUseId() {
+        return useId;
+    }
+
+    public void setUseId(String useId) {
+        this.useId = useId;
+    }
+
     /**
      * 定时任务
      * @return
@@ -262,8 +279,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             return null;
         }
 
-        String  bookingId= Func.parseStr(UUIDUtil.generateID());
-        String mess = appBookService.createOrder(bookingId, houseId, startDate, endDate, houseOrderNumber, userName, userPhone, userId,complaintId);
+        String bookingId = Func.parseStr(UUIDUtil.generateID());
+        String mess = appBookService.createOrder(bookingId, houseId, startDate, endDate, houseOrderNumber, userName, userPhone, userId, complaintId, useId);
         if (!Func.checkNull(mess)) {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
             jsonObject.put(B.message, mess);
@@ -805,6 +822,24 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 //用户开启支付,写入数据操作
                 bookinglogService.addBooklog("用户点击订单,进行支付"  ,booking);
 
+                //通过订单id找到所属优惠券
+                List<HotelCouponStatus> hotelCouponStatusList = hotelCoupomStatusService.getBookingId(bookingId);
+                if (hotelCouponStatusList != null && hotelCouponStatusList.size() > 0) {
+                    for (HotelCouponStatus hotelCouponStatus : hotelCouponStatusList) {
+                        String complaintId = hotelCouponStatus.getComplaintId();
+                        HotelCoupon hotelCoupon = hotelCoupomService.getById(complaintId);
+                        if (hotelCoupon!=null) {
+                            Integer reversedNumber = hotelCoupon.getReversedNumber();
+                            if (reversedNumber==null) {
+                                reversedNumber=0;
+                            }
+                            hotelCoupon.setReversedNumber(reversedNumber+1);
+                            hotelCoupon.setModifyDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+                            hotelCoupomService.update(hotelCoupon);
+                        }
+                    }
+                }
+
                 resultjson.put(B.code, ResultStatusCode.OK.getStatus());
                 resultjson.put(B.message, "返回成功");
                 resultjson.put(B.data, pay);

+ 1 - 1
mhotel/src/com/happy/action/AppHomePageAction.java

@@ -205,7 +205,7 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
 
         // 添加是否已收藏的酒店
         if (!Func.checkNull(userId))
-           appHomePageService.assignCollect(userId, hotel);
+           hotel=appHomePageService.assignCollect(userId, hotel);
 
         //region 2023-09-12 A-jax 添加房型均价:入住的每一天的价格之和 / 入住天数
         List<HousePriceDataVo> hprd = housePriceService.queryHousePriceDatas(hotel.getManagerId(), queryStartTime, TimeExchange.TimeDesD(queryEndTime, -1));

+ 1 - 0
mhotel/src/com/happy/dao/HotelCoupomStatusDao.java

@@ -25,4 +25,5 @@ public interface HotelCoupomStatusDao {
 
     int update(HotelCouponStatus hotelCouponStatus);
 
+    List<HotelCouponStatus> getBookingId(String bookingId);
 }

+ 17 - 1
mhotel/src/com/happy/dao/impl/HotelCoupomStatusImplDao.java

@@ -103,7 +103,7 @@ public class HotelCoupomStatusImplDao implements HotelCoupomStatusDao {
 
     @Override
     public HotelCouponStatus getById(String id) {
-        String sql = "select * from hotel_coupon_status AND id = :id ";
+        String sql = "select * from hotel_coupon_status where id = :id and status=1";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("id",id);
         List<HotelCouponStatus> list = null;
@@ -140,4 +140,20 @@ public class HotelCoupomStatusImplDao implements HotelCoupomStatusDao {
         return num;
 
     }
+
+    @Override
+    public List<HotelCouponStatus> getBookingId(String bookingId) {
+        String sql="select * from hotel_coupon_status where booking_id=:bookingId and status=1 ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("bookingId",bookingId);
+        List<HotelCouponStatus> list = null;
+        try{
+            list = namedParameterJdbcTemplate.query(sql, sps,
+                    new BeanPropertyRowMapper<>(HotelCouponStatus.class));
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        if(list != null && list.size()>0) return list;
+        return null;
+    }
 }

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

@@ -106,7 +106,7 @@ public class HotelCouponImplDao implements HotelCouponDao {
 
     @Override
     public HotelCoupon getById(String id) {
-        String sql = selectSql + " AND id = :id ";
+        String sql = selectSql + " AND id = :id and status=1";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("id",id);
         List<HotelCoupon> list = null;

+ 2 - 1
mhotel/src/com/happy/dao/impl/HotelImplDao.java

@@ -169,7 +169,8 @@ public class HotelImplDao implements HotelDao {
     public List<Hotel> queryPagePrice(String sqlx, int page, int rows) {
         SqlUtil.filterKeyword(sqlx);
         int start = (page - 1) * rows;// 每页的起始下标
-        String sql = "SELECT a.*,b.min_price,c.hotel_township,d.hotel_township_name, e.h_type_name,c.hotel_name,c.link_pro_url FROM `hotel` a " +
+        String sql = "SELECT a.*,b.min_price,c.hotel_township,d.hotel_township_name, e.h_type_name,c.hotel_name,c.link_pro_url,(SELECT round( AVG( score ), 1 ) as score FROM `booking_comment` bc where bc.comment_parent_id IS NULL AND bc.hotel_id = a.id AND `status` = 1) as score" +
+                " FROM `hotel` a " +
                 "left join (select manager_id,min(price) min_price from house where status=1 group by manager_id) b on a.manager_id = b.manager_id " +
                 "left join (select id,manager_id,hotel_township,hotel_name,type,status,link_pro_url from admin_manager ) c on a.manager_id = c.id " +
                 "LEFT JOIN (  SELECT  id,name as hotel_township_name,status  FROM  hotel_dict GROUP BY  id) d ON d.id = c.hotel_township " +

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

@@ -19,7 +19,7 @@ public interface AppBookService {
      * @param userId
      * @return
      */
-    public String createOrder(String bookingId, String houseId,String startTime,String endTime,String houseOrderNumber,String userName,String userPhone, String userId,String complaintId);
+    public String createOrder(String bookingId, String houseId,String startTime,String endTime,String houseOrderNumber,String userName,String userPhone, String userId,String complaintId,String useId);
 
 
 //    /**

+ 10 - 0
mhotel/src/com/happy/service/HotelCoupomStatusService.java

@@ -25,4 +25,14 @@ public interface HotelCoupomStatusService {
     HotelCouponStatus getById(String id);
 
     int update(HotelCouponStatus hotelCouponStatus);
+
+    List<HotelCouponStatus> getBookingId(String bookingId);
+
+    /**
+     * 通过订单id返还优惠券
+     * @param bookingId
+     * @return
+     */
+    int restitution(List<HotelCouponStatus> list);
+
 }

+ 28 - 8
mhotel/src/com/happy/service/impl/AppBookImplService.java

@@ -16,6 +16,7 @@ import com.happy.dto.IPage;
 import com.happy.service.*;
 import org.apache.struts2.ServletActionContext;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -42,11 +43,14 @@ public class AppBookImplService implements AppBookService {
 
     @Resource
     public HotelCoupomService hotelCoupomService;
+    @Resource
+    public HotelCoupomStatusService hotelCoupomStatusService;
 
     @Override
-    public String createOrder(String bookingId, String houseId, String startTime, String endTime, String houseOrderNumber, String userName, String userPhone, String userId,String complaintId) {
-        if (Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
-                ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
+    @Transactional(rollbackFor = Exception.class)
+    public String createOrder(String bookingId, String houseId, String startTime, String endTime, String houseOrderNumber, String userName, String userPhone, String userId, String complaintId, String useId) {
+        if (Func.checkNull(houseId) || Func.checkNull(startTime) || Func.checkNull(endTime)
+                || Func.checkNull(houseOrderNumber) || Func.checkNull(userName) || Func.checkNull(userPhone) || Func.checkNull(userId))
             return null;
 
         House house = houseService.getById(Func.parseInt(houseId));
@@ -91,8 +95,12 @@ public class AppBookImplService implements AppBookService {
         booking.setHouseRemake(house.getRemark());
         double totalPrice = Func.parseDbl(houseOrderNumber) * house.getPrice() * day;
 
-        if (!Func.checkNull(complaintId)) {
-            BigDecimal totalPriceBigDecimal = new BigDecimal(totalPrice);
+        if (!Func.checkNull(complaintId) && !Func.checkNull(useId)) {
+            HotelCouponStatus hotelCouponStatus = hotelCoupomStatusService.getById(useId);
+            if (hotelCouponStatus!=null) {
+                hotelCouponStatus.setStatus(2);
+                hotelCouponStatus.setBookingId(bookingId);
+                BigDecimal totalPriceBigDecimal = new BigDecimal(totalPrice);
 
             //        优惠券
             HotelCoupon hotelCoupon = hotelCoupomService.getById(complaintId);
@@ -108,7 +116,9 @@ public class AppBookImplService implements AppBookService {
                     BigDecimal deductionPriceBigDecimal = new BigDecimal(deductionPrice);
                     //            实付金额
                     BigDecimal subtract = totalPriceBigDecimal.subtract(deductionPriceBigDecimal);
-                    totalPrice=subtract.doubleValue();
+                    totalPrice = subtract.doubleValue();
+                    hotelCouponStatus.setDiscountAmount(deductionPrice);
+                    hotelCoupomStatusService.update(hotelCouponStatus);
                 }
 
             } else if (2 == type) {
@@ -129,9 +139,19 @@ public class AppBookImplService implements AppBookService {
                 double v1 = subtract.doubleValue();
 
                 if (v > v1) {
-                    totalPrice=v;
+                    totalPrice = v;
+                    BigDecimal subtract1 = totalPriceBigDecimal.subtract(bigDecimal);
+                    hotelCouponStatus.setDiscountAmount(subtract1.doubleValue());
                 } else if (v < v1) {
-                    totalPrice=v1;
+                    totalPrice = v1;
+                    hotelCouponStatus.setDiscountAmount(maxDeduction);
+                }else if (v==v1){
+                    totalPrice = v1;
+                    hotelCouponStatus.setDiscountAmount(maxDeduction);
+                }
+
+                hotelCoupomStatusService.update(hotelCouponStatus);
+
                 }
             }
         }

+ 2 - 1
mhotel/src/com/happy/service/impl/AppHomePageImplService.java

@@ -104,7 +104,8 @@ public class AppHomePageImplService implements AppHomePageService {
         boolean flag = false; // 标识是否收获过当前酒店,Collect_hotel为空时未收藏, Collect_hotel未包含hotelid未收藏
         if (!Func.checkNull(users.getCollect_hotel()))
         {
-            flag = users.getCollect_hotel().contains(Func.parseStr(hotel.getId()));
+            String collect_hotel = users.getCollect_hotel();
+            flag = collect_hotel.contains(hotel.getId()+"");
         }
         hotel.setIs_collect_hotel(flag);
         return hotel;

+ 18 - 0
mhotel/src/com/happy/service/impl/HotelCoupomStatusImplService.java

@@ -43,4 +43,22 @@ public class HotelCoupomStatusImplService implements HotelCoupomStatusService {
     public int update(HotelCouponStatus hotelCouponStatus) {
         return hotelCoupomStatusDao.update(hotelCouponStatus);
     }
+
+    @Override
+    public List<HotelCouponStatus> getBookingId(String bookingId) {
+        return hotelCoupomStatusDao.getBookingId(bookingId);
+    }
+
+    @Override
+    public int restitution(List<HotelCouponStatus> list) {
+        int update=0;
+        for (HotelCouponStatus hotelCouponStatus : list) {
+            hotelCouponStatus.setStatus(1);
+            hotelCouponStatus.setBookingId("");
+            hotelCouponStatus.setDiscountAmount(0.0);
+             update = update(hotelCouponStatus);
+        }
+
+        return update;
+    }
 }