示例#1
0
        public object Do_MemberReg(BaseApi baseApi)
        {
            MemberRegParam memberRegParam = JsonConvert.DeserializeObject <MemberRegParam>(baseApi.param.ToString());

            if (memberRegParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            SessionBag sessionBag = SessionContainer.GetSession(baseApi.token);

            if (sessionBag == null)
            {
                throw new ApiException(CodeMessage.InvalidToken, "InvalidToken");
            }

            OpenDao openDao = new OpenDao();
            string  openID  = Utils.GetOpenID(baseApi.token);
            var     member  = openDao.GetMember(openID);

            if (member != null)
            {
                throw new ApiException(CodeMessage.MemberExist, "MemberExist");
            }

            if (!openDao.MemberReg(memberRegParam, openID))
            {
                throw new ApiException(CodeMessage.MemberRegError, "MemberRegError");
            }
            member = openDao.GetMember(openID);
            SessionUser sessionUser = JsonConvert.DeserializeObject <SessionUser>(sessionBag.Name);

            sessionUser.openid   = sessionBag.OpenId;
            sessionUser.memberId = member.memberId;
            sessionUser.userType = "MEMBER";
            sessionBag.Name      = JsonConvert.SerializeObject(sessionUser);
            SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S));

            return("");
        }
示例#2
0
        /// <summary>
        /// 获取订单信息
        /// </summary>
        /// <param name="baseApi"></param>
        /// <returns></returns>
        public object Do_GetBookingListById(BaseApi baseApi)
        {
            BookingListParam param = JsonConvert.DeserializeObject <BookingListParam>(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.billId == null || param.billId == "")
            {
                throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError");
            }
            string  openId  = Utils.GetOpenID(baseApi.token);
            OpenDao openDao = new OpenDao();

            //处理10分取消未支付订单
            openDao.UpdateBookingStatusBy10Minute(openId);

            return(openDao.getBillListById(param.billId, openId));
        }
示例#3
0
        public object Do_Payment(BaseApi baseApi)
        {
            PaymentParam paymentParam = JsonConvert.DeserializeObject <PaymentParam>(baseApi.param.ToString());

            if (paymentParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }
            if (paymentParam.billId == null || paymentParam.billId == "")
            {
                throw new ApiException(CodeMessage.InterfaceValueError, "InterfaceValueError");
            }

            string  openId  = Utils.GetOpenID(baseApi.token);
            OpenDao openDao = new OpenDao();

            //处理10分取消未支付订单
            openDao.UpdateBookingStatusBy10Minute(openId);
            BILLLIST billList = openDao.getBillListById(paymentParam.billId, openId);

            if (billList == null)
            {
                throw new ApiException(CodeMessage.PaymentBillError, "PaymentBillError");
            }
            if (billList.bookingState != "1")
            {
                throw new ApiException(CodeMessage.PaymentStateError, "PaymentStateError");
            }
            var billId     = paymentParam.billId;
            int totalPrice = Convert.ToInt32(billList.billPrice * 100);

            if (totalPrice <= 0)
            {
                throw new ApiException(CodeMessage.PaymentTotalPriceZero, "PaymentTotalPriceZero");
            }

            //if (billList.prePayId!=null && billList.prePayId!="" && billList.prePayTime != null && billList.prePayTime != "")
            //{
            //    try
            //    {
            //        DateTime preDateTime = Convert.ToDateTime(billList.prePayTime);
            //        if (DateTime.Now.AddHours(-2)< preDateTime)
            //        {
            //            var timeStamp = TenPayV3Util.GetTimestamp();
            //            var nonceStr = TenPayV3Util.GetNoncestr();
            //            var product = "船票";
            //            var package = string.Format("prepay_id={0}", billList.prePayId);
            //            var paySign = TenPayV3.GetJsPaySign(tenPayV3Info.AppId, timeStamp, nonceStr, package, tenPayV3Info.Key);

            //            PaymentResults paymentResults = new PaymentResults();
            //            paymentResults.appId = tenPayV3Info.AppId;
            //            paymentResults.nonceStr = nonceStr;
            //            paymentResults.package = package;
            //            paymentResults.paySign = paySign;
            //            paymentResults.timeStamp = timeStamp;
            //            paymentResults.product = product;
            //            paymentResults.billId = billId;

            //            return paymentResults;
            //        }
            //    }
            //    catch (Exception)
            //    {

            //    }

            //}

            try
            {
                var timeStamp   = TenPayV3Util.GetTimestamp();
                var nonceStr    = TenPayV3Util.GetNoncestr();
                var product     = "船票";
                var xmlDataInfo =
                    new TenPayV3UnifiedorderRequestData(
                        tenPayV3Info.AppId,
                        tenPayV3Info.MchId,
                        product,
                        billId,
                        totalPrice,
                        "127.0.0.1",
                        tenPayV3Info.TenPayV3Notify,
                        TenPayV3Type.JSAPI,
                        openId,
                        tenPayV3Info.Key,
                        nonceStr);

                var result = TenPayV3.Html5Order(xmlDataInfo);
                if (result.return_msg != "")
                {
                    openDao.writeLog(Global.POSCODE, "", "pay", result.return_msg);
                }

                pDao.writePrePayId(billId, result.prepay_id);
                var package = string.Format("prepay_id={0}", result.prepay_id);
                var paySign = TenPayV3.GetJsPaySign(tenPayV3Info.AppId, timeStamp, nonceStr, package, tenPayV3Info.Key);

                PaymentResults paymentResults = new PaymentResults();
                paymentResults.appId     = tenPayV3Info.AppId;
                paymentResults.nonceStr  = nonceStr;
                paymentResults.package   = package;
                paymentResults.paySign   = paySign;
                paymentResults.timeStamp = timeStamp;
                paymentResults.product   = product;
                paymentResults.billId    = billId;

                return(paymentResults);
            }
            catch (Exception ex)
            {
                throw new ApiException(CodeMessage.PaymentError, "PaymentError");
            }
        }
示例#4
0
        public object Do_Login(BaseApi baseApi)
        {
            LoginParam loginParam = JsonConvert.DeserializeObject <LoginParam>(baseApi.param.ToString());

            if (loginParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            var jsonResult = SnsApi.JsCode2Json(Global.APPID, Global.APPSECRET, loginParam.code);

            if (jsonResult.errcode == Senparc.Weixin.ReturnCode.请求成功)
            {
                AccessTokenContainer.Register(Global.APPID, Global.APPSECRET);
                var sessionBag = SessionContainer.UpdateSession(null, jsonResult.openid, jsonResult.session_key, jsonResult.unionid);

                OpenDao     openDao     = new OpenDao();
                SessionUser sessionUser = new SessionUser();
                if (loginParam.tempOpenId != null && loginParam.tempOpenId.StartsWith("3rd-"))
                {
                    Member member1 = openDao.GetMember(Utils.GetOpenID(sessionBag.Key));

                    if (member1 == null)
                    {
                        openDao.UpdateMemberOpenID(Utils.GetOpenID(sessionBag.Key), loginParam.tempOpenId);
                    }
                    else
                    {
                        Member member2 = openDao.GetMember(loginParam.tempOpenId);
                        if (member1.openid != member2.openid)
                        {
                            openDao.MoveMember(member1.memberId, member2.memberId, member2.heart);
                        }
                    }
                }
                Member member = openDao.GetMember(Utils.GetOpenID(sessionBag.Key));
                if (member == null)
                {
                    sessionUser.userType = "GUEST";
                    sessionBag.Name      = JsonConvert.SerializeObject(sessionUser);

                    SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S));
                    return(new { token = sessionBag.Key, isReg = false });
                }
                else
                {
                    sessionUser.userType = "MEMBER";
                    sessionUser.openid   = sessionBag.OpenId;
                    sessionUser.memberId = member.memberId;
                    sessionBag.Name      = JsonConvert.SerializeObject(sessionUser);
                    SessionContainer.Update(sessionBag.Key, sessionBag, new TimeSpan(Global.SESSION_EXPIRY_H, Global.SESSION_EXPIRY_M, Global.SESSION_EXPIRY_S));
                    openDao.AddMemberHeartCommit(member);
                    return(new {
                        token = sessionBag.Key,
                        isReg = true,
                        member.memberId,
                        member.memberName,
                        member.memberImg,
                        member.memberPhone,
                        member.memberSex,
                        member.scanCode
                    });
                }
            }
            else
            {
                throw new ApiException(CodeMessage.SenparcCode, jsonResult.errmsg);
            }
        }
示例#5
0
        public string GetPaymentResult(ResponseHandler resHandler)
        {
            OpenDao openDao     = new OpenDao();
            string  return_code = "SUCCESS";
            string  return_msg  = "OK";

            try
            {
                return_code = resHandler.GetParameter("return_code");
                return_msg  = resHandler.GetParameter("return_msg");
                string openid         = resHandler.GetParameter("openid");
                string total_fee      = resHandler.GetParameter("total_fee");
                string time_end       = resHandler.GetParameter("time_end");
                string out_trade_no   = resHandler.GetParameter("out_trade_no");
                string transaction_id = resHandler.GetParameter("transaction_id");
                openDao.writeLog(Global.POSCODE, openid, "payCallBack", return_msg + "#" + out_trade_no + "#" + transaction_id + "#" + total_fee + "#" + time_end);

                resHandler.SetKey(tenPayV3Info.Key);
                //验证请求是否从微信发过来(安全)
                if (resHandler.IsTenpaySign() && return_code.ToUpper() == "SUCCESS")
                {
                    /* 这里可以进行订单处理的逻辑 */
                    // transaction_id:微信支付单号
                    // out_trade_no:商城实际订单号
                    // openId:用户信息
                    // total_fee:实际支付价格

                    if (checkOrderTotalPrice(out_trade_no, Convert.ToDouble(total_fee)))
                    {
                        if (pDao.updateOrderForPay(out_trade_no, transaction_id))
                        {
                            string          SetPayIdResult = SetPayId(Global.POSCODE, out_trade_no, transaction_id);
                            WebBillIdResult web1           = JsonConvert.DeserializeObject <WebBillIdResult>(SetPayIdResult);
                            if (web1.MESSAGE[0].IS_SUCCESS == "TRUE")
                            {
                                string          PayTicketDoneResult = PayTicketDone(Global.POSCODE, out_trade_no, transaction_id);
                                WebBillIdResult web2 = JsonConvert.DeserializeObject <WebBillIdResult>(PayTicketDoneResult);
                                if (web2.MESSAGE[0].IS_SUCCESS == "TRUE")
                                {
                                    pDao.insertPayLog(out_trade_no, transaction_id, total_fee, openid, "支付完成-成功");
                                }
                                else
                                {
                                    pDao.insertPayLog(out_trade_no, transaction_id, total_fee, openid, "支付完成-确认付款失败");
                                }
                            }
                            else
                            {
                                pDao.insertPayLog(out_trade_no, transaction_id, total_fee, openid, "支付完成-同步设置支付单号失败");
                            }
                        }
                        else
                        {
                            pDao.insertPayLog(out_trade_no, transaction_id, total_fee, openid, "支付完成-修改订单状态失败");
                        }
                    }
                    else
                    {
                        pDao.insertPayLog(out_trade_no, transaction_id, total_fee, openid, "支付完成-订单状态不为1或支付金额与订单总金额不符");
                    }
                }
                else
                {
                    return_code = "FAIL";
                    return_msg  = "不是从微信发过来";

                    openDao.writeLog(Global.POSCODE, openid, "payCallBack", return_msg + "#" + out_trade_no + "#" + transaction_id + "#" + total_fee + "#" + time_end);
                }
                return(string.Format(@"<xml><return_code><![CDATA[{0}]]></return_code><return_msg><![CDATA[{1}]]></return_msg></xml>", return_code, return_msg));
            }
            catch (Exception ex)
            {
                return_code = "FAIL";
                return_msg  = ex.ToString();
                openDao.writeLog(Global.POSCODE, "", "payCallBack", return_msg);
                return(string.Format(@"<xml><return_code><![CDATA[{0}]]></return_code><return_msg><![CDATA[{1}]]></return_msg></xml>", return_code, return_msg));
            }
        }
示例#6
0
        /// <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");
            }
        }
示例#7
0
        /// <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);
        }
示例#8
0
        /// <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");
            }
        }