|
@@ -76,10 +76,10 @@ public class OrdersPayService
|
|
|
|
|
|
function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-6", "支付时间监控");
|
|
|
//通过Code获取OpenId
|
|
|
- string openid = OpenId(Code, PayMode);
|
|
|
+ string openid = GetOpenIdByCodeAndPayMode(Code, PayMode);
|
|
|
function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-7", "支付时间监控");
|
|
|
-
|
|
|
- int ConsumerId = 0;
|
|
|
+ //通过OpenId获取ConsumerId
|
|
|
+ int ConsumerId = GetConsumerIdByOpenId(openid);
|
|
|
|
|
|
string OrderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
|
|
|
bool ActFlag = merchantset.IsAll == 1 ? false : true;
|
|
@@ -87,6 +87,7 @@ public class OrdersPayService
|
|
|
{
|
|
|
ActFlag = false;
|
|
|
}
|
|
|
+
|
|
|
ConsumerOrders order = maindb.ConsumerOrders.Add(new ConsumerOrders()
|
|
|
{
|
|
|
// Id = PublicFunction.MakeConsumerOrderId(),
|
|
@@ -104,12 +105,14 @@ public class OrdersPayService
|
|
|
SeoDescription = Newtonsoft.Json.JsonConvert.SerializeObject(merchantset),
|
|
|
}).Entity;
|
|
|
maindb.SaveChanges();
|
|
|
+
|
|
|
maindb.ConsumerOrderForNo.Add(new ConsumerOrderForNo()
|
|
|
{
|
|
|
OrderNo = OrderNo,
|
|
|
OrderIds = order.Id,
|
|
|
});
|
|
|
maindb.SaveChanges();
|
|
|
+
|
|
|
if (PayMode == 1)
|
|
|
{
|
|
|
string backString = new AlipayFunction().CreateTrade(OrderNo, merchant.Name, PayMoney, openid, merchantAdd.AlipayAuthToken, ConfigurationManager.AppSettings["SpHost"].ToString() + "/api/alipay/notice");
|
|
@@ -160,14 +163,14 @@ public class OrdersPayService
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
- #region 通过Code获取OpenId
|
|
|
+ #region 通过Code和支付方式获取OpenId
|
|
|
/// <summary>
|
|
|
/// 通过Code获取OpenId
|
|
|
/// </summary>
|
|
|
- /// <param name="Code"></param>
|
|
|
- /// <param name="PayMode"></param>
|
|
|
+ /// <param name="Code">消费者编码</param>
|
|
|
+ /// <param name="PayMode">支付方式(1 支付宝 2 微信)</param>
|
|
|
/// <returns></returns>
|
|
|
- public string OpenId(string Code, int PayMode)
|
|
|
+ public string GetOpenIdByCodeAndPayMode(string Code, int PayMode)
|
|
|
{
|
|
|
var OpenId = "";
|
|
|
if (PayMode == 1)
|
|
@@ -194,15 +197,16 @@ public class OrdersPayService
|
|
|
/// <summary>
|
|
|
/// 通过OpenId获取ConsumerId
|
|
|
/// </summary>
|
|
|
- /// <param name="OpenId"></param>
|
|
|
+ /// <param name="OpenId">消费者唯一标识</param>
|
|
|
/// <returns></returns>
|
|
|
- public string OpenId(string OpenId)
|
|
|
+ public int GetConsumerIdByOpenId(string OpenId)
|
|
|
{
|
|
|
WebCMSEntities maindb = new WebCMSEntities();
|
|
|
var ConsumerId = 0;
|
|
|
- ConsumerOpenIds check = maindb.ConsumerOpenIds.FirstOrDefault(m => m.OpenId == openid);
|
|
|
+ Consumers check = maindb.Consumers.FirstOrDefault(m => m.WechatOpenId == OpenId);
|
|
|
if (check == null)
|
|
|
{
|
|
|
+ // ConsumerId = PublicFunction.MakeConsumerId();
|
|
|
Consumers consumer = maindb.Consumers.Add(new Consumers()
|
|
|
{
|
|
|
Id = ConsumerId,
|
|
@@ -211,18 +215,13 @@ public class OrdersPayService
|
|
|
}).Entity;
|
|
|
maindb.SaveChanges();
|
|
|
ConsumerId = consumer.Id;
|
|
|
- check = maindb.ConsumerOpenIds.Add(new ConsumerOpenIds()
|
|
|
- {
|
|
|
- OpenId = OpenId,
|
|
|
- ConsumerId = ConsumerId,
|
|
|
- }).Entity;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- ConsumerId = check.ConsumerId;
|
|
|
+ ConsumerId = check.Id;
|
|
|
}
|
|
|
maindb.SaveChanges();
|
|
|
-
|
|
|
+
|
|
|
return ConsumerId;
|
|
|
}
|
|
|
#endregion
|