/// <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"); } }