コード例 #1
0
        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);
        }
コード例 #2
0
        public Int32 AddVIPCardPayment(VIPCardPayment cardPayment, out string tradePayNo)
        {
            string json = JsonConvert.SerializeObject(cardPayment);

            byte[] jsonByte = Encoding.UTF8.GetBytes(json);

            int cByte = ParamFieldLength.PACKAGE_HEAD + jsonByte.Length;

            byte[] sendByte   = new byte[cByte];
            int    byteOffset = 0;

            Array.Copy(BitConverter.GetBytes((int)Command.ID_ADD_CARDPAYMENT), sendByte, BasicTypeLength.INT32);
            byteOffset = BasicTypeLength.INT32;
            Array.Copy(BitConverter.GetBytes(cByte), 0, sendByte, byteOffset, BasicTypeLength.INT32);
            byteOffset += BasicTypeLength.INT32;
            Array.Copy(jsonByte, 0, sendByte, byteOffset, jsonByte.Length);
            byteOffset += jsonByte.Length;

            int result = 0;

            tradePayNo = string.Empty;
            using (SocketClient socket = new SocketClient(ConstantValuePool.BizSettingConfig.IPAddress, ConstantValuePool.BizSettingConfig.Port))
            {
                Byte[] receiveData = null;
                Int32  operCode    = socket.SendReceive(sendByte, out receiveData);
                if (operCode == (int)RET_VALUE.SUCCEEDED)
                {
                    result     = BitConverter.ToInt32(receiveData, ParamFieldLength.PACKAGE_HEAD);
                    tradePayNo = Encoding.UTF8.GetString(receiveData, ParamFieldLength.PACKAGE_HEAD + BasicTypeLength.INT32, receiveData.Length - ParamFieldLength.PACKAGE_HEAD - BasicTypeLength.INT32).Trim('\0');
                }
                socket.Close();
            }
            return(result);
        }
コード例 #3
0
        public Int32 AddVIPCardPayment(VIPCardPayment cardPayment, out string tradePayNo)
        {
            int result = 0;

            tradePayNo = string.Empty;
            try
            {
                _daoManager.OpenConnection();
                //日结号
                string dailyStatementNo = _dailyStatementDao.GetCurrentDailyStatementNo();
                result = _vipCardTradeDao.AddVIPCardPayment(cardPayment.CardNo, cardPayment.PayAmount, cardPayment.PayIntegral, cardPayment.OrderNo, cardPayment.EmployeeNo, cardPayment.DeviceNo, dailyStatementNo, out tradePayNo);
            }
            catch (Exception exception)
            {
                LogHelper.GetInstance().Error(string.Format("[AddVIPCardPayment]参数:cardPayment_{0}", JsonConvert.SerializeObject(cardPayment)), exception);
            }
            finally
            {
                _daoManager.CloseConnection();
            }
            return(result);
        }
コード例 #4
0
        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);
        }