| | |
| | | using cylsg.Core; |
| | | using cylsg.Model.TransferOrder; |
| | | using cylsg.Model.UserModel; |
| | | using cylsg.utility; |
| | | using cylsg.utility.Extend; |
| | | using Cylsg.Filter; |
| | | using EzCoreNet.Redis; |
| | | using EzInitqMessageDef; |
| | | using EzWechat; |
| | | using Furion.LinqBuilder; |
| | | using MapsterMapper; |
| | | using Newtonsoft.Json; |
| | | using SKIT.FlurlHttpClient.Wechat.Api.Models; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Security.Claims; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using TencentCloud.Ame.V20190916.Models; |
| | | using static SKIT.FlurlHttpClient.Wechat.Api.Models.ChannelsLeadsGetLeadsInfoByComponentIdResponse.Types; |
| | | |
| | | namespace cylsg.Application.Transfer |
| | | { |
| | |
| | | public class UserTransfer |
| | | { |
| | | |
| | | |
| | | public UserTransfer() { } |
| | | private readonly IEzCoreNetRedisService _redisService; |
| | | private readonly IWecharPayServicecs _wecharPayServicecs; |
| | | |
| | | public UserTransfer(IEzCoreNetRedisService ezCoreNetRedisService,IWecharPayServicecs wecharPayServicecs) { |
| | | |
| | | _redisService = ezCoreNetRedisService; |
| | | _wecharPayServicecs = wecharPayServicecs; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 提现 |
| | | /// </summary> |
| | | /// <param name="Money"></param> |
| | | [LimitFilter(LimiType = Limttype.User,timespan =10,ResponseMeg ="请勿在10秒内重复请求")] |
| | | public async Task GetTransferMoney( [FromQuery]decimal Money) |
| | | [LimitFilter(LimiType = Limttype.User, timespan = 10, ResponseMeg = "请勿在10秒内重复请求")] |
| | | public async Task GetTransferMoney([FromQuery] decimal Money) |
| | | { |
| | | var rs= new BaseRepository<UserWorker>(); |
| | | |
| | | if (Money < 0.3m) |
| | | throw Oops.Oh("必须大于0.3元"); |
| | | if (Money > 2000) |
| | | throw Oops.Oh("每人每天最多只能提取2000元"); |
| | | |
| | | var rs = new BaseRepository<UserWorker>(); |
| | | var UserID = App.User?.FindFirstValue("UserID"); |
| | | int userid = 0; |
| | | if (!string.IsNullOrEmpty(UserID)) |
| | |
| | | |
| | | throw Oops.Oh("没有识别到用户收入"); |
| | | } |
| | | var uw= await rs.GetByIdAsync(userid); |
| | | if((uw.TiXianZonge-uw.YiTiXianJine)< Money) |
| | | |
| | | if (await _redisService.TryLock(StaticStringDef.TransferMoneyLockKey + userid.ToString(), 300)) |
| | | { |
| | | throw Oops.Oh("用户余额不足"); |
| | | |
| | | try |
| | | { |
| | | var UserRs = new BaseRepository<User>(); |
| | | var user = await UserRs.GetByIdAsync(userid); |
| | | if (user == null) |
| | | { |
| | | throw Oops.Oh($"没有找到用户"); |
| | | } |
| | | if (string.IsNullOrEmpty(user.WxOpenId)) |
| | | { |
| | | throw Oops.Oh($"用户微信OpenID确实"); |
| | | } |
| | | var uw = await rs.GetFirstAsync(x => x.UserId == userid); |
| | | if (uw == null) |
| | | { |
| | | throw Oops.Oh("该用户没有收入"); |
| | | } |
| | | if ((uw.TiXianZonge - uw.YiTiXianJine) < Money) |
| | | { |
| | | throw Oops.Oh("用户余额不足"); |
| | | } |
| | | |
| | | |
| | | var totle = _redisService.Get<decimal>(StaticStringDef.TransferMoneyManKey + userid.ToString()); |
| | | if (totle + Money > 2000) |
| | | { |
| | | throw Oops.Oh("提现金额不可超出2000"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | var UserTiXianDetailwork = new BaseRepository<UserTiXianDetail>(); |
| | | var WeChatTransferOrderwork = new BaseRepository<WeChatTransferOrder>(); |
| | | if ((uw != null) && ((uw.TiXianZonge - uw.YiTiXianJine) >= Money)) |
| | | { |
| | | //满足条件,发起支付 |
| | | var TransferOrder = new WeChatTransferOrder |
| | | { |
| | | |
| | | CreateBy = uw.UserId.ToString(), |
| | | CreateTime = DateTime.Now, |
| | | // BatchId = _redisService.Get32sn(), |
| | | OutBatchNumber = _redisService.Get32sn(), |
| | | Remake = "川印工资支付", |
| | | TransferDetailList = new List<WeChatTransferItem>(), |
| | | UserID = uw.UserId, |
| | | |
| | | |
| | | |
| | | |
| | | }; |
| | | try |
| | | { |
| | | |
| | | await UserTiXianDetailwork.AsTenant().BeginTranAsync(); |
| | | |
| | | |
| | | |
| | | |
| | | var moneylist = Money; |
| | | |
| | | var maxPayItem = Convert.ToDecimal(App.Configuration["WechartPay:PayMoneyMax"].toInt()); ; |
| | | while ((moneylist > maxPayItem)) |
| | | { |
| | | TransferOrder.TransferDetailList.Add(new WeChatTransferItem |
| | | { |
| | | CreateBy = uw.UserId.ToString(), |
| | | CreateTime = TransferOrder.CreateTime, |
| | | IsEn = true, |
| | | OpenId = user.WxOpenId, |
| | | OutDetailNumber = _redisService.Get32sn(), |
| | | |
| | | TransferAmount = (int)maxPayItem * 100, |
| | | TransferRemark = "川印工资支付", |
| | | |
| | | }); |
| | | |
| | | moneylist -= maxPayItem; |
| | | } |
| | | if (moneylist <= 0.3m) |
| | | { |
| | | //如果这里低于0.3毛,将社区预检,留下次处理 |
| | | Money -= moneylist; |
| | | } |
| | | else |
| | | |
| | | { |
| | | TransferOrder.TransferDetailList.Add(new WeChatTransferItem |
| | | { |
| | | CreateBy = uw.UserId.ToString(), |
| | | CreateTime = TransferOrder.CreateTime, |
| | | IsEn = true, |
| | | OpenId = user.WxOpenId, |
| | | OutDetailNumber = _redisService.Get32sn(), |
| | | |
| | | TransferAmount = (int)(moneylist * 100), |
| | | TransferRemark = "川印工资支付", |
| | | |
| | | }); |
| | | } |
| | | |
| | | TransferOrder.TotalAmount = (int)(Money * 100); |
| | | TransferOrder.TotalNum = TransferOrder.TransferDetailList.Count(); |
| | | |
| | | TransferOrder = await WeChatTransferOrderwork.AsSugarClient().InsertNav(TransferOrder).Include(x => x.TransferDetailList).ExecuteReturnEntityAsync(); |
| | | await UserTiXianDetailwork.InsertAsync(new UserTiXianDetail |
| | | { |
| | | CreateBy = uw.UserId.ToString(), |
| | | CreateTime = DateTime.Now, |
| | | UserId = user.Id, |
| | | ZhiChuShouRu = 0, |
| | | YiTiXianJine = Money, |
| | | WeChatTransferOrderID = TransferOrder.Id, |
| | | |
| | | }); |
| | | //钱包余额调整 |
| | | uw.YiTiXianJine += Money; |
| | | uw.UpDataBy = uw.UserId.ToString(); |
| | | uw.UpDataTime = DateTime.Now; |
| | | await rs.UpdateAsync(uw); |
| | | |
| | | |
| | | await UserTiXianDetailwork.AsTenant().CommitTranAsync(); |
| | | |
| | | totle += Money; |
| | | //设置每日提现限额 |
| | | _redisService.Add(StaticStringDef.TransferMoneyManKey + userid.ToString(), totle, 60 * 60 * 24); |
| | | //发起支付 |
| | | await InitQMessages.SendMessageAsync(InitQMessages.WxTransfer, TransferOrder.Id.ToString()); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | await UserTiXianDetailwork.AsTenant().RollbackTranAsync(); |
| | | throw; |
| | | } |
| | | // 发起支付 |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | finally |
| | | { |
| | | await _redisService.TryUnLock(StaticStringDef.TransferMoneyLockKey + userid.ToString()); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | var b = await InitQMessages.SendMessageAsync(InitQMessages.WxTransferMSQ, Money.ToString()); |
| | | if (b) |
| | | return; |
| | | else |
| | | throw Oops.Oh("请求失败"); |
| | | else |
| | | throw Oops.Oh("请不要频繁重复申请"); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取为支付列表 |
| | | /// </summary> |
| | | [AllowAnonymous] |
| | | [HttpPost] |
| | | [ApiExplorerSettings(IgnoreApi = true)] |
| | | public async Task<TransferOderOut> GetTransferOder(SearchTransferOder param) |
| | | { |
| | | |
| | | var WeChatTransferOrderwork = new BaseRepository<WeChatTransferOrder>(); |
| | | PageModel pageModel = new PageModel |
| | | { PageIndex = param.PageIndex, PageSize = param.PageSize }; |
| | | |
| | | |
| | | Expression<Func<WeChatTransferOrder, bool>> SearchList = (x) => true; |
| | | |
| | | |
| | | if (!string.IsNullOrEmpty(param.BatchStatus)) |
| | | { |
| | | SearchList= SearchList.And(x => x.BatchStatus.Contains(param.BatchStatus)); |
| | | } |
| | | if (!string.IsNullOrEmpty(param.NoTBatchStatus)) |
| | | { |
| | | var lisstring = param.NoTBatchStatus?.Split('|'); |
| | | foreach (var lis in lisstring) |
| | | { |
| | | SearchList= SearchList.And(x => x.BatchStatus != lis); |
| | | } |
| | | } |
| | | if (param.HasSendOk == false) |
| | | SearchList= SearchList.And(x => x.BatchId == null); |
| | | else |
| | | SearchList= SearchList.And(x => x.BatchId != null); |
| | | var data = await WeChatTransferOrderwork.GetPageListAsync(SearchList, pageModel); |
| | | |
| | | return new TransferOderOut |
| | | { |
| | | listdata = data, |
| | | TotalCount=pageModel.TotalCount, |
| | | }; |
| | | } |
| | | /// <summary> |
| | | /// 重新支付 |
| | | /// </summary> |
| | | /// <param name="Id"> 按订单批次操作</param> |
| | | /// <returns></returns> |
| | | [AllowAnonymous] |
| | | [HttpGet] |
| | | [ApiExplorerSettings(IgnoreApi = true)] |
| | | public async Task<bool> ReSendTransferOder([FromQuery] string ids) |
| | | { |
| | | var itmsRes = new BaseRepository<WeChatTransferOrder>(); |
| | | if (string.IsNullOrEmpty(ids)) |
| | | throw Oops.Oh("参数错误"); |
| | | var idsr= ids.Split(',').Select(x=>x.toInt()).ToList(); |
| | | |
| | | foreach (var id in idsr) |
| | | { |
| | | |
| | | |
| | | if (itmsRes.GetById(id) != null) |
| | | await InitQMessages.SendMessageAsync(InitQMessages.WxTransferAg, id.ToString()); |
| | | |
| | | |
| | | } |
| | | return true; |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class SearchTransferOder |
| | | { |
| | | |
| | | /// <summary> |
| | | /// 搜索状态值 模糊查询 |
| | | /// </summary> |
| | | public string BatchStatus { get; set; } |
| | | /// <summary> |
| | | /// 排除搜索值状态 要排除的状态值必须是全称,多个之间用 “|”间隔 |
| | | /// </summary> |
| | | public string NoTBatchStatus { get; set; } |
| | | /// <summary> |
| | | /// 是否已经成功发起了 |
| | | /// </summary> |
| | | public bool HasSendOk { get; set; } = false; |
| | | /// <summary> |
| | | /// 当前页码 |
| | | /// </summary> |
| | | public int PageIndex { get; set; } |
| | | /// <summary> |
| | | /// 页面大小 |
| | | /// </summary> |
| | | public int PageSize { get; set; } |
| | | |
| | | } |
| | | |
| | | public class TransferOderOut |
| | | { |
| | | public List<WeChatTransferOrder> listdata { get; set; } |
| | | public int TotalCount { get; set; } |
| | | } |
| | | |
| | | |
| | | } |