private OrderMenu() { //加载配置文件 XMLTool xmlTool = new XMLTool("CfgFiles\\foodMenu.xml"); XElement xRoot = xmlTool.LoadXml(); var foodList = xRoot.Elements("Food"); Type type = typeof(AbstractFood); foreach (var item in foodList) { //1:找到类的名称 var csName = item.Element("FoodName").Value; //2:通过反射来实例化对象 Assembly assembly = Assembly.Load("NineFive.Model"); AbstractFood food = assembly.CreateInstance($"NineFive.Model.OrderSystem.{csName}Food") as AbstractFood; if (food == null) { continue; } //3:赋值 foreach (var propItem in type.GetProperties()) { var propValue = item.Element(propItem.Name)?.Value; if (!string.IsNullOrEmpty(propValue)) { propItem.SetValue(food, Convert.ChangeType(propValue, propItem.PropertyType), null); } } AllFoods.Add(food); } }
/// <summary> /// 初始化实体数据集合. /// </summary> public void InitStoreItemList() { //xml文件路径. string xmlPath = "Assets/Datas/StoreData.xml"; //读取XML中的信息到集合中. XMLTool.ReadXMLByPath(xmlPath, storeItemList); for (int i = 0; i < storeItemList.Count; i++) { string str = storeItemList[i].ToString(); Debug.Log(str); } }
public void init() { if (!isLevelLoaded) { StartCoroutine(XMLTool.LoadLevelsXML()); } if (!isLetterLoaded) { StartCoroutine(XMLTool.LoadLettersXML()); } if (!isDressingLoaded) { StartCoroutine(XMLTool.LoadDressingXML()); } }
public Level getLevel(int levelId) { Level lvl = null; if (Levels.Length > levelId) { if (Levels[levelId] == null) { Levels[levelId] = XMLTool.LoadLevelXML(levelId); } lvl = Levels[levelId]; } else { lvl = null; } if (lvl == null || lvl.Segments == null) { lvl = generateRandomLevel(levelId); } return(lvl); }
/////////////////////// #region 班次時刻表 // 取得航班時刻表 //public static List<TrafficTimeTableModel> GetApkgTimeTable(string prod_no, DateTime s_date, string carrier_code, int total_psg)//, bool IsAEOneWayForce = false) //{ // List<TrafficTimeTableModel> time_tables = new List<TrafficTimeTableModel>(); // try // { // // 列出有關航假航段內容 // var apkg_sectors = sectors.Where(s => s.TRAFFIC_TYPE == "0001" && GetQtyTypeRule(s.CARRIER_CODE) == "CRS").ToList(); // time_tables.AddRange(QueryCrsTimeTable(carrier_code, s_date, apkg_sectors, total_psg)); // // 非航假航段內容 // var other_sectors = sectors.Where(s => !apkg_sectors.Contains(s)).ToList(); // time_tables.AddRange(QueryTimeTable(prod_no, s_date, null, other_sectors)); // } // catch (Exception ex) // { // Website.Instance.logger.FatalFormat("{0},{1}", ex.Message, ex.StackTrace); // } // return time_tables; //} // 查詢 DPKG CRS, 取得航班時刻 protected static List <TrafficTimeTableModel> QueryCrsTimeTable(DateTime s_date, DateTime e_date, TrafficSectorModel sector, int total_psg) //(string carrier_code, DateTime S_DATE, string cityfrom, string cityto, int total_psg) { List <TrafficTimeTableModel> time_tables = new List <TrafficTimeTableModel>(); try { var soapClients = Website.Instance.Configuration.GetSection("SoapClient"); var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport) { MaxReceivedMessageSize = Int32.MaxValue }; var ep = new EndpointAddress(soapClients["WS_DPKG_CRS"]); WS_DPKG_CRS.CrsServiceSoapClient crs_service = new WS_DPKG_CRS.CrsServiceSoapClient(binding, ep); Request_GetAv reqGetAv = new Request_GetAv(); reqGetAv.CrsSystem = sector.CARRIER_CODE.Equals("B7") ? CrsSystemOption.B7 : sector.CARRIER_CODE.Equals("AE") ? CrsSystemOption.AE : CrsSystemOption.GE; if (sector.CARRIER_CODE == "AE") { reqGetAv.Rule_Type = sector.RULE_TYPE; } List <Segment> dep_seg = new List <Segment>(); dep_seg.Add(new Segment() { Airline = sector.CARRIER_CODE, TripFlag = sector.FORWARD_FLAG, DepartureDate = e_date.ToString("yyyyMMdd"), DepartureTime = "0000", DepartureAirport = sector.DEP_FROM, ArrivalDate = s_date.ToString("yyyyMMdd"), ArrivalTime = "2359", ArrivalAirport = sector.ARR_TO, BookingSeatCount = total_psg }); List <Itinerary> _Itinerary = new List <Itinerary>(); _Itinerary.Add(new Itinerary() { Segment = dep_seg.ToArray() }); reqGetAv.Itinerary = _Itinerary.ToArray(); // 詢問CRSGW有效位控 string xmlResp = GetAvTask(crs_service, XMLTool.XMLSerialize(reqGetAv)).Result; Response_GetAv respGetAv = new Response_GetAv(); respGetAv = (Response_GetAv)XMLTool.XMLDeSerialize(xmlResp, respGetAv.GetType().ToString()); var sel_segs = respGetAv.AvItinerary.Where(s => s.Segments != null && s.Segments.Count() > 0).SelectMany(s => s.Segments); // 產出 Time Table foreach (var seg in sel_segs) { foreach (var item in seg.Segment) { var sec = sector.Where(s => s.DEP_FROM.Equals(item.DepartureAirport) && s.ARR_TO.Equals(item.ArrivalAirport)).FirstOrDefault(); DateTime dept_date = DateTime.ParseExact(item.DepartureDate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture); //DateTime arrv_date = DateTime.ParseExact(item.ArrivalDate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture); //成本與搭乘限制 DataSet dtl_ds = LimitDAL.GetTrafficCostDtl(sector.TRAFFIC_COST_PRICE_XID, sector.TRAFFIC_XID, sector.TRAFFIC_COST_XID, S_DATE.ToString("yyyyMMdd")); int nInvalidRules = 0; //未符合規則計數, 0: 通過 //過濾交通限制 if (dtl_ds.Tables[0].Rows.Count != 0) { // 檢查是否指定使用 FAIR_BASIS var sel_fair_basis = dtl_ds.Tables[0].AsEnumerable().Where(r => !string.IsNullOrEmpty(r.Field <string>("FAIR_BASIS"))).Select(b => b.Field <string>("FAIR_BASIS")).Distinct().ToList(); if (sel_fair_basis.Count() > 0) { // 比對 FAIR_BASIS if (sel_fair_basis.Where(f => f.Equals(item.FareBasis, StringComparison.InvariantCultureIgnoreCase)).Count() < 1) { nInvalidRules++; // 累計未符合規則 } } // 過濾無效航班規則 bool IsValidFlight = FilterTraffic(dr.ToDateTime("S_DATE"), item.DepartureTime.Replace(":", ""), item.FlightNumber, sector, dtl_ds.Tables[0]); if (!IsValidFlight) { nInvalidRules++; // 累計未符合規則 } } if (nInvalidRules == 0) { //var HL_FLAG = sector.FLY_HL_FLAG.Equals("0") ? false : true; var HL_FLAG = sector.FLY_HL_FLAG; // 通過過濾規則放入時刻表 time_tables.Add(new TrafficTimeTableModel() { S_DATE = dept_date.ToString(), FORWARD_FLAG = item.TripFlag, DEP_FROM_NAME = sector.DEP_FROM_NAME, DEP_FROM = item.DepartureAirport, ARR_TO_NAME = sector.ARR_TO_NAME, ARR_TO = item.ArrivalAirport, FLY_NO = item.FlightNumber, DEP_FROM_TIME = item.DepartureTime, ARR_TO_TIME = item.ArrivalTime, BOOKING_CLASS = item.BookingClass, SEAT_COUNT = item.BookingSeatCount.Value, FARE_BASIS = item.FareBasis, CAN_HL = HL_FLAG }); } } } } catch (Exception ex) { throw ex; } return(time_tables); }
public BookingResponseModel Booking([FromBody] BookingRequestModel bookRQ) { Website.Instance.logger.Info($"JTR Booking Start!"); BookingResponseModel bookRS = new BookingResponseModel(); Metadata metadata = new Metadata(); Data data = new Data(); List <Mappinginfo> info = new List <Mappinginfo>(); try { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); //I.Prod的Mapping //bookRQ.pkg_oid+價格別(bookRQ.Price1Qty) 找出訂購JTR的商編 string jtr_prod_no = ""; try { var xdoc = XDocument.Load(System.AppDomain.CurrentDomain.BaseDirectory + "//App_Data//ProdMapping.xml"); if (bookRQ.order.price1Qty > 0) { if (xdoc.Descendants("item").Where(x => x.Element("kkday_prod_pkg").Value.Contains(bookRQ.order.packageOid) && x.Element("kkday_price_type").Value.Equals("price1")).Count() <= 0) { throw new Exception("此套餐編號找不到相對應JTR產編,請與BD確認產編再請it修改"); } jtr_prod_no = xdoc.Descendants("item").Where(x => x.Element("kkday_prod_pkg").Value.Equals(bookRQ.order.packageOid) && x.Element("kkday_price_type").Value.Equals("price1")). Select(x => x.Element("jtr_prod_no").Value).FirstOrDefault().ToString(); info.Add(new Mappinginfo() { price_type = "price1", qty = bookRQ.order.price1Qty, jtr_prod_no = jtr_prod_no//"10457115"// }); } if (bookRQ.order.price2Qty > 0) { if (xdoc.Descendants("item").Where(x => x.Element("kkday_prod_pkg").Value.Contains(bookRQ.order.packageOid) && x.Element("kkday_price_type").Value.Equals("price2")).Count() <= 0) { throw new Exception("此套餐編號找不到相對應JTR產編,請與BD確認產編再請it修改"); } jtr_prod_no = xdoc.Descendants("item").Where(x => x.Element("kkday_prod_pkg").Value.Equals(bookRQ.order.packageOid) && x.Element("kkday_price_type").Value.Equals("price2")). Select(x => x.Element("jtr_prod_no").Value).FirstOrDefault().ToString(); info.Add(new Mappinginfo() { price_type = "price2", qty = bookRQ.order.price2Qty, jtr_prod_no = jtr_prod_no//"10457115"// }); } if (bookRQ.order.price3Qty > 0 || bookRQ.order.price4Qty > 0) { throw new Exception("旅客購買的套餐身份別(老人,嬰兒)不在即訂即付的約定內"); } } catch (Exception ex) { metadata.status = $"JTR-10002"; metadata.description = $"{ex.Message}"; bookRS.metadata = metadata; Website.Instance.logger.FatalFormat($"Mapping Error :{ex.Message},{ex.StackTrace}"); return(bookRS); } pay_result payRS = new pay_result(); order_result orderRS = new order_result(); List <JtrRsinfo> RS_info = new List <JtrRsinfo>(); List <Orderinfo> OD_info = new List <Orderinfo>(); int qty = 1; try { //II.依照jtr_prod_no數量 呼叫JTR order API 及 pay API foreach (var lst in info) { //訂單資訊!!因商品結構單純 放必須值即可 link_man 為旅客代表人orderCusList得第一位 order jtrorder = new order() { info_id = lst.jtr_prod_no ?? string.Empty, cust_id = bookRQ.sup_id ?? string.Empty, order_source_id = info.Count() > 1 ? $"{bookRQ.order.orderMid}-{qty.ToString()}" : bookRQ.order.orderMid, travel_date = bookRQ.order.begLstGoDt, num = lst.qty, link_man = bookRQ.order.orderCusList[0].cusFirstname.ToUpper() + bookRQ.order.orderCusList[0].cusLastname.ToUpper(), link_phone = string.Empty, link_email = Website.Instance.Configuration["CONTENT_EMAIL"] ?? "*****@*****.**" }; //需replace成UTF-8不然會有error string orderRSxmlData = XMLTool.XMLSerialize(jtrorder).Replace("utf-16", "utf-8").Replace("utf - 16", "utf - 8"); string orderUrl = $"{Website.Instance.Configuration["JTR_API_URL:ORDER_URL"]}?custId={bookRQ.sup_id}&apikey={bookRQ.sup_key}¶m={orderRSxmlData}".Replace("\n", ""); HttpResponseMessage orderResponse = client.GetAsync(orderUrl).Result; Website.Instance.logger.Info($"URL:{Website.Instance.Configuration["JTR_API_URL:ORDER_URL"]},URL Response StatusCode:{orderResponse.StatusCode}"); orderRS = (order_result)XMLTool.XMLDeSerialize(orderResponse.Content.ReadAsStringAsync().Result, orderRS.GetType().ToString()); Website.Instance.logger.Info($"[ORDER]kkOrderNo:{bookRQ.order.orderMid},priceType:{lst.price_type},jtrOrderNo:{orderRS.order_id},jtrErr:{orderRS.error_msg}"); string payUrl = $"{Website.Instance.Configuration["JTR_API_URL:PAY_URL"]}?custId={bookRQ.sup_id}&apikey={bookRQ.sup_key}&orderId={orderRS.order_id}"; HttpResponseMessage payRresponse = client.GetAsync(payUrl).Result; Website.Instance.logger.Info($"URL:{Website.Instance.Configuration["JTR_API_URL:PAY_URL"]},URL Response StatusCode:{payRresponse.StatusCode}"); payRS = (pay_result)XMLTool.XMLDeSerialize(payRresponse.Content.ReadAsStringAsync().Result, payRS.GetType().ToString()); Website.Instance.logger.Info($"[PAY]kkOrderNo:{bookRQ.order.orderMid},priceType:{lst.price_type},jtrTktNo:{payRS.code},jtrErr:{payRS.error_msg}"); RS_info.Add( new JtrRsinfo() { kkOrder_no = jtrorder.order_source_id, kkprice_type = lst.price_type, kkprice_qty = lst.qty, order_id = orderRS.order_id ?? string.Empty, order_error_msg = orderRS.error_msg ?? string.Empty, order_error_state = orderRS.error_state ?? string.Empty, code = payRS.code ?? string.Empty, pay_error_msg = payRS.error_msg ?? string.Empty, pay_error_state = payRS.error_state ?? string.Empty }); //RS 狀況一 //第一筆 訂單成立/付款失敗 直接跳出迴圈 if (qty == 1 && (payRS.error_state != "10000" || string.IsNullOrEmpty(payRS.code) || orderRS.error_state != "10000" || string.IsNullOrEmpty(orderRS.order_id))) { break; } qty++; } //RS 判斷Mapping //result = "OK","OrdErr","PayErr","NoTicket" foreach (var rs in RS_info) { data.isMuiltSupOrder = info.Count() > 1 ? true : false; data.supTicketNumber += !string.IsNullOrEmpty(rs.code) ? rs.code + "<br/>" : ""; OD_info.Add(new Orderinfo() { priceType = rs.kkprice_type, qty = rs.kkprice_qty, kkOrderNo = rs.kkOrder_no, ticketNumber = rs.code, result = !string.IsNullOrEmpty(rs.code) && rs.order_error_state == "10000" && rs.pay_error_state == "10000" ? "OK" : string.IsNullOrEmpty(rs.code) && rs.order_error_state != "10000" && rs.pay_error_state != "10000" ? "OrdErr" : string.IsNullOrEmpty(rs.code) && rs.order_error_state == "10000" && rs.pay_error_state != "10000" ? "PayErr" : string.IsNullOrEmpty(rs.code) && rs.order_error_state == "10000" && rs.pay_error_state == "10000" ? "NoTicket" : string.Empty }); } data.orderinfo = OD_info; bookRS.data = data; //metadata status 跟 描述 mapping //order error string code = "", note = ""; if (OD_info.AsEnumerable().Any(x => x.result.Contains("OrdErr"))) { //多筆 if (data.isMuiltSupOrder && OD_info.Count() > 1) { code = RS_info[1].order_error_state; note = $"1對多訂單類型,其中第1筆 {RS_info[0].order_id}支付成功,{RS_info[0].code},但第2筆成立訂單失敗,請OP至JTR後台協助確認"; } else if (data.isMuiltSupOrder && OD_info.Count() == 1) { code = RS_info[0].order_error_state; note = $"1對多訂單類型,下單失敗,{RS_info[0].order_error_msg}"; } else { code = RS_info[0].order_error_state; note = RS_info[0].order_error_msg; } } else if (OD_info.AsEnumerable().Any(x => x.result.Contains("PayErr"))) { //多筆 if (data.isMuiltSupOrder && OD_info.Count() > 1) { code = RS_info[1].pay_error_state; note = $"1對多訂單類型,其中第1筆{RS_info[0].order_id},{RS_info[0].code},但第2筆{RS_info[1].order_id},{RS_info[1].pay_error_msg},請OP至JTR後台協助確認"; } else if (data.isMuiltSupOrder && OD_info.Count() > 1) { code = RS_info[0].pay_error_state; note = $"1對多訂單類型,第1筆{RS_info[0].order_id}支付失敗,{RS_info[0].pay_error_msg},請確認訂單其他細項是否完成"; } else { code = RS_info[0].pay_error_state; note = $"{RS_info[0].order_id}支付失敗,{RS_info[0].pay_error_msg}"; } } else if (OD_info.AsEnumerable().Any(x => x.result.Contains("NoTicket"))) { //多筆 if (data.isMuiltSupOrder && OD_info.Count() > 1) { code = "10091"; note = $"1對多訂單類型,其中第1筆{RS_info[0].order_id}交易支付成功{RS_info[0].code},但第2筆{RS_info[1].order_id}支付成功未取得12碼供應商訂編,請OP至JTR後台協助確認"; } else { code = "10091"; note = $"{RS_info[0].order_id}支付成功,但未取得12碼供應商訂編,請OP至JTR後台協助確認"; } } else { code = RS_info[0].pay_error_state; note = RS_info[0].pay_error_msg; } metadata.status = $"JTR-{code}"; metadata.description = note; bookRS.metadata = metadata; } catch (Exception ex) { //與JTR API串接 Website.Instance.logger.FatalFormat($"JTR Connect Error :{ex.Message},{ex.StackTrace}"); throw ex; } } catch (TimeoutException timeoutex) { metadata.status = $"JTR-10090"; metadata.description = timeoutex.Message; bookRS.metadata = metadata; Website.Instance.logger.FatalFormat($"Timeout Error :{timeoutex.Message},{timeoutex.StackTrace}"); return(bookRS); } catch (Exception ex) { metadata.status = $"JTR-00000"; metadata.description = $"System Error :{ex.Message}"; bookRS.metadata = metadata; Website.Instance.logger.FatalFormat($"System Error :{ex.Message},{ex.StackTrace}"); return(bookRS); } return(bookRS); }