新增邀请码

development
温天培 2 years ago
parent bc4d606448
commit d201c7fdf2

@ -0,0 +1,23 @@
using System;
using SqlSugar;
using System.ComponentModel;
using GDZZ.Core.Entity;
namespace GDZZ.Application.Entity
{
/// <summary>
/// 邀请码表
/// </summary>
[SugarTable("InvitationCode")]
[Description("邀请码表")]
public class InvitationCode : DEntityBase
{
/// <summary>
/// 企业ID
/// </summary>
public long EnterpriseID { get; set; }
/// <summary>
/// 邀请码
/// </summary>
public long InviteCode { get; set; }
}
}

@ -0,0 +1,27 @@
using System;
using SqlSugar;
using System.ComponentModel;
using GDZZ.Core.Entity;
namespace GDZZ.Application.Entity
{
/// <summary>
/// 邀请用户表
/// </summary>
[SugarTable("Invite_user_pos")]
[Description("邀请用户表")]
public class InviteUserPos : PrimaryKeyEntity
{
/// <summary>
/// 邀请码ID
/// </summary>
public long InviteID { get; set; }
/// <summary>
/// 被邀请用户ID
/// </summary>
public long UserID { get; set; }
/// <summary>
/// 邀请人ID
/// </summary>
public long InviteUserID { get; set; }
}
}

@ -16,6 +16,7 @@
<ItemGroup>
<None Remove="applicationsettings.json" />
<None Remove="Entity\ public class Balance " />
<None Remove="GDZZ.Application.xml" />
</ItemGroup>

@ -199,6 +199,41 @@
反馈意见
</summary>
</member>
<member name="T:GDZZ.Application.Entity.InvitationCode">
<summary>
邀请码表
</summary>
</member>
<member name="P:GDZZ.Application.Entity.InvitationCode.EnterpriseID">
<summary>
企业ID
</summary>
</member>
<member name="P:GDZZ.Application.Entity.InvitationCode.InviteCode">
<summary>
邀请码
</summary>
</member>
<member name="T:GDZZ.Application.Entity.InviteUserPos">
<summary>
邀请用户表
</summary>
</member>
<member name="P:GDZZ.Application.Entity.InviteUserPos.InviteID">
<summary>
邀请码ID
</summary>
</member>
<member name="P:GDZZ.Application.Entity.InviteUserPos.UserID">
<summary>
被邀请用户ID
</summary>
</member>
<member name="P:GDZZ.Application.Entity.InviteUserPos.InviteUserID">
<summary>
邀请人ID
</summary>
</member>
<member name="T:GDZZ.Application.Entity.LiveHistoryContacts">
<summary>
聊天历史任务列表
@ -706,6 +741,20 @@
</summary>
<returns></returns>
</member>
<member name="M:GDZZ.Application.Help.Utils.ShowHelp(System.DateTime)">
<summary>
</summary>
<param name="date"></param>
<returns></returns>
</member>
<member name="M:GDZZ.Application.Help.Utils.Encode(System.Int64)">
<summary>
根据ID生成六位随机邀请码
</summary>
<param name="id">用户id</param>
<returns>返回6位邀请码</returns>
</member>
<member name="F:GDZZ.Application.Service.Auth.AuthService._oauthConfig">
<summary>
获取配置文件
@ -1558,6 +1607,104 @@
<param name="backInput"></param>
<returns></returns>
</member>
<member name="T:GDZZ.Application.InvitationCodeDto">
<summary>
邀请码表输出参数
</summary>
</member>
<member name="P:GDZZ.Application.InvitationCodeDto.Id">
<summary>
主键Id
</summary>
</member>
<member name="P:GDZZ.Application.InvitationCodeDto.EnterpriseID">
<summary>
企业ID
</summary>
</member>
<member name="P:GDZZ.Application.InvitationCodeDto.Code">
<summary>
邀请码
</summary>
</member>
<member name="T:GDZZ.Application.InvitationCodeInput">
<summary>
邀请码表输入参数
</summary>
</member>
<member name="P:GDZZ.Application.InvitationCodeInput.EnterpriseID">
<summary>
企业ID
</summary>
</member>
<member name="P:GDZZ.Application.InvitationCodeInput.InviteCode">
<summary>
邀请码
</summary>
</member>
<member name="P:GDZZ.Application.DeleteInvitationCodeInput.Id">
<summary>
主键Id
</summary>
</member>
<member name="P:GDZZ.Application.UpdateInvitationCodeInput.Id">
<summary>
主键Id
</summary>
</member>
<member name="T:GDZZ.Application.InvitationCodeOutput">
<summary>
邀请码表输出参数
</summary>
</member>
<member name="P:GDZZ.Application.InvitationCodeOutput.Id">
<summary>
主键Id
</summary>
</member>
<member name="P:GDZZ.Application.InvitationCodeOutput.EnterpriseID">
<summary>
企业ID
</summary>
</member>
<member name="P:GDZZ.Application.InvitationCodeOutput.Code">
<summary>
邀请码
</summary>
</member>
<member name="T:GDZZ.Application.InvitationCodeService">
<summary>
邀请码表服务
</summary>
</member>
<member name="M:GDZZ.Application.InvitationCodeService.AddOrUpdate(GDZZ.Application.AddInvitationCodeInput)">
<summary>
获取邀请码
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:GDZZ.Application.InvitationCodeService.Get(GDZZ.Application.QueryeInvitationCodeInput)">
<summary>
获取邀请码详情
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:GDZZ.Application.InvitationCodeService.GetPNumber">
<summary>
获取邀请人数
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:GDZZ.Application.InvitationCodeService.Receive(GDZZ.Application.AddInvitationCodeInput)">
<summary>
填写邀请码
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:GDZZ.Application.LiveHistoryContactsDto">
<summary>
聊天历史任务列表输出参数

@ -1,13 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace GDZZ.Application.Help
{
public class Utils
public static class Utils
{
//自定义进制(0、O没有加入,容易混淆同时排除X,用X补位)
private static char[] r = new char[] { 'Q', 'W', 'E', '8', 'A', 'S', '2', 'D', 'Z', '9', 'C', '7', 'P', '5', 'I', 'K', '3', 'M', 'J', 'U', 'F', 'R', '4', 'V', 'Y', 'L', 'T', 'N', '6', 'B', 'G', 'H' };
//不能与自定义进制有重复
private static char b = 'X';
//进制长度
private static int binLen = r.Length;
//生成的邀请码长度
private static int length = 6;
static Random random = new Random();
/// <summary>
///
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static bool ShowHelp(DateTime date)
{
bool isTheDay = false;
@ -27,5 +44,48 @@ namespace GDZZ.Application.Help
}
return isTheDay;
}
/// <summary>
/// 根据ID生成六位随机邀请码
/// </summary>
/// <param name="id">用户id</param>
/// <returns>返回6位邀请码</returns>
public static string Encode(long id)
{
char[] buf = new char[32];
int charPos = 32;
while ((id / binLen) > 0)
{
int ind = (int)(id % binLen);
buf[--charPos] = r[ind];
id /= binLen;
}
buf[--charPos] = r[(int)(id % binLen)];
String str = new String(buf, charPos, (32 - charPos));
//不够长度的自动随机补全
if (str.Length < length)
{
StringBuilder sb = new StringBuilder();
sb.Append(b);
Random rnd = new Random();
for (int i = 1; i < length - str.Length; i++)
{
sb.Append(r[rnd.Next(binLen)]);
}
str += sb.ToString();
}
return str;
}
public static long NextLong(long minValue, long maxValue)
{
byte[] buffer = new byte[8];
random.NextBytes(buffer);
long result = BitConverter.ToInt64(buffer, 0);
return (Math.Abs(result % (maxValue - minValue)) + minValue);
}
}
}

@ -0,0 +1,27 @@
using System;
using GDZZ.Core;
namespace GDZZ.Application
{
/// <summary>
/// 邀请码表输出参数
/// </summary>
public class InvitationCodeDto
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 企业ID
/// </summary>
public long EnterpriseID { get; set; }
/// <summary>
/// 邀请码
/// </summary>
public long Code { get; set; }
}
}

@ -0,0 +1,53 @@
using GDZZ.Core;
using System;
using System.ComponentModel.DataAnnotations;
namespace GDZZ.Application
{
/// <summary>
/// 邀请码表输入参数
/// </summary>
public class InvitationCodeInput : PageInputBase
{
/// <summary>
/// 企业ID
/// </summary>
public virtual long EnterpriseID { get; set; }
/// <summary>
/// 邀请码
/// </summary>
public long InviteCode { get; set; }
}
public class AddInvitationCodeInput : InvitationCodeInput
{
}
public class DeleteInvitationCodeInput
{
/// <summary>
/// 主键Id
/// </summary>
[Required(ErrorMessage = "主键Id不能为空")]
public long Id { get; set; }
}
public class UpdateInvitationCodeInput : InvitationCodeInput
{
/// <summary>
/// 主键Id
/// </summary>
[Required(ErrorMessage = "主键Id不能为空")]
public long Id { get; set; }
}
public class QueryeInvitationCodeInput : DeleteInvitationCodeInput
{
}
}

@ -0,0 +1,26 @@
using System;
namespace GDZZ.Application
{
/// <summary>
/// 邀请码表输出参数
/// </summary>
public class InvitationCodeOutput
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 企业ID
/// </summary>
public long EnterpriseID { get; set; }
/// <summary>
/// 邀请码
/// </summary>
public long Code { get; set; }
}
}

@ -0,0 +1,13 @@
using GDZZ.Core;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
namespace GDZZ.Application
{
public interface IInvitationCodeService
{
Task AddOrUpdate(AddInvitationCodeInput input);
Task<InvitationCode> Get([FromQuery] QueryeInvitationCodeInput input);
}
}

@ -0,0 +1,130 @@
using GDZZ.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
using GDZZ.Application.Help;
using Furion.DistributedIDGenerator;
using Furion.FriendlyException;
using System;
namespace GDZZ.Application
{
/// <summary>
/// 邀请码表服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "InvitationCode", Order = 1)]
public class InvitationCodeService : IInvitationCodeService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<InvitationCode> _rep;
private readonly SqlSugarRepository<InviteUserPos> inviteUserPosrep;
public InvitationCodeService(SqlSugarRepository<InvitationCode> rep, SqlSugarRepository<InviteUserPos> inviteUserPosrep)
{
_rep = rep;
this.inviteUserPosrep = inviteUserPosrep;
}
/// <summary>
/// 获取邀请码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/InvitationCode/AddOrUpdate")]
public async Task AddOrUpdate(AddInvitationCodeInput input)
{
var entity = input.Adapt<InvitationCode>();
var first = await this._rep.FirstOrDefaultAsync(x => x.InviteCode == entity.InviteCode);
if (first.IsNullOrZero())
{
entity.InviteCode = Utils.NextLong(0, 100000000);
entity.EnterpriseID = UserManager.UserId;
var incode = await this._rep.FirstOrDefaultAsync(x => x.InviteCode == entity.InviteCode);
if (incode.IsNullOrZero())
await _rep.InsertAsync(entity);
}
else
{
first.InviteCode = Utils.NextLong(0, 100000000);
await _rep.AsUpdateable(first).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
}
/// <summary>
/// 获取邀请码详情
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/InvitationCode/Detail")]
public async Task<InvitationCode> Get([FromQuery] QueryeInvitationCodeInput input)
{
var invitation = await _rep.FirstOrDefaultAsync(u => u.CreatedUserId == UserManager.UserId);
if (invitation == null)
throw Oops.Oh("暂无邀请码");
return invitation;
}
/// <summary>
/// 获取邀请人数
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/InvitationCode/GetPNumber")]
public async Task<int> GetPNumber()
{
var invitation = await this.inviteUserPosrep.Where(u => u.InviteUserID == UserManager.UserId).ToArrayAsync();
if (invitation.IsNullOrZero())
throw Oops.Oh("暂无邀请人");
return invitation.Count();
}
/// <summary>
/// 填写邀请码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Mini/InvitationCode/Receive")]
public async Task Receive(AddInvitationCodeInput input)
{
var incode = await this._rep.FirstOrDefaultAsync(x => x.InviteCode == input.InviteCode);
if (incode.IsNullOrZero())
throw Oops.Oh("无此邀请码!");
this.inviteUserPosrep.Insert(new InviteUserPos()
{
InviteID = incode.Id,
InviteUserID = (long)incode.CreatedUserId,
UserID = UserManager.UserId,
});
}
/// <summary>
/// 获取邀请码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/InvitationCode/GetNumber")]
public async Task<long> GetNumber()
{
var inviteUserPos = await this.inviteUserPosrep.FirstOrDefaultAsync(u => u.UserID == UserManager.UserId);
if (inviteUserPos.IsNullOrZero())
return 0;
var res = await this._rep.FirstOrDefaultAsync(x => x.Id == inviteUserPos.InviteID);
return res.InviteCode;
}
}
}

@ -9395,6 +9395,13 @@
<param name="dataType"></param>
<returns></returns>
</member>
<member name="M:GDZZ.Core.InvitaCode.Encode(System.Int64)">
<summary>
根据ID生成六位随机邀请码
</summary>
<param name="id">用户id</param>
<returns>返回6位邀请码</returns>
</member>
<member name="T:GDZZ.Core.EnumEntity">
<summary>
枚举的Entity类

@ -24,6 +24,7 @@ namespace GDZZ.Core.Service;
[ApiDescriptionSettings(Name = "User", Order = 150)]
public class SysUserService : ISysUserService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
private readonly ISysCacheService _sysCacheService;

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace GDZZ.Core
{
public class InvitaCode
{
//自定义进制(0、O没有加入,容易混淆同时排除X,用X补位)
private static char[] r = new char[] { 'Q', 'W', 'E', '8', 'A', 'S', '2', 'D', 'Z', '9', 'C', '7', 'P', '5', 'I', 'K', '3', 'M', 'J', 'U', 'F', 'R', '4', 'V', 'Y', 'L', 'T', 'N', '6', 'B', 'G', 'H' };
//不能与自定义进制有重复
private static char b = 'X';
//进制长度
private static int binLen = r.Length;
//生成的邀请码长度
private static int length = 6;
/// <summary>
/// 根据ID生成六位随机邀请码
/// </summary>
/// <param name="id">用户id</param>
/// <returns>返回6位邀请码</returns>
public static string Encode(long id)
{
char[] buf = new char[32];
int charPos = 32;
while ((id / binLen) > 0)
{
int ind = (int)(id % binLen);
buf[--charPos] = r[ind];
id /= binLen;
}
buf[--charPos] = r[(int)(id % binLen)];
String str = new String(buf, charPos, (32 - charPos));
//不够长度的自动随机补全
if (str.Length < length)
{
StringBuilder sb = new StringBuilder();
sb.Append(b);
Random rnd = new Random();
for (int i = 1; i < length - str.Length; i++)
{
sb.Append(r[rnd.Next(binLen)]);
}
str += sb.ToString();
}
return str;
}
}
}
Loading…
Cancel
Save