xieli 2 лет назад
Родитель
Сommit
929e48930a

+ 19 - 0
mhotel/src/com/happy/Model/weixin/Users.java

@@ -18,6 +18,9 @@ public class Users {
     private String contactName;   // 关联人姓名(用于常联系人关联)
     private String dataType; // 数据类型
     private String headPhoto; // 用户头像地址
+    private String collect_hotel; // 收藏酒店
+    private String live_hotel;// 住过酒店
+
 
     public int getId() {
         return id;
@@ -122,4 +125,20 @@ public class Users {
     public void setHeadPhoto(String headPhoto) {
         this.headPhoto = headPhoto;
     }
+
+    public String getCollect_hotel() {
+        return collect_hotel;
+    }
+
+    public void setCollect_hotel(String collect_hotel) {
+        this.collect_hotel = collect_hotel;
+    }
+
+    public String getLive_hotel() {
+        return live_hotel;
+    }
+
+    public void setLive_hotel(String live_hotel) {
+        this.live_hotel = live_hotel;
+    }
 }

+ 1 - 0
mhotel/src/com/happy/Until/Enum/OrderEnum.java

@@ -3,3 +3,4 @@ package com.happy.Until.Enum;
 public enum OrderEnum {
     间, 晚,房间已满,超出限定房间数量,有空房,微信支付,微信退款,生成订单,将订单设置为已超时,用户访问量;
 }
+

+ 5 - 0
mhotel/src/com/happy/Until/Enum/TempEnum.java

@@ -0,0 +1,5 @@
+package com.happy.Until.Enum;
+
+public enum TempEnum {
+    收藏,住过;
+}

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

@@ -1,8 +1,11 @@
 package com.happy.action;
 
+import com.baidubce.model.User;
 import com.happy.Model.Hotel;
+import com.happy.Model.weixin.Users;
 import com.happy.Until.DateUtil;
 import com.happy.Until.Enum.B;
+import com.happy.Until.Enum.TempEnum;
 import com.happy.Until.Func;
 import com.happy.Until.ResponseUtil;
 import com.happy.Until.ResultUtil;
@@ -12,6 +15,7 @@ import com.happy.dto.IPage;
 import com.happy.service.AppHomePageService;
 import com.happy.service.FileService;
 import com.happy.service.HotelService;
+import com.happy.service.UserService;
 import com.opensymphony.xwork2.ActionSupport;
 import net.sf.json.JSONObject;
 import org.apache.struts2.ServletActionContext;
@@ -32,6 +36,8 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
     @Resource
     public UserVisitsDao userVisitsDao;
     @Resource
+    public UserService userService;
+    @Resource
     public AppHomePageService appHomePageService;
     @Resource
     public HotelService hotelService;
@@ -118,12 +124,52 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
         IPage iPage = appHomePageService.getHotelList(queryValue, hotel_township,page,rows);
 
         // 用户访问量数据
-        userVisitsDao.add(this.userId);
+        userVisitsDao.add(userId);
         ResponseUtil.writeJsonIPage(ServletActionContext.getResponse(),iPage);
         return null;
     }
 
     /**
+     * 用户点击收藏民宿
+     * userId
+     * hotelId
+     * @return
+     */
+    public String collectHotel()
+    {
+        if (Func.checkNull(userId) || Func.checkNull(hotelId))
+            return null;
+
+        Users users = userService.addhotelAndUsers(hotelId,userId, TempEnum.收藏);
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put(B.code,ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.data,users);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
+        return null;
+    }
+
+    /**
+     * 用户点击取消 收藏民宿
+     * userId 用户id
+     * hotelId 酒店id
+     * @return
+     */
+    public String delCollectHotel()
+    {
+        if (Func.checkNull(userId) || Func.checkNull(hotelId))
+            return null;
+
+        Users users = userService.delhotelAndUsers(hotelId,userId, TempEnum.收藏);
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put(B.code,ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.data,users);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
+        return null;
+    }
+
+    /**
      * hotelId 酒店id
      * 通过酒店的id获取到房间信息
      * @return

+ 40 - 1
mhotel/src/com/happy/action/AppMePageAction.java

@@ -4,10 +4,12 @@ import com.baidubce.model.User;
 import com.google.gson.Gson;
 import com.happy.Model.Booking;
 import com.happy.Model.FileInfo;
+import com.happy.Model.Hotel;
 import com.happy.Model.weixin.*;
 import com.happy.Until.*;
 import com.happy.Until.Enum.B;
 import com.happy.Until.Enum.DataType;
+import com.happy.Until.Enum.TempEnum;
 import com.happy.common.http.HttpsClient;
 import com.happy.common.wx.WxUtil;
 import com.happy.constant.ConstDefault;
@@ -43,6 +45,8 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
     public HotelService hotelService;
     @Resource
     public FileService fileService;
+    @Resource
+    public AppHomePageService appHomePageService;
 
     private String contactUserName; // 常用联系人姓名
     private String contactUserIdNum; // 常用联系人身份证
@@ -61,7 +65,7 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
 
     private String userCode; // 第一次进来获取用户的code
     private String queryValue; // 首页查寻搜索关键词
-
+    public  String type; // 类型:收藏、住过
     public HttpServletRequest getRequest() {
         return request;
     }
@@ -141,6 +145,41 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
     }
 
     /**
+     * 收藏、住过的酒店列表
+     * userId
+     * type  收藏、住过
+     * @return
+     */
+    public String getHotelAndUsersList()
+    {
+        if (Func.checkNull(userId) || Func.checkNull(type))
+            return null;
+
+        Users users = userService.queryByUserId(userId);
+        if (users == null)
+            return null;
+
+        List<String> collectList = new ArrayList<>();
+        List<String> liveList = new ArrayList<>();
+        if (!Func.checkNull(users.getCollect_hotel()))
+            collectList = Arrays.asList(users.getCollect_hotel().split(","));
+        if (!Func.checkNull(users.getLive_hotel()))
+            liveList = Arrays.asList(users.getLive_hotel().split(","));
+
+        IPage<Hotel>  iPage = new IPage<>();
+        if (TempEnum.收藏.name().equals(type))
+        {
+            iPage = appHomePageService.getHotelList(collectList,page,rows);
+        }else if (TempEnum.住过.name().equals(type))
+        {
+            iPage = appHomePageService.getHotelList(liveList,page,rows);
+        }
+
+        ResponseUtil.writeJsonIPage(ServletActionContext.getResponse(),iPage);
+        return null;
+    }
+
+    /**
      * 通过订单id查订单数据
      * @return
      */

+ 2 - 0
mhotel/src/com/happy/action/bookAction.java

@@ -6,6 +6,7 @@ import com.happy.Model.Booking;
 import com.happy.Model.HotelDict;
 import com.happy.Model.weixin.Users;
 import com.happy.Until.*;
+import com.happy.Until.Enum.TempEnum;
 import com.happy.Until.Excel.toExcel;
 import com.happy.common.http.Message;
 import com.happy.dto.BookTypeEto;
@@ -129,6 +130,7 @@ public class bookAction extends ActionSupport implements ServletRequestAware {
                     book.setOrderStatus("4");
                     book.setLiveTime(UUIDUtil.getNewDate());
                     book.setUpdateTime(UUIDUtil.getNewDate());
+                    userService.addhotelAndUsers(book.getHotelId(),book.getCreateUserid(), TempEnum.住过); // 办理入住,则将信息写入用户入住过的酒店  editor by xieli
                     msg = "入住办理";
                     break;
                 case 3://退房

+ 18 - 2
mhotel/src/com/happy/dao/impl/UserDaoImpl.java

@@ -30,7 +30,8 @@ public class UserDaoImpl implements UserDao {
     }
 
     public int insert(Users users){
-        String sql = "insert into `users`(card_number,user_name,user_phone,user_zz,openid,create_time,remark,identity_type,contact_id,contact_name,data_type,head_photo) values(:card_number,:user_name,:user_phone,:user_zz,:openid,:create_time,:remark,:identity_type,:contact_id,:contact_name,:data_type,:head_photo) ";
+        String sql = "insert into `users`(card_number,user_name,user_phone,user_zz,openid,create_time,remark,identity_type,contact_id,contact_name,data_type,head_photo,collect_hotel,live_hotel)" +
+                " values(:card_number,:user_name,:user_phone,:user_zz,:openid,:create_time,:remark,:identity_type,:contact_id,:contact_name,:data_type,:head_photo,:collect_hotel,:live_hotel) ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("card_number", users.getCard_number());
         sps.addValue("user_name", users.getUser_name());
@@ -44,6 +45,8 @@ public class UserDaoImpl implements UserDao {
         sps.addValue("contact_name", users.getContactName());
         sps.addValue("data_type", users.getDataType());
         sps.addValue("head_photo", users.getHeadPhoto());
+        sps.addValue("collect_hotel", users.getCollect_hotel());
+        sps.addValue("live_hotel", users.getLive_hotel());
         int num = 0;
         try{
             num = namedParameterJdbcTemplate.update(sql, sps);
@@ -56,7 +59,8 @@ public class UserDaoImpl implements UserDao {
 
     // 修改信息
     public int update(Users users){
-        String sql = "update `users` set user_name=:user_name,user_phone=:user_phone,user_zz=:user_zz,remark=:remark, head_photo=:head_photo,card_number=:card_number  where id=:id ";
+        String sql = "update `users` set user_name=:user_name,user_phone=:user_phone,user_zz=:user_zz,remark=:remark, head_photo=:head_photo,card_number=:card_number,collect_hotel=:collect_hotel,live_hotel=:live_hotel" +
+                "  where id=:id ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("id", users.getId());
         sps.addValue("user_name", users.getUser_name());
@@ -65,6 +69,8 @@ public class UserDaoImpl implements UserDao {
         sps.addValue("remark", users.getRemark());
         sps.addValue("head_photo", users.getHeadPhoto());
         sps.addValue("card_number", users.getCard_number());
+        sps.addValue("collect_hotel", users.getCollect_hotel());
+        sps.addValue("live_hotel", users.getLive_hotel());
         int num = 0;
         try{
             num = namedParameterJdbcTemplate.update(sql, sps);
@@ -151,6 +157,16 @@ public class UserDaoImpl implements UserDao {
             stringBuffer.append(" head_photo=:head_photo ,");
             msp.addValue("head_photo", users.getHeadPhoto());
         }
+        if (!Func.checkNull(users.getCollect_hotel()))
+        {
+            stringBuffer.append(" collect_hotel=:collect_hotel ,");
+            msp.addValue("collect_hotel", users.getCollect_hotel());
+        }
+        if (!Func.checkNull(users.getLive_hotel()))
+        {
+            stringBuffer.append(" live_hotel=:live_hotel ,");
+            msp.addValue("live_hotel", users.getLive_hotel());
+        }
 
         stringBuffer.append(" remark=''");
     }

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

@@ -21,6 +21,15 @@ public interface AppHomePageService {
      */
     public IPage getHotelList(String queryValue,String hotel_township, int page, int rows);
 
+    /**
+     * 通过id 查询酒店信息
+     * @param ids
+     * @param page
+     * @param rows
+     * @return
+     */
+    IPage<Hotel> getHotelList(List<String> ids, int page, int rows);
+
     public int getHotelTotal(String queryValue);
 
     /**
@@ -29,4 +38,5 @@ public interface AppHomePageService {
      * @return
      */
     public Hotel getHotelAndHouseByHotelId(String hotelId, String queryStartTime, String queryEndTime);
+
 }

+ 19 - 0
mhotel/src/com/happy/service/UserService.java

@@ -2,6 +2,7 @@ package com.happy.service;
 
 import com.happy.Model.Booking;
 import com.happy.Model.weixin.Users;
+import com.happy.Until.Enum.TempEnum;
 import com.happy.dto.IPage;
 
 import java.util.List;
@@ -36,4 +37,22 @@ public interface UserService {
     public int queryUserTotal(String sqlStr);
 
     public IPage<Users> queryUserPage(String sqlx, int page, int rows);
+
+    /**
+     * 收藏或住过酒店
+     * @param hotelId
+     * @param userId
+     * @param type
+     * @return
+     */
+    Users addhotelAndUsers(String hotelId, String userId, TempEnum type);
+
+    /**
+     * 取消 收藏或取消住过酒店
+     * @param hotelId
+     * @param userId
+     * @param type
+     * @return
+     */
+    Users delhotelAndUsers(String hotelId, String userId, TempEnum type);
 }

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

@@ -4,13 +4,10 @@ import com.happy.Model.Booking;
 import com.happy.Model.FileInfo;
 import com.happy.Model.Hotel;
 import com.happy.Model.House;
-import com.happy.Until.DateUtil;
 import com.happy.Until.Enum.PayEnum;
 import com.happy.Until.Func;
-import com.happy.Until.TimeExchange;
 import com.happy.dao.BookDao;
 import com.happy.dao.HouseDao;
-import com.happy.dao.impl.FileImplInfoDao;
 import com.happy.dto.IPage;
 import com.happy.service.*;
 import org.springframework.stereotype.Service;
@@ -50,6 +47,24 @@ public class AppHomePageImplService implements AppHomePageService {
     }
 
     @Override
+    public IPage<Hotel> getHotelList(List<String> ids, int page, int rows) {
+        if (ids == null || ids.size() <= 0 )
+            return null;
+
+        StringBuilder strSql = new StringBuilder(" and hstatus=1 "); // 酒店正在营业中才显示" and hstatus=1 "
+        strSql.append(" and a.id in( ");
+        for (String id: ids) {
+            if (Func.checkNull(id))
+                continue;
+            strSql.append(" "+ id + ",");
+        }
+        strSql.delete(strSql.length() - 1, strSql.length());
+        strSql.append(" )");
+
+        return hotelService.queryPagePrice(strSql.toString(),page,rows);
+    }
+
+    @Override
     public int getHotelTotal(String queryValue) {
 
 

+ 72 - 1
mhotel/src/com/happy/service/impl/UserServiceImpl.java

@@ -1,10 +1,17 @@
 package com.happy.service.impl;
 
 import com.happy.Model.Booking;
+import com.happy.Model.Hotel;
 import com.happy.Model.House;
 import com.happy.Model.weixin.Users;
+import com.happy.Until.Enum.OrderEnum;
+import com.happy.Until.Enum.TempEnum;
+import com.happy.Until.Enum.VisitsEnum;
+import com.happy.Until.Func;
+import com.happy.dao.HotelDao;
 import com.happy.dao.UserDao;
 import com.happy.dto.IPage;
+import com.happy.service.HotelService;
 import com.happy.service.UserService;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -19,6 +26,8 @@ public class UserServiceImpl implements UserService {
 
     @Resource
     public UserDao userDao;
+    @Resource
+    public HotelDao hotelDao;
 
     public int insert(Users users){
         return userDao.insert(users);
@@ -55,7 +64,6 @@ public class UserServiceImpl implements UserService {
     }
 
     public IPage<Users> queryUserPage(String sqlx, int page, int rows){
-
         IPage<Users> iPage = new IPage();
         List<Users> usersList = userDao.queryUserPage(sqlx,page,rows);
         int total = userDao.queryUserTotal(sqlx);
@@ -67,4 +75,67 @@ public class UserServiceImpl implements UserService {
         return iPage;
     }
 
+    @Override
+    public Users addhotelAndUsers(String hotelId, String userId, TempEnum type)
+    {
+        if (Func.checkNull(hotelId) || Func.checkNull(userId))
+            throw new RuntimeException("未传入数据hotelId、userId、type");
+
+        Users users = userDao.queryByUserId(userId);
+        Hotel hotel = hotelDao.getById(Func.parseInt(hotelId));
+        if (users == null || hotel == null)
+            throw new RuntimeException("无法查询到数据users-hotel");
+
+        String live = users.getLive_hotel();
+        String collect = users.getCollect_hotel();
+        switch (type){
+            case 住过:
+                if (Func.checkNull(live) || !live.contains(hotelId))
+                    users.setLive_hotel(live + hotelId+ ",");
+                break;
+            case 收藏:
+                if (Func.checkNull(collect) || !collect.contains(hotelId))
+                    users.setCollect_hotel(collect + hotelId+ ",");
+                break;
+        }
+        userDao.update(users);
+        return users;
+    }
+    @Override
+    public Users delhotelAndUsers(String hotelId, String userId, TempEnum type)
+    {
+        if (Func.checkNull(hotelId) || Func.checkNull(userId))
+            throw new RuntimeException("未传入数据hotelId、userId、type");
+
+        Users users = userDao.queryByUserId(userId);
+        Hotel hotel = hotelDao.getById(Func.parseInt(hotelId));
+        if (users == null || hotel == null)
+            throw new RuntimeException("无法查询到数据users-hotel");
+
+        String live = users.getLive_hotel();
+        String collect = users.getCollect_hotel();
+        switch (type){
+            case 住过:
+                if (Func.checkNull(live))
+                    break;
+                if (live.contains(hotelId+ ","))
+                    users.setLive_hotel(live.replace(hotelId+ ",",""));
+
+                break;
+            case 收藏:
+                if (Func.checkNull(collect))
+                    break;
+
+                if (collect.contains(hotelId+ ","))
+                    users.setCollect_hotel(collect.replace(hotelId+ ",",""));
+                break;
+        }
+
+        userDao.update(users);
+        return users;
+    }
+
+
+
+
 }