/// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="baseApi"></param>
        /// <returns></returns>
        public object Do_ReturnBill(BaseApi baseApi)
        {
            BookingListParam param = JsonConvert.DeserializeObject <BookingListParam>(baseApi.param.ToString());

            if (param == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }
            if (param.billId == null || param.billId == "")
            {
                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 != "0" && billList.bookingState != "1")
            {
                throw new ApiException(CodeMessage.RetrunBillStateError, "RetrunBillStateError");
            }
            if (openDao.returnBill(param.billId, openId))
            {
                return(true);
            }
            else
            {
                throw new ApiException(CodeMessage.RetrunBillError, "RetrunBillError");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 核对订单总金额和支付金额
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="totalPrice"></param>
        /// <returns></returns>
        public bool checkOrderTotalPrice(string billId, double totalPrice)
        {
#if DEBUG
            return(true);
#endif

            OpenDao  openDao  = new OpenDao();
            BILLLIST billList = openDao.getBillListByBillId(billId);
            if (billList == null)
            {
                throw new ApiException(CodeMessage.PaymentBillError, "PaymentBillError");
            }
            if (billList.bookingState == "1")
            {
                if (billList.billPrice * 100 == totalPrice)
                {
                    return(true);
                }
            }
            return(false);
        }
        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");
            }
        }
        /// <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");
            }
        }
Beispiel #5
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");
            }
        }