|
@@ -217,115 +217,223 @@ namespace MySystem.Areas.Api.Controllers.v1
|
|
|
{
|
|
|
return new AppResultJson() { Status = "-1", Info = "请填写正确的支付金额" };
|
|
|
}
|
|
|
-
|
|
|
+ Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
|
MerchantQrCode qrcode = MerchantQrCodeDbconn.Instance.Get(SnNo) ?? new MerchantQrCode();
|
|
|
-
|
|
|
+ PosMachinesTwo pos = PosMachinesTwoDbconn.Instance.Get(SnNo) ?? new PosMachinesTwo();
|
|
|
// PosMachines machine = PosMachinesDbconn.Instance.Get(qrcode.SnId) ?? new PosMachines();
|
|
|
// if (machine.BindMerchantId == 0) machine.BindMerchantId = 1; // TODO: 需要绑定二维码
|
|
|
- MerchantInfo merchant = MerchantInfoDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantInfo();
|
|
|
- MerchantAddInfo merchantAdd = MerchantAddInfoDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantAddInfo();
|
|
|
- MerchantParamSet merchantset = MerchantParamSetDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantParamSet();
|
|
|
- string openid = "";
|
|
|
- if (PayMode == 1)
|
|
|
- {
|
|
|
- openid = new AlipayFunction(_accessor.HttpContext).GetAlipayUserId(Code);
|
|
|
- if (openid.Contains("|"))
|
|
|
+ if(pos.OpId == 1)
|
|
|
+ {
|
|
|
+ MerchantInfo merchant = MerchantInfoDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantInfo();
|
|
|
+ MerchantAddInfo merchantAdd = MerchantAddInfoDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantAddInfo();
|
|
|
+ MerchantParamSet merchantset = MerchantParamSetDbconn.Instance.Get(qrcode.MerchantId) ?? new MerchantParamSet();
|
|
|
+ string openid = "";
|
|
|
+ if (PayMode == 1)
|
|
|
+ {
|
|
|
+ openid = new AlipayFunction(_accessor.HttpContext).GetAlipayUserId(Code);
|
|
|
+ if (openid.Contains("|"))
|
|
|
+ {
|
|
|
+ openid = openid.Split('|')[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- openid = openid.Split('|')[0];
|
|
|
+ string result = function.GetWebRequest("https://api.weixin.qq.com/sns/jscode2session?appid=" + new WeChatFunction().AppId + "&secret=" + new WeChatFunction().AppSecret + "&js_code=" + Code + "&grant_type=authorization_code");
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n" + result, "微信小程序获取openid");
|
|
|
+ JsonData jsonObj = JsonMapper.ToObject(result);
|
|
|
+ openid = jsonObj["openid"].ToString();
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- string result = function.GetWebRequest("https://api.weixin.qq.com/sns/jscode2session?appid=" + new WeChatFunction().AppId + "&secret=" + new WeChatFunction().AppSecret + "&js_code=" + Code + "&grant_type=authorization_code");
|
|
|
- function.WriteLog(DateTime.Now.ToString() + "\n" + result, "微信小程序获取openid");
|
|
|
- JsonData jsonObj = JsonMapper.ToObject(result);
|
|
|
- openid = jsonObj["openid"].ToString();
|
|
|
- }
|
|
|
- int ConsumerId = 0;
|
|
|
- ConsumerOpenIds check = maindb.ConsumerOpenIds.FirstOrDefault(m => m.OpenId == openid);
|
|
|
- if (check == null)
|
|
|
- {
|
|
|
- // ConsumerId = PublicFunction.MakeConsumerId();
|
|
|
- Consumers consumer = maindb.Consumers.Add(new Consumers()
|
|
|
+ int ConsumerId = 0;
|
|
|
+ ConsumerOpenIds check = maindb.ConsumerOpenIds.FirstOrDefault(m => m.OpenId == openid);
|
|
|
+ if (check == null)
|
|
|
{
|
|
|
- Id = ConsumerId,
|
|
|
- CreateDate = DateTime.Now,
|
|
|
- WechatOpenId = openid,
|
|
|
- }).Entity;
|
|
|
+ // ConsumerId = PublicFunction.MakeConsumerId();
|
|
|
+ Consumers consumer = maindb.Consumers.Add(new Consumers()
|
|
|
+ {
|
|
|
+ Id = ConsumerId,
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ WechatOpenId = openid,
|
|
|
+ }).Entity;
|
|
|
+ maindb.SaveChanges();
|
|
|
+ ConsumerId = consumer.Id;
|
|
|
+ check = maindb.ConsumerOpenIds.Add(new ConsumerOpenIds()
|
|
|
+ {
|
|
|
+ OpenId = openid,
|
|
|
+ ConsumerId = ConsumerId,
|
|
|
+ }).Entity;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ConsumerId = check.ConsumerId;
|
|
|
+ }
|
|
|
maindb.SaveChanges();
|
|
|
- ConsumerId = consumer.Id;
|
|
|
- check = maindb.ConsumerOpenIds.Add(new ConsumerOpenIds()
|
|
|
+ string OrderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
|
|
|
+ bool ActFlag = merchantset.IsAll == 1 ? false : true;
|
|
|
+ if(PayMoney < merchantset.MinPayMoney) //支付金额小于活动最小金额,则不分账
|
|
|
+ {
|
|
|
+ ActFlag = false;
|
|
|
+ }
|
|
|
+ ConsumerOrders order = maindb.ConsumerOrders.Add(new ConsumerOrders()
|
|
|
{
|
|
|
- OpenId = openid,
|
|
|
- ConsumerId = ConsumerId,
|
|
|
+ // Id = PublicFunction.MakeConsumerOrderId(),
|
|
|
+ CreateDate = DateTime.Now, //创建时间
|
|
|
+ MerchantId = qrcode.MerchantId, //商户
|
|
|
+ ConsumerId = ConsumerId, //消费者
|
|
|
+ UserId = merchant.UserId, //创客
|
|
|
+ PayMode = PayMode, //支付方式
|
|
|
+ PayMoney = PayMoney, //支付金额
|
|
|
+ SnNo = SnNo, //SN号
|
|
|
+ OrderNo = OrderNo,
|
|
|
+ MaxDivi = ActFlag ? PayMoney * merchantset.DiviPercent / 100 : 0,
|
|
|
+ IsAct = ActFlag ? 1u : 0u,
|
|
|
+ MerchantActualAmount = ActFlag ? PayMoney * merchantset.GetPercent / 100 : PayMoney,
|
|
|
+ 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(_accessor.HttpContext).CreateTrade(OrderNo, merchant.Name, PayMoney, openid, merchantAdd.AlipayAuthToken, SpHost + "/api/alipay/notice");
|
|
|
+ JsonData obj = JsonMapper.ToObject(backString);
|
|
|
+ if (obj["alipay_trade_create_response"]["code"].ToString() == "10000")
|
|
|
+ {
|
|
|
+ string tradeNo = obj["alipay_trade_create_response"]["trade_no"].ToString();
|
|
|
+ Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
|
|
|
+ Obj.Add("tradeNo", tradeNo);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
|
|
|
+ Obj.Add("tradeNo", "");
|
|
|
+ return new AppResultJson() { Status = "-1", Info = obj["alipay_trade_create_response"]["sub_msg"].ToString(), Data = Obj };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (PayMode == 2)
|
|
|
+ {
|
|
|
+ string SubMchId = merchantAdd.SubMchid;
|
|
|
+ string Description = merchant.Name;
|
|
|
+ string OpenId = openid;
|
|
|
+ string Key = AppConfig.WeChatParam.AesGemKey;
|
|
|
+ string NotifyUrl = SpHost + "/api/wechat/notice";
|
|
|
+ Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Pay(SubMchId, PayMoney, OrderNo, Description, OpenId, Key, NotifyUrl, ActFlag);
|
|
|
+ Obj.Add("appId", dic["appId"]); //微信小程序appid
|
|
|
+ Obj.Add("timeStamp", dic["timeStamp"]); //时间戳
|
|
|
+ Obj.Add("nonceStr", dic["nonceStr"]); //随机字符串
|
|
|
+ Obj.Add("package", dic["package"]); //统一支付接口返回的prepayid参数值
|
|
|
+ Obj.Add("paySign", dic["paySign"]); //支付签名
|
|
|
+ Obj.Add("ConsumerId", ConsumerId);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- ConsumerId = check.ConsumerId;
|
|
|
- }
|
|
|
- maindb.SaveChanges();
|
|
|
- Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
|
- string OrderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
|
|
|
- bool ActFlag = merchantset.IsAll == 1 ? false : true;
|
|
|
- if(PayMoney < merchantset.MinPayMoney) //支付金额小于活动最小金额,则不分账
|
|
|
- {
|
|
|
- ActFlag = false;
|
|
|
- }
|
|
|
- ConsumerOrders order = maindb.ConsumerOrders.Add(new ConsumerOrders()
|
|
|
- {
|
|
|
- // Id = PublicFunction.MakeConsumerOrderId(),
|
|
|
- CreateDate = DateTime.Now, //创建时间
|
|
|
- MerchantId = qrcode.MerchantId, //商户
|
|
|
- ConsumerId = ConsumerId, //消费者
|
|
|
- UserId = merchant.UserId, //创客
|
|
|
- PayMode = PayMode, //支付方式
|
|
|
- PayMoney = PayMoney, //支付金额
|
|
|
- SnNo = SnNo, //SN号
|
|
|
- OrderNo = OrderNo,
|
|
|
- MaxDivi = ActFlag ? PayMoney * merchantset.DiviPercent / 100 : 0,
|
|
|
- IsAct = ActFlag ? 1u : 0u,
|
|
|
- MerchantActualAmount = ActFlag ? PayMoney * merchantset.GetPercent / 100 : PayMoney,
|
|
|
- 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(_accessor.HttpContext).CreateTrade(OrderNo, merchant.Name, PayMoney, openid, merchantAdd.AlipayAuthToken, SpHost + "/api/alipay/notice");
|
|
|
- JsonData obj = JsonMapper.ToObject(backString);
|
|
|
- if (obj["alipay_trade_create_response"]["code"].ToString() == "10000")
|
|
|
+ MainModels2.MerchantInfo merchant = maindb2.MerchantInfo.FirstOrDefault(m => m.Id == qrcode.MerchantId) ?? new MainModels2.MerchantInfo();
|
|
|
+ MainModels2.MerchantAddInfo merchantAdd = maindb2.MerchantAddInfo.FirstOrDefault(m => m.Id == qrcode.MerchantId) ?? new MainModels2.MerchantAddInfo();
|
|
|
+ MainModels2.MerchantParamSet merchantset = maindb2.MerchantParamSet.FirstOrDefault(m => m.Id == qrcode.MerchantId) ?? new MainModels2.MerchantParamSet();
|
|
|
+ string openid = "";
|
|
|
+ if (PayMode == 1)
|
|
|
+ {
|
|
|
+ openid = new AlipayFunction(_accessor.HttpContext).GetAlipayUserId(Code);
|
|
|
+ if (openid.Contains("|"))
|
|
|
+ {
|
|
|
+ openid = openid.Split('|')[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string result = function.GetWebRequest("https://api.weixin.qq.com/sns/jscode2session?appid=" + new WeChatFunction().AppId + "&secret=" + new WeChatFunction().AppSecret + "&js_code=" + Code + "&grant_type=authorization_code");
|
|
|
+ function.WriteLog(DateTime.Now.ToString() + "\n" + result, "微信小程序获取openid");
|
|
|
+ JsonData jsonObj = JsonMapper.ToObject(result);
|
|
|
+ openid = jsonObj["openid"].ToString();
|
|
|
+ }
|
|
|
+ int ConsumerId = 0;
|
|
|
+ MainModels2.ConsumerOpenIds check = maindb2.ConsumerOpenIds.FirstOrDefault(m => m.OpenId == openid);
|
|
|
+ if (check == null)
|
|
|
{
|
|
|
- string tradeNo = obj["alipay_trade_create_response"]["trade_no"].ToString();
|
|
|
- Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
|
|
|
- Obj.Add("tradeNo", tradeNo);
|
|
|
+ MainModels2.Consumers consumer = maindb2.Consumers.Add(new MainModels2.Consumers()
|
|
|
+ {
|
|
|
+ Id = ConsumerId,
|
|
|
+ CreateDate = DateTime.Now,
|
|
|
+ WechatOpenId = openid,
|
|
|
+ }).Entity;
|
|
|
+ maindb2.SaveChanges();
|
|
|
+ ConsumerId = consumer.Id;
|
|
|
+ check = maindb2.ConsumerOpenIds.Add(new MainModels2.ConsumerOpenIds()
|
|
|
+ {
|
|
|
+ OpenId = openid,
|
|
|
+ ConsumerId = ConsumerId,
|
|
|
+ }).Entity;
|
|
|
}
|
|
|
else
|
|
|
+ {
|
|
|
+ ConsumerId = check.ConsumerId;
|
|
|
+ }
|
|
|
+ maindb2.SaveChanges();
|
|
|
+ string OrderNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
|
|
|
+ bool ActFlag = merchantset.IsAll == 1 ? false : true;
|
|
|
+ if(PayMoney < merchantset.MinPayMoney) //支付金额小于活动最小金额,则不分账
|
|
|
+ {
|
|
|
+ ActFlag = false;
|
|
|
+ }
|
|
|
+ MainModels2.ConsumerOrders order = maindb2.ConsumerOrders.Add(new MainModels2.ConsumerOrders()
|
|
|
+ {
|
|
|
+ // Id = PublicFunction.MakeConsumerOrderId(),
|
|
|
+ CreateDate = DateTime.Now, //创建时间
|
|
|
+ MerchantId = qrcode.MerchantId, //商户
|
|
|
+ ConsumerId = ConsumerId, //消费者
|
|
|
+ UserId = merchant.UserId, //创客
|
|
|
+ PayMode = PayMode, //支付方式
|
|
|
+ PayMoney = PayMoney, //支付金额
|
|
|
+ SnNo = SnNo, //SN号
|
|
|
+ OrderNo = OrderNo,
|
|
|
+ MaxDivi = ActFlag ? PayMoney * merchantset.DiviPercent / 100 : 0,
|
|
|
+ IsAct = ActFlag ? 1u : 0u,
|
|
|
+ MerchantActualAmount = ActFlag ? PayMoney * merchantset.GetPercent / 100 : PayMoney,
|
|
|
+ SeoDescription = Newtonsoft.Json.JsonConvert.SerializeObject(merchantset),
|
|
|
+ }).Entity;
|
|
|
+ maindb2.SaveChanges();
|
|
|
+ maindb2.ConsumerOrderForNo.Add(new MainModels2.ConsumerOrderForNo()
|
|
|
+ {
|
|
|
+ OrderNo = OrderNo,
|
|
|
+ OrderIds = order.Id,
|
|
|
+ });
|
|
|
+ maindb2.SaveChanges();
|
|
|
+ if (PayMode == 1)
|
|
|
{
|
|
|
- Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
|
|
|
- Obj.Add("tradeNo", "");
|
|
|
- return new AppResultJson() { Status = "-1", Info = obj["alipay_trade_create_response"]["sub_msg"].ToString(), Data = Obj };
|
|
|
+ string backString = new AlipayFunction(_accessor.HttpContext).CreateTrade(OrderNo, merchant.Name, PayMoney, openid, merchantAdd.AlipayAuthToken, SpHost + "/api/alipay/notice");
|
|
|
+ JsonData obj = JsonMapper.ToObject(backString);
|
|
|
+ if (obj["alipay_trade_create_response"]["code"].ToString() == "10000")
|
|
|
+ {
|
|
|
+ string tradeNo = obj["alipay_trade_create_response"]["trade_no"].ToString();
|
|
|
+ Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
|
|
|
+ Obj.Add("tradeNo", tradeNo);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Obj.Add("respCode", obj["alipay_trade_create_response"]["code"].ToString());
|
|
|
+ Obj.Add("tradeNo", "");
|
|
|
+ return new AppResultJson() { Status = "-1", Info = obj["alipay_trade_create_response"]["sub_msg"].ToString(), Data = Obj };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (PayMode == 2)
|
|
|
+ {
|
|
|
+ string SubMchId = merchantAdd.SubMchid;
|
|
|
+ string Description = merchant.Name;
|
|
|
+ string OpenId = openid;
|
|
|
+ string Key = AppConfig.WeChatParam.AesGemKey;
|
|
|
+ string NotifyUrl = SpHost + "/api/wechat/notice";
|
|
|
+ Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Pay(SubMchId, PayMoney, OrderNo, Description, OpenId, Key, NotifyUrl, ActFlag);
|
|
|
+ Obj.Add("appId", dic["appId"]); //微信小程序appid
|
|
|
+ Obj.Add("timeStamp", dic["timeStamp"]); //时间戳
|
|
|
+ Obj.Add("nonceStr", dic["nonceStr"]); //随机字符串
|
|
|
+ Obj.Add("package", dic["package"]); //统一支付接口返回的prepayid参数值
|
|
|
+ Obj.Add("paySign", dic["paySign"]); //支付签名
|
|
|
+ Obj.Add("ConsumerId", ConsumerId);
|
|
|
}
|
|
|
- }
|
|
|
- else if (PayMode == 2)
|
|
|
- {
|
|
|
- string SubMchId = merchantAdd.SubMchid;
|
|
|
- string Description = merchant.Name;
|
|
|
- string OpenId = openid;
|
|
|
- string Key = AppConfig.WeChatParam.AesGemKey;
|
|
|
- string NotifyUrl = SpHost + "/api/wechat/notice";
|
|
|
- Dictionary<string, string> dic = new WeChatFunction(_accessor.HttpContext).Pay(SubMchId, PayMoney, OrderNo, Description, OpenId, Key, NotifyUrl, ActFlag);
|
|
|
- Obj.Add("appId", dic["appId"]); //微信小程序appid
|
|
|
- Obj.Add("timeStamp", dic["timeStamp"]); //时间戳
|
|
|
- Obj.Add("nonceStr", dic["nonceStr"]); //随机字符串
|
|
|
- Obj.Add("package", dic["package"]); //统一支付接口返回的prepayid参数值
|
|
|
- Obj.Add("paySign", dic["paySign"]); //支付签名
|
|
|
- Obj.Add("ConsumerId", ConsumerId);
|
|
|
}
|
|
|
return new AppResultJson() { Status = "1", Info = "", Data = Obj };
|
|
|
}
|