/// <summary> /// 获取是否停航 /// </summary> /// <param name="baseApi"></param> /// <returns></returns> public object Do_CheckPlan(BaseApi baseApi) { IfSuspend obj = Utils.GetCache <IfSuspend>("IfSuspend"); if (obj == null) { int time = 0; int.TryParse(Global.IfBookingTime, out time); obj = JsonConvert.DeserializeObject <IfSuspend>(GetIfSuspend(Global.POSCODE, time, "")); Utils.SetCache("IfSuspend", obj, 0, 1, 0); } string IfSuspend = "0"; foreach (var item in obj.PORTLIST) { IfSuspend = item.COUNT; } return(IfSuspend); }
/// <summary> /// 下订单 /// </summary> /// <param name="baseApi"></param> /// <returns></returns> public object Do_WebBookingTicket(BaseApi baseApi) { OpenDao openDao = new OpenDao(); BookingTicketParam param = JsonConvert.DeserializeObject <BookingTicketParam>(baseApi.param.ToString()); if (param == null) { throw new ApiException(CodeMessage.InvalidParam, "InvalidParam"); } //if (param.posCode == null || param.posCode == "") //{ // throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); //} if (param.planId == null || param.planId == "") { throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); } if (param.gradeId == null || param.gradeId == "") { throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); } if (param.mobile == null || param.mobile == "") { throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); } if (param.passengerList == null || param.passengerList.Count == 0) { throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError"); } string openId = Utils.GetOpenID(baseApi.token); //处理10分取消未支付订单 openDao.UpdateBookingStatusBy10Minute(openId); //判断用户是否被禁用 Member member = openDao.GetMember(openId); if (member.status == "0") { throw new ApiException(CodeMessage.MemberStatusError, "MemberStatusError"); } //判断船是否是开航前多少分钟所以不能订票 int time = 0; int.TryParse(Global.XCIfBookingTime, out time); IfSuspend obj = JsonConvert.DeserializeObject <IfSuspend>(OpenBuss.GetIfSuspend(Global.POSCODE, time, param.planId)); if (obj.PORTLIST.Count > 0) { if (obj.PORTLIST[0].COUNT == "0") { throw new ApiException(CodeMessage.TimeError, "TimeError"); } } //if (!openDao.ifBooking(param.planId, Global.XCIfBookingTime)) //{ // throw new ApiException(CodeMessage.BookingTicketError, "BookingTicketError"); //} //先判断订票用户和账号是否匹配。 string error = ""; if (param.passengerList.Count > 5) { openDao.writeLog(Global.XCPOSCODE, openId, "PassengerNumError", "订票人超过5个"); throw new ApiException(CodeMessage.PassengerNumError, "订票人超过5个"); } foreach (Passenger passenger in param.passengerList) { //判断用户是否订过同一航次 if (openDao.checkOnePlan(param.planId, passenger.passengerCard)) { throw new ApiException(CodeMessage.OnePlanError, "OnePlanError"); } } //再判断是否都是一个等级 string grade = param.passengerList[0].passengerType; foreach (Passenger passenger in param.passengerList) { if (grade != passenger.passengerType) { error += "不是同一个类型,一个订单只支持同一个类型的票;"; } } if (error != "") { openDao.writeLog(Global.XCPOSCODE, openId, "BookingTicket", error); throw new ApiException(CodeMessage.CheckPassengerError, error); } //用第一个人的信息生成一个新的订单号 string bookBillId = ""; string GetBookBillIdUserResult = GetBookBillIdUser(Global.XCPOSCODE, param.name, param.mobile, param.card, openId); WebBillIdResult web1 = JsonConvert.DeserializeObject <WebBillIdResult>(GetBookBillIdUserResult); if (web1.MESSAGE[0].IS_SUCCESS == "TRUE") { bookBillId = web1.BILLID[0].BILL_ID; } else { openDao.writeLog(Global.XCPOSCODE, openId, "BookingTicket", web1.MESSAGE[0].MESSAGE); throw new ApiException(CodeMessage.GetBillIdError, "GetBillIdError"); } //订票 string allotType = Global.XCALLOTTYPE, ticketType = param.passengerList[0].passengerType; int ticketNum = param.passengerList.Count; if (param.passengerList[0].passengerType == "004") { allotType = "999"; } string BookTicketAutoByTicketResult = BookTicketAutoByTicketType(Global.XCPOSCODE, param.planId, param.gradeId, allotType, ticketNum, bookBillId, ticketType); WebResult web2 = JsonConvert.DeserializeObject <WebResult>(BookTicketAutoByTicketResult); if (web2.MESSAGE[0].IS_SUCCESS == "TRUE") { } else { openDao.writeLog(Global.XCPOSCODE, openId, "BookingTicket", web2.MESSAGE[0].MESSAGE); throw new ApiException(CodeMessage.BookTicketError, "BookTicketError"); } //获取订票状态 string GetBookBillStateResult = GetBookBillStateNew(Global.XCPOSCODE, bookBillId); WebBookBillStateResult web3 = JsonConvert.DeserializeObject <WebBookBillStateResult>(GetBookBillStateResult); if (web3.MESSAGE[0].IS_SUCCESS == "TRUE") { List <WEBBILLSTATE> billState = web3.BILLSTATE; int billPrice = 0; //订单总金额 //用订票用户信息补充票明细信息 for (int i = 0; i < billState.Count; i++) { billPrice += billState[i].FACT_PRICE; string AddTicketInfoResult = AddTicketInfo(Global.XCPOSCODE, bookBillId, billState[i].TICKET_ID, param.passengerList[i].passengerName, param.passengerList[i].passengerCard); //WebResult web4 = JsonConvert.DeserializeObject<WebResult>(AddTicketInfoResult); openDao.insertBillInfo(bookBillId, param.passengerList[i].passengerId, param.passengerList[i].passengerType, param.passengerList[i].passengerName, param.passengerList[i].passengerCardType, param.passengerList[i].passengerCard, param.passengerList[i].passengerTel, billState[i].BUNK_GRADE_NAME, billState[i].BUNK_CODE, billState[i].FACT_PRICE, billState[i].TICKET_ID, billState[i].MARK_CODE); } //订票成功后添加一条记录在mysql里 string[] ports = billState[0].SEAROUTE_NAME.Split("-"); string[] times = billState[0].SAILING_TIME.Split(":"); DateTime dtime = Convert.ToDateTime(billState[0].DEPARTURE_TIME); dtime = dtime.AddHours(Convert.ToInt16(times[0])); dtime = dtime.AddMinutes(Convert.ToInt16(times[1])); string ARRIVE_TIME = dtime.ToString("yyyy-MM-dd HH:mm:ss"); if (!openDao.insertBillList(Global.XCPOSCODE, openId, bookBillId, "1", param.passengerList[0].passengerName, param.passengerList[0].passengerTel, param.passengerList[0].passengerCard, billState[0].DEPARTURE_TIME, ARRIVE_TIME, billState[0].SHIP_NAME, ports[0], ports[1], billState.Count, billPrice, billState[0].PLAN_ID, "")) { openDao.writeLog(Global.XCPOSCODE, openId, "InsertBillList", "InsertBillListError"); throw new ApiException(CodeMessage.InsertBillListError, "InsertBillListError"); } } else { openDao.writeLog(Global.XCPOSCODE, openId, "GetBookBillState", web3.MESSAGE[0].MESSAGE); throw new ApiException(CodeMessage.GetBookBillStateError, "GetBookBillStateError"); } //返回订单号 return(bookBillId); }