初始化
This commit is contained in:
@@ -0,0 +1,210 @@
|
||||
using BLV_API.Dal;
|
||||
using BLV_API.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace BLV_API.Controllers
|
||||
{
|
||||
public class ApiController : Controller
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.Title = "宝来威客控与PMS对接API";
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// Luopan PMS对接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult LuopanToBLV()
|
||||
{
|
||||
Request.InputStream.Position = 0;
|
||||
byte[] reqBody = new byte[Request.InputStream.Length];
|
||||
Request.InputStream.Read(reqBody, 0, reqBody.Length);
|
||||
string reqData = System.Text.Encoding.UTF8.GetString(reqBody);
|
||||
if (string.IsNullOrEmpty(reqData))
|
||||
{
|
||||
return Json(new LuopanEntity.Result() { status = 1, error_msg = "传递参数不能为空" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
//LogHelper.WriteLog("收到Luopan请求:" + reqData);
|
||||
try
|
||||
{
|
||||
LuopanEntity.Root req = JsonConvert.DeserializeObject<LuopanEntity.Root>(reqData);
|
||||
ServiceReference1.blwwsSoapClient client = new ServiceReference1.blwwsSoapClient();
|
||||
string errorMsg = "";
|
||||
bool blvResult = true;
|
||||
StringBuilder xmlString = new StringBuilder();
|
||||
string phoneNumber = "";
|
||||
string idNumber = "";
|
||||
switch (req.Action)
|
||||
{
|
||||
case "CheckIn"://入住
|
||||
if (req.GuestInfo.Count > 0)
|
||||
{
|
||||
phoneNumber = req.GuestInfo[0].Mobile;
|
||||
idNumber = req.GuestInfo[0].IDCardNo;
|
||||
xmlString.Append("<interface>");
|
||||
foreach (LuopanEntity.GuestInfo guest in req.GuestInfo)
|
||||
{
|
||||
xmlString.Append("<item idtype=\"" + guest.IDCardTypeId + "\" idcard = \"" + guest.IDCardNo + "\" customer = \"" + guest.GuestName + "\" sex =\"" +
|
||||
(guest.Gender == 0 ? "男" : "女") + "\" country =\"0\" checkindate = \"" + req.CheckInTime.ToString("yyyy-MM-dd HH:mm:ss") + "\"/>");
|
||||
}
|
||||
xmlString.Append("</interface>");
|
||||
}
|
||||
blvResult = client.CheckIn("blw_ws@2015", req.HotelId, req.RoomNo, req.CheckInTime, xmlString.ToString(), ref errorMsg, phoneNumber, idNumber);
|
||||
LogHelper.WriteLog($"转发BLV内部开房接口,结果:{blvResult},消息:{errorMsg}");
|
||||
break;
|
||||
case "CheckOut"://退房
|
||||
blvResult = client.CheckOut("blw_ws@2015", req.HotelId, req.RoomNo, req.CheckOutTime, ref errorMsg);
|
||||
LogHelper.WriteLog($"转发BLV内部退房接口,结果:{blvResult},消息:{errorMsg}");
|
||||
break;
|
||||
case "MoveRoom"://换房
|
||||
//先退房
|
||||
blvResult = client.CheckOut("blw_ws@2015", req.HotelId, req.OldRoomNo, req.MoveTime, ref errorMsg);
|
||||
LogHelper.WriteLog($"转发BLV内部退房接口,结果:{blvResult},消息:{errorMsg}");
|
||||
//再开房
|
||||
if (req.GuestInfo.Count > 0)
|
||||
{
|
||||
phoneNumber = req.GuestInfo[0].Mobile;
|
||||
idNumber = req.GuestInfo[0].IDCardNo;
|
||||
xmlString.Append("<interface>");
|
||||
foreach (LuopanEntity.GuestInfo guest in req.GuestInfo)
|
||||
{
|
||||
xmlString.Append("<item idtype=\"" + guest.IDCardTypeId + "\" idcard = \"" + guest.IDCardNo + "\" customer = \"" + guest.GuestName + "\" sex =\"" +
|
||||
(guest.Gender == 0 ? "男" : "女") + "\" country =\"0\" checkindate = \"" + req.CheckInTime.ToString("yyyy-MM-dd HH:mm:ss") + "\"/>");
|
||||
}
|
||||
xmlString.Append("</interface>");
|
||||
}
|
||||
blvResult = client.CheckIn("blw_ws@2015", req.HotelId, req.NewRoomNo, req.CheckInTime, xmlString.ToString(), ref errorMsg, phoneNumber, idNumber);
|
||||
LogHelper.WriteLog($"转发BLV内部开房接口,结果:{blvResult},消息:{errorMsg}");
|
||||
break;
|
||||
default:
|
||||
LogHelper.WriteLog("BLV未处理type:" + req.Action);
|
||||
break;
|
||||
}
|
||||
if (blvResult)
|
||||
{
|
||||
return Json(new LuopanEntity.Result() { status = 0, error_msg = "" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new LuopanEntity.Result() { status = 1, error_msg = errorMsg }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLog(ex.ToString());
|
||||
return Json(new LuopanEntity.Result() { status = 1, error_msg = ex.Message }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Luopan2 PMS对接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult Luopan2ToBLV()
|
||||
{
|
||||
Request.InputStream.Position = 0;
|
||||
byte[] reqBody = new byte[Request.InputStream.Length];
|
||||
Request.InputStream.Read(reqBody, 0, reqBody.Length);
|
||||
string reqData = System.Text.Encoding.UTF8.GetString(reqBody);
|
||||
if (string.IsNullOrEmpty(reqData))
|
||||
{
|
||||
return Json(new LuopanEntity.Result() { status = 1, error_msg = "传递参数不能为空" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
//LogHelper.WriteLog("收到Luopan2请求:" + reqData);
|
||||
try
|
||||
{
|
||||
Luopan2Entity.Root req = JsonConvert.DeserializeObject<Luopan2Entity.Root>(reqData);
|
||||
//CRICSEntity.Request cricsEntity = new CRICSEntity.Request();
|
||||
//cricsEntity.HotelCode = req.hotel_id;
|
||||
//cricsEntity.RoomNumber = req.room_no;
|
||||
ServiceReference1.blwwsSoapClient client = new ServiceReference1.blwwsSoapClient();
|
||||
string errorMsg = "";
|
||||
bool blvResult = true;
|
||||
StringBuilder xmlString = new StringBuilder();
|
||||
string phoneNumber = "";
|
||||
string idNumber = "";
|
||||
switch (req.type)
|
||||
{
|
||||
case "reg.checkin"://入住
|
||||
//cricsEntity.RoomStatusID = 2;
|
||||
//①转发客控后台
|
||||
if (req.guests.Count > 0)
|
||||
{
|
||||
phoneNumber = req.guests[0].mobile;
|
||||
idNumber = req.guests[0].id_card_no;
|
||||
xmlString.Append("<interface>");
|
||||
foreach (Luopan2Entity.GuestsItem guest in req.guests)
|
||||
{
|
||||
xmlString.Append("<item idtype=\"" + guest.id_card_type_id + "\" idcard = \"" + guest.id_card_no + "\" customer = \"" + guest.last_name+guest.first_name + "\" sex =\"" +
|
||||
(guest.gender_id == 0 ? "男" : "女") + "\" country =\"0\" checkindate = \"" + req.check_in_time.ToString("yyyy-MM-dd HH:mm:ss") + "\"/>");
|
||||
}
|
||||
xmlString.Append("</interface>");
|
||||
}
|
||||
blvResult = client.CheckIn("blw_ws@2015", req.hotel_id, req.room_no, req.check_in_time, xmlString.ToString(), ref errorMsg, phoneNumber, idNumber);
|
||||
LogHelper.WriteLog($"转发BLV内部开房接口,结果:{blvResult},消息:{errorMsg}");
|
||||
//②转发人脸机
|
||||
//③转发宝镜系统
|
||||
break;
|
||||
case "reg.checkout"://退房
|
||||
//cricsEntity.RoomStatusID = 8;
|
||||
blvResult = client.CheckOut("blw_ws@2015", req.hotel_id, req.room_no, req.check_out_time, ref errorMsg);
|
||||
LogHelper.WriteLog($"转发BLV内部退房接口,结果:{blvResult},消息:{errorMsg}");
|
||||
break;
|
||||
case "reg.move"://换房
|
||||
//cricsEntity.RoomStatusID = 2;
|
||||
//先退房
|
||||
blvResult = client.CheckOut("blw_ws@2015", req.hotel_id, req.old_room_no, req.move_time, ref errorMsg);
|
||||
LogHelper.WriteLog($"转发BLV内部退房接口,结果:{blvResult},消息:{errorMsg}");
|
||||
//再开房
|
||||
if (req.guests.Count > 0)
|
||||
{
|
||||
phoneNumber = req.guests[0].mobile;
|
||||
idNumber = req.guests[0].id_card_no;
|
||||
xmlString.Append("<interface>");
|
||||
foreach (Luopan2Entity.GuestsItem guest in req.guests)
|
||||
{
|
||||
xmlString.Append("<item idtype=\"" + guest.id_card_type_id + "\" idcard = \"" + guest.id_card_no + "\" customer = \"" + guest.last_name+guest.first_name + "\" sex =\"" +
|
||||
(guest.gender_id == 0 ? "男" : "女") + "\" country =\"0\" checkindate = \"" + req.check_in_time.ToString("yyyy-MM-dd HH:mm:ss") + "\"/>");
|
||||
}
|
||||
xmlString.Append("</interface>");
|
||||
}
|
||||
blvResult = client.CheckIn("blw_ws@2015", req.hotel_id, req.new_room_no, req.check_in_time, xmlString.ToString(), ref errorMsg, phoneNumber, idNumber);
|
||||
LogHelper.WriteLog($"转发BLV内部开房接口,结果:{blvResult},消息:{errorMsg}");
|
||||
break;
|
||||
default:
|
||||
LogHelper.WriteLog("BLV未处理type:" + req.type);
|
||||
break;
|
||||
}
|
||||
if (blvResult)
|
||||
{
|
||||
return Json(new LuopanEntity.Result() { status = 0, error_msg = "" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new LuopanEntity.Result() { status = 1, error_msg = errorMsg }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
//string postData = JsonConvert.SerializeObject(cricsEntity);
|
||||
//string blvResult = Tools.PostWebRequest("https://pms.boonlive-rcu.com/api/SyncRoomStatus", postData);
|
||||
//CRICSEntity.Response response = JsonConvert.DeserializeObject<CRICSEntity.Response>(blvResult);
|
||||
//if (!response.IsSuccess)
|
||||
//{
|
||||
// return Json(new LuopanEntity.Result() { status = 1, error_msg = response.Result }, JsonRequestBehavior.AllowGet);
|
||||
//}
|
||||
//return Json(new LuopanEntity.Result() { status = 0, error_msg = "" }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLog(ex.ToString());
|
||||
return Json(new LuopanEntity.Result() { status = 1, error_msg = ex.Message }, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user