修改即时通讯问题

development
温天培 1 year ago
parent 703a0db421
commit c0b827dd1c

@ -1246,6 +1246,19 @@
<param name="phoneModel"></param> <param name="phoneModel"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:GDZZ.Application.Service.UtilService.#ctor(GDZZ.Core.SqlSugarRepository{GDZZ.Application.Entity.MiniRecharge})">
<summary>
奖励重载
</summary>
<param name="rechargeRep"></param>
</member>
<member name="M:GDZZ.Application.Service.UtilService.Reward(System.Int64,System.Decimal)">
<summary>
奖励
</summary>
<param name="userID"></param>
<param name="prize"></param>
</member>
<member name="T:GDZZ.Application.Service.WXPay.Dto.BalanceOut"> <member name="T:GDZZ.Application.Service.WXPay.Dto.BalanceOut">
<summary> <summary>

@ -43,6 +43,8 @@ namespace GDZZ.Application.Service.Auth
private readonly WechatOAuth _wechatOAuth; //微信权限服务 private readonly WechatOAuth _wechatOAuth; //微信权限服务
private readonly IHttpContextAccessor _httpContextAccessor; //http服务 private readonly IHttpContextAccessor _httpContextAccessor; //http服务
private readonly IEventPublisher _eventPublisher; //事件写入服务 private readonly IEventPublisher _eventPublisher; //事件写入服务
private readonly SqlSugarRepository<InviteUserPos> invitaitionRey;
private readonly SqlSugarRepository<MiniRecharge> rechargeRep; //充值仓储
#endregion #endregion
/// <summary> /// <summary>
/// 获取配置文件 /// 获取配置文件
@ -60,6 +62,8 @@ namespace GDZZ.Application.Service.Auth
SqlSugarRepository<Company> CompanyRep, SqlSugarRepository<Company> CompanyRep,
SqlSugarRepository<MiniPayTake> payTakeRep, SqlSugarRepository<MiniPayTake> payTakeRep,
SqlSugarRepository<SysConfig> sysConfigRep, SqlSugarRepository<SysConfig> sysConfigRep,
SqlSugarRepository<InviteUserPos> invitaitionRey,
SqlSugarRepository<MiniRecharge> rechargeRep,
ISysCacheService sysCacheService, ISysCacheService sysCacheService,
ICacheService cacheService, ICacheService cacheService,
WechatOAuth wechatOAuth, WechatOAuth wechatOAuth,
@ -77,6 +81,8 @@ namespace GDZZ.Application.Service.Auth
this.payTakeRep = payTakeRep; this.payTakeRep = payTakeRep;
this._sysCacheService= sysCacheService; this._sysCacheService= sysCacheService;
this._sysConfigRep= sysConfigRep; this._sysConfigRep= sysConfigRep;
this.invitaitionRey = invitaitionRey;
this.rechargeRep= rechargeRep;
_wechatOAuth = wechatOAuth; _wechatOAuth = wechatOAuth;
_oauthConfig = options.Value.Wechat; _oauthConfig = options.Value.Wechat;
} }
@ -94,9 +100,9 @@ namespace GDZZ.Application.Service.Auth
Company company = new Company(); 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() 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()) if (wxUser.IsEmpty())
{ {
@ -178,8 +184,31 @@ namespace GDZZ.Application.Service.Auth
} }
if (wxUser.IsEmpty() || sysUser.IsEmpty()) if (wxUser.IsEmpty() || sysUser.IsEmpty())
throw Oops.Oh(ErrorCode.xg1002); 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); var Self = await this.Self.FirstOrDefaultAsync(x => x.CreatedUserId == sysUser.Id);
@ -249,14 +278,14 @@ namespace GDZZ.Application.Service.Auth
Company company = new Company(); Company company = new Company();
AuthUserOut authUserOut = new AuthUserOut(); AuthUserOut authUserOut = new AuthUserOut();
//验证电话和验证码一致 //验证电话和验证码一致
var verIfy = await this.cacheService.GetVerifyCode(phoneModel.phone); var verIfy = await this.cacheService.GetVerifyCode(phoneModel.Phone);
if (verIfy != phoneModel.checkingCode) if (verIfy != phoneModel.CheckingCode)
throw new Exception("验证码错误"); throw new Exception("验证码错误");
//查询系统用户 //查询系统用户
var sysUser = this._sysUserRep.AsQueryable() var sysUser = this._sysUserRep.AsQueryable()
.Filter("TenantId", true) .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() sysUser = await this._sysUserRep.InsertReturnEntityAsync(new SysUser()
{ {
Account = phoneModel.phone.ToString(), Account = phoneModel.Phone.ToString(),
AdminType = AdminType.None, AdminType = AdminType.None,
Avatar = "https://gdzongzhi.com/assets/img/logo.png", Avatar = "https://gdzongzhi.com/assets/img/logo.png",
Birthday = DateTime.Now, Birthday = DateTime.Now,
@ -275,10 +304,10 @@ namespace GDZZ.Application.Service.Auth
Status = CommonStatus.ENABLE, Status = CommonStatus.ENABLE,
Email = null, Email = null,
IsDeleted = false, IsDeleted = false,
Name = phoneModel.phone.ToString(), Name = phoneModel.Phone.ToString(),
Password = MD5Encryption.Encrypt("123456"), Password = MD5Encryption.Encrypt("123456"),
TenantId = 392820661919813, TenantId = 392820661919813,
Phone = phoneModel.phone.ToString(), Phone = phoneModel.Phone.ToString(),
NickName = "", NickName = "",
Tel = null, 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() var wxUser = await this.Baseuser.AsQueryable()
.Filter("TenantId", true) .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()) if (wxUser.IsEmpty())
{ {
@ -309,7 +338,7 @@ namespace GDZZ.Application.Service.Auth
OpenID = tokenModel.OpenId, OpenID = tokenModel.OpenId,
TenantId = 392820661919813, TenantId = 392820661919813,
Type = (int)UserEnum.JOB, Type = (int)UserEnum.JOB,
UserName = phoneModel.phone.ToString(), UserName = phoneModel.Phone.ToString(),
}); });
} }
else else

@ -13,6 +13,8 @@ using Furion.FriendlyException;
using System; using System;
using GDZZ.Core.Entity; using GDZZ.Core.Entity;
using System.Collections.Generic; using System.Collections.Generic;
using GDZZ.Application.Service.WXPay;
using GDZZ.Application.Service;
namespace GDZZ.Application namespace GDZZ.Application
{ {
@ -127,15 +129,19 @@ namespace GDZZ.Application
if (incode.IsNullOrZero()) if (incode.IsNullOrZero())
throw Oops.Oh("无此邀请码!"); throw Oops.Oh("无此邀请码!");
//奖励 UtilService utilService = new UtilService(this.rechargeRep);
this.inviteUserPosrep.Insert(new InviteUserPos() var res = this.inviteUserPosrep.Insert(new InviteUserPos()
{ {
InviteID = incode.Id, InviteID = incode.Id,
InviteUserID = (long)incode.CreatedUserId, InviteUserID = (long)incode.CreatedUserId,
UserID = UserManager.UserId, UserID = UserManager.UserId,
}); });
if (res < 1)
throw Oops.Oh("填写邀请码失败!");
//发放奖励
utilService.Reward(UserManager.UserId, 1);
} }
@ -155,5 +161,7 @@ namespace GDZZ.Application
} }
} }
} }

@ -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<MiniRecharge> rechargeRep; //充值仓储
/// <summary>
/// 奖励重载
/// </summary>
/// <param name="rechargeRep"></param>
public UtilService(SqlSugarRepository<MiniRecharge> rechargeRep)
{
this.rechargeRep = rechargeRep;
}
/// <summary>
/// 奖励
/// </summary>
/// <param name="userID"></param>
/// <param name="prize"></param>
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("奖励发放失败!");
}
}
}

@ -24,6 +24,7 @@ using System.Collections.Generic;
using Mapster; using Mapster;
using Furion.FriendlyException; using Furion.FriendlyException;
using Senparc.CO2NET.Cache.Redis; using Senparc.CO2NET.Cache.Redis;
using GDZZ.Core.Service;
namespace GDZZ.Application.Service.WXPay namespace GDZZ.Application.Service.WXPay
{ {
@ -473,6 +474,8 @@ namespace GDZZ.Application.Service.WXPay
#endregion #endregion
} }
#endregion #endregion
} }
} }

@ -3580,26 +3580,41 @@
是否租户管理员 是否租户管理员
</summary> </summary>
</member> </member>
<member name="P:GDZZ.Core.OAuth.PhoneModel.logInType"> <member name="P:GDZZ.Core.OAuth.PhoneModel.LogInType">
<summary> <summary>
登录类型 登录类型
</summary> </summary>
</member> </member>
<member name="P:GDZZ.Core.OAuth.PhoneModel.checkingCode"> <member name="P:GDZZ.Core.OAuth.PhoneModel.EncryptedDataStr">
<summary>
</summary>
</member>
<member name="P:GDZZ.Core.OAuth.PhoneModel.Iv">
<summary>
</summary>
</member>
<member name="P:GDZZ.Core.OAuth.PhoneModel.CheckingCode">
<summary> <summary>
验证码 验证码
</summary> </summary>
</member> </member>
<member name="P:GDZZ.Core.OAuth.PhoneModel.code"> <member name="P:GDZZ.Core.OAuth.PhoneModel.Code">
<summary> <summary>
登录code 登录code
</summary> </summary>
</member> </member>
<member name="P:GDZZ.Core.OAuth.PhoneModel.phone"> <member name="P:GDZZ.Core.OAuth.PhoneModel.Phone">
<summary> <summary>
手机号码 手机号码
</summary> </summary>
</member> </member>
<member name="P:GDZZ.Core.OAuth.PhoneModel.Scene">
<summary>
邀请标志
</summary>
</member>
<member name="T:GDZZ.Core.TokenModel"> <member name="T:GDZZ.Core.TokenModel">
<summary> <summary>
AccessToken参数 AccessToken参数

@ -31,6 +31,7 @@ public class ChatHub : Hub<IChatClient>
/// <returns></returns> /// <returns></returns>
public override async Task OnConnectedAsync() public override async Task OnConnectedAsync()
{ {
Console.WriteLine("上线连接");
var token = Context.GetHttpContext().Request.Query["access_token"]; var token = Context.GetHttpContext().Request.Query["access_token"];
var claims = JWTEncryption.ReadJwtToken(token)?.Claims; var claims = JWTEncryption.ReadJwtToken(token)?.Claims;
var userId = claims.FirstOrDefault(e => e.Type == ClaimConst.CLAINM_USERID)?.Value; var userId = claims.FirstOrDefault(e => e.Type == ClaimConst.CLAINM_USERID)?.Value;
@ -42,16 +43,16 @@ public class ChatHub : Hub<IChatClient>
await _sysOnlineUerRep.DeleteAsync(m => m.Account == account && m.LastLoginIp == ip); await _sysOnlineUerRep.DeleteAsync(m => m.Account == account && m.LastLoginIp == ip);
} }
OnlineUser user = new OnlineUser() { //OnlineUser user = new OnlineUser() {
ConnectionId = Context.ConnectionId, // ConnectionId = Context.ConnectionId,
UserId = long.Parse(userId), // UserId = long.Parse(userId),
LastTime = DateTime.Now, // LastTime = DateTime.Now,
LastLoginIp= ip, // LastLoginIp= ip,
Account= account, // Account= account,
Name=name, // Name=name,
TenantId=Convert.ToInt64(tenantId) // TenantId=Convert.ToInt64(tenantId)
}; //};
await _sysOnlineUerRep.InsertAsync(user); //await _sysOnlineUerRep.InsertAsync(user);
} }
/// <summary> /// <summary>

@ -12,26 +12,37 @@ namespace GDZZ.Core.OAuth
/// <summary> /// <summary>
/// 登录类型 /// 登录类型
/// </summary> /// </summary>
public int logInType { get; set; } public int LogInType { get; set; }
public string encryptedDataStr { get; set; } /// <summary>
///
/// </summary>
public string EncryptedDataStr { get; set; }
public string iv { get; set; } /// <summary>
///
/// </summary>
public string Iv { get; set; }
/// <summary> /// <summary>
/// 验证码 /// 验证码
/// </summary> /// </summary>
public string checkingCode { get; set; } public string CheckingCode { get; set; }
/// <summary> /// <summary>
/// 登录code /// 登录code
/// </summary> /// </summary>
public string code { get; set; } public string Code { get; set; }
/// <summary> /// <summary>
/// 手机号码 /// 手机号码
/// </summary> /// </summary>
public string phone { get; set; } public string Phone { get; set; }
/// <summary>
/// 邀请标志
/// </summary>
public long? Scene { get; set; }
} }

@ -41,7 +41,7 @@ public class WechatOAuth : IWechatOAuth, ISingleton
{ {
["appid"] = _oauthConfig.app_id, ["appid"] = _oauthConfig.app_id,
["redirect_uri"] = _oauthConfig.redirect_uri, ["redirect_uri"] = _oauthConfig.redirect_uri,
["response_type"] = "code", ["response_type"] = "Code",
["scope"] = _oauthConfig.scope, ["scope"] = _oauthConfig.scope,
["state"] = state ["state"] = state
}; };

@ -171,6 +171,7 @@ public class Startup : AppStartup
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
endpoints.MapHub<ChatHub>("/hubs/chathub"); endpoints.MapHub<ChatHub>("/hubs/chathub");
endpoints.MapControllerRoute( endpoints.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");

Loading…
Cancel
Save