|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|