diff --git a/DSWeb/Areas/Account/Controllers/Chfee_invoice_HangXinController.cs b/DSWeb/Areas/Account/Controllers/Chfee_invoice_HangXinController.cs index 1397109..0a7b1ab 100644 --- a/DSWeb/Areas/Account/Controllers/Chfee_invoice_HangXinController.cs +++ b/DSWeb/Areas/Account/Controllers/Chfee_invoice_HangXinController.cs @@ -1486,14 +1486,21 @@ namespace DSWeb.Areas.Account.Controllers /// public ContentResult NNReadInv(string BILLNO, string redirecturl) { - //如果已有pdf地址 则直接返回 - var isfee = ChinvoiceDAL.GetStCount("PAYBILLNO='" + BILLNO + "'"); - if (isfee != 0) + + var headdata = ChinvoiceDAL.GetData(" cm.BILLNO='" + BILLNO + "'"); + + + if (headdata.PTORRED == "2") { + //如果已有pdf地址 则直接返回 + var isfee = ChinvoiceDAL.GetStCount("PAYBILLNO='" + BILLNO + "'"); + if (isfee != 0) + { - var jsonRespose2 = new JsonResponse { Success = false, Message = "已发票结算,不允许冲红" }; - return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; + var jsonRespose2 = new JsonResponse { Success = false, Message = "已发票结算,不允许冲红" }; + return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; + } } var canlogin = BasicDataRefDAL.CheckLogin(Session); if (!canlogin.Success) @@ -1501,9 +1508,6 @@ namespace DSWeb.Areas.Account.Controllers return (ContentResult)canlogin.Data; } - var headdata = ChinvoiceDAL.GetData(" cm.BILLNO='" + BILLNO + "'"); - - JsonResponse result = new JsonResponse(); diff --git a/DSWeb/Areas/Account/Models/Chfee_invoice_HangXin/Chfee_Invoice.cs b/DSWeb/Areas/Account/Models/Chfee_invoice_HangXin/Chfee_Invoice.cs index b7c9532..d5f3a89 100644 --- a/DSWeb/Areas/Account/Models/Chfee_invoice_HangXin/Chfee_Invoice.cs +++ b/DSWeb/Areas/Account/Models/Chfee_invoice_HangXin/Chfee_Invoice.cs @@ -27,11 +27,15 @@ using DSWeb.Areas.CommMng.Controllers; using DSWeb.MvcShipping.DAL.MsSysParamSet; using System.Web; using DSWeb.MvcShipping.DAL.MsOpExpressDAL; -using DSWeb.Areas.SysMng.DAL.SysUser; using DSWeb.Common.DB; -using DSWeb.MvcShipping.Models.MsChFee; using System.Linq; +using DSWeb.MvcShipping.DAL.MsSysThirdPartyAccount; +using DSWeb.MvcShipping.Models.MsSysThirdPartyAccount; +using DSWeb.MvcShipping.Models.MsChFee; using System.Data.Entity.Migrations; +using IKVM.NativeCode.sun.reflect; +using System.Web.UI; +using DSWeb.Areas.SysMng.DAL.SysUser; namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin { @@ -467,8 +471,10 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin public string buyerAccount { - get { return - ChInvoice_HangXin.CUSTBANK.Replace(" ",""); + get + { + return + ChInvoice_HangXin.CUSTBANK.Replace(" ", ""); } } @@ -945,14 +951,18 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin public NuoNuoQuanDian_RedConfirm(ChInvoice_HangXin _ChInvoice) { ChInvoice_HangXin = _ChInvoice; + + //ChInvoice_HangXin.billUuid= _ChInvoice.billUuid; } /// /// 红字确认单申请号,需要保持唯一,不传的话系统自动生成一个; /// 此处使用蓝票的billno + /// 20240423 改为使用红票的GID 并去除- + /// 在初次冲红时记录在蓝票的billUuid /// - public string billId { get { return ChInvoice_HangXin.BILLNO; } } + public string billId { get; set; } /// /// 对应蓝票发票种类: bs:电子发票(增值税专用发票), pc:电子发票(普通发票),es:全电纸质发票(增值税专用发票), ec:全电纸质发票(普通发票 @@ -1088,8 +1098,19 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin public string billStatus { get; set; } /// /// 红字确认单申请号 ds7当中红票的billno + /// 20240423 改为使用红票的GID 并去除- + /// 在初次冲红时记录在蓝票的billUuid /// - public string billId { get { return ChInvoice_HangXin.BILLNO; } } + public string billId + { + get + { + + return ChInvoice_HangXin.billUuid; + + } + + } /// /// 红字确认单编号 /// @@ -1558,14 +1579,14 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin } } - protected static HangXinRequestHelper getPortToken_诺诺全电发票自应用模式(string taxnum,string CORPID) + protected static HangXinRequestHelper getPortToken_诺诺全电发票自应用模式(string taxnum, string CORPID) { try { var result = new HangXinRequestHelper(); - var INVITERFACE = MsSysInvInterFaceSetDAL.GetData($"INVITERFACE='诺诺全电发票' and CORPID='{CORPID}'", ""); + var INVITERFACE = MsSysInvInterFaceSetDAL.GetData($"INVITERFACE in('诺诺全电发票','东胜乐企他用') and CORPID='{CORPID}'", ""); if (string.IsNullOrWhiteSpace(INVITERFACE.NUONUOAPPKEY)) { @@ -1659,8 +1680,9 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin }; //诺诺全电token接口 var porturl = "http://47.104.90.170:5200/fp/free_type/"; - + BasicDataRefDAL.SaveLog(Newtonsoft.Json.JsonConvert.SerializeObject(dic), "诺诺全电", "重置token", "发送值"); var rtn = WebRequestHelper.DoPost(porturl, dic, 10000); + BasicDataRefDAL.SaveLog(rtn, "诺诺全电", "重置token", "返回值"); //var rtn = WebRequestHelper.DoPost(_SandBoxURL, dic, 20000); //RepCZModel CZM = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); @@ -2185,7 +2207,7 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin return result; } - public static 诺诺全电发票 RegainToken(string TAXCODE,string SALECORPID)//string taxnum,string CORPID) + public static 诺诺全电发票 RegainToken(string TAXCODE, string SALECORPID)//string taxnum,string CORPID) { var _token = 诺诺全电发票重置token(TAXCODE, SALECORPID); @@ -2268,7 +2290,131 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin head.INVOICECODE = info.invoiceCode; head.INVOICENO = info.invoiceNo; head.EINVOICESTATE = info.status; - head.INVOICEINFOURL = info.pdfUrl; + head.INVOICEINFOURL = info.pictureUrl; + head.INVOICEPDFURL = info.pdfUrl; + + head.INVOICEMAKETIME = BasicDataRefDAL.Timestamp2Datetime(info.invoiceTime).ToString("yyyy-MM-dd HH:mm:ss"); + //if (!string.IsNullOrWhiteSpace(info.invoiceSerialNum)) + //{ + // head.INVOICESERIALNUM = info.invoiceSerialNum; + //} + //head.REMARK = head.REMARK.Replace(info.remark,"")+ info.remark; + + head.DbOperationType = DbOperationType.DbotUpd; + head.ModelUIStatus = "E"; + //head.INVOICEMAKETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + var modb = new ModelObjectDB(); + var result = modb.Save(head); + if (!result.Success) + return result; + + result.Message = info.statusMsg; + if (result.Message.IndexOf("失败") >= 0) + { + result.Success = false; + result.Message += ":" + info.failCause; + + //此处调用一次重推 + var hx = getHelper(head); + hx.重推(head); + } + else + { + result.Message += ":" + info.failCause; + } + result.Data = head; + return result; + + } + else + { + var failCause = ""; + + try + { + var info = _return.result[0]; + failCause = "[" + info.failCause + "]"; + } + catch + { + + } + + var msg = _return.code + ":" + _return.describe + failCause; + var result = new DBResult { Success = false, Message = DSWeb.TruckMng.Helper.JsonConvert.Serialize(msg), Data = "" }; + return result; + + } + } + + public DBResult ReadRedInvoice(ChInvoice_HangXin head) + { + if (string.IsNullOrEmpty(head.INVOICESERIALNUM) && !head.全电发票()) + { + var result = new DBResult { Success = false, Message = "还未成功进行平台开票,无可读数据", Data = "" }; + return result; + } + + string method = "nuonuo.OpeMplatform.queryInvoiceResult"; + var json = "{" + "\"serialNos\":[\"" + head.INVOICESERIALNUM + "\"]," + "\"orderNo\":[]," + "\"isOfferInvoiceDetail\":0 }"; + + + if (string.IsNullOrWhiteSpace(head.INVOICESERIALNUM)) + { + //如果流水号为空 则改为按业务编号读取 + method = "nuonuo.OpeMplatform.queryInvoiceResult"; + json = "{" + "\"orderNos\":[\"" + head.GID.Replace("-", "") + "\"]," + "\"serialNos\":[]," + "\"isOfferInvoiceDetail\":0 }"; + } + + //读取业务 + //string method = "nuonuo.electronInvoice.querySerialNum"; + //var json = "{" + "\"orderNo\":[\"" + head.BILLNO + "\"]" + "}"; + + + BasicDataRefDAL.SaveLog("URL=" + URL + ";appKey=" + appKey + ";appSecret=" + appSecret + ";accessToken=" + accessToken + ";taxnum=" + taxnum + ";method=" + method + ";content=" + json, "诺诺平台", "读取发票信息", "发送值"); + string _r = NNOpenSDK.sendPostSyncRequest(URL, getSendid(), appKey, appSecret, accessToken, taxnum, method, json); + BasicDataRefDAL.SaveLog(_r, "诺诺平台", "读取发票信息", "返回值"); + var _return = dealresponse_Read(_r); + + if (_return.code == "070101" || _return.code == "070301") + { + //appkey与token问题 需要重新认证 + //HangXinRequestHelper.clear(accessToken); + var result = new DBResult(false, "需要重新认证", null); + return result; + } + if (_return.code == "070302") + { + //appkey与token问题 需要重新认证 + //HangXinRequestHelper.clear(accessToken); + var result = new DBResult(false, "需要联系诺诺平台开通相关权限", null); + return result; + } + + + if (_return.code == "E0000") + { + //开票信息读取成功 + var returndate = new ChInvoice_HangXin(); + + if (!head.全电发票()) + { + returndate = ChinvoiceDAL.GetData("cm.INVOICESERIALNUM='" + head.INVOICESERIALNUM + "'"); + } + if (head.全电发票()) + { + returndate = ChinvoiceDAL.GetData("cm.BILLNO='" + head.BILLNO + "'"); + } + head = returndate; + + //var invoiceSerialNum = _return.result[0].invoiceSerialNum; + var info = _return.result[0]; + //立即调用读取发票信息的方法 将返回值设置进head 并保存 + //head.INVOICESERIALNUM = invoiceSerialNum; + head.INVOICECODE = info.invoiceCode; + head.INVOICENO = info.invoiceNo; + head.EINVOICESTATE = info.status; + head.INVOICEINFOURL = info.pictureUrl; head.INVOICEPDFURL = info.pdfUrl; head.INVOICEMAKETIME = BasicDataRefDAL.Timestamp2Datetime(info.invoiceTime).ToString("yyyy-MM-dd HH:mm:ss"); @@ -2409,7 +2555,7 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin head.DbOperationType = DbOperationType.DbotUpd; head.ModelUIStatus = "E"; - + var modb = new ModelObjectDB(); var result = modb.Save(head); @@ -2521,17 +2667,19 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin /// /// /// - public DBResult PostRedConfirm(ChInvoice_HangXin head, ref ChInvoice_HangXin bluehead, List detailList,HttpSessionStateBase Session) + public DBResult PostRedConfirm(ChInvoice_HangXin head, ref ChInvoice_HangXin bluehead, List detailList, HttpSessionStateBase Session) { //var billno = head.BILLNO; //20230529 增加判断 如果INVOICEMAKETIME到当前时间 小于24小时 则提示错误并返回 // - + var _head = new NuoNuoQuanDian_RedConfirm(head); _head.extensionNumber = extensionNumber; + _head.billId = bluehead.GID.Replace("-", ""); + var json = DSWeb.TruckMng.Helper.JsonConvert.Serialize(_head); string method = "nuonuo.OpeMplatform.saveInvoiceRedConfirm"; @@ -2541,7 +2689,6 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin BasicDataRefDAL.SaveLog(rtn, "诺诺全电", "红字确认单", "返回值"); - var _return = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<红字申请单发送返回值>(rtn.Trim('"')); var result = new DBResult(); @@ -2549,14 +2696,14 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin if (_return.code == "E0000") { //红字申请单提交成功 - + head.billUuid = bluehead.GID.Replace("-", ""); //读取红字确认单 var _r = ReadRedConfirm(ref head, detailList); if (!_r.Success) { - if (_r.Message != "红字确认单申请中") - bluehead.billUuid = ""; + //if (_r.Message != "红字确认单申请中") + // bluehead.billUuid = ""; return _r; } else @@ -2598,7 +2745,7 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin //将原票内的申请和费用恢复原状 var BlueInvoice = ChinvoiceDAL.GetData(" cm.INVOICECODE='" + head.REDCODE + "' and cm.INVOICENO='" + head.REDNUM + "'"); - result = ChinvoiceDAL.SetInvoiceFee(BlueInvoice,Session); + result = ChinvoiceDAL.SetInvoiceFee(BlueInvoice, Session); } //如果状态为开出成功 则执行锁定 @@ -2616,16 +2763,11 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin returndate = ChinvoiceDAL.GetData(" BILLNO='" + head.BILLNO + "'"); } - result.Data = returndate; return result; } - - - - } //else if (_return.code == "070101" || _return.code == "070301") //{ @@ -2642,7 +2784,7 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin //} else { - bluehead.billUuid = ""; + //bluehead.billUuid = ""; var reault = new DBResult(false, _return.message, head); return reault; } @@ -2690,6 +2832,9 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin head.INVOICESERIALNUM = ""; var modb = new ModelObjectDB(); + head.BILLNO = _return.result.list[0].orderNo; + head.INVOICESERIALNUM = _return.result.list[0].invoiceSerialNum; + result = ChinvoiceDAL.SaveInvDetail(head.GID, detailList); if (result.Success == true) { @@ -3100,6 +3245,7 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin } } + public class PortTokenmb { public string message { get; set; } @@ -3223,7 +3369,7 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin public string errormsg() { - if (list == null || list.Count == 0) return null; + if (list == null || list.Count == 0) return ""; return list[0].billMessage; } } @@ -3331,6 +3477,11 @@ namespace DSWeb.Areas.Account.Models.Chfee_Invoice_HangXin /// /// public string billNo { get; set; } + + + public string orderNo { get; set; } + public string invoiceSerialNum { get; set; } + /// /// /// diff --git a/HcDBUtility/Comm/DBResult.cs b/HcDBUtility/Comm/DBResult.cs index 759344a..36021fa 100644 --- a/HcDBUtility/Comm/DBResult.cs +++ b/HcDBUtility/Comm/DBResult.cs @@ -96,7 +96,7 @@ namespace HcUtility.Comm if (Success != success) Message = ""; Success = success; - if (Message.IndexOf(message) >= 0) + if (!string.IsNullOrWhiteSpace(message) && Message.IndexOf(message) >= 0) { }