/// <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);
        }
        /// <summary>
        /// 申请退订单
        /// </summary>
        /// <param name="baseApi"></param>
        /// <returns></returns>
        public object Do_ReturnTicket(BaseApi baseApi)
        {
            ReturnTicketParam param = JsonConvert.DeserializeObject <ReturnTicketParam>(baseApi.param.ToString());

            if (param == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }
            if (param.billId == null || param.billId == "")
            {
                throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError");
            }
            if (param.id == null || param.id == "")
            {
                throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError");
            }
            string  openId  = Utils.GetOpenID(baseApi.token);
            OpenDao openDao = new OpenDao();

            BILLLIST billList = openDao.getBillListById(param.billId, openId);

            if (billList == null)
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "未查到订票信息");
            }
            if (billList.bookingState != "2")
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "订票状态错误");
            }
            DateTime dtime = Convert.ToDateTime(billList.beginDate + " " + billList.beginTime);

            //判断开船30分内不许退票
            if (dtime < DateTime.Now.AddMinutes(30))
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "开船30分内不许退票");
            }
            //判断是否已经打票
            BILLINFO billInfo = openDao.getBillInfoById(param.billId, param.id);

            if (billInfo == null)
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "退票信息不正确");
            }
            if (billInfo.ticketState != "2")
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
            }
            bool   checkTicketIdError     = true;
            string GetBookBillStateResult = GetBookBillStateNew(Global.XCPOSCODE, param.billId);
            WebBookBillStateResult web3   = JsonConvert.DeserializeObject <WebBookBillStateResult>(GetBookBillStateResult);

            if (web3.MESSAGE[0].IS_SUCCESS == "TRUE")
            {
                List <WEBBILLSTATE> billState = web3.BILLSTATE;
                for (int i = 0; i < billState.Count; i++)
                {
                    if (billInfo.ticketId == billState[i].TICKET_ID)
                    {
                        checkTicketIdError = false;
                        if (billState[i].MARK_CODE == null || billState[i].MARK_CODE == "" || billState[i].MARK_CODE.Length == 0)
                        {
                            throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
                        }
                        else if (billState[i].MARK_CODE.Substring(0, 1).ToUpper() != "W" || billState[i].PAY_BOOK_STATE == "3")
                        {
                            throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
                        }
                    }
                }
                if (checkTicketIdError)
                {
                    throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
                }
            }
            else
            {
                throw new ApiException(CodeMessage.GetBookBillStateError, "GetBookBillStateError");
            }



            if (openDao.returnTicket(param.billId, openId, param.id, "4"))
            {
                if (!openDao.checkBillInfo(param.billId))
                {
                    openDao.returnBooking(param.billId, openId, "4");
                }
            }
            else
            {
                throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
            }
            string          ReturnBookTicketResult = ReturnBookTicket(Global.POSCODE, billInfo.ticketId, param.billId, "0001");
            WebBillIdResult web1 = JsonConvert.DeserializeObject <WebBillIdResult>(ReturnBookTicketResult);

            if (web1.MESSAGE[0].IS_SUCCESS == "TRUE")
            {
                double price     = billList.billPrice * 100;
                double refundFee = Math.Round(billInfo.factPrice * 0.2, 1);
                double amount    = Math.Round(billInfo.factPrice * 0.8 * 100, 1);
                if (openDao.UpdateBillInfoByRetrun(param.billId, param.id, "5", refundFee.ToString()))
                {
                    if (!openDao.checkBillInfo(param.billId))
                    {
                        openDao.UpdateBillListByRetrun(param.billId, openId, "5", "", refundFee.ToString());
                    }
                    return(true);
                }
                else
                {
                    throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
                }
            }
            else
            {
                openDao.writeLog(Global.POSCODE, openId, "BookingTicket", web1.MESSAGE[0].MESSAGE);
                throw new ApiException(CodeMessage.GetBillIdError, "GetBillIdError");
            }
        }
        /// <summary>
        /// 申请退订单
        /// </summary>
        /// <param name="baseApi"></param>
        /// <returns></returns>
        public object Do_ReturnTicket(BaseApi baseApi)
        {
            ReturnTicketParam param = JsonConvert.DeserializeObject <ReturnTicketParam>(baseApi.param.ToString());

            if (param == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }
            if (param.billId == null || param.billId == "")
            {
                throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError");
            }
            if (param.id == null || param.id == "")
            {
                throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError");
            }
            string  openId  = Utils.GetOpenID(baseApi.token);
            OpenDao openDao = new OpenDao();

            BILLLIST billList = openDao.getBillListById(param.billId, openId);

            if (billList == null)
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
            }
            if (billList.bookingState != "2")
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
            }
            DateTime dtime = Convert.ToDateTime(billList.beginDate + " " + billList.beginTime);

            //判断开船30分内不许退票
            if (dtime < DateTime.Now.AddMinutes(30))
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
            }
            //判断是否已经打票
            BILLINFO billInfo = openDao.getBillInfoById(param.billId, param.id);

            if (billInfo == null)
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
            }
            bool   checkTicketIdError     = true;
            string GetBookBillStateResult = GetBookBillStateNew(Global.POSCODE, param.billId);
            WebBookBillStateResult web3   = JsonConvert.DeserializeObject <WebBookBillStateResult>(GetBookBillStateResult);

            if (web3.MESSAGE[0].IS_SUCCESS == "TRUE")
            {
                List <WEBBILLSTATE> billState = web3.BILLSTATE;
                for (int i = 0; i < billState.Count; i++)
                {
                    if (billInfo.ticketId == billState[i].TICKET_ID)
                    {
                        checkTicketIdError = false;
                        if (billState[i].MARK_CODE == null || billState[i].MARK_CODE == "" || billState[i].MARK_CODE.Length == 0)
                        {
                            throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
                        }
                        else if (billState[i].MARK_CODE.Substring(0, 1).ToUpper() != "W" || billState[i].PAY_BOOK_STATE == "3")
                        {
                            throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
                        }
                    }
                }
                if (checkTicketIdError)
                {
                    throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
                }
            }
            else
            {
                throw new ApiException(CodeMessage.GetBookBillStateError, "GetBookBillStateError");
            }



            if (openDao.returnTicket(param.billId, openId, param.id, "4"))
            {
                if (!openDao.checkBillInfo(param.billId))
                {
                    openDao.returnBooking(param.billId, openId, "4");
                    sendReturnTicketMessage(param.billId);
                }
            }
            else
            {
                throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
            }

            string          ReturnBookTicketResult = ReturnBookTicket(Global.POSCODE, billInfo.ticketId, param.billId, "0001");
            WebBillIdResult web1 = JsonConvert.DeserializeObject <WebBillIdResult>(ReturnBookTicketResult);

            if (web1.MESSAGE[0].IS_SUCCESS == "TRUE")
            {
                double price         = billList.billPrice * 100;
                double refundFee     = Math.Round(billInfo.factPrice * 0.2, 1);
                double amount        = Math.Round(billInfo.factPrice * 0.8 * 100, 1);
                string out_refund_no = billInfo.ticketId.Substring(4);
                string result        = WxPayRefund.Run(billList.payNo, param.billId, out_refund_no, price.ToString(), amount.ToString());
                //string result = WxPayRefund.Run("4200000349201907300338688862", "YYG-0000143985", out_refund_no, "100", "10");

                try
                {
                    WxPayData wxPayData = new WxPayData();
                    SortedDictionary <string, object> sd = wxPayData.FromXml(result);
                    if (sd.Count != 0)
                    {
                        string refundId    = sd["refund_id"].ToString();
                        string outRefundNo = sd["out_refund_no"].ToString();
                        double refundPrice = Convert.ToDouble(sd["refund_fee"]) / 100;
                        if (outRefundNo == out_refund_no)
                        {
                            if (openDao.UpdateBillInfoByRetrun(param.billId, param.id, "5", refundFee.ToString()))
                            {
                                string returnFee = openDao.getBillInfoReturnFee(param.billId);
                                if (!openDao.checkBillInfo(param.billId))
                                {
                                    openDao.UpdateBillListByRetrun(param.billId, openId, "5", refundId, returnFee);
                                    sendReturnTicketMessage(param.billId);
                                }
                                else
                                {
                                    openDao.UpdateBillListByRetrun(param.billId, openId, "2", refundId, returnFee);
                                }
                                return(true);
                            }
                            else
                            {
                                throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
                            }
                        }
                        else
                        {
                            openDao.insertPayLog(param.billId, billList.payNo, amount.ToString(), "", "退票操作-失败:商户订单号对应不上");
                            throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
                        }
                    }
                    else
                    {
                        openDao.insertPayLog(param.billId, billList.payNo, amount.ToString(), "", "退票操作-失败:" + result);
                        throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
                    }
                }
                catch (WxPayException ex)
                {
                    openDao.insertPayLog(param.billId, billList.payNo, amount.ToString(), "", "退票操作-失败:" + ex.ToString());
                    throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
                }
                catch (Exception ex)
                {
                    openDao.insertPayLog(param.billId, billList.payNo, amount.ToString(), "", "退票操作-失败:" + ex.ToString());
                    throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
                }
            }
            else
            {
                openDao.writeLog(Global.POSCODE, openId, "BookingTicket", web1.MESSAGE[0].MESSAGE);
                throw new ApiException(CodeMessage.GetBillIdError, "GetBillIdError");
            }
        }