diff --git a/GDZZ.Application/GDZZ.Application.xml b/GDZZ.Application/GDZZ.Application.xml index 0b5c5fc..e2adc09 100644 --- a/GDZZ.Application/GDZZ.Application.xml +++ b/GDZZ.Application/GDZZ.Application.xml @@ -1246,6 +1246,19 @@ + + + 奖励重载 + + + + + + 奖励 + + + + diff --git a/GDZZ.Application/Service/Auth/AuthService.cs b/GDZZ.Application/Service/Auth/AuthService.cs index 73aceb8..3395a39 100644 --- a/GDZZ.Application/Service/Auth/AuthService.cs +++ b/GDZZ.Application/Service/Auth/AuthService.cs @@ -43,6 +43,8 @@ namespace GDZZ.Application.Service.Auth private readonly WechatOAuth _wechatOAuth; //微信权限服务 private readonly IHttpContextAccessor _httpContextAccessor; //http服务 private readonly IEventPublisher _eventPublisher; //事件写入服务 + private readonly SqlSugarRepository invitaitionRey; + private readonly SqlSugarRepository rechargeRep; //充值仓储 #endregion /// /// 获取配置文件 @@ -60,7 +62,9 @@ namespace GDZZ.Application.Service.Auth SqlSugarRepository CompanyRep, SqlSugarRepository payTakeRep, SqlSugarRepository sysConfigRep, - ISysCacheService sysCacheService, + SqlSugarRepository invitaitionRey, + SqlSugarRepository rechargeRep, + ISysCacheService sysCacheService, ICacheService cacheService, WechatOAuth wechatOAuth, IEventPublisher eventPublisher, @@ -77,6 +81,8 @@ namespace GDZZ.Application.Service.Auth this.payTakeRep = payTakeRep; this._sysCacheService= sysCacheService; this._sysConfigRep= sysConfigRep; + this.invitaitionRey = invitaitionRey; + this.rechargeRep= rechargeRep; _wechatOAuth = wechatOAuth; _oauthConfig = options.Value.Wechat; } @@ -94,9 +100,9 @@ namespace GDZZ.Application.Service.Auth Company company = new Company(); //读取凭证 - var tokenModel = await this._wechatOAuth.GetCode2SessionAsync(phoneModel.code); + var tokenModel = await this._wechatOAuth.GetCode2SessionAsync(phoneModel.Code); //解析电话 - var phoneInfo = MiniProgramUtil.AESDecrypt(phoneModel.encryptedDataStr, tokenModel.SessionKey, phoneModel.iv); + var phoneInfo = MiniProgramUtil.AESDecrypt(phoneModel.EncryptedDataStr, tokenModel.SessionKey, phoneModel.Iv); //查询系统用户 var sysUser = this._sysUserRep.AsQueryable() @@ -136,7 +142,7 @@ namespace GDZZ.Application.Service.Auth } //区分不同类型账号 - if (phoneModel.logInType ==(int)UserEnum.JOB) + if (phoneModel.LogInType ==(int)UserEnum.JOB) { if (wxUser.IsEmpty()) { @@ -178,9 +184,32 @@ namespace GDZZ.Application.Service.Auth } if (wxUser.IsEmpty() || sysUser.IsEmpty()) throw Oops.Oh(ErrorCode.xg1002); + //判断是否存在邀请 + if(phoneModel.Scene != null) + { + //判断当前用户是否被邀请过 + var invi = await this.invitaitionRey.FirstOrDefaultAsync(x => x.UserID == UserManager.UserId); + if (invi.IsNullOrZero()) + { + var invres = await this.invitaitionRey.FirstOrDefaultAsync(x => x.InviteID == phoneModel.Scene); + //未被邀请 + var invrey = await this.invitaitionRey.InsertAsync(new InviteUserPos() + { + UserID = UserManager.UserId, + InviteUserID = (long)phoneModel.Scene, + InviteID = invres.InviteID + }); + if (invrey > 0) + { + //附加奖励给邀请人 + UtilService utilService = new UtilService(this.rechargeRep); + utilService.Reward((long)phoneModel.Scene, 1); + } + } - + } + var Self = await this.Self.FirstOrDefaultAsync(x => x.CreatedUserId == sysUser.Id); // 获取加密后的密码 @@ -249,14 +278,14 @@ namespace GDZZ.Application.Service.Auth Company company = new Company(); AuthUserOut authUserOut = new AuthUserOut(); //验证电话和验证码一致 - var verIfy = await this.cacheService.GetVerifyCode(phoneModel.phone); - if (verIfy != phoneModel.checkingCode) + var verIfy = await this.cacheService.GetVerifyCode(phoneModel.Phone); + if (verIfy != phoneModel.CheckingCode) throw new Exception("验证码错误"); //查询系统用户 var sysUser = this._sysUserRep.AsQueryable() .Filter("TenantId", true) - .First(x => x.Phone == phoneModel.phone.ToString()); + .First(x => x.Phone == phoneModel.Phone.ToString()); //账号不存在 生成系统账号 @@ -264,7 +293,7 @@ namespace GDZZ.Application.Service.Auth { sysUser = await this._sysUserRep.InsertReturnEntityAsync(new SysUser() { - Account = phoneModel.phone.ToString(), + Account = phoneModel.Phone.ToString(), AdminType = AdminType.None, Avatar = "https://gdzongzhi.com/assets/img/logo.png", Birthday = DateTime.Now, @@ -275,10 +304,10 @@ namespace GDZZ.Application.Service.Auth Status = CommonStatus.ENABLE, Email = null, IsDeleted = false, - Name = phoneModel.phone.ToString(), + Name = phoneModel.Phone.ToString(), Password = MD5Encryption.Encrypt("123456"), TenantId = 392820661919813, - Phone = phoneModel.phone.ToString(), + Phone = phoneModel.Phone.ToString(), NickName = "", Tel = null, }); @@ -286,7 +315,7 @@ namespace GDZZ.Application.Service.Auth //读取凭证 - var tokenModel = await this._wechatOAuth.GetCode2SessionAsync(phoneModel.code); + var tokenModel = await this._wechatOAuth.GetCode2SessionAsync(phoneModel.Code); var wxUser = await this.Baseuser.AsQueryable() .Filter("TenantId", true) @@ -294,7 +323,7 @@ namespace GDZZ.Application.Service.Auth //区分不同类型账号 - if (phoneModel.logInType == (int)UserEnum.JOB) + if (phoneModel.LogInType == (int)UserEnum.JOB) { if (wxUser.IsEmpty()) { @@ -309,7 +338,7 @@ namespace GDZZ.Application.Service.Auth OpenID = tokenModel.OpenId, TenantId = 392820661919813, Type = (int)UserEnum.JOB, - UserName = phoneModel.phone.ToString(), + UserName = phoneModel.Phone.ToString(), }); } else diff --git a/GDZZ.Application/Service/InvitationCode/InvitationCodeService.cs b/GDZZ.Application/Service/InvitationCode/InvitationCodeService.cs index 9bafc60..f5f0068 100644 --- a/GDZZ.Application/Service/InvitationCode/InvitationCodeService.cs +++ b/GDZZ.Application/Service/InvitationCode/InvitationCodeService.cs @@ -13,6 +13,8 @@ using Furion.FriendlyException; using System; using GDZZ.Core.Entity; using System.Collections.Generic; +using GDZZ.Application.Service.WXPay; +using GDZZ.Application.Service; namespace GDZZ.Application { @@ -127,15 +129,19 @@ namespace GDZZ.Application if (incode.IsNullOrZero()) throw Oops.Oh("无此邀请码!"); - //奖励 + UtilService utilService = new UtilService(this.rechargeRep); - - this.inviteUserPosrep.Insert(new InviteUserPos() + + var res = this.inviteUserPosrep.Insert(new InviteUserPos() { InviteID = incode.Id, InviteUserID = (long)incode.CreatedUserId, UserID = UserManager.UserId, }); + if (res < 1) + throw Oops.Oh("填写邀请码失败!"); + //发放奖励 + utilService.Reward(UserManager.UserId, 1); } @@ -155,5 +161,7 @@ namespace GDZZ.Application } + + } } diff --git a/GDZZ.Application/Service/UtilService.cs b/GDZZ.Application/Service/UtilService.cs new file mode 100644 index 0000000..4ba3c5d --- /dev/null +++ b/GDZZ.Application/Service/UtilService.cs @@ -0,0 +1,49 @@ +using Furion.FriendlyException; +using GDZZ.Application.Entity; +using GDZZ.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GDZZ.Application.Service +{ + public class UtilService + { + + private readonly SqlSugarRepository rechargeRep; //充值仓储 + + /// + /// 奖励重载 + /// + /// + public UtilService(SqlSugarRepository rechargeRep) + { + this.rechargeRep = rechargeRep; + } + + + + /// + /// 奖励 + /// + /// + /// + public async void Reward(long userID, decimal prize) + { + + var recharge = await this.rechargeRep.InsertAsync(new MiniRecharge() + { + CreatedUserId = userID, + PaymentMoney = prize, + Status = (int)RechargeEnum.Finish, + Type = (int)RechargeTypeEnum.Reward, + TotalPrice = prize + }); + if (recharge < 1) + throw Oops.Oh("奖励发放失败!"); + + } + } +} diff --git a/GDZZ.Application/Service/WXPay/WXPayService.cs b/GDZZ.Application/Service/WXPay/WXPayService.cs index 80cb57d..1361bbc 100644 --- a/GDZZ.Application/Service/WXPay/WXPayService.cs +++ b/GDZZ.Application/Service/WXPay/WXPayService.cs @@ -24,6 +24,7 @@ using System.Collections.Generic; using Mapster; using Furion.FriendlyException; using Senparc.CO2NET.Cache.Redis; +using GDZZ.Core.Service; namespace GDZZ.Application.Service.WXPay { @@ -473,6 +474,8 @@ namespace GDZZ.Application.Service.WXPay #endregion } + + #endregion } } diff --git a/GDZZ.Core/GDZZ.Core.xml b/GDZZ.Core/GDZZ.Core.xml index ade3d7d..510e34b 100644 --- a/GDZZ.Core/GDZZ.Core.xml +++ b/GDZZ.Core/GDZZ.Core.xml @@ -3580,26 +3580,41 @@ 是否租户管理员 - + 登录类型 - + + + + + + + + + + + 验证码 - + 登录code - + 手机号码 + + + 邀请标志 + + AccessToken参数 diff --git a/GDZZ.Core/Hubs/ChatHub.cs b/GDZZ.Core/Hubs/ChatHub.cs index 5febd6d..52467e9 100644 --- a/GDZZ.Core/Hubs/ChatHub.cs +++ b/GDZZ.Core/Hubs/ChatHub.cs @@ -31,6 +31,7 @@ public class ChatHub : Hub /// public override async Task OnConnectedAsync() { + Console.WriteLine("上线连接"); var token = Context.GetHttpContext().Request.Query["access_token"]; var claims = JWTEncryption.ReadJwtToken(token)?.Claims; var userId = claims.FirstOrDefault(e => e.Type == ClaimConst.CLAINM_USERID)?.Value; @@ -42,16 +43,16 @@ public class ChatHub : Hub await _sysOnlineUerRep.DeleteAsync(m => m.Account == account && m.LastLoginIp == ip); } - OnlineUser user = new OnlineUser() { - ConnectionId = Context.ConnectionId, - UserId = long.Parse(userId), - LastTime = DateTime.Now, - LastLoginIp= ip, - Account= account, - Name=name, - TenantId=Convert.ToInt64(tenantId) - }; - await _sysOnlineUerRep.InsertAsync(user); + //OnlineUser user = new OnlineUser() { + // ConnectionId = Context.ConnectionId, + // UserId = long.Parse(userId), + // LastTime = DateTime.Now, + // LastLoginIp= ip, + // Account= account, + // Name=name, + // TenantId=Convert.ToInt64(tenantId) + //}; + //await _sysOnlineUerRep.InsertAsync(user); } /// diff --git a/GDZZ.Core/OAuth/PhoneModel.cs b/GDZZ.Core/OAuth/PhoneModel.cs index d793958..6f24fcb 100644 --- a/GDZZ.Core/OAuth/PhoneModel.cs +++ b/GDZZ.Core/OAuth/PhoneModel.cs @@ -12,26 +12,37 @@ namespace GDZZ.Core.OAuth /// /// 登录类型 /// - public int logInType { get; set; } + public int LogInType { get; set; } - public string encryptedDataStr { get; set; } + /// + /// + /// + public string EncryptedDataStr { get; set; } - public string iv { get; set; } + /// + /// + /// + public string Iv { get; set; } /// /// 验证码 /// - public string checkingCode { get; set; } + public string CheckingCode { get; set; } /// /// 登录code /// - public string code { get; set; } + public string Code { get; set; } /// /// 手机号码 /// - public string phone { get; set; } + public string Phone { get; set; } + + /// + /// 邀请标志 + /// + public long? Scene { get; set; } } diff --git a/GDZZ.Core/OAuth/WechatOAuth.cs b/GDZZ.Core/OAuth/WechatOAuth.cs index 14c9baf..2246f5c 100644 --- a/GDZZ.Core/OAuth/WechatOAuth.cs +++ b/GDZZ.Core/OAuth/WechatOAuth.cs @@ -41,7 +41,7 @@ public class WechatOAuth : IWechatOAuth, ISingleton { ["appid"] = _oauthConfig.app_id, ["redirect_uri"] = _oauthConfig.redirect_uri, - ["response_type"] = "code", + ["response_type"] = "Code", ["scope"] = _oauthConfig.scope, ["state"] = state }; diff --git a/GDZZ.Web.Core/Startup.cs b/GDZZ.Web.Core/Startup.cs index 88f2e9f..468c5d3 100644 --- a/GDZZ.Web.Core/Startup.cs +++ b/GDZZ.Web.Core/Startup.cs @@ -171,6 +171,7 @@ public class Startup : AppStartup app.UseEndpoints(endpoints => { endpoints.MapHub("/hubs/chathub"); + endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");