/// <summary> /// 生成银行及物业订单 /// </summary> /// <param name="Row"></param> /// <returns></returns> public string GenerateOrder(DataRow Row) { bool IsBankOk = false; bool IsPropertyOk = false; string PropertyOrderId = ""; string BankOrderId = ""; string CommunityId = Row["CommunityId"].ToString(); string FeesIds = Row["FeesIds"].ToString(); string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string CustID = Row["CustID"].ToString(); //2017-06-05添加可选参数openId //用于区分是否来自于微信H5支付 //默认为空 string openId = Row.Table.Columns.Contains("openId") ? Row["openId"].ToString() : ""; string UserId = null; if (Row.Table.Columns.Contains("UserID") && !string.IsNullOrEmpty(Row["UserID"].ToString())) { UserId = Row["UserID"].ToString(); } int UsePoints = 0; if (Row.Table.Columns.Contains("UsePoints") && !string.IsNullOrEmpty(Row["UsePoints"].ToString())) { UsePoints = AppGlobal.StrToInt(Row["UsePoints"].ToString()); } //增加FeesIds重复验证 if (FeesIds == "") { return(JSONHelper.FromString(false, "未选择任何费用")); } string[] feesArray = FeesIds.Split(',').Distinct().ToArray(); FeesIds = string.Join(",", feesArray.ToArray()); WxPayConfig wxPayConfig = GenerateConfig(CommunityId); if (null == wxPayConfig) { return(JSONHelper.FromString(false, "该小区不支持微信支付")); } PubConstant.hmWyglConnectionString = GetConnection(CommunityId); using (var appConn = new SqlConnection(PubConstant.UnifiedContionString)) { if (appConn.State == ConnectionState.Closed) { appConn.Open(); } var appTrans = appConn.BeginTransaction(); // 检查数据 string useHistoryID = null; int Amount = 0; // 缴费总额 decimal propertyAmount = 0.0m; // 物业费缴费总额 decimal parkingAmount = 0.0m; // 车位费缴费总额 decimal deductionAmount = 0.0m; // 积分可抵扣金额 decimal propertyMaxDiscountsAmount = 0.0m; // 物管费最大可抵用金额 decimal parkingMaxDiscountsAmount = 0.0m; // 车位费最大可抵用金额 int pointBalance = 0; // 积分余额 var deductionObject = new List <string>(); // 积分可抵扣对象 #region 获取积分抵扣规则 // 要使用的积分是否大于用户积分余额 pointBalance = appConn.Query <int>("SELECT PointBalance FROM Tb_App_UserPoint WHERE UserID=@UserID", new { UserID = UserId }, appTrans).FirstOrDefault(); if (pointBalance < UsePoints) { return(new ApiResult(false, "积分余额不足").toJson()); } // 企业编号 short corpId = appConn.Query <short>("SELECT CorpID FROM Tb_Community WHERE Id=@CommunityId", new { CommunityId = CommunityId }, appTrans).FirstOrDefault(); // 积分权限控制 var controlInfo = appConn.Query <Tb_Control_AppPoint>(@"SELECT * FROM Tb_Control_AppPoint WHERE CorpID=@CorpID AND IsEnable=1 AND (CommunityID=@CommunityId OR CommunityID IS NULL) ORDER BY CommunityID DESC", new { CorpID = corpId, CommunityId = CommunityId }, appTrans).FirstOrDefault(); if (controlInfo == null || controlInfo.IsEnable == false) { controlInfo = Tb_Control_AppPoint.DefaultControl; controlInfo.CorpID = corpId; controlInfo.CommunityID = Guid.Empty.ToString(); } // 允许抵用物业费 if (controlInfo.AllowDeductionPropertyFees) { deductionObject.Add($@"'{AppPointUsableObjectConverter.GetKey(AppPointUsableObject.PropertyFee)}'"); } // 允许抵用车位费 if (controlInfo.AllowDeductionParkingFees) { deductionObject.Add($@"'{AppPointUsableObjectConverter.GetKey(AppPointUsableObject.ParkingFee)}'"); } #endregion #region 获取缴费列表,读取欠费总额 using (IDbConnection erpConn = new SqlConnection(PubConstant.hmWyglConnectionString)) { try { IEnumerable <dynamic> arrearsList = erpConn.Query($@"SELECT * FROM view_HSPR_Fees_Filter WHERE FeesID IN({FeesIds})"); // 允许抵用物业费 if (controlInfo.AllowDeductionPropertyFees) { foreach (dynamic item in arrearsList) { if (item.SysCostSign != null && item.SysCostSign.ToString() == "B0001") { propertyAmount += item.DebtsAmount; } } } // 允许抵用车位费 if (controlInfo.AllowDeductionParkingFees) { foreach (dynamic item in arrearsList) { if (item.SysCostSign != null && item.SysCostSign.ToString() == "B0002") { parkingAmount += item.DebtsAmount; } } } } catch (Exception) { appTrans.Rollback(); return(new ApiResult(false, "验证欠费列表失败").toJson()); } } #endregion if (UsePoints > 0 && !string.IsNullOrEmpty(UserId)) { #region 判断积分是否足够 try { if (deductionObject.Count == 0) { return(new ApiResult(false, "暂不支持积分抵用功能").toJson()); } // 积分抵用规则 var ruleInfo = appConn.Query($@"SELECT IID,ConditionAmount,DiscountsAmount,DeductionObject,b.Remark AS SysCostSign,StartTime,EndTime FROM Tb_App_Point_PropertyDeductionRule a LEFT JOIN Tb_Dictionary_Point_UsableObject b ON a.DeductionObject=b.[Key] WHERE CommunityID=@CommunityId AND DeductionObject IN({string.Join(", ", deductionObject) }) AND getdate() BETWEEN StartTime AND EndTime AND a.IsDelete=0 ORDER BY ConditionAmount,DiscountsAmount", new { CommunityId = CommunityId }, appTrans); if (ruleInfo.Count() == 0) { return(new ApiResult(false, "积分抵用规则未设置或已失效").toJson()); } // 确定物管费可抵用金额 if (propertyAmount > 0) { string key = AppPointUsableObjectConverter.GetKey(AppPointUsableObject.PropertyFee); foreach (var item in ruleInfo) { if (item.DeductionObject == key && propertyAmount >= item.ConditionAmount) { propertyMaxDiscountsAmount = item.DiscountsAmount; } } } // 确定车位费可抵用金额 if (parkingAmount > 0) { string key = AppPointUsableObjectConverter.GetKey(AppPointUsableObject.ParkingFee); foreach (var item in ruleInfo) { if (item.DeductionObject == key && parkingAmount >= item.ConditionAmount) { parkingMaxDiscountsAmount = item.DiscountsAmount; } } } // 要使用积分抵用的金额 deductionAmount = UsePoints / (decimal)controlInfo.PointExchangeRatio; // 积分数量不正常 if (deductionAmount > (parkingMaxDiscountsAmount + propertyMaxDiscountsAmount)) { return(new ApiResult(false, "使用积分超过可抵用最大金额").toJson()); } else { decimal tmp = deductionAmount; // 部分抵扣物业费 if (propertyMaxDiscountsAmount != 0) { if (tmp <= propertyMaxDiscountsAmount) { propertyMaxDiscountsAmount = tmp; tmp = 0; } else { tmp -= propertyMaxDiscountsAmount; } } // 部分抵扣车位费 if (parkingMaxDiscountsAmount != 0 && tmp > 0) { if (tmp <= parkingMaxDiscountsAmount) { parkingMaxDiscountsAmount = tmp; tmp = 0; } else { tmp -= parkingMaxDiscountsAmount; } } if (tmp != 0) { return(new ApiResult(false, "积分抵用出错").toJson()); } } if (UsePoints > 0 && deductionAmount > 0) { useHistoryID = Guid.NewGuid().ToString(); } } catch (Exception) { appTrans.Rollback(); return(new ApiResult(false, "积分验证失败").toJson()); } #endregion } // 积分数量正常,生成订单 try { // 生成ERP账单 string PropertyResult = GeneratePropertyOrder(CommunityId, FeesIds, txnTime, CustID, ref IsPropertyOk, ref Amount, ref PropertyOrderId, wxPayConfig); // ERP订单生成成功 if (IsPropertyOk == true) { // 应缴总金额 Amount = Amount - (int)(deductionAmount * 100); // 微信签名订单信息 WxPayData Data = new WxPayData(); string BankResult = GenerateBankOrder(CommunityId, UserId, feesArray.First(), PropertyOrderId, txnTime, Amount, ref IsBankOk, ref BankOrderId, ref Data, wxPayConfig, openId); if (IsBankOk == true) { // 微信订单信息 WxPayData result = new WxPayData(); result.SetValue("appid", Data.GetValue("appid")); result.SetValue("partnerid", Data.GetValue("mch_id")); result.SetValue("prepayid", Data.GetValue("prepay_id")); result.SetValue("noncestr", Data.GetValue("nonce_str")); result.SetValue("package", "Sign=WXPay"); result.SetValue("timestamp", (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); result.SetValue("sign", result.MakeSign()); // 计算预赠送积分 new AppPoint().CalcPresentedPointForPropertyFees(CommunityId, propertyAmount - propertyMaxDiscountsAmount, parkingAmount - parkingMaxDiscountsAmount, out int p1, out int p2); result.SetValue("presented_points", (p1 + p2)); if (!string.IsNullOrEmpty(useHistoryID)) { result.SetValue("out_trade_no", PropertyOrderId); result.SetValue("deduction_amount", deductionAmount); result.SetValue("point_use_history_id", useHistoryID); appConn.Execute($@"UPDATE Tb_App_UserPoint SET PointBalance=(PointBalance-@UsePoints) WHERE UserID=@UserID; INSERT INTO Tb_App_Point_UseHistory(IID, UserID, UseWay, UsePoints, PointBalance, DeductionAmount, Remark) VALUES(@UseHistoryID, @UserID, @UseWay, @UsePoints, @PointBalance, @DeductionAmount, @Remark); INSERT INTO Tb_App_Point_Locked(UserID, UseHistoryID, LockedPoints) VALUES (@UserID, @UseHistoryID, @LockedPoints);", new { UsePoints = UsePoints, UserID = UserId, UseHistoryID = useHistoryID, UseWay = AppPointUseWayConverter.GetKey(AppPointUseWay.PropertyFeeDeduction), PointBalance = pointBalance - UsePoints, DeductionAmount = deductionAmount, Remark = AppPointUseWayConverter.GetValue(AppPointUseWay.PropertyFeeDeduction), LockedPoints = UsePoints }, appTrans); string usableObject = string.Join(",", deductionObject.Select(obj => AppPointUsableObjectConverter.GetValue(obj.Replace("'", "")))); // 存储积分使用记录与订单关联关系 appConn.Execute(@"INSERT INTO Tb_App_Point_UseHistoryOrder(UseHistoryID, OrderID, Payment, UsableObject) VALUES(@UseHistoryID, @OrderID, '微信', @UsableObject)", new { UseHistoryID = useHistoryID, OrderID = PropertyOrderId, UsableObject = usableObject }, appTrans); } using (var erpConn = new SqlConnection(PubConstant.hmWyglConnectionString)) { // 更新订单 erpConn.Execute(@"UPDATE Tb_OL_WeiXinPayOrder SET prepay_id=@prepay_id WHERE out_trade_no = @out_trade_no ", new { prepay_id = Data.GetValue("prepay_id").ToString(), out_trade_no = PropertyOrderId }); } appTrans?.Commit(); return(JSONHelper.FromJsonString(true, result.ToJson())); } else { appTrans?.Rollback(); return(JSONHelper.FromString(false, BankResult)); } } else { appTrans?.Rollback(); return(JSONHelper.FromString(false, PropertyResult)); } } catch (Exception ex) { appTrans?.Rollback(); return(JSONHelper.FromString(false, ex.Message + ex.StackTrace)); } } }
/// <summary> /// /// </summary> /// <param name="Ds"></param> /// <returns></returns> public string GenerateOrder(DataSet Ds) { DataRow Row = Ds.Tables[0].Rows[0]; bool IsBankOk = false; bool IsBusinessOk = false; string OrderId = ""; string prepay_str = ""; string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string BussId = Row["BussId"].ToString(); string UserId = Row["UserId"].ToString(); bool IsConfig = GenerateConfig(BussId); if (IsConfig == false) { return(JSONHelper.FromString(false, "未配置证书文件")); } string Name = Row["Name"].ToString(); string Mobile = Row["Mobile"].ToString(); string DeliverAddress = Row["DeliverAddress"].ToString(); string subject = ""; decimal Amount = 0.0m; decimal CouponAmount = 0.0m; // 俊发需求5896 string communityId = null; if (Row.Table.Columns.Contains("CommunityId") && !string.IsNullOrEmpty(Row["CommunityId"].ToString())) { communityId = Row["CommunityId"].ToString(); } //生成商家账单 string BussinessResult = GenerateBusinessOrder(Ds, communityId, BussId, UserId, txnTime, ref IsBusinessOk, ref Amount, ref CouponAmount, ref OrderId, Name, Mobile, DeliverAddress); if (IsBusinessOk == true) { using (IDbConnection Conn = new SqlConnection(ConnectionDb.GetBusinessConnection())) { Tb_System_BusinessCorp bussInfo = Conn.Query <Tb_System_BusinessCorp>(@"SELECT * FROM Tb_System_BusinessCorp WHERE BussId=@BussId", new { BussId = BussId }).FirstOrDefault(); if (bussInfo != null) { subject = bussInfo.BussName + "订单,共" + Ds.Tables["Product"].Rows.Count + "种商品"; } } //生成预支付单,并返回订单ID string BankResult = GenerateBankOrder(BussId, OrderId, txnTime, (Amount - CouponAmount), ref IsBankOk, ref prepay_str, subject); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { using (IDbConnection conn = new SqlConnection(ConnectionDb.GetBusinessConnection())) { string sql; if ((Amount - CouponAmount) == 0) { sql = string.Format(@"UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str,Method='支付宝',IsPay='已付款',ReturnCode='TRADE_FINISHED',ReturnMsg='TRADE_FINISHED',PayDate=GetDate(),Amount={0},CouponAmount={1},RealAmount=0 WHERE OrderId = @OrderId", Amount, CouponAmount); } else { sql = @"UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str WHERE OrderId = @OrderId"; } try { conn.Execute(sql, new { prepay_str = prepay_str.ToString(), OrderId = OrderId }); IDbConnection tw2bsConn = new SqlConnection(PubConstant.UnifiedContionString.ToString()); var commInfo = tw2bsConn.QueryFirstOrDefault($"SELECT CorpID,CommName FROM Tb_Community WHERE Id ='{communityId}'"); if (commInfo.CorpID == 1985)//俊发需求6662 { var info = conn.QueryFirstOrDefault($@"SELECT HeadquartersPhone,CommPhone,BusinessPhone FROM Tb_NotificationManager WHERE CommunityID = '{communityId}'"); if (info != null) { string msg = $@"【俊发物业】{commInfo.CommName}项目,有新的已支付订单,请尽快去后台跟进处理。"; Common.Sms.Send_v2(1410, "jfwy", "jfwy0424", info.HeadquartersPhone, msg, out string strErrMsg); Common.Sms.Send_v2(1410, "jfwy", "jfwy0424", info.CommPhone, msg, out string strErrMsg1); Common.Sms.Send_v2(1410, "jfwy", "jfwy0424", info.BusinessPhone, msg, out string strErrMsg2); } } } catch (Exception) { } } //返回请求字符串 return(JSONHelper.FromJsonString(true, prepay_str, false)); } } else { return(JSONHelper.FromString(false, BussinessResult)); } }
/// <summary> /// 订单继续支付 /// </summary> public string GoOnGenerateOrder(DataSet Ds) { DataRow Row = Ds.Tables[0].Rows[0]; bool IsBankOk = false; bool IsBusinessOk = true;//商家订单是否生成成功 string OrderId = Row["OrderId"].ToString(); string prepay_str = ""; //取得上一次商家订单信息 IDbConnection ConnOrder = new SqlConnection(ConnectionDb.GetBusinessConnection()); string OrderQuery = "SELECT * FROM Tb_Charge_Receipt WHERE OrderId=@OrderId OR Id=@OrderId"; Model.Model.Buss.Tb_Charge_Receipt TOrder = ConnOrder.Query <Model.Model.Buss.Tb_Charge_Receipt>(OrderQuery, new { OrderId = OrderId }).SingleOrDefault(); if (TOrder != null) { IsBusinessOk = true; } string txnTime = TOrder.txnTime.ToString(); string BussId = TOrder.BussId.ToString(); bool IsConfig = GenerateConfig(BussId); if (IsConfig == false) { return(JSONHelper.FromString(false, "未配置证书文件")); } decimal realAmount = 0.0m; string sql = @"SELECT * FROM Tb_Charge_ReceiptDetail WHERE ReceiptCode=@ReceiptCode"; IEnumerable <Tb_Charge_ReceiptDetail> ReceiptDetails = ConnOrder.Query <Tb_Charge_ReceiptDetail>(sql, new { ReceiptCode = TOrder.Id }); Dictionary <String, decimal> keyValuePairs = new Dictionary <string, decimal>(); foreach (Tb_Charge_ReceiptDetail item in ReceiptDetails) { decimal unitPrice = 0.0m; // 计算此时应该多少钱 sql = @"SELECT * FROM Tb_Resources_Details WHERE ResourcesID=@ResourcesID"; Tb_Resources_Details resources = ConnOrder.Query <Tb_Resources_Details>(sql, new { ResourcesID = item.ResourcesID }).FirstOrDefault(); if (resources != null) { if (resources.IsGroupBuy == "是" && resources.GroupBuyEndDate.HasValue && resources.GroupBuyEndDate.Value > DateTime.Now && resources.GroupBuyStartDate.HasValue && resources.GroupBuyStartDate.Value < DateTime.Now ) { realAmount += (item.GroupPrice.HasValue ? item.GroupPrice.Value : 0) * item.Quantity; unitPrice = item.GroupPrice.HasValue ? item.GroupPrice.Value : 0; } else { unitPrice = (item.SalesPrice.Value - item.DiscountPrice.Value) >= 0 ? item.SalesPrice.Value - item.DiscountPrice.Value : 0; //如果销售价格 小于 优惠价 则算成0 realAmount += ((item.SalesPrice.Value - item.DiscountPrice.Value) >= 0 ? item.SalesPrice.Value - item.DiscountPrice.Value : 0) * item.Quantity; } keyValuePairs.Add(item.RpdCode, unitPrice); if (item.OffsetMoney.HasValue) { realAmount -= item.OffsetMoney.Value; } if (item.OffsetMoney2.HasValue) { realAmount -= item.OffsetMoney2.Value; } //修改当前商品的团购价 } } //加上运费 var money = realAmount + TOrder.Freight; //如果不需要给钱 直接完成该订单 if (money <= 0) { String result = ReceBusinessOrder(OrderId, 0); return(JsonConvert.SerializeObject(new { Result = result.ToLower() == "success" ? "true" : "false", Msg = result, })); } ChangeUnitPrice(keyValuePairs); if (IsBusinessOk == true) { sql = "SELECT * FROM Tb_System_BusinessCorp WHERE BussId=@BussId"; Tb_System_BusinessCorp bussInfo = ConnOrder.Query <Tb_System_BusinessCorp>(sql, new { BussId = TOrder.BussId }).FirstOrDefault(); //生成预支付单,并返回订单ID string BankResult = GenerateBankOrder(BussId, OrderId, txnTime, money, ref IsBankOk, ref prepay_str, bussInfo.BussName + "订单,共" + ReceiptDetails.Count() + "种商品"); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { //更新订单银行流水号 IDbConnection Conn = new SqlConnection(ConnectionDb.GetBusinessConnection()); string Query = @"UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str WHERE OrderId = @OrderId OR Id=@OrderId "; Conn.Execute(Query, new { prepay_str = prepay_str.ToString(), OrderId = OrderId }); //返回请求字符串 return(JSONHelper.FromJsonString(true, prepay_str)); } } return(JSONHelper.FromString(false, "生成订单失败")); }
/// <summary> /// 威富通支付接口,不存数据库,仅做支付用 /// </summary> /// <param name="Row"></param> /// <returns></returns> private string GenerateWftOrder(DataRow Row) { string CommunityId = Row["CommunityId"].ToString(); string FeesIds = Row["FeesIds"].ToString(); string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string CustID = Row["CustID"].ToString(); //2017-06-05添加可选参数openId //用于区分是否来自于微信H5支付 //默认为空 if (!Row.Table.Columns.Contains("openId")) { return(JSONHelper.FromString(false, "请通过微信访问!")); } string openId = Row["openId"].ToString(); //增加FeesIds重复验证 if (FeesIds == "") { return(JSONHelper.FromString(false, "未选择费用!")); } string[] FeesStr = FeesIds.Split(','); HashSet <string> h = new HashSet <string>(); for (int i = 0; i < FeesStr.Length; i++) { h.Add(FeesStr[i]); } if (h.Count != FeesStr.Length) { return(JSONHelper.FromString(false, "费用重复!")); } DataTable CommunityTable = new DbHelperSQLP(PubConstant.UnifiedContionString.ToString()).Query("SELECT * FROM Tb_Community WHERE Id='" + CommunityId.ToString() + "'").Tables[0]; if (null == CommunityTable || CommunityTable.Rows.Count <= 0) { return(JSONHelper.FromString(false, "获取数据库信息失败!")); } //连接字符串 string connStr = UnionUtil.GetConnectionString(CommunityTable.Rows[0]); double Amount = 0.00d; using (IDbConnection conn = new SqlConnection(connStr)) { Amount = conn.ExecuteScalar <double>("SELECT ISNULL(SUM(DebtsAmount),0)+ISNULL(SUM(DebtsLateAmount),0) AS Amount FROM Tb_HSPR_Fees WHERE FeesID IN (" + FeesIds + ")", null, null, null, CommandType.Text); } if (Amount <= 0) { return(JSONHelper.FromString(false, "缴费金额必须大于0!")); } //把金额转换为分 int fen = (int)Amount * 100; //商户订单号,当前10位时间戳+16位随机字符 string out_trade_no = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000) + Utils.Nmrandom(); RequestHandler reqHandler = new RequestHandler(null); reqHandler.setGateUrl("https://pay.swiftpass.cn/pay/gateway"); reqHandler.setKey("9d101c97133837e13dde2d32a5054abb"); reqHandler.setParameter("out_trade_no", out_trade_no); //商户订单号 reqHandler.setParameter("body", "物管费"); //商品描述 reqHandler.setParameter("attach", CommunityId); //附加信息 reqHandler.setParameter("total_fee", "1"); //总金额 reqHandler.setParameter("mch_create_ip", "125.64.16.10"); //终端IP reqHandler.setParameter("time_start", ""); //订单生成时间 reqHandler.setParameter("time_expire", ""); //订单超时时间 reqHandler.setParameter("service", "pay.weixin.jspay"); //接口类型:pay.weixin.jspay reqHandler.setParameter("mch_id", "7551000001"); //必填项,商户号,由平台分配 reqHandler.setParameter("version", "1.0"); //接口版本号 reqHandler.setParameter("notify_url", "http://125.64.16.10:9999/TwInterface/Service/WeiXinPayCallBack/WeiXinWftPay.ashx"); //通知地址,必填项,接收平台通知的URL,需给绝对路径,255字符内;此URL要保证外网能访问 reqHandler.setParameter("nonce_str", Utils.random()); //随机字符串,必填项,不长于 32 位 reqHandler.setParameter("charset", "UTF-8"); //字符集 reqHandler.setParameter("sign_type", "MD5"); //签名方式 reqHandler.setParameter("is_raw", "1"); //原生JS值 reqHandler.setParameter("device_info", ""); //终端设备号 reqHandler.setParameter("sub_openid", ""); //测试账号不传值,此处默认给空值。正式账号必须传openid值,获取openid值指导文档地址:http://www.cnblogs.com/txw1958/p/weixin76-user-info.html reqHandler.setParameter("callback_url", ""); //前台地址 交易完成后跳转的 URL,需给绝对路径,255字 符 内 格 式如:http://wap.tenpay.com/callback.asp reqHandler.setParameter("goods_tag", ""); //商品标记 reqHandler.createSign(); //创建签名 //以上参数进行签名 string data = Utils.toXml(reqHandler.getAllParameters()); //生成XML报文 Dictionary <string, string> reqContent = new Dictionary <string, string>(); reqContent.Add("url", reqHandler.getGateUrl()); reqContent.Add("data", data); PayHttpClient pay = new PayHttpClient(); pay.setReqContent(reqContent); if (!pay.call()) { return(JSONHelper.FromString(false, pay.getErrInfo())); } ClientResponseHandler resHandler = new ClientResponseHandler(); resHandler.setContent(pay.getResContent()); resHandler.setKey("9d101c97133837e13dde2d32a5054abb"); Hashtable param = resHandler.getAllParameters(); if (!resHandler.isTenpaySign()) { return(JSONHelper.FromString(false, param["message"].ToString())); } //当返回状态与业务结果都为0时才返回,其它结果请查看接口文档 if (int.Parse(param["status"].ToString()) != 0 || int.Parse(param["result_code"].ToString()) != 0) { return(JSONHelper.FromString(false, param["err_msg"].ToString())); } return(JSONHelper.FromJsonString(true, param["pay_info"].ToString())); }
/// <summary> /// 客服动态 /// </summary> /// <returns></returns> public string GetIncidentDynamic(DataRow row) { #region int iCommID = 0; if (row.Table.Columns.Contains("CommID")) { iCommID = AppGlobal.StrToInt(row["CommID"].ToString()); } string userCode = Global_Var.LoginUserCode; if (row.Table.Columns.Contains("UserCode")) { userCode = row["UserCode"].ToString(); } string organCode = null; string strCommName = AppGlobal.GetCommName(iCommID); string strOrganName = ""; //未分派的报事 int NoDispIncidentNum = 0; //未完结的协调单 int NoCoordinateIncidentNum = 0; //逾期的协调单 int BeOverdueIncidentNum = 0; string strDate = ""; string strReText = ""; int iIncidentNum1 = 0; int iIncidentNum2 = 0; int iIncidentNum3 = 0; int iIncidentNum4 = 0; int iIncidentNum5 = 0; decimal iIncidentRate1 = 0; decimal iIncidentRate2 = 0; decimal iIncidentRate3 = 0; decimal iIncidentRate4 = 0; #endregion string strSQL = ""; int temp = 3; // 项目客服动态 if (iCommID != 0) { strSQL = " and CommID = " + iCommID.ToString() + " and datediff(day,StatDate,getdate()) = 1 and StatType = 1 "; } else { if (row.Table.Columns.Contains("OrganCode")) { organCode = row["OrganCode"].ToString(); } if (string.IsNullOrEmpty(organCode)) { organCode = "01"; } strOrganName = AppGlobal.GetOrganName4(organCode); // 分公司 if (organCode.Length == 4) { temp = 2; strSQL = " and OrganCode like '" + organCode + "%' and datediff(day,StatDate,getdate()) = 1 and StatType = 2 "; } // 总公司 if (organCode.Length == 2) { temp = 1; strSQL = " and datediff(day,StatDate,getdate()) = 1 and StatType = 3 "; } } MobileSoft.BLL.Sys.Bll_Tb_Sys_TakePic Bll = new MobileSoft.BLL.Sys.Bll_Tb_Sys_TakePic(); DataTable dTable = Bll.GetListFromProc(strSQL).Tables[0]; if (dTable.Rows.Count > 0) { DataRow DRow = dTable.Rows[0]; NoDispIncidentNum = AppGlobal.StrToInt(DRow["NoDispIncidentNum"].ToString()); NoCoordinateIncidentNum = AppGlobal.StrToInt(DRow["NoCoordinateIncidentNum"].ToString()); BeOverdueIncidentNum = AppGlobal.StrToInt(DRow["BeOverdueIncidentNum"].ToString()); iIncidentNum1 = AppGlobal.StrToInt(DRow["IncidentNum1"].ToString()); iIncidentNum2 = AppGlobal.StrToInt(DRow["IncidentNum2"].ToString()); iIncidentNum3 = AppGlobal.StrToInt(DRow["IncidentNum3"].ToString()); iIncidentNum4 = AppGlobal.StrToInt(DRow["IncidentNum4"].ToString()); iIncidentNum5 = AppGlobal.StrToInt(DRow["IncidentNum5"].ToString()); iIncidentRate1 = AppGlobal.StrToDec(DRow["IncidentRate1"].ToString()); iIncidentRate2 = AppGlobal.StrToDec(DRow["IncidentRate2"].ToString()); iIncidentRate3 = AppGlobal.StrToDec(DRow["IncidentRate3"].ToString()); iIncidentRate4 = AppGlobal.StrToDec(DRow["IncidentRate4"].ToString()); strDate = AppGlobal.StrToDate(DRow["StatDate"].ToString()).ToString("yyyy年MM月dd日"); } dTable.Dispose(); if (string.IsNullOrEmpty(strDate)) { strDate = DateTime.Now.ToString("yyyy年MM月dd日"); } // 读取报时预警信息 MobileSoft.BLL.HSPR.Bll_Tb_HSPR_TempIncidentWarning Bll3 = new MobileSoft.BLL.HSPR.Bll_Tb_HSPR_TempIncidentWarning(); DataTable dTable3 = Bll3.GetList(userCode, iCommID).Tables[0]; string value1 = ""; string value2 = ""; string value3 = ""; if (dTable3.Rows.Count > 0) { DataRow DRow = dTable3.Rows[0]; value1 = DRow[0].ToString(); value2 = DRow[1].ToString(); value3 = DRow[2].ToString(); } switch (temp) { case 3: strReText = string.Format(@"【{0}】<br/>1、截止到{1},未分派报事{2}件,未完结的派工单{3}件(其中逾期{4}件),未完结的协调单{5}件(其中逾期{6}件);本月派工单完结率{7}%,本年累计{8}%;本月协调单完结率{9}%,本年累计{10}%。<br/>2、{11},共有{12}件报事,其中{13}件未完结。<br/>3、超时预警:已受理未分派超时工单{14}件,已分派未处理超时工单{15}件,已处理未回访超时工单{16}件;", strCommName, strDate, NoDispIncidentNum.ToString(), iIncidentNum1.ToString(), iIncidentNum2.ToString(), NoCoordinateIncidentNum.ToString(), BeOverdueIncidentNum.ToString(), iIncidentRate1.ToString("N2"), iIncidentRate2.ToString("N2"), iIncidentRate3.ToString("N2"), iIncidentRate4.ToString("N2"), strDate, iIncidentNum4.ToString(), iIncidentNum5.ToString(), value1, value2, value3); break; case 2: case 1: strReText = string.Format(@"【{0}】<br/>1、截止到{1},未分派报事{2}件,未完结的派工单{3}件(其中逾期{4}件),未完结的协调单{5}件(其中逾期{6}件);本月派工单完结率{7}%,本年累计{8}%;本月协调单完结率{9}%,本年累计{10}%。<br/>2、{11},共有{12}件报事,其中{13}件未完结。<br/>3、超时预警:已受理未分派超时工单{14}件,已分派未处理超时工单{15}件,已处理未回访超时工单{16}件;", strOrganName, strDate, NoDispIncidentNum.ToString(), iIncidentNum1.ToString(), iIncidentNum2.ToString(), NoCoordinateIncidentNum.ToString(), BeOverdueIncidentNum.ToString(), iIncidentRate1.ToString("N2"), iIncidentRate2.ToString("N2"), iIncidentRate3.ToString("N2"), iIncidentRate4.ToString("N2"), strDate, iIncidentNum4.ToString(), iIncidentNum5.ToString(), value1, value2, value3); break; } // 客服动态图表统计 MobileSoft.BLL.Sys.Bll_Tb_Sys_TakePicIncidentTypeDeskTop Bll2 = new MobileSoft.BLL.Sys.Bll_Tb_Sys_TakePicIncidentTypeDeskTop(); DataTable dTable2 = Bll2.GetList(organCode, iCommID).Tables[0]; string chart = JSONHelper.FromDataTable(dTable2); return(JSONHelper.FromJsonString(true, "{\"Info\":\"" + strReText + "\", \"Chart\":" + chart + "}")); }
/// <summary> /// 生成银行及物业订单 /// </summary> /// <param name="Row"></param> /// <returns></returns> public string GenerateOrder(DataRow Row) { bool IsBankOk = false; bool IsPropertyOk = false; string PropertyOrderId = ""; string prepay_str = ""; string CommunityId = Row["CommunityId"].ToString(); string CostID = Row["CostID"].ToString(); string RoomID = Row["RoomID"].ToString(); if (!Row.Table.Columns.Contains("HandID") || !long.TryParse(Row["HandID"].ToString(), out long HandID)) { HandID = 0; } string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string CustID = Row["CustID"].ToString(); string Amount = Row["Amount"].ToString(); float tmpAmount = 0; if (float.TryParse(Amount, out tmpAmount) == false) { return(JSONHelper.FromString(false, "金额错误")); } bool IsConfig = GenerateConfig(CommunityId); if (IsConfig == false) { return(JSONHelper.FromString(false, "未配置证书文件")); } string erpConnStr = GetConnection(CommunityId); PubConstant.hmWyglConnectionString = erpConnStr; //生成物业账单 string PropertyResult = GeneratePropertyOrder(CommunityId, CostID, RoomID, txnTime, CustID, ref IsPropertyOk, ref Amount, ref PropertyOrderId); if (IsPropertyOk == true) { #region 物业订单创建成功就保存车位ID if (HandID != 0) { if (!Tb_OL_ParkCar_Insert(erpConnStr, PropertyOrderId, HandID)) { return(JSONHelper.FromString(false, "保存车位预存明细失败")); } } #endregion //返回签名的订单信息 string BankResult = GenerateBankOrder(CommunityId, CustID, RoomID, PropertyOrderId, txnTime, Amount, ref IsBankOk, ref prepay_str); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { //更新订单银行流水号 IDbConnection Conn = new SqlConnection(erpConnStr); string Query = "UPDATE Tb_OL_AlipayOrder SET prepay_str=@prepay_str WHERE out_trade_no = @out_trade_no "; Conn.Execute(Query, new { prepay_str = prepay_str.ToString(), out_trade_no = PropertyOrderId }); //返回请求字符串 return(JSONHelper.FromJsonString(true, prepay_str)); } } else { return(JSONHelper.FromString(false, PropertyResult)); } }
/// <summary> /// 生成银行及物业订单 /// </summary> /// <param name="Row"></param> /// <returns></returns> public string GenerateOrder(DataRow Row) { bool IsBankOk = false; bool IsPropertyOk = false; string PropertyOrderId = ""; string BankOrderId = ""; string CommunityId = Row["CommunityId"].ToString(); string CostID = Row["CostID"].ToString(); string RoomID = Row["RoomID"].ToString(); if (!Row.Table.Columns.Contains("HandID") || !long.TryParse(Row["HandID"].ToString(), out long HandID)) { HandID = 0; } string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string CustID = Row["CustID"].ToString(); string Amount = Row["Amount"].ToString(); //2017-06-05添加可选参数openId //用于区分是否来自于微信H5支付 //默认为空 string openId = Row.Table.Columns.Contains("openId") ? Row["openId"].ToString() : ""; WxPayConfig wxPayConfig = GenerateConfig(CommunityId); if (null == wxPayConfig) { return(JSONHelper.FromString(false, "未配置证书文件")); } string erpConnStr = GetConnection(CommunityId); PubConstant.hmWyglConnectionString = erpConnStr; //生成物业账单 string PropertyResult = GeneratePropertyOrder(CommunityId, CostID, RoomID, txnTime, CustID, ref IsPropertyOk, ref Amount, ref PropertyOrderId, wxPayConfig); if (IsPropertyOk == true) { #region 物业订单创建成功就保存车位ID if (HandID != 0) { if (!Tb_OL_ParkCar_Insert(erpConnStr, PropertyOrderId, HandID)) { return(JSONHelper.FromString(false, "保存车位预存明细失败")); } } #endregion //生成银行订单,返回银行流水号 WxPayData Data = new WxPayData(); string BankResult = GenerateBankOrder(CommunityId, CustID, RoomID, PropertyOrderId, txnTime, Amount, ref IsBankOk, ref BankOrderId, ref Data, wxPayConfig, openId); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { //更新订单银行流水号 IDbConnection Conn = new SqlConnection(GetConnection(CommunityId)); string Query = "UPDATE Tb_OL_WeiXinPayOrder SET prepay_id=@prepay_id WHERE out_trade_no = @out_trade_no "; Conn.Execute(Query, new { prepay_id = Data.GetValue("prepay_id").ToString(), out_trade_no = PropertyOrderId }); //向手机端返回银行记录 WxPayData result = new WxPayData(); result.SetValue("appid", Data.GetValue("appid")); result.SetValue("partnerid", Data.GetValue("mch_id")); result.SetValue("prepayid", Data.GetValue("prepay_id")); result.SetValue("noncestr", Data.GetValue("nonce_str")); result.SetValue("package", "Sign=WXPay"); result.SetValue("timestamp", (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); result.SetValue("sign", result.MakeSign()); result.SetValue("out_trade_no", PropertyOrderId); return(JSONHelper.FromJsonString(true, result.ToJson())); } } else { return(JSONHelper.FromString(false, PropertyResult)); } }
/// <summary> /// /// </summary> /// <param name="Ds"></param> /// <returns></returns> public string GenerateOrder(DataSet Ds) { DataRow Row = Ds.Tables[0].Rows[0]; bool IsBankOk = false; bool IsBusinessOk = false; string OrderId = ""; string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string UserId = Row["UserId"].ToString(); string BussId = Row["BussId"].ToString(); WxPayConfig wxPayConfig = GenerateConfig(BussId); if (null == wxPayConfig) { return(JSONHelper.FromString(false, "未配置证书文件")); } string Name = Row["Name"].ToString(); string Mobile = Row["Mobile"].ToString(); string DeliverAddress = Row["DeliverAddress"].ToString(); string subject = ""; int Amount = 0; int CouponAmount = 0; // 俊发需求5896 string communityId = null; if (Row.Table.Columns.Contains("CommunityId") && !string.IsNullOrEmpty(Row["CommunityId"].ToString())) { communityId = Row["CommunityId"].ToString(); } //生成商家账单 string BussinessResult = GenerateBusinessOrder(Ds, communityId, BussId, UserId, txnTime, ref IsBusinessOk, ref Amount, ref CouponAmount, ref OrderId, Name, Mobile, DeliverAddress, wxPayConfig); if (IsBusinessOk == true) { using (IDbConnection Conn = new SqlConnection(ConnectionDb.GetBusinessConnection())) { Tb_System_BusinessCorp bussInfo = Conn.Query <Tb_System_BusinessCorp>(@"SELECT * FROM Tb_System_BusinessCorp WHERE BussId=@BussId", new { BussId = BussId }).FirstOrDefault(); if (bussInfo != null) { subject = bussInfo.BussName + "订单,共" + Ds.Tables["Product"].Rows.Count + "种商品"; } } //生成银行订单,返回银行流水号 WxPayData Data = new WxPayData(); string BankResult = GenerateBankOrder(BussId, OrderId, txnTime, (Amount - CouponAmount), ref IsBankOk, ref Data, wxPayConfig); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { using (IDbConnection conn = new SqlConnection(ConnectionDb.GetBusinessConnection())) { string sql; if ((Amount - CouponAmount) == 0) { sql = string.Format(@"UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str,Method='微信',IsPay='已付款',ReturnCode='TRADE_FINISHED',ReturnMsg='TRADE_FINISHED',PayDate=GetDate(),Amount={0:###.##},CouponAmount={1:###.##},RealAmount=0 WHERE OrderId = @OrderId", Amount / 100, CouponAmount / 100); } else { sql = @"UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str WHERE OrderId = @OrderId"; } conn.Execute(sql, new { prepay_str = Data.GetValue("prepay_id").ToString(), OrderId = OrderId }); } //向手机端返回银行记录 WxPayData result = new WxPayData(); result.SetValue("appid", Data.GetValue("appid")); result.SetValue("partnerid", Data.GetValue("mch_id")); result.SetValue("prepayid", Data.GetValue("prepay_id")); result.SetValue("noncestr", Data.GetValue("nonce_str")); result.SetValue("package", "Sign=WXPay"); result.SetValue("timestamp", (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); result.SetValue("sign", result.MakeSign()); // 上面的顺序不允许变动 result.SetValue("total_fee", Amount); return(JSONHelper.FromJsonString(true, result.ToJson())); } } else { return(JSONHelper.FromString(false, BussinessResult)); } }
/// <summary> /// 订单继续支付 /// </summary> public string GoOnGenerateOrder(DataSet Ds) { DataRow Row = Ds.Tables[0].Rows[0]; bool IsBankOk = false; bool IsBusinessOk = true;//商家订单是否生成成功 string OrderId = Row["OrderId"].ToString(); string prepay_str = ""; //取得上一次商家订单信息 IDbConnection ConnOrder = new SqlConnection(ConnectionDb.GetBusinessConnection()); string OrderQuery = "SELECT * FROM Tb_Charge_Receipt WHERE OrderId=@OrderId"; Model.Model.Buss.Tb_Charge_Receipt TOrder = ConnOrder.Query <Model.Model.Buss.Tb_Charge_Receipt>(OrderQuery, new { OrderId = OrderId }).SingleOrDefault(); if (TOrder != null) { IsBusinessOk = true; } string txnTime = TOrder.txnTime.ToString(); string BussId = TOrder.BussId.ToString(); WxPayConfig wxPayConfig = GenerateConfig(BussId); if (null == wxPayConfig) { return(JSONHelper.FromString(false, "未配置证书文件")); } decimal realAmount = 0.0m; string sql = @"SELECT * FROM Tb_Charge_ReceiptDetail WHERE ReceiptCode=@ReceiptCode"; IEnumerable <Tb_Charge_ReceiptDetail> ReceiptDetails = ConnOrder.Query <Tb_Charge_ReceiptDetail>(sql, new { ReceiptCode = TOrder.Id }); foreach (Tb_Charge_ReceiptDetail item in ReceiptDetails) { // 计算此时应该多少钱 sql = @"SELECT * FROM Tb_Resources_Details WHERE ResourcesID=@ResourcesID"; Tb_Resources_Details resources = ConnOrder.Query <Tb_Resources_Details>(sql, new { ResourcesID = item.ResourcesID }).FirstOrDefault(); if (resources != null) { if (resources.IsGroupBuy == "是" && resources.GroupBuyEndDate.HasValue && resources.GroupBuyEndDate.Value > DateTime.Now) { realAmount += (resources.GroupBuyPrice.Value + item.Quantity); } else { realAmount += (resources.ResourcesSalePrice - resources.ResourcesDisCountPrice) * item.Quantity; } if (item.OffsetMoney.HasValue) { realAmount -= item.OffsetMoney.Value; } if (item.OffsetMoney2.HasValue) { realAmount -= item.OffsetMoney2.Value; } } } if (IsBusinessOk == true) { sql = "SELECT * FROM Tb_System_BusinessCorp WHERE BussId=@BussId"; Tb_System_BusinessCorp bussInfo = ConnOrder.Query <Tb_System_BusinessCorp>(sql, new { BussId = TOrder.BussId }).FirstOrDefault(); //生成银行订单,返回银行流水号 WxPayData Data = new WxPayData(); string BankResult = GenerateBankOrder(BussId, OrderId, txnTime, (int)(realAmount * 100), ref IsBankOk, ref Data, wxPayConfig); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { //更新订单银行流水号 IDbConnection Conn = new SqlConnection(ConnectionDb.GetBusinessConnection()); string Query = "UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str WHERE OrderId = @OrderId "; Conn.Execute(Query, new { prepay_str = prepay_str.ToString(), OrderId = OrderId }); //返回请求字符串 //向手机端返回银行记录 WxPayData result = new WxPayData(); result.SetValue("appid", Data.GetValue("appid")); result.SetValue("partnerid", Data.GetValue("mch_id")); result.SetValue("prepayid", Data.GetValue("prepay_id")); result.SetValue("noncestr", Data.GetValue("nonce_str")); result.SetValue("package", "Sign=WXPay"); result.SetValue("timestamp", (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); result.SetValue("sign", result.MakeSign()); return(JSONHelper.FromJsonString(true, result.ToJson())); } } return(JSONHelper.FromString(false, "生成订单失败")); }
/// <summary> /// 订单继续支付 /// </summary> public string GoOnGenerateOrder(DataSet Ds) { DataRow Row = Ds.Tables[0].Rows[0]; bool IsBankOk = false; bool IsBusinessOk = true;//商家订单是否生成成功 string OrderId = Row["OrderId"].ToString(); string prepay_str = ""; //取得上一次商家订单信息 IDbConnection ConnOrder = new SqlConnection(ConnectionDb.GetBusinessConnection()); string OrderQuery = "SELECT * FROM Tb_Charge_Receipt WHERE OrderId=@OrderId"; Model.Model.Buss.Tb_Charge_Receipt TOrder = ConnOrder.Query <Model.Model.Buss.Tb_Charge_Receipt>(OrderQuery, new { OrderId = OrderId }).SingleOrDefault(); if (TOrder != null) { IsBusinessOk = true; } string txnTime = TOrder.txnTime.ToString(); string BussId = TOrder.BussId.ToString(); bool IsConfig = GenerateConfig(BussId); if (IsConfig == false) { return(JSONHelper.FromString(false, "未配置证书文件")); } decimal realAmount = 0.0m; string sql = @"SELECT * FROM Tb_Charge_ReceiptDetail WHERE ReceiptCode=@ReceiptCode"; IEnumerable <Tb_Charge_ReceiptDetail> ReceiptDetails = ConnOrder.Query <Tb_Charge_ReceiptDetail>(sql, new { ReceiptCode = TOrder.Id }); foreach (Tb_Charge_ReceiptDetail item in ReceiptDetails) { // 计算此时应该多少钱 sql = @"SELECT * FROM Tb_Resources_Details WHERE ResourcesID=@ResourcesID"; Tb_Resources_Details resources = ConnOrder.Query <Tb_Resources_Details>(sql, new { ResourcesID = item.ResourcesID }).FirstOrDefault(); if (resources != null) { if (resources.IsGroupBuy == "是" && resources.GroupBuyEndDate.HasValue && resources.GroupBuyEndDate.Value > DateTime.Now) { realAmount += (resources.GroupBuyPrice.Value + item.Quantity); } else { realAmount += (resources.ResourcesSalePrice - resources.ResourcesDisCountPrice) * item.Quantity; } if (item.OffsetMoney.HasValue) { realAmount -= item.OffsetMoney.Value; } if (item.OffsetMoney2.HasValue) { realAmount -= item.OffsetMoney2.Value; } } } if (IsBusinessOk == true) { sql = "SELECT * FROM Tb_System_BusinessCorp WHERE BussId=@BussId"; Tb_System_BusinessCorp bussInfo = ConnOrder.Query <Tb_System_BusinessCorp>(sql, new { BussId = TOrder.BussId }).FirstOrDefault(); //生成预支付单,并返回订单ID string BankResult = GenerateBankOrder(BussId, OrderId, txnTime, realAmount, ref IsBankOk, ref prepay_str, bussInfo.BussName + "订单,共" + ReceiptDetails.Count() + "种商品"); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { //更新订单银行流水号 IDbConnection Conn = new SqlConnection(ConnectionDb.GetBusinessConnection()); string Query = "UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str WHERE OrderId = @OrderId "; Conn.Execute(Query, new { prepay_str = prepay_str.ToString(), OrderId = OrderId }); //返回请求字符串 return(JSONHelper.FromJsonString(true, prepay_str)); } } return(JSONHelper.FromString(false, "生成订单失败")); }
/// <summary> /// /// </summary> /// <param name="Ds"></param> /// <returns></returns> public string GenerateOrder(DataSet Ds) { DataRow Row = Ds.Tables[0].Rows[0]; bool IsBankOk = false; bool IsBusinessOk = false; string OrderId = ""; string prepay_str = ""; string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string BussId = Row["BussId"].ToString(); string UserId = Row["UserId"].ToString(); bool IsConfig = GenerateConfig(BussId); if (IsConfig == false) { return(JSONHelper.FromString(false, "未配置证书文件")); } string Name = Row["Name"].ToString(); string Mobile = Row["Mobile"].ToString(); string DeliverAddress = Row["DeliverAddress"].ToString(); string subject = ""; decimal Amount = 0.0m; decimal CouponAmount = 0.0m; // 俊发需求5896 string communityId = null; if (Row.Table.Columns.Contains("CommunityId") && !string.IsNullOrEmpty(Row["CommunityId"].ToString())) { communityId = Row["CommunityId"].ToString(); } //生成商家账单 string BussinessResult = GenerateBusinessOrder(Ds, communityId, BussId, UserId, txnTime, ref IsBusinessOk, ref Amount, ref CouponAmount, ref OrderId, Name, Mobile, DeliverAddress); if (IsBusinessOk == true) { using (IDbConnection Conn = new SqlConnection(ConnectionDb.GetBusinessConnection())) { Tb_System_BusinessCorp bussInfo = Conn.Query <Tb_System_BusinessCorp>(@"SELECT * FROM Tb_System_BusinessCorp WHERE BussId=@BussId", new { BussId = BussId }).FirstOrDefault(); if (bussInfo != null) { subject = bussInfo.BussName + "订单,共" + Ds.Tables["Product"].Rows.Count + "种商品"; } } //生成预支付单,并返回订单ID string BankResult = GenerateBankOrder(BussId, OrderId, txnTime, (Amount - CouponAmount), ref IsBankOk, ref prepay_str, subject); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { using (IDbConnection conn = new SqlConnection(ConnectionDb.GetBusinessConnection())) { string sql; if ((Amount - CouponAmount) == 0) { sql = string.Format(@"UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str,Method='支付宝',IsPay='已付款',ReturnCode='TRADE_FINISHED',ReturnMsg='TRADE_FINISHED',PayDate=GetDate(),Amount={0},CouponAmount={1},RealAmount=0 WHERE OrderId = @OrderId", Amount, CouponAmount); } else { sql = @"UPDATE Tb_Charge_Receipt SET PrepayStr=@prepay_str WHERE OrderId = @OrderId"; } conn.Execute(sql, new { prepay_str = prepay_str.ToString(), OrderId = OrderId }); } //返回请求字符串 return(JSONHelper.FromJsonString(true, prepay_str)); } } else { return(JSONHelper.FromString(false, BussinessResult)); } }
/// <summary> /// 生成银行及物业订单 /// </summary> /// <param name="Row"></param> /// <returns></returns> public string GenerateOrder(DataRow Row) { bool IsBankOk = false; bool IsPropertyOk = false; string PropertyOrderId = ""; string BankOrderId = ""; string CommunityId = Row["CommunityId"].ToString(); string CostID = Row["CostID"].ToString(); string StanID = Row["StanID"].ToString(); string HandID = Row["HandID"].ToString(); string RoomID = Row["RoomID"].ToString(); string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string CustID = Row["CustID"].ToString(); string UserID = Row["UserID"].ToString(); int Months = AppGlobal.StrToInt(Row["Months"].ToString()); if (Months == 0) { return(JSONHelper.FromString(false, "请选择预存月数")); } //2017-06-05添加可选参数openId //用于区分是否来自于微信H5支付 //默认为空 string openId = Row.Table.Columns.Contains("openId") ? Row["openId"].ToString() : ""; WxPayConfig wxPayConfig = GenerateConfig(CommunityId); if (null == wxPayConfig) { return(JSONHelper.FromString(false, "未配置证书文件")); } PubConstant.hmWyglConnectionString = GetConnection(CommunityId); Global_Var.CorpSQLConnstr = PubConstant.hmWyglConnectionString; string Amount = "0"; //生成物业账单 string PropertyResult = GeneratePropertyOrder(CommunityId, CostID, StanID, HandID, RoomID, txnTime, CustID, Months, ref IsPropertyOk, ref Amount, ref PropertyOrderId, wxPayConfig); if (IsPropertyOk == true) { //生成银行订单,返回银行流水号 WxPayData Data = new WxPayData(); string BankResult = GenerateBankOrder(CommunityId, CustID, RoomID, UserID, Months, PropertyOrderId, txnTime, Amount, ref IsBankOk, ref BankOrderId, ref Data, wxPayConfig, openId); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { //更新订单银行流水号 IDbConnection Conn = new SqlConnection(PubConstant.hmWyglConnectionString); string Query = "UPDATE Tb_OL_WeiXinPayOrder SET prepay_id=@prepay_id WHERE out_trade_no = @out_trade_no "; Conn.Execute(Query, new { prepay_id = Data.GetValue("prepay_id").ToString(), out_trade_no = PropertyOrderId }); //向手机端返回银行记录 WxPayData result = new WxPayData(); result.SetValue("appid", Data.GetValue("appid")); result.SetValue("partnerid", Data.GetValue("mch_id")); result.SetValue("prepayid", Data.GetValue("prepay_id")); result.SetValue("noncestr", Data.GetValue("nonce_str")); result.SetValue("package", "Sign=WXPay"); result.SetValue("timestamp", (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000); result.SetValue("sign", result.MakeSign()); int presentedPoint = new AppPoint().CalcPresentedPointForPrec_lf(Months); result.SetValue("presented_points", presentedPoint); result.SetValue("out_trade_no", PropertyOrderId); return(JSONHelper.FromJsonString(true, result.ToJson())); } } else { return(JSONHelper.FromString(false, PropertyResult)); } }
/// <summary> /// 生成银行及物业订单 /// </summary> /// <param name="Row"></param> /// <returns></returns> public string GenerateOrder(DataRow Row) { bool IsBankOk = false; bool IsPropertyOk = false; string PropertyOrderId = ""; string prepay_str = ""; string CommunityId = Row["CommunityId"].ToString(); string FeesIds = Row["FeesIds"].ToString(); string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string CustID = ""; if (Row.Table.Columns.Contains("CustID")) { CustID = Row["CustID"].ToString().Trim(); } if (Row.Table.Columns.Contains("RoomID")) { CustID = GetCustID(Row["RoomID"].ToString().Trim()); } //string CustID = Row["CustID"].ToString().Trim(); //string CustID = GetCustID(Row["RoomID"].ToString().Trim()); string Memo = Row["Memo"].ToString(); //获取配置信息 bool IsConfig = GenerateConfig(CommunityId); string Amount = "0"; if (IsConfig == false) { return(JSONHelper.FromString(false, "未配置证书文件")); } string[] feesArr = FeesIds.Split(','); if (feesArr.Length > 100) { return(JSONHelper.FromString(false, "单次缴费科目不能超过100条,请重新选择")); } //生成物业账单 string PropertyResult = GeneratePropertyOrder(CommunityId, FeesIds, txnTime, CustID, Memo, ref IsPropertyOk, ref Amount, ref PropertyOrderId); if (IsPropertyOk == true) { //返回签名的订单信息 string BankResult = GenerateBankOrder(CommunityId, PropertyOrderId, txnTime, Amount, ref IsBankOk, ref prepay_str); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { //构建链接字符串 string strcon = PubConstant.GetConnectionString("APPConnection"); //更新订单银行流水号 IDbConnection Conn = new SqlConnection(strcon); string Query = "UPDATE Tb_OL_AlipayOrder SET prepay_str=@prepay_str WHERE out_trade_no = @out_trade_no "; Conn.Execute(Query, new { prepay_str = prepay_str.ToString(), out_trade_no = PropertyOrderId }); //返回请求字符串 return(JSONHelper.FromJsonString(true, prepay_str)); } } else { return(JSONHelper.FromString(false, PropertyResult)); } }
/// <summary> /// 生成银行及物业订单 /// </summary> /// <param name="Row"></param> /// <returns></returns> public string GenerateOrder(DataRow Row) { bool IsBankOk = false; bool IsPropertyOk = false; string PropertyOrderId = ""; string prepay_str = ""; string CommunityId = Row["CommunityId"].ToString(); string CostID = Row["CostID"].ToString(); string StanID = Row["StanID"].ToString(); string HandID = Row["HandID"].ToString(); string RoomID = Row["RoomID"].ToString(); string txnTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string CustID = Row["CustID"].ToString(); string UserID = Row["UserID"].ToString(); int Months = AppGlobal.StrToInt(Row["Months"].ToString()); if (Months == 0) { return(JSONHelper.FromString(false, "请选择预存月数")); } bool IsConfig = GenerateConfig(CommunityId); if (IsConfig == false) { return(JSONHelper.FromString(false, "未配置证书文件")); } PubConstant.hmWyglConnectionString = GetConnection(CommunityId); Global_Var.CorpSQLConnstr = PubConstant.hmWyglConnectionString; string Amount = "0"; //生成物业账单 string PropertyResult = GeneratePropertyOrder(CommunityId, CostID, StanID, HandID, RoomID, txnTime, CustID, Months, ref IsPropertyOk, ref Amount, ref PropertyOrderId); if (IsPropertyOk == true) { //返回签名的订单信息 string BankResult = GenerateBankOrder(CommunityId, CustID, RoomID, UserID, Months, PropertyOrderId, txnTime, Amount, ref IsBankOk, ref prepay_str); if (IsBankOk == false) { return(JSONHelper.FromString(false, BankResult)); } else { int presentedPoint = new AppPoint().CalcPresentedPointForPrec_lf(Months); prepay_str = prepay_str.Insert(prepay_str.Length - 1, ",\"presented_points\":" + presentedPoint + ""); //更新订单银行流水号 IDbConnection Conn = new SqlConnection(PubConstant.hmWyglConnectionString); string Query = "UPDATE Tb_OL_AlipayOrder SET prepay_str=@prepay_str WHERE out_trade_no = @out_trade_no "; Conn.Execute(Query, new { prepay_str = prepay_str.ToString(), out_trade_no = PropertyOrderId }); //返回请求字符串 return(JSONHelper.FromJsonString(true, prepay_str)); } } else { return(JSONHelper.FromString(false, PropertyResult)); } }