public APIResult UpdateConglomeration() { _logger.LogInformation("=================【更新拼团状态】UpdateConglomeration服务开始=========="); var orders = shopDb.ConglomerationOrder.Where(m => !m.IsDel && (m.Status.Equals(ShopOrderStatus.待成团) || m.Status.Equals(ShopOrderStatus.待自提) || m.Status.Equals(ShopOrderStatus.待配送)) && (!m.ConglomerationSetUp.IsDel && m.ConglomerationSetUp.EndTime <= DateTime.Now && (m.ConglomerationSetUp.Status.Equals(ConglomerationSetUpStatus.未成团) || m.ConglomerationSetUp.Status.Equals(ConglomerationSetUpStatus.已取消)))) .Include(m => m.ConglomerationSetUp); _logger.LogInformation($"需更新订单数量 :{orders.Count()}"); foreach (var ordersItem in orders) { try { //执行退款改变订单状态 var shop = shopDb.Shops.Find(ordersItem.ShopId); Refunds refunds = new Refunds(proxyFactory); var memberTradeForRechange = shopDb.MemberTradeForRechange.FirstOrDefault(m => m.Status.Equals(MemberTradeForRechangeStatus.成功) && m.ConglomerationOrderId.Equals(ordersItem.Id)); _logger.LogInformation($"支付记录ID :{memberTradeForRechange.Id}"); if (memberTradeForRechange == null) { _logger.LogInformation($"错误无法找到支付记录 订单ID :{ordersItem.Id}"); return(Error("无法找到支付记录")); } var isOk = refunds.RefundAction(new RefundArgsModel() { ShopFlag = shop.Flag, TradeNo = memberTradeForRechange.TradeNo }); _logger.LogInformation($"退款结果 isOk :{isOk.Status}"); if (isOk.Status == MemberTradeForRefundStatus.成功) { ordersItem.Status = ShopOrderStatus.已退款; } if (isOk.Status == MemberTradeForRefundStatus.退款中) { ordersItem.Status = ShopOrderStatus.退款中; } ordersItem.ConglomerationSetUp.Status = ConglomerationSetUpStatus.已取消; ShopConglomerationActivityOptions.RemoveSetup(ordersItem.ConglomerationSetUp.Id); } catch (Exception e) { _logger.LogInformation($"更新出错错误信息{e.Message} 订单ID :{ordersItem.Id}"); } } shopDb.SaveChanges(); _logger.LogInformation("=================【更新拼团状态】UpdateConglomeration服务结束=========="); return(Success("ok")); }
public APIResult CancelThePayment([FromBody] CancelThePayment input) { ShopConglomerationActivityOptions.NotifyOkRemoveList(input.ConglomerationOrderId, db, _logger); return(Success()); }
public APIResult Participation([FromBody] ParticipationModel input) { var conglomerationSetUp = db.ConglomerationSetUp.Find(input.ConglomerationSetUpId); if (conglomerationSetUp == null || conglomerationSetUp.IsDel) { return(Error("记录不存在")); } if (conglomerationSetUp.MemberId.Equals(GetMemberId())) { return(Error("不能参加自己的拼团")); } var conglomerationActivity = db.ConglomerationActivity.Find(conglomerationSetUp.ConglomerationActivityId); if (conglomerationActivity.ActivityEndTime <= DateTime.Now) { return(Error("活动已经结束")); } //开始执行逻辑 if (conglomerationSetUp.EndTime <= DateTime.Now || conglomerationSetUp.CurrentMemberNumber.Equals(conglomerationSetUp.MemberNumber) || conglomerationSetUp.Status.Equals(ConglomerationSetUpStatus.已经成团)) { return(Error("该拼团已经结束")); } var conglomerationParticipations = db.ConglomerationParticipation.Where(m => !m.IsDel && m.ConglomerationSetUpId.Equals(input.ConglomerationSetUpId)); if (conglomerationParticipations.Count() >= conglomerationSetUp.MemberNumber) { return(Error("该拼团已经结束")); } //获取请求集合 var list = ShopConglomerationActivityOptions.GetSetupIdAndMemberId(conglomerationSetUp.Id, _logger); if ((conglomerationSetUp.MemberNumber - conglomerationSetUp.CurrentMemberNumber) <= list.Count()) { //判断是否还可以加入集合,如果不可以则提示稍后重试 return(Error("请稍后再试")); } //否则加入集合 ShopConglomerationActivityOptions.AddList(list, new ShopConglomerationActivityOptions.RequestModel() { CreateTime = DateTime.Now, MmeberId = GetMemberId() }); _logger.LogInformation($"==============================添加到请求集合用户ID{GetMemberId()}==============="); var conglomerationActivityType = db.ConglomerationActivityType.Find(conglomerationSetUp.ConglomerationActivityTypeId); //生成订单 var memberId = GetMemberId(); var memberAddress = db.Query <MemberAddress>().FirstOrDefault(m => m.Id.Equals(input.MemberAddressId)); if (memberAddress == null) { memberAddress = db.Query <MemberAddress>().FirstOrDefault(m => m.IsUsed); } ShopConglomerationOrderDto shopConglomerationOrderDto = new ShopConglomerationOrderDto() { AddIp = GetIp(), ConglomerationSetUpId = conglomerationSetUp.Id, ConglomerationSetUp = conglomerationSetUp, MemberAddressId = input.MemberAddressId, //MemberId = 70, MemberId = memberId, ShopId = input.ShopId, Type = input.Type, Name = memberAddress.Name, Phone = memberAddress.Phone, Delivery = input.Delivery, FormId = input.FormId }; var order = _shopConglomerationOrderServer.Create(db, shopConglomerationOrderDto); return(Success(new { ConglomerationOrderId = order.Id })); }
public ActionResult Notify() { _logger.LogInformation("=====================支付回调开始======================"); //var logDb = ZRui.Web.BLL.DbContextFactory.LogDbContext; //logDb.Add<TaskLog>(new TaskLog() { AddTime = DateTime.Now, TaskName = "进入Notify" }); string body = new StreamReader(Request.Body).ReadToEnd(); byte[] requestData = Encoding.UTF8.GetBytes(body); Stream inputStream = new MemoryStream(requestData); using (StreamReader sr = new StreamReader(inputStream)) { try { var xml = sr.ReadToEnd(); _logger.LogInformation($"获取到result{xml}"); //logDb.Add<TaskLog>(new TaskLog() { AddTime = DateTime.Now, TaskName = "Notify", ExeResult = xml }); //logDb.SaveChanges(); var notify = new SwiftpassPayResponseHandler(null, xml); ShopPayInfo shopPayInfo = shopdb.Query <ShopPayInfo>() .Where(m => !m.IsDel) .Where(m => m.AppId == notify.SwiftpassAppid) .Where(m => m.MchId == notify.SwiftpassMchid) .FirstOrDefault(); if (shopPayInfo == null) { return(Content("failure1")); } PayProxyBase payProxy = proxyFactory.GetProxy(shopPayInfo); // if (notify.isTenpaySign()) //{ if (notify.Status == 0 && notify.ResultCode == 0 && notify.TradeState != "NOTPAY") { _logger.LogInformation("支付成功"); //此处可以在添加相关处理业务,校验通知参数中的商户订单号out_trade_no和金额total_fee是否和商户业务系统的单号和金额是否一致,一致后方可更新数据库表中的记录。 var rechange = db.Query <MemberTradeForRechange>() .Where(m => m.TradeNo == notify.OutTradeNo) .FirstOrDefault(); if (rechange == null) { throw new Exception("指定的OutTradeNo不存在"); } if (rechange.TotalFee != notify.TotalFee) { throw new Exception("指定的金额不对应"); } rechange.OutBank = notify.Xml; rechange.MechanismTradeNo = notify.TransactionId; if (notify.getAllParameters()["result_code"].ToString() == "0") { rechange.SetFinish(printDbContext, shopdb, db, woptions, thirdConfig, _logger); db.SaveChanges(); shopdb.SaveChanges(); _logger.LogInformation("回调成功返回success"); if (rechange.ConglomerationOrderId.HasValue) { ShopConglomerationOrderOptions.MemberInform(shopdb, _memberDbContext, rechange.ConglomerationOrderId.Value, _logger); ShopConglomerationActivityOptions.NotifyOkRemoveList(rechange, shopdb, _logger); } _logger.LogInformation("=====================支付回调结束======================"); return(Content("success")); } else { _logger.LogInformation("回调失败返回failure1"); _logger.LogInformation("=====================支付回调结束======================"); return(Content("failure1")); } //var result = payProxy.GetPayResult(rechange); //_logger.LogInformation($"获取到result{result.Xml}"); // //if (result.TradeState != "NOTPAY") //{ // if (rechange.Status == MemberTradeForRechangeStatus.未完成) // { // if (rechange.TotalFee != result.TotalFee) throw new Exception("指定的金额不对应"); // rechange.OutBank = result.Xml; // rechange.MechanismTradeNo = result.TransactionId; // switch (result.TradeState) // { // case "SUCCESS": // rechange.SetFinish(printDbContext, shopdb, db, woptions, _logger); // break; // case "CLOSED": // rechange.Status = MemberTradeForRechangeStatus.取消; // break; // default: // db.SetMemberTradeForRechangeFail(rechange, result.TradeState); // break; // } // } //} } else { _logger.LogInformation($"=====================支付回调结束======================"); return(Content("failure1")); } // } //else //{ // return Content("failure2"); //} } catch (Exception e) { _logger.LogInformation($"回调错误{e}"); return(Content("failure1")); } } }