public static byte[] AddVIPCardPayment(byte[] itemBuffer) { byte[] objRet = null; string strReceive = Encoding.UTF8.GetString(itemBuffer, ParamFieldLength.PACKAGE_HEAD, itemBuffer.Length - ParamFieldLength.PACKAGE_HEAD).Trim('\0'); VIPCardPayment cardPayment = JsonConvert.DeserializeObject <VIPCardPayment>(strReceive); string tradePayNo = string.Empty; int result; //验证卡身份 VIPCard card; int resultCode = VIPCardService.GetInstance().GetVIPCard(cardPayment.CardNo, cardPayment.CardPassword, out card); if (resultCode == 1 && card != null) { result = VIPCardTradeService.GetInstance().AddVIPCardPayment(cardPayment, out tradePayNo); } else { result = 99; //会员卡号或者密码错误 } byte[] buffer = Encoding.UTF8.GetBytes(tradePayNo); int transCount = ParamFieldLength.PACKAGE_HEAD + BasicTypeLength.INT32 + ParamFieldLength.TRADEPAYNO; objRet = new byte[transCount]; Array.Copy(BitConverter.GetBytes((int)RET_VALUE.SUCCEEDED), 0, objRet, 0, BasicTypeLength.INT32); Array.Copy(BitConverter.GetBytes(transCount), 0, objRet, BasicTypeLength.INT32, BasicTypeLength.INT32); Array.Copy(BitConverter.GetBytes(result), 0, objRet, ParamFieldLength.PACKAGE_HEAD, BasicTypeLength.INT32); Array.Copy(buffer, 0, objRet, ParamFieldLength.PACKAGE_HEAD + BasicTypeLength.INT32, buffer.Length); return(objRet); }
public static byte[] RefundVIPCardPayment(byte[] itemBuffer) { byte[] objRet = null; string cardNo = Encoding.UTF8.GetString(itemBuffer, ParamFieldLength.PACKAGE_HEAD, ParamFieldLength.CARD_NO).Trim('\0'); string cardPassword = Encoding.UTF8.GetString(itemBuffer, ParamFieldLength.PACKAGE_HEAD + ParamFieldLength.CARD_NO, ParamFieldLength.CARD_PASSWORD).Trim('\0'); string tradePayNo = Encoding.UTF8.GetString(itemBuffer, ParamFieldLength.PACKAGE_HEAD + ParamFieldLength.CARD_NO + ParamFieldLength.CARD_PASSWORD, ParamFieldLength.TRADEPAYNO).Trim('\0'); int result; //验证卡身份 VIPCard card; int resultCode = VIPCardService.GetInstance().GetVIPCard(cardNo, cardPassword, out card); if (resultCode == 1 && card != null) { result = VIPCardTradeService.GetInstance().RefundVIPCardPayment(cardNo, tradePayNo); } else { result = 99; //会员卡号或者密码错误 } //返回对象 objRet = new byte[ParamFieldLength.PACKAGE_HEAD + BasicTypeLength.INT32]; Array.Copy(BitConverter.GetBytes((int)RET_VALUE.SUCCEEDED), 0, objRet, 0, BasicTypeLength.INT32); Array.Copy(BitConverter.GetBytes(ParamFieldLength.PACKAGE_HEAD + BasicTypeLength.INT32), 0, objRet, BasicTypeLength.INT32, BasicTypeLength.INT32); Array.Copy(BitConverter.GetBytes(result), 0, objRet, ParamFieldLength.PACKAGE_HEAD, BasicTypeLength.INT32); return(objRet); }
public static byte[] GetVIPCardTradeList(byte[] itemBuffer) { byte[] objRet = null; string cardNo = Encoding.UTF8.GetString(itemBuffer, ParamFieldLength.PACKAGE_HEAD, ParamFieldLength.CARD_NO).Trim('\0'); string beginDate = Encoding.UTF8.GetString(itemBuffer, ParamFieldLength.PACKAGE_HEAD + ParamFieldLength.CARD_NO, ParamFieldLength.BEGINDATE).Trim('\0'); string endDate = Encoding.UTF8.GetString(itemBuffer, ParamFieldLength.PACKAGE_HEAD + ParamFieldLength.CARD_NO + ParamFieldLength.BEGINDATE, ParamFieldLength.ENDDATE).Trim('\0'); VIPCardTradeRecord cardTradeRecord; Int32 result = VIPCardTradeService.GetInstance().GetVIPCardTradeList(cardNo, DateTime.Parse(beginDate), DateTime.Parse(endDate), out cardTradeRecord); string json = JsonConvert.SerializeObject(cardTradeRecord); byte[] jsonByte = Encoding.UTF8.GetBytes(json); int transCount = BasicTypeLength.INT32 + BasicTypeLength.INT32 + BasicTypeLength.INT32 + jsonByte.Length; objRet = new byte[transCount]; Array.Copy(BitConverter.GetBytes((int)RET_VALUE.SUCCEEDED), 0, objRet, 0, BasicTypeLength.INT32); Array.Copy(BitConverter.GetBytes(transCount), 0, objRet, BasicTypeLength.INT32, BasicTypeLength.INT32); Array.Copy(BitConverter.GetBytes(result), 0, objRet, 2 * BasicTypeLength.INT32, BasicTypeLength.INT32); Array.Copy(jsonByte, 0, objRet, 3 * BasicTypeLength.INT32, jsonByte.Length); return(objRet); }
private void btnConfirm_Click(object sender, EventArgs e) { string cardNo = txtCardNo.Text.Trim(); if (string.IsNullOrEmpty(cardNo)) { MessageBox.Show("请输入您的会员卡号!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(_cardPassword)) { MessageBox.Show("请重新输入您的会员卡号!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(txtStoreAmout.Text.Trim())) { MessageBox.Show("请输入充值金额!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } decimal storeAmount; if (!decimal.TryParse(txtStoreAmout.Text.Trim(), out storeAmount)) { MessageBox.Show("请输入正确的充值金额格式!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (_curPayoffWay == null) { MessageBox.Show("请选择充值付款方式!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } VIPCard card; int resultCode = VIPCardService.GetInstance().SearchVIPCard(cardNo, _cardPassword, out card); if (card == null || resultCode != 1) { txtCardNo.Text = string.Empty; MessageBox.Show("您输入的会员卡号或者密码错误!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } VIPCardAddMoney cardAddMoney = new VIPCardAddMoney { CardNo = cardNo, CardPassword = _cardPassword, StoreMoney = storeAmount, EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo, DeviceNo = ConstantValuePool.BizSettingConfig.DeviceNo, PayoffID = _curPayoffWay.PayoffID, PayoffName = _curPayoffWay.PayoffName }; string tradePayNo; int result = VIPCardTradeService.GetInstance().AddVIPCardStoredValue(cardAddMoney, out tradePayNo); if (result == 1) { VIPCard card2; int resultCode2 = VIPCardService.GetInstance().SearchVIPCard(cardNo, _cardPassword, out card2); if (card2 != null && resultCode2 == 1) { PrintMemberCard printCard = new PrintMemberCard { MemberVoucher = "会员充值凭单", CardNo = cardNo, ShopName = ConstantValuePool.CurrentShop.ShopName, TradeType = "充值", TranSequence = tradePayNo, TradeTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), PreTradeAmount = card.Balance.ToString("f2"), PostTradeAmount = card2.Balance.ToString("f2"), Payment = _curPayoffWay.PayoffName, StoreValue = storeAmount.ToString("f2"), GivenAmount = (card2.Balance - card.Balance - storeAmount).ToString("f2"), PresentExp = (card2.Integral - card.Integral).ToString(), AvailablePoints = card2.Integral.ToString(), Operator = ConstantValuePool.CurrentEmployee.EmployeeNo, Remark = string.Empty }; int copies = ConstantValuePool.BizSettingConfig.printConfig.OrderCopies; string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverCardPrint printer = DriverCardPrint.GetInstance(printerName, paperName, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintCardStore(printCard); } } MessageBox.Show("会员充值成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else if (result == 2) { MessageBox.Show("卡号不存在,请确认输入的卡号是否正确!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (result == 3) { MessageBox.Show("该卡未开通,请先开卡!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (result == 4) { MessageBox.Show("该卡已挂失,不能充值!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (result == 5) { MessageBox.Show("该卡已锁卡,不能充值!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (result == 6) { MessageBox.Show("该卡已作废,不能充值!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (result == 7) { MessageBox.Show("该卡所属会员组没有储值功能!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (result == 99) { txtCardNo.Text = string.Empty; MessageBox.Show("会员卡号或者密码错误!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("服务器出现错误,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnRefundPay_Click(object sender, EventArgs e) { bool hasChecked = false; foreach (DataGridViewRow row in this.dataGirdViewExt1.Rows) { hasChecked = Convert.ToBoolean(row.Cells["colCheck"].Value); if (hasChecked) { break; } } if (!hasChecked) { MessageBox.Show("请选择需要进行支付退款操作的卡号!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool result = true; CardRefundPayService refundPayService = new CardRefundPayService(); foreach (DataGridViewRow row in this.dataGirdViewExt1.Rows) { bool isCheck = Convert.ToBoolean(row.Cells["colCheck"].Value); if (isCheck) { string cardNo = row.Cells["colCardNo"].Value.ToString(); string tradePayNo = row.Cells["colTradePayNo"].Value.ToString(); string cardPassword; //获取卡密码 Feature.FormNumericKeypad keyForm = new Feature.FormNumericKeypad(false); keyForm.DisplayText = string.Format("请输入卡号'{0}'的密码", cardNo); keyForm.IsPassword = true; keyForm.ShowDialog(); if (!string.IsNullOrEmpty(keyForm.KeypadValue)) { cardPassword = keyForm.KeypadValue; } else { continue; } int returnValue = VIPCardTradeService.GetInstance().RefundVipCardPayment(cardNo, cardPassword, tradePayNo); if (returnValue == 0) { result = false; break; } int storeValueId = int.Parse(row.Cells["colStoreValueID"].Value.ToString()); refundPayService.UpdateFixedPayInfo(storeValueId, true); } } if (result) { List <CardRefundPay> cardRefundPayList = refundPayService.GetCardRefundPayList(); if (cardRefundPayList == null || cardRefundPayList.Count == 0) { this.Close(); } else { BindCardRefundPay(cardRefundPayList); } } else { List <CardRefundPay> cardRefundPayList = refundPayService.GetCardRefundPayList(); BindCardRefundPay(cardRefundPayList); MessageBox.Show("退款过程出现错误,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSearch_Click(object sender, EventArgs e) { string cardNo = txtCardNo.Text.Trim(); if (string.IsNullOrEmpty(cardNo)) { MessageBox.Show("请输入您的会员卡号!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string beginDate = dtBeginDate.Value.ToString("yyyy-MM-dd"); string endDate = dtEndDate.Value.ToString("yyyy-MM-dd"); VIPCardTradeRecord cardTradeRecord = null; Int32 result = VIPCardTradeService.GetInstance().GetVIPCardTradeList(cardNo, beginDate, endDate, ref cardTradeRecord); if (result == 1 && cardTradeRecord != null) { txtBalance.Text = cardTradeRecord.Balance.ToString("f2"); txtDiscount.Text = cardTradeRecord.DiscountRate.ToString("f2"); txtIntegral.Text = cardTradeRecord.Integral.ToString(); if (cardTradeRecord.VIPCardTradeList != null && cardTradeRecord.VIPCardTradeList.Count > 0) { dataGirdViewExt1.Rows.Clear(); foreach (VIPCardTrade item in cardTradeRecord.VIPCardTradeList) { int index = dataGirdViewExt1.Rows.Add(); dataGirdViewExt1.Rows[index].Cells["colCardNo"].Value = item.CardNo; dataGirdViewExt1.Rows[index].Cells["colTradePayNo"].Value = item.TradePayNo; string tradeType = " "; if (item.TradeType == 1) { tradeType += "储值"; dataGirdViewExt1.Rows[index].Cells["colTradeType"].Style.ForeColor = Color.Green; } if (item.TradeType == 2) { tradeType += "储值赠送"; dataGirdViewExt1.Rows[index].Cells["colTradeType"].Style.ForeColor = Color.Green; } if (item.TradeType == 3) { tradeType += "消费"; dataGirdViewExt1.Rows[index].Cells["colTradeType"].Style.ForeColor = Color.Tomato; } dataGirdViewExt1.Rows[index].Cells["colTradeType"].Value = tradeType; dataGirdViewExt1.Rows[index].Cells["colTradeAmount"].Value = item.TradeAmount; dataGirdViewExt1.Rows[index].Cells["colTradeIntegral"].Value = item.TradeIntegral; dataGirdViewExt1.Rows[index].Cells["colTradeTime"].Value = item.TradeTime.ToString("yyyy-MM-dd HH:mm"); dataGirdViewExt1.Rows[index].Cells["colOrderNo"].Value = item.OrderNo; dataGirdViewExt1.Rows[index].Cells["colEmployeeNo"].Value = item.EmployeeNo; } } else { dataGirdViewExt1.Rows.Clear(); txtCardNo.Text = string.Empty; MessageBox.Show("找不到该卡号的交易记录!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (result == 0) { dataGirdViewExt1.Rows.Clear(); txtCardNo.Text = string.Empty; MessageBox.Show("该卡未开通!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (result == 2) { dataGirdViewExt1.Rows.Clear(); txtCardNo.Text = string.Empty; MessageBox.Show("该卡已挂失!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (result == 3) { dataGirdViewExt1.Rows.Clear(); txtCardNo.Text = string.Empty; MessageBox.Show("该卡已锁卡!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (result == 4) { dataGirdViewExt1.Rows.Clear(); txtCardNo.Text = string.Empty; MessageBox.Show("该卡已作废!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool IsVipCardPaySuccess(out Dictionary <string, VIPCardPayment> dicCardPayment, out Dictionary <string, string> dicCardTradePayNo) { bool isSuccess = false; //key: cardNo dicCardPayment = new Dictionary <string, VIPCardPayment>(); dicCardTradePayNo = new Dictionary <string, string>(); foreach (KeyValuePair <string, OrderPayoff> item in dic) { if (item.Value.Quantity > 0 && item.Value.PayoffType == (int)PayoffWayMode.MembershipCard) { if (string.IsNullOrEmpty(item.Value.CardNo)) { continue; } string[] cardArr = item.Value.CardNo.Split('#'); //会员卡支付 string cardNo = cardArr[0]; string cardPassword = cardArr[1]; decimal payAmount = item.Value.AsPay * item.Value.Quantity - item.Value.NeedChangePay; const int payIntegral = 0; VIPCard card; int resultCode = VIPCardService.GetInstance().SearchVIPCard(cardNo, cardPassword, out card); if (card == null || resultCode != 1) { continue; } VIPCardPayment cardPayment = new VIPCardPayment { CardNo = cardNo, CardPassword = cardPassword, PayAmount = payAmount, PayIntegral = payIntegral, OrderNo = m_SalesOrder.order.OrderNo, EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo, DeviceNo = ConstantValuePool.BizSettingConfig.DeviceNo }; string tradePayNo; int result = VIPCardTradeService.GetInstance().AddVIPCardPayment(cardPayment, out tradePayNo); if (result == 1) { VIPCard card2; int resultCode2 = VIPCardService.GetInstance().SearchVIPCard(cardNo, cardPassword, out card2); if (card2 != null && resultCode2 == 1) { PrintMemberCard printCard = new PrintMemberCard { MemberVoucher = "会员消费凭单", CardNo = cardNo, ShopName = ConstantValuePool.CurrentShop.ShopName, TradeType = "消费", TranSequence = tradePayNo, TradeTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), PreConsumeAmount = card.Balance.ToString("f2"), PostConsumeAmount = card2.Balance.ToString("f2"), ConsumeAmount = payAmount.ToString("f2"), ConsumePoints = payIntegral.ToString(), AvailablePoints = card2.Integral.ToString(), LastConsumeTime = card.LastConsumeTime == null ? string.Empty : ((DateTime)card.LastConsumeTime).ToString("yyyy/MM/dd HH:mm:ss"), Operator = ConstantValuePool.CurrentEmployee.EmployeeNo, Remark = string.Empty }; int copies = ConstantValuePool.BizSettingConfig.printConfig.OrderCopies; string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverCardPrint printer = DriverCardPrint.GetInstance(printerName, paperName, paperWidth); for (int i = 0; i < copies; i++) { printer.DoPrintCardConsume(printCard); } } //会员充值成功 dicCardPayment.Add(item.Value.CardNo, cardPayment); dicCardTradePayNo.Add(item.Value.CardNo, tradePayNo); isSuccess = true; } } else if (result == 2) { MessageBox.Show(string.Format("卡号'{0}'不存在,请确认输入的卡号是否正确!", item.Value.CardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); isSuccess = false; break; } else if (result == 3) { MessageBox.Show(string.Format("卡号'{0}'未开通,请先开卡!", item.Value.CardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); isSuccess = false; break; } else if (result == 4) { MessageBox.Show(string.Format("卡号'{0}'已挂失,不能充值!", item.Value.CardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); isSuccess = false; break; } else if (result == 5) { MessageBox.Show(string.Format("卡号'{0}'已锁卡,不能充值!", item.Value.CardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); isSuccess = false; break; } else if (result == 6) { MessageBox.Show(string.Format("卡号'{0}'已作废,不能充值!", item.Value.CardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); isSuccess = false; break; } else if (result == 7) { MessageBox.Show(string.Format("卡号'{0}'所属会员组没有储值功能!", item.Value.CardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); isSuccess = false; break; } else if (result == 99) { MessageBox.Show("会员卡号或者密码错误!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); isSuccess = false; break; } else { MessageBox.Show("服务器出现错误,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); isSuccess = false; break; } } } if (isSuccess) { return(true); } if (dicCardPayment.Count > 0) { //取消会员卡支付 foreach (KeyValuePair <string, VIPCardPayment> item in dicCardPayment) { string cardNo = item.Value.CardNo; //将支付成功的会员卡取消支付 int returnValue = VIPCardTradeService.GetInstance().RefundVipCardPayment(cardNo, item.Value.CardPassword, dicCardTradePayNo[cardNo]); if (returnValue == 1) { continue; } if (returnValue == 2) { MessageBox.Show(string.Format("交易流水号'{0}'不存在或者已作废", dicCardTradePayNo[cardNo]), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (returnValue == 99) { MessageBox.Show(string.Format("'{0}'的会员卡号或者密码错误!", cardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("服务器出现错误,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //保存到本地Sqlite CardRefundPay cardRefundPay = new CardRefundPay { CardNo = cardNo, ShopID = ConstantValuePool.CurrentShop.ShopID.ToString(), TradePayNo = dicCardTradePayNo[cardNo], PayAmount = item.Value.PayAmount, EmployeeNo = item.Value.EmployeeNo, DeviceNo = item.Value.DeviceNo }; CardRefundPayService refundPayService = new CardRefundPayService(); refundPayService.AddRefundPayInfo(cardRefundPay); } dicCardPayment = new Dictionary <string, VIPCardPayment>(); dicCardTradePayNo = new Dictionary <string, string>(); } return(false); }
private void btnCheckOut_Click(object sender, EventArgs e) { if (m_ActualPayMoney > m_PaidInAmount) { // 支付的金额不足 MessageBox.Show("支付的金额不足,请确认后重新付款!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (m_PaidInAmount > m_ActualPayMoney) { decimal cash = 0, noCash = 0; List <OrderPayoff> noCashPayoff = new List <OrderPayoff>(); foreach (KeyValuePair <string, OrderPayoff> item in dic) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { cash += item.Value.AsPay * item.Value.Quantity; } else { noCash += item.Value.AsPay * item.Value.Quantity; noCashPayoff.Add(item.Value); } } if (noCash > m_ActualPayMoney) { //非现金支付方式按单位价值从高到低排序 OrderPayoff[] noCashPayoffArr = noCashPayoff.ToArray(); for (int j = 0; j < noCashPayoffArr.Length; j++) { for (int i = noCashPayoffArr.Length - 1; i > j; i--) { if (noCashPayoffArr[j].AsPay < noCashPayoffArr[i].AsPay) { OrderPayoff temp = noCashPayoffArr[j]; noCashPayoffArr[j] = noCashPayoffArr[i]; noCashPayoffArr[i] = temp; } } } if (noCash - noCashPayoffArr[noCashPayoffArr.Length - 1].AsPay < m_ActualPayMoney) { if (cash > 0) { MessageBox.Show("现金支付方式多余!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("非现金支付方式金额过多,请重新支付!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { //由全部非现金及部分现金来支付 decimal changePay = m_PaidInAmount - m_ActualPayMoney; foreach (KeyValuePair <string, OrderPayoff> item in dic) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { item.Value.NeedChangePay = changePay; break; } } } } //计算支付的金额并填充OrderPayoff bool isContainsCash = false; bool isContainsVipCard = false; decimal paymentMoney = 0; decimal needChangePay = 0; List <OrderPayoff> orderPayoffList = new List <OrderPayoff>(); foreach (KeyValuePair <string, OrderPayoff> item in dic) { if (item.Value.Quantity > 0) { if (item.Value.PayoffType == (int)PayoffWayMode.Cash) { isContainsCash = true; } if (item.Value.PayoffType == (int)PayoffWayMode.MembershipCard) { isContainsVipCard = true; } OrderPayoff orderPayoff = item.Value; paymentMoney += orderPayoff.AsPay * orderPayoff.Quantity; needChangePay += orderPayoff.NeedChangePay; orderPayoffList.Add(orderPayoff); } } if (isContainsCash) { //支付方式中包含现金,需要打开钱箱 OpenCashBox(); } bool paySuccess = false; if (isContainsVipCard) { Dictionary <string, VIPCardPayment> dicCardPayment; Dictionary <string, string> dicCardTradePayNo; if (IsVipCardPaySuccess(out dicCardPayment, out dicCardTradePayNo)) { //组合交易流水号,因为需要支持多张会员卡 string strTradePayNo = string.Empty; foreach (KeyValuePair <string, string> item in dicCardTradePayNo) { strTradePayNo += "," + item.Value; } strTradePayNo = strTradePayNo.Substring(1); //将支付方式中的卡号密码去掉 foreach (var orderPayoff in orderPayoffList) { if (orderPayoff.PayoffType == (int)PayoffWayMode.MembershipCard) { if (!string.IsNullOrEmpty(orderPayoff.CardNo)) { orderPayoff.CardNo = orderPayoff.CardNo.Split('#')[0]; } } } // 支付服务尝试三次 int times = 0; while (times < 3 && !paySuccess) { paySuccess = PayForOrder(orderPayoffList, paymentMoney, needChangePay, strTradePayNo); times++; Thread.Sleep(500); } if (!paySuccess) { //取消会员卡支付 foreach (KeyValuePair <string, VIPCardPayment> item in dicCardPayment) { string cardNo = item.Value.CardNo; //将支付成功的会员卡取消支付 int returnValue = VIPCardTradeService.GetInstance().RefundVipCardPayment(cardNo, item.Value.CardPassword, dicCardTradePayNo[cardNo]); if (returnValue == 1) { continue; } if (returnValue == 2) { MessageBox.Show(string.Format("交易流水号'{0}'不存在或者已作废", dicCardTradePayNo[cardNo]), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (returnValue == 99) { MessageBox.Show(string.Format("'{0}'的会员卡号或者密码错误!", cardNo), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("服务器出现错误,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //保存到本地Sqlite CardRefundPay cardRefundPay = new CardRefundPay(); cardRefundPay.CardNo = cardNo; cardRefundPay.ShopID = ConstantValuePool.CurrentShop.ShopID.ToString(); cardRefundPay.TradePayNo = dicCardTradePayNo[cardNo]; cardRefundPay.PayAmount = item.Value.PayAmount; cardRefundPay.EmployeeNo = item.Value.EmployeeNo; cardRefundPay.DeviceNo = item.Value.DeviceNo; CardRefundPayService refundPayService = new CardRefundPayService(); refundPayService.AddRefundPayInfo(cardRefundPay); } } } else { MessageBox.Show("会员卡支付操作失败,请稍后再试!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { paySuccess = PayForOrder(orderPayoffList, paymentMoney, needChangePay, string.Empty); } if (paySuccess) { //打印小票 PrintData printData = new PrintData(); printData.ShopName = ConstantValuePool.CurrentShop.ShopName; printData.DeskName = m_SalesOrder.order.DeskName; printData.PersonNum = m_SalesOrder.order.PeopleNum.ToString(); printData.PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); printData.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo; printData.TranSequence = m_SalesOrder.order.TranSequence.ToString(); printData.ShopAddress = ConstantValuePool.CurrentShop.RunAddress; printData.Telephone = ConstantValuePool.CurrentShop.Telephone; printData.ReceivableMoney = m_ActualPayMoney.ToString("f2"); printData.ServiceFee = "0.00"; printData.PaidInMoney = paymentMoney.ToString("f2"); printData.NeedChangePay = needChangePay.ToString("f2"); printData.GoodsOrderList = new List <GoodsOrder>(); printData.PayingOrderList = new List <PayingGoodsOrder>(); foreach (OrderDetails item in m_SalesOrder.orderDetailsList) { string strLevelFlag = string.Empty; int levelCount = item.ItemLevel * 2; for (int i = 0; i < levelCount; i++) { strLevelFlag += "-"; } GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.GoodsName = strLevelFlag + item.GoodsName; goodsOrder.GoodsNum = item.ItemQty.ToString("f1"); goodsOrder.SellPrice = item.SellPrice.ToString("f2"); goodsOrder.TotalSellPrice = item.TotalSellPrice.ToString("f2"); goodsOrder.TotalDiscount = item.TotalDiscount.ToString("f2"); goodsOrder.Unit = item.Unit; printData.GoodsOrderList.Add(goodsOrder); } foreach (OrderPayoff orderPayoff in orderPayoffList) { PayingGoodsOrder payingOrder = new PayingGoodsOrder(); payingOrder.PayoffName = orderPayoff.PayoffName; payingOrder.PayoffMoney = (orderPayoff.AsPay * orderPayoff.Quantity).ToString("f2"); payingOrder.NeedChangePay = orderPayoff.NeedChangePay.ToString("f2"); printData.PayingOrderList.Add(payingOrder); } string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth; if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER) { string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name; string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName; DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth); printer.DoPrintPaidOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM) { string port = ConstantValuePool.BizSettingConfig.printConfig.Name; if (port.Length > 3) { if (port.Substring(0, 3).ToUpper() == "COM") { string portName = port.Substring(0, 4).ToUpper(); InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth); printer.DoPrintPaidOrder(printData); } } } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET) { string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name; InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth); printer.DoPrintPaidOrder(printData); } if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB) { string vid = ConstantValuePool.BizSettingConfig.printConfig.VID; string pid = ConstantValuePool.BizSettingConfig.printConfig.PID; string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID; InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth); printer.DoPrintPaidOrder(printData); } //判断单据类型,如果是外带并且是直接出货 if (m_SalesOrder.order.EatType == (int)EatWayType.Takeout && ConstantValuePool.BizSettingConfig.DirectShipping) { CustomerOrder customerOrder = new CustomerOrder { OrderID = m_SalesOrder.order.OrderID, DeliveryEmployeeNo = string.Empty }; CustomersService.GetInstance().UpdateTakeoutOrderStatus(customerOrder); } m_IsPaidOrder = true; this.Close(); } else { MessageBox.Show("账单支付失败!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }