using Aop.Api; using Aop.Api.Request; using Aop.Api.Response; using DevComponents.DotNetBar.SuperGrid; using NLog; using POSV.Card; using POSV.Component; using POSV.Entity; using POSV.Helper; using POSV.PayApi; using POSV.Report; using POSV.ShoppingCart; using POSV.Utils; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; namespace POSV.Member { public partial class CardRechargeLogForm : BusinessForm { private static Logger logger = NLog.LogManager.GetCurrentClassLogger(); List rechargeLsit = null; private string selectId = null; private PayMode CurrentPayMode = null; public CardRechargeLogForm() { InitializeComponent(); DefaultGridStyle.setDefaultGridStyle(this.detailGrid); this.controlBox1.Text = "POS充值记录"; this.controlBox1.ShowApplicationVersion = false; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); BuilderOrderGrid(); if (this.DesignMode) return; this.startPicker.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")); this.endPicker.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); this.Focus(); this.noTextBox.Focus(); this.noTextBox.SelectAll(); this.ActiveControl = this.noTextBox; QueryTicket(); } public void QueryTicket() { rechargeLsit = new List(); try { using (var db = Global.Instance.OpenDataBase) { StringBuilder sqlBuf = new StringBuilder(); sqlBuf.Append(" select a.id,a.tenantId,a.workerNo,a.workerName,a.cardNo, a.rechargeNo,a.payStatus,a.rechargeStatus,a.money,b.payNo,b.payName,a.createDate"); sqlBuf.Append(" from pos_card_recharge a"); sqlBuf.Append(" left join pos_card_recharge_pay b on a.id=b.rechargeId "); sqlBuf.Append(" where a.storeId = '{0}' "); sqlBuf.Append(" and a.posNo ='{1}' "); sqlBuf.Append(" and a.createDate <='{2}' "); sqlBuf.Append(" and a.createDate>='{3}' "); sqlBuf.Append(" and rechargeNo like '%{4}%' "); sqlBuf.Append(" and a.payStatus =2 "); sqlBuf.Append(" order by a.createDate desc "); string startTime = this.startPicker.Value.ToString("yyyy-MM-dd HH:mm:ss"); string endTime = this.endPicker.Value.ToString("yyyy-MM-dd HH:mm:ss"); string payNo = this.noTextBox.Text; string sql = string.Format(sqlBuf.ToString(), Global.Instance.BusinessPlanLog.StoreId, Global.Instance.Authc.PosNo, endTime, startTime, payNo); rechargeLsit = db.Query(sql).ToList(); } } catch (Exception ex) { LOGGER.Error(ex); } detailGrid.PrimaryGrid.DataSource = rechargeLsit; } private void BuilderOrderGrid() { var panel = detailGrid.PrimaryGrid; panel.DefaultRowHeight = 40; panel.RowHeaderIndexOffset = 1; var cols = ReportUtils.GetGridObject("POSV.Member.", "CardRechargeLog.json"); if (cols != null) { Assembly asmb = Assembly.LoadFrom("DevComponents.DotNetBar.SuperGrid.dll"); foreach (var col in cols) { panel.Columns.Add(new DevComponents.DotNetBar.SuperGrid.GridColumn() { Name = col.Name, HeaderText = col.HeaderText, DataPropertyName = col.DataPropertyName, Visible = col.Display, Width = col.Width, AllowEdit = col.AllowEdit, EditorType = asmb.GetType(col.EditorType, true) }); } } else { panel.NoRowsText = "加载报表错误,请联系管理员"; } } private void Query_Click(object sender, EventArgs e) { QueryTicket(); } private void Exit_Click(object sender, EventArgs e) { //先关闭父窗体 if (this.Owner != null) { this.Owner.Close(); } //再关闭当前窗体 this.Close(); } private void OnCloseTouchClick(object sender, EventArgs e) { //先关闭父窗体 if (this.Owner != null) { this.Owner.Close(); } //再关闭当前窗体 this.Close(); } private void Recharge_Click(object sender, EventArgs e) { //if (selectId==null ||"".Equals(selectId)) { // this.ShowToastNotify(this, "请先选中要处理的单据"); // return; //} //try //{ // using (var db = Global.Instance.OpenDataBase) // { // string sql = "select * from pos_card_recharge where id = '{0}'"; // sql = string.Format(sql, selectId); // CardRecharge cardRecharge = db.FirstOrDefault(sql); // if (cardRecharge ==null) { // this.ShowToastNotify(this, "获取充值单据数据失败!"); // return; // } // if (cardRecharge.RechargeStatus != 3) { // this.ShowToastNotify(this, "请选择正确的单据状态!"); // return; // } // else if (cardRecharge.PayStatus == 2 && cardRecharge.RechargeStatus == 3)//支付成功,但是充值异常,先发起充值状态查询,看是否充值成功 // { // DoQuery(cardRecharge); // } // } //} //catch (Exception ex) //{ // LOGGER.Error(ex); //} } public void updateCardRechargePayType(CardRecharge cardRecharge) { try { lock (Global.Instance.SyncLock) { using (var db = Global.Instance.OpenDataBase) { using (var transaction = db.GetTransaction()) { string sql_pay = "update pos_card_recharge_pay set payNo ='{0}' ,payName ='{1}' where voucherNo = '{2}'"; sql_pay = string.Format(sql_pay, this.CurrentPayMode.No, this.CurrentPayMode.Name, cardRecharge.RechargeNo); db.Execute(sql_pay, null); transaction.Complete(); logger.Info("单号:[{2}]支付方式 payNo==>{1},payName==>{1}......成功", this.CurrentPayMode.No, this.CurrentPayMode.Name, cardRecharge.RechargeNo); } } } } catch (Exception ex) { LOGGER.Error(ex); } } public void DoQuery(CardRecharge cardRecharge) { var requestRecharge = JsonUtils.Deserialize(cardRecharge.RequestMessage); logger.Info("发起充值查询 请求,凭证号[{0}]......", cardRecharge.RechargeNo); CardRechargeQueryRequest request = new CardRechargeQueryRequest(); request.PayVoucherNo = cardRecharge.RechargeNo; request.ShopNo = Global.Instance.Authc.StoreNo; request.PosNo = Global.Instance.Authc.PosNo; request.WorkerNo = Global.Instance.Worker.No; request.SourceSign = "pos"; //转换请求对象 var response = CardUtils.CardRechargeQuery(request); //先去查询充值状态 if (response.Item1 && response.Item3.Data!=null && response.Item3.Data.CardNo!=null) { //如果充值单号已成功充值 logger.Info("充值查询 已成功,凭证号[{0}]......", cardRecharge.RechargeNo); //更新本地充值状态 updateCardRecharge(cardRecharge.RechargeNo, 2, 2); this.ShowToastNotify(this, response.Item2); //打印充值结果 logger.Info("充值查询 成功打印,凭证号[{0}]......", cardRecharge.RechargeNo); this.ShowToastNotify(this, "开始打印"); //构建收银小票模版参数打印 var vars = CardHelper.BuilderRechargeQueryVariable(requestRecharge, response.Item3.Data); //充值打印份数 int ticketCount = Global.Instance.GlobalConfigIntValue(ConfigConstant.PERIPHERAL_CASHIER_RECHARGE_COUNT, 1); //打印延迟 int delaySecond = Global.Instance.GlobalConfigIntValue(ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY, 1); Tuple result = CardHelper.PrinterTicket("会员卡充值", vars, true, false, ticketCount, delaySecond); this.ShowToastNotify(this, string.Format("{0}", result.Item2)); //刷新订单 QueryTicket(); } //zhangy 2020-10-28 Edit 查询业务不应该默认尝试充值 //else { // //发起充值请求 // Recharge(cardRecharge); //} } public void Recharge(CardRecharge cardRecharge) { logger.Info("发起充值重试请求,凭证号[{0}]......", cardRecharge.RechargeNo); var request = JsonUtils.Deserialize(cardRecharge.RequestMessage); //转换请求对象 var response = CardUtils.CardRecharge(request); int RechargeStatus = response.Item1 ? 2 : 3; updateCardRecharge(cardRecharge.RechargeNo, 2, RechargeStatus); //成功 if (response.Item1) { logger.Info("充值成功,凭证号[{0}]......", cardRecharge.RechargeNo); this.ShowToastNotify(this, response.Item2); //打印充值结果 logger.Info("充值成功打印,凭证号[{0}]......", cardRecharge.RechargeNo); this.ShowToastNotify(this, "开始打印"); //构建收银小票模版参数打印 var vars = CardHelper.BuilderRechargeVariable(request, response.Item3.Data); //充值打印份数 int ticketCount = Global.Instance.GlobalConfigIntValue(ConfigConstant.PERIPHERAL_CASHIER_RECHARGE_COUNT, 1); //打印延迟 int delaySecond = Global.Instance.GlobalConfigIntValue(ConfigConstant.PERIPHERAL_CASHIER_CARD_PRINT_DELAY, 1); Tuple result = CardHelper.PrinterTicket("会员卡充值", vars, true, false, ticketCount, delaySecond); this.ShowToastNotify(this, string.Format("{0}", result.Item2)); //刷新订单 QueryTicket(); } else { //对于支付成功,充值失败的可以进行重试 this.ShowToastNotify(this, response.Item2); } } public void updateCardRecharge(string rechargeNo, int payStatus, int rechargeStatus) { try { lock (Global.Instance.SyncLock) { using (var db = Global.Instance.OpenDataBase) { using (var transaction = db.GetTransaction()) { logger.Info("单号:[{0}]更改订单状态 payStatus==>{1},rechargeStatus==>{2}......开始", rechargeNo, payStatus, rechargeStatus); string sql = "update pos_card_recharge set payStatus ={0} ,rechargeStatus ={1},planNo ='{3}',planName='{4}',createDate ='{5}' where rechargeNo = '{2}'"; sql = string.Format(sql, payStatus, rechargeStatus, rechargeNo, Global.Instance.BusinessPlanLog.No, Global.Instance.BusinessPlanLog.Name, DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); db.Execute(sql, null); transaction.Complete(); logger.Info("单号:[{0}]更改订单状态 payStatus==>{1},rechargeStatus==>{2}......成功", rechargeNo, payStatus, rechargeStatus); } } } } catch (Exception ex) { LOGGER.Error(ex); } } private void OnTicketRowActivated(object sender, DevComponents.DotNetBar.SuperGrid.GridRowActivatedEventArgs e) { GridPanel grid = e.GridPanel; if (e.NewActiveRow != null) { GridRow row = e.NewActiveRow as GridRow; grid.SetSelected(e.NewActiveRow, false); grid.SetActiveRow(e.NewActiveRow); selectId = row.Cells["id"].Value.ToString();//选中的ID } } private void buttonX2_Click(object sender, EventArgs e) { if (selectId == null || "".Equals(selectId)) { this.ShowToastNotify(this, "请先选中要处理的单据"); return; } try { CardRecharge cardRecharge = null; using (var db = Global.Instance.OpenDataBase) { string sql = "select * from pos_card_recharge where id = '{0}'"; sql = string.Format(sql, selectId); cardRecharge = db.FirstOrDefault(sql); } if (cardRecharge == null) { this.ShowToastNotify(this, "获取充值单据数据失败!"); return; } if (cardRecharge.PayStatus == 2 && cardRecharge.RechargeStatus == 2)//支付成功,但是充值异常,先发起充值状态查询,看是否充值成功 { DoQuery(cardRecharge); } else { this.ShowToastNotify(this, "充值单据不合法!"); } } catch (Exception ex) { LOGGER.Error(ex); } } } }