public async Task <Result> Modify(RechargeDto dto, string opt) { var redis = ObjectContainer.Resolve <RedisHelper>(); var balance = ObjectContainer.Resolve <IBalanceService>(); var obj = ObjectContainer.Resolve <IRechargeService>(); var b = new BalanceDto { Bank = dto.Bank, RechargeMode = dto.RechargeMode, SalesMan = dto.SalesMan, UserId = dto.UserId, Value = dto.Value, Money = dto.Money, OperatorId = LoginInfo.Id, ModifyDate = DateTime.Now, Remark = dto.Remark, TradeResult = TradeResult.Success, TradeType = TradeType.Offline, IdenTity = IdenTity.Server }; if (opt == "add") { await balance.Rechange(b, LoginInfo.Role); await redis.StringGetAsync(RedisKeyName.CreateUserAmountKey(dto.UserId)); await redis.StringIncrementAsync(RedisKeyName.CreateUserAmountKey(dto.UserId), dto.Value); return(new Result { Status = true }); } return(await Task.Run(() => obj.Update(dto))); }
public Result Update(RechargeDto dto) { try { var entity = dto.MapTo <RechargeEntity>(); var rlt = UnitOfWorkService.Execute(() => _repo.Update(entity)); if (!rlt) { return new Result { Status = false, Message = "数据库操作失败" } } ; return(new Result { Status = true }); } catch (Exception ex) { Logger.Error("update Recharge error", ex); return(new Result { Status = false, Message = "内部服务器错误" }); } }
public async Task <ResponseViewModel <string> > AliPaySign([FromBody] RequestViewModel obj) { ResponseViewModel <string> response = null; string result = string.Empty; obj = JsonHelper.DeserializeJsonToObject <RequestViewModel>(Content(User.Identity.Name).Content); var sysCode = SysCode.Ok; bool isLog = _token.VerifyToken(obj.HendInfo.UserOpenId, obj.HendInfo.SessionToken); if (isLog) { string json = RedisHelper.StringGet($"{CacheKey.Token}{obj.HendInfo.UserOpenId}", RedisFolderEnum.token, RedisEnum.Three); var userLog = JsonHelper.DeserializeJsonToObject <UserLoginDto>(json); int itemId = StringExtension.ToInt((string)obj.Data.itemId); //; //商品Id RechargeCommodityDto rechargeCommodity = await _recharge.GetRechargeCommodityByIdAsync(itemId); if (rechargeCommodity == null) { sysCode = SysCode.RechargeCommodityIsNULL; //充值商品不存在, } if (sysCode == SysCode.Ok) { string order = Guid.NewGuid().ToString(); result = _recharge.CreateAlipaySign(rechargeCommodity, order); AliPayOrderDto AliPayOrder = new AliPayOrderDto() { Commodity_id = itemId, Out_trade_no = order, Createtime = DateTime.Now, Updatetime = DateTime.Now, Gmt_payment = DateTime.Now, Userid = userLog.Userid, Total_amount = rechargeCommodity.Money }; await _recharge.RecordAlipayOrderAsync(AliPayOrder);//记录支付宝订单。 RechargeDto recharge = new RechargeDto() { Amount = rechargeCommodity.Amount, createtime = DateTime.Now, Pay_type = 1, //支付类型 1支付宝,2微信,3苹果内购 Status = 1, //1 待处理 2 已支付 3 支付失败 4 超时 updatetime = DateTime.Now, UserId = userLog.Userid, Order_id = AliPayOrder.Out_trade_no, }; await _recharge.RecordRechargeLogAsync(recharge); //记录充值订 } } else { /*短令牌失效*/ sysCode = SysCode.SessionTokenLose; } response = new ResponseViewModel <string>(sysCode, sysCode == SysCode.Ok ? result : null, obj.Encrypt, _sys, obj.Secret); return(response); }
/// <summary> /// 记录充值记录 /// author:陶林辉 /// </summary> /// <param name="recharge">object</param> /// <returns></returns> public async Task <long> RecordRechargeLogAsync(RechargeDto recharge) { var entity = _mapper.Map <RechargeDto, RechargeEntity>(recharge); _context.Recharge.Add(entity); await _context.SaveChangesAsync(); return(entity.Id); }
public async Task <H5ResponseViewModel <AliPayH5View> > PayRequest([FromBody] H5RequestViewModel Parameters) { var sysCode = _sys.CheckParameters(Parameters.data, "payrequest"); H5ResponseViewModel <AliPayH5View> response = null; AliPayH5View result = null; string token = Parameters.data.token; bool isLog = _token.VerifyToken(token); if (sysCode == SysCode.Ok) { if (isLog) { string json = RedisHelper.StringGet($"{CacheKey.Token}{token}", RedisFolderEnum.token, RedisEnum.Five); UserLoginDto userLogin = JsonHelper.DeserializeJsonToObject <UserLoginDto>(json); int id = int.Parse((string)Parameters.data.id); var rechargeCommodity = await _recharge.GetRechargeCommodityByIdAsync(id); string order = Guid.NewGuid().ToString(); result = _recharge.CreateAlipayH5Receipt(rechargeCommodity, order); AliPayOrderDto AliPayOrder = new AliPayOrderDto() { Commodity_id = id, Out_trade_no = order, Createtime = DateTime.Now, Updatetime = DateTime.Now, Gmt_payment = DateTime.Now, Userid = userLogin.Userid, Total_amount = rechargeCommodity.Money //人名币 }; await _recharge.RecordAlipayOrderAsync(AliPayOrder); //记录支付宝订单。 RechargeDto recharge = new RechargeDto() { Amount = rechargeCommodity.Amount, //虚拟币 createtime = DateTime.Now, Pay_type = 1, //支付类型 1支付宝,2微信,3苹果内购 Status = 1, //1 待处理 2 已支付 3 支付失败 4 超时 updatetime = DateTime.Now, UserId = userLogin.Userid, Order_id = AliPayOrder.Out_trade_no, }; await _recharge.RecordRechargeLogAsync(recharge); //记录充值订 } else { sysCode = SysCode.TokenLose; } } response = new H5ResponseViewModel <AliPayH5View>(sysCode, result ?? null); return(response); }
public IActionResult Modify(string id, string opt) { var obj = ObjectContainer.Resolve <IRechargeService>(); ViewBag.opt = opt; ViewBag.id = id; var model = new RechargeDto(); if (!id.Equals("0")) { model = obj.Get(id); } return(View(model)); }
public Result Add(RechargeDto dto, UserType roleId) { try { var entity = dto.MapTo <RechargeEntity>(); var rlt = UnitOfWorkService.Execute(() => { var id = _repo.InsertAndGetId(entity); var orgId = _staffRepository.GetOrgId(dto.SalesMan).OrgId; var dataInOrg = new DataInOrgEntity { DataId = id.ToString(), DataType = (int)DataType.Recharge, OrgId = orgId, RoleId = ((int)roleId).ToString() }; var dataRlt = _dataInOrgRepository.Inserts(dataInOrg); if (id <= 0 && !dataRlt) { return(new Result { Status = false, Message = "数据库操作失败" }); } return(new Result { Status = true }); }); return(rlt); } catch (Exception ex) { Logger.Error("add Recharge error", ex); return(new Result { Status = false, Message = "内部服务器错误" }); } }
//public IActionResult PayDo(List<IFormFile> formFiles) //{ // try // { // var pay = Request.Form["pay"].ToString(); // ali/wx // var payment = CreatePayment(pay); //创建支付类型,支付宝/微信 // //订单编号 10线上 11线下 // var outTradeNo = DateTime.Now.ToStringTimeStamp();//_orderService.CreateOrderId("10")); // + Request.Query["Id"];商户订单号,需要保证不重复 // //订单名称,必填 // var subject = Request.Form["Name"]; // ////流水号 // //var Sernumber = DateTime.Now.ToStringTimeStamp(); // + Request.Query["Id"]; // //付款金额,必填 // var totalFee = Convert.ToDecimal(Request.Form["Money"]); // //总条数 // var num = Convert.ToInt32(Request.Form["Total"]); // //商品编号 // var prodId = Request.Form["Id"].ToString(); // //生成订单发送到支付宝/微信 // var payRlt = payment.Pay(outTradeNo, subject, totalFee); // //订单写入数据库 todo:充值表.余额表 redis 或者考虑加一张订单表 // // var addOrder = AddOrder(pay, prodId, outTradeNo, totalFee, num); // var rlt = Add(pay, outTradeNo, totalFee, num, subject); // if (pay == "wx") // { // //string ImageUrl = "/Wx/MakeQrCode?data=" + HttpUtility.UrlEncode(payRlt.Message); // //Request.HttpContext.Session.SetString("ImageUrl", ImageUrl); // //HttpContext.Session.CommitAsync(); // //return Redirect("/Prod/WxPay"); //微信二维码支付页面 // } // return Content(payRlt.Message, "text/html"); //支付宝支付页面 // } // catch (Exception ex) // { // Logger.Error("Pay.PayDo:", ex); // return Content(ex.Message); // } //} private Result Add(string pay, string outTradeNo, decimal totalFee, int total, string subject) { var salesMan = _customer.Get(LoginInfo.Id).SalesMan; var orderDto = new RechargeDto { UserId = LoginInfo.Id, OperatorId = LoginInfo.Id, Value = total, Money = Convert.ToInt32(totalFee), CreateDate = DateTime.Now, OrderNumber = outTradeNo, OrderName = subject, IdenTity = IdenTity.Client, OrderDate = DateTime.Now, TradeType = pay.Equals("ali") ? TradeType.AliPay : TradeType.WxPay, TradeResult = TradeResult.Wait, SalesMan = salesMan, RechargeMode = RechargeMode.ContinuedCharge, TranId = "" }; var result = _rechargeService.Add(orderDto, UserType.Admin); return(result); }
public async Task <ResponseViewModel <AppleProductViewModel> > AcquireAppleProduct([FromBody] RequestViewModel obj) { ResponseViewModel <AppleProductViewModel> response = null; obj = JsonHelper.DeserializeJsonToObject <RequestViewModel>(Content(User.Identity.Name).Content); var sysCode = SysCode.Ok; bool isLog = _token.VerifyToken(obj.HendInfo.UserOpenId, obj.HendInfo.SessionToken); AppleProductViewModel result = null; if (isLog) { int itemId = int.Parse((string)obj.Data.itemId); string strJson = RedisHelper.StringGet($"{CacheKey.Token}{obj.HendInfo.UserOpenId}", RedisFolderEnum.token, RedisEnum.Three); UserLoginDto userLog = JsonHelper.DeserializeJsonToObject <UserLoginDto>(strJson); var dto = await _recharge.GetAppleProductAsync(itemId); //查询苹果商品信息 if (dto != null) { /*苹果充值记录*/ AppleReceiptDto appleReceipt = new AppleReceiptDto() { Apple_id = dto.Product_id, Item_id = itemId, Createtime = DateTime.Now, Receipt = "", Userid = userLog.Userid, Updatetime = DateTime.Now, Order_id = Guid.NewGuid().ToString(), }; await _recharge.RecordAppleOrderAsync(appleReceipt); /*用户充值记录*/ RechargeDto recharge = new RechargeDto() { Amount = dto.Amount, createtime = DateTime.Now, Order_id = appleReceipt.Order_id, Pay_type = 0, //0苹果内购, 1支付宝,2微信 ,3卡密 Status = 1, //1 待处理 2 已支付 3 支付失败 4 超时 UserId = userLog.Userid, updatetime = DateTime.Now, }; await _recharge.RecordRechargeLogAsync(recharge); result = new AppleProductViewModel { AppleId = dto.Apple_id, ProductId = dto.Product_id, OrderId = recharge.Order_id,//记录充值订 }; } } else { /*短令牌失效*/ sysCode = SysCode.SessionTokenLose; } response = new ResponseViewModel <AppleProductViewModel>(sysCode, sysCode == SysCode.Ok ? result : null, obj.Encrypt, _sys, obj.Secret); return(response); }