using Microsoft.AspNetCore.Http.Metadata; using Microsoft.AspNetCore.Mvc; using Qiniu.Util; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using ZhonTai.Admin.Core.Attributes; using ZhonTai.Admin.Core.Configs; using ZhonTai.Admin.Core.Consts; using ZhonTai.Admin.Core.Dto; using ZhonTai.Admin.Domain.User; using ZhonTai.Admin.Repositories.Project; using ZhonTai.Admin.Repositories.ProjectLink; using ZhonTai.Admin.Services.DiTuiAPI.Dto; using ZhonTai.Admin.Services.Notice.Dto; using ZhonTai.Admin.Services.Project; using ZhonTai.Admin.Services.ProjectLink.Dto; using ZhonTai.DynamicApi; using ZhonTai.DynamicApi.Attributes; namespace ZhonTai.Admin.Services.DiTuiAPI { /// /// 项目接口 /// [DynamicApi(Area = AdminConsts.DiTuiName)] //public class DiTuiAPIService : BaseService, IDiTuiAPIService, IDynamicApi public class ProjectsService : BaseService, IProjectsService, IDynamicApi { private ProjectLinkRepository _ProjectLinkRepository; private ProjectRepository _projectRepository; private ProjectPriceRepository _projectPriceRepository; private ProjectStatRepository _projectStatRepository; private ProjectConfigRepository _projectConfigRepository; public ProjectsService( ProjectLinkRepository projectLinkRepository, ProjectRepository projectRepository, ProjectPriceRepository projectPriceRepository, ProjectStatRepository projectStatRepository, ProjectConfigRepository projectConfigRepository) { _ProjectLinkRepository = projectLinkRepository; _projectRepository = projectRepository; _projectPriceRepository = projectPriceRepository; _projectStatRepository = projectStatRepository; _projectConfigRepository = projectConfigRepository; } /// /// 我的项目 /// /// [HttpGet] [NoOprationLog] public async Task MyProjectAsync() { MyProjectOutput myProjectOutput = new MyProjectOutput(); var linkList = _ProjectLinkRepository.Select .DisableGlobalFilter(FilterNames.Tenant) .Where(a => a.ModifiedUserId == User.Id) .GroupBy(m => new { m.ProjectId, m.Company }) .ToList(m => new ProjectLinkManagePageOutput() { ProjectId = m.Key.ProjectId, Company = m.Key.Company, Count = m.Count(), UseCount = m.Sum(m.Value.IsUse == 1 ? 1 : 0), ProjectName = "" }); var priceList = await _projectConfigRepository.Select .Where(m=> m.EffectDate < DateTime.Now) .OrderByDescending(m => m.DrawAmount) //.GroupBy(m => m.ProjectId) .ToListAsync( m => new { ProjectId = m.ProjectId, ProjectPriceId = m.ProjectPriceId, DrawAmount = m.DrawAmount, EffectDate = m.EffectDate, }); var listProjectId = linkList.Select(m => m.ProjectId).Distinct().ToList(); if (listProjectId.Count() > 0) { var listProject = await _projectRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => listProjectId.Contains(m.Id)).ToListAsync(m => new MyProject( m.Id, m.Name, m.Logo, //m.MaxPrice.ToString(), "", "T+" + m.SettleDay.ToString() + "结算" )); foreach(var projectItem in listProject) { var maxPrice = await _projectPriceRepository .Select .DisableGlobalFilter(FilterNames.Tenant) .Where(m => m.ProjectId == projectItem.Id) .OrderByDescending(m => m.Price) .FirstAsync(m => new { ProjectPriceId = m.Id, ProjectPrice = m.Price }); var priceConfig = await _projectConfigRepository .Select .DisableGlobalFilter(FilterNames.Tenant) .Where(m => m.ProjectPriceId == maxPrice.ProjectPriceId) .FirstAsync(m => new { DrawAmount = m.DrawAmount }) ; if(priceConfig is null) { // 未单独设置佣金抽成 默认抽取 5% 取 一位小数 projectItem.Price = (Convert.ToDecimal(projectItem.Price) - ProjectPriceService.GetDrawAmount(Convert.ToDecimal( projectItem.Price),Convert.ToDecimal(5.00))).ToString(); } else { projectItem.Price = (maxPrice.ProjectPrice - priceConfig.DrawAmount).ToString(); } } foreach (var proItem in listProject) { proItem.Price = proItem.Price + "元"; } myProjectOutput.MyProjects = listProject; } return myProjectOutput; } /// /// 项目详情 /// /// /// [HttpGet] [NoOprationLog] public async Task ProjectDescAsync(long id = 0) { if(id == 0) { throw ResultOutput.Exception($"ID 不可为空"); } // 根据ID查询到项目的相关信息返回 var result = await _projectRepository.Select.DisableGlobalFilter() .Where(a => a.Id == id) .FirstAsync(a => new ProjectDescOutput(a.Id,a.Logo,a.Name,"",a.SettleDay.ToString(),a.Tips)); var maxPrice = await _projectPriceRepository .Select .DisableGlobalFilter(FilterNames.Tenant) .Where(m => m.ProjectId == id) .OrderByDescending(m => m.Price) .FirstAsync(m => new { ProjectPriceId = m.Id, ProjectPrice = m.Price }); var priceConfig = await _projectConfigRepository .Select .DisableGlobalFilter(FilterNames.Tenant) .Where(m => m.ProjectPriceId == maxPrice.ProjectPriceId) .FirstAsync(m => new { DrawAmount = m.DrawAmount }); if (priceConfig is null) { // 未单独设置佣金抽成 默认抽取 5% 取 一位小数 result.Price = (Convert.ToDecimal(maxPrice.ProjectPrice) - ProjectPriceService.GetDrawAmount(Convert.ToDecimal(maxPrice.ProjectPrice), Convert.ToDecimal(5.00))).ToString(); } else { result.Price = (maxPrice.ProjectPrice - priceConfig.DrawAmount).ToString(); } return result; } /// /// 项目说明 /// /// /// [HttpGet] [NoOprationLog] public async Task ProjectSpecAsync(long id = 0) { if (id == 0) { throw ResultOutput.Exception($"ID 不可为空"); } var result = await _projectRepository.Select.DisableGlobalFilter() .Where(a => a.Id == id) .FirstAsync(a => new ProjectSpecOutput(a.Id, a.VideoUrl, a.Detail)); result.Prices = await _projectPriceRepository.Select.DisableGlobalFilter() .Where(a => a.ProjectId == id) .ToListAsync(a => new ProjectPrice( a.Id, a.Name, a.Price.ToString() )); var priceList = await _projectConfigRepository.Select .Where(m => m.EffectDate < DateTime.Now) .Where(m => m.ProjectId == id) .OrderByDescending(m => m.DrawAmount) .ToListAsync( m => new { ProjectId = m.ProjectId, ProjectPriceId = m.ProjectPriceId, DrawAmount = m.DrawAmount, EffectDate = m.EffectDate, }); if(priceList.Count() == 0) { foreach (var priceItem in result.Prices) { priceItem.Price = (Convert.ToDecimal(priceItem.Price) - ProjectPriceService.GetDrawAmount(Convert.ToDecimal(priceItem.Price), Convert.ToDecimal(5.00))).ToString(); } } else { foreach (var item in priceList) { foreach (var priceItem in result.Prices) { if (item.ProjectPriceId == priceItem.Id) { priceItem.Price = (Convert.ToDecimal(priceItem.Price) - item.DrawAmount).ToString(); } else { priceItem.Price = (Convert.ToDecimal(priceItem.Price) - ProjectPriceService.GetDrawAmount(Convert.ToDecimal(priceItem.Price), Convert.ToDecimal(5.00))).ToString(); } } } } return result; //ProjectSpecOutput projectSpecOutput = new ProjectSpecOutput(); //projectSpecOutput.VideoUrl = "https://test-dt.zhongjie51.com/assetsImg/test.mp4"; //projectSpecOutput.Detail = "

注意事项:

\r\n1.新老用户均可下单,从未在抖店下过单的即可。成功领取抖音平台通用新人券的为电商新用户

2.提醒用户第二天务必打开APP,查看物流信息,确保商家正常发货 

3.仅限抖音APP,请勿使用极速版、火山版下单

4.复购订单必须直接在抖音商城下单!直播间下单无法结算!

5.必须真实推广,禁止机刷,机刷不结算并上报司法机关 

6.禁止一机多单,禁止一个支付账号(微信、支付宝、银行卡)多次支付,禁止代付等行为 

7.禁止填写同一收货人姓名、手机号、地址,必项填写注册手机号及客户真实收货信息 

8.禁止使用WIFI、热点作业\r\n\r\n

9.为了避免活动下线,做单没有数据。请所有业务员务必每天扫描一次母码,获取新的作业码!

(具体步骤请参考下图)


拉新流程:

\r\n1.使用抖音扫描拉新二维码 

2.扫码以后弹出的活动界面,完成新人首购,挑选任意商品,点击领券购买

3.填写收货信息(注意必须填写真实的收货信息)选择任意支付方式,支付即可

4.第二天,再次扫码(不扫码也可复购,只是没有实时数据)跳转到活动界面,完成复购,复购无金额要求!


图文教程:

\r\n


"; //List projectPrices = new List(); ////projectPrices.Add(new ProjectPrice( )); //projectPrices.Add(new ProjectPrice("新设备次播", "25")); //projectPrices.Add(new ProjectPrice("新设备3留", "8")); //projectPrices.Add(new ProjectPrice("申领礼品", "20")); //projectPrices.Add(new ProjectPrice("老设备次留", "5")); //projectSpecOutput.Prices = projectPrices; //return projectSpecOutput; } /// /// 项目详情-推广码 /// /// /// [HttpGet] public async Task> ProjectQrcodePageAsync(PageInput input) { var keyWrods = input.Filter?.Keywords; string Salesman = null; string SalesmanPhone = null; //var Salesman = input.Filter?.Salesman; //var Salesman = input.Filter?.Salesman; //var SalesmanPhone = input.Filter?.SalesmanPhone; //var SalesmanPhone = input.Filter?.SalesmanPhone; //var SalesmanPhone = input.Filter?.SalesmanPhone; if (!string.IsNullOrEmpty(keyWrods)) { if(IsPhoneNumber(keyWrods)) { SalesmanPhone = keyWrods; } else { Salesman = keyWrods; } } var ProjectId = input.Filter?.ProjectId; if (ProjectId == 0 || string.IsNullOrEmpty(ProjectId.ToString())) { throw ResultOutput.Exception("项目 ID 不可为空"); } var list = _ProjectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant) .WhereIf(ProjectId.HasValue && ProjectId.Value > 0, a => a.ProjectId == ProjectId) .WhereIf(Salesman.NotNull(), a => a.Salesman.Contains(Salesman)) .WhereIf(SalesmanPhone.NotNull(), a => a.SalesmanPhone.Contains(SalesmanPhone)) .Where(a=> a.IsUse == 1 && a.TenantId == User.TenantId) .OrderByDescending(a => a.UseTime) .Count(out var total) .Page(input.CurrentPage, input.PageSize) .ToList(m => new ProjectQrcodePageOutput() { Id = m.Id, Salesman = m.Salesman, UseTime = m.UseTime, QrcodeUrl = m.QrcodeUrl, QueryUrl = m.QueryUrl }); var data = new PageOutput() { List = list, Total = total }; return data; } /// /// 项目统计 /// /// /// [HttpGet] public async Task> ProjectCountPageAsync(PageInput input) { var ProjectId = input.Filter?.ProjectId; var Date = input.Filter?.Date; if(ProjectId == null) { ProjectId = 0; } if(ProjectId == 0) { throw ResultOutput.Exception("项目 ID 不可为空"); } var listStat = _projectStatRepository .Select .DisableGlobalFilter(FilterNames.Tenant) .Where(a => a.ProjectId == ProjectId) .WhereIf(Date.NotNull(), a => a.EffectDate.ToString().Contains(Date)) .GroupBy(a => a.EffectDate) .Page(input.CurrentPage, input.PageSize) .ToList(m => new { SettleDate = m.Key}); List list = new List(); foreach (var countDate in listStat) { //string.Format("{0:yyyy-MM-dd HH:mm:ss}", m.CreatedTime) string countDateString = string.Format("{0:yyyy-MM-dd}", countDate.SettleDate); //List settleCounts = new List(); var sr = _projectStatRepository.Select.DisableGlobalFilter(FilterNames.Tenant) .Where(a => a.ProjectId == ProjectId) .Where(a => a.EffectDate.ToString().Contains(countDateString)) .ToList(m => new SettleRecord(m.Name,m.ValidCount.ToString(),m.ValidCount.ToString()){}); List sc = new List(); long validCount = 0; long Count = 0; long commission = 0; foreach(var item in sr) { validCount += Convert.ToInt16(item.ValidCount); Count += Convert.ToInt16( item.Count); //commission += Convert.ToInt16(item.Commission); sc.Add(new SettleCount(item.SettleStandard, item.ValidCount + "/" + item.ValidCount)); } sc.Add(new SettleCount("汇总", validCount + "/" + Count, "--")); list.Add(new ProjectCountPageOutput((long)ProjectId, countDateString, "", sc)); } var total = list.Count; var data = new PageOutput() { List = list, Total = total }; return data; } /// /// 开码 /// /// /// [HttpPost] [NoOprationLog] public async Task BindQrcodeAsync(BindQrcodeInput input) { var project = await _projectRepository.Select.DisableGlobalFilter().Where(a => a.Id == input.ProjectId).FirstAsync(a => new {a.Status}); if(project.Status == 4) { throw ResultOutput.Exception($"项目暂停"); } if(project.Status == 5) { throw ResultOutput.Exception($"项目名额已满"); } if (project.Status == 3) { throw ResultOutput.Exception($"项目已下架"); } if (project.Status == 1) { throw ResultOutput.Exception($"项目未上架"); } // 判断用户是否已经 开码 同租户 同项目 手机号唯一 var doubleUser = await _ProjectLinkRepository.Select.Where(a => a.SalesmanPhone == input.SalesmanPhone && a.ProjectId == input.ProjectId) .FirstAsync(a => new { a.Salesman, a.SalesmanPhone, a.Id }); if(doubleUser != null) { throw ResultOutput.Exception($"手机号已开码"); } // 查询未使用的链接的第一条数据 TODO 当前需要查询 TenantID 为空的数据 后期会查询 各平台自己的链接 var existsLink = await _ProjectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant) .Where(a => a.IsUse == 0 && a.ProjectId == input.ProjectId) .FirstAsync(a => new { a.Id, a.ModifiedTime}); if (existsLink == null) { throw ResultOutput.Exception($"当前项目已无可用链接"); } var qrcode = await _ProjectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant) .Where(a => a.Id == existsLink.Id) .FirstAsync(); Mapper.Map(input, qrcode); qrcode.IsUse = 1; qrcode.TenantId = User.TenantId; qrcode.UsedUserId = User.Id; qrcode.UseTime = DateTime.Now; var resault = await _ProjectLinkRepository.UpdateDiy.DisableGlobalFilter(FilterNames.Tenant) .SetSource(qrcode) .UpdateColumns(a => new { a.TenantId, a.IsUse, a.Salesman,a.SalesmanPhone,a.SalesmanProvince,a.SalesmanCity,a.SalesmanRemark,a.UsedUserId,a.UseTime}) .ExecuteAffrowsAsync(); // 返回 链接ID return qrcode.Id.ToString(); } /// /// 获取开码信息 /// /// 二维码ID(链接ID) /// [HttpGet] [NoOprationLog] public async Task GetBindQrcodeAsync(long id = 0) { if (id == 0) { throw ResultOutput.Exception($"无效参数"); } var result = await _ProjectLinkRepository.GetAsync(id); return result; } /// /// 推广码每日统计 /// /// /// [HttpGet] public async Task> QrcodeCountPageAsync(PageInput input) { var Id = input.Filter?.Id; if (Id == null) { Id = 0; } //var list = _ProjectLinkRepository.Select.DisableGlobalFilter(FilterNames.Tenant) // .WhereIf(ProjectId.HasValue && ProjectId.Value > 0, a => a.ProjectId == ProjectId) // .WhereIf(Salesman.NotNull(), a => a.Salesman.Contains(Salesman)) // .WhereIf(SalesmanPhone.NotNull(), a => a.SalesmanPhone.Contains(SalesmanPhone)) //.Count(out var total) //.Page(input.CurrentPage, input.PageSize) //.ToList(m => new ProjectQrcodePageOutput() //{ // Id = m.Id, // Salesman = m.Salesman, // UseTime = m.UseTime, // QrcodeUrl = m.QrcodeUrl, // QueryUrl = m.QueryUrl //}); List list = new List(); List settleCounts = new List(); settleCounts.Add(new SettleCount("电商首购A级", "200/300单", "200元")); settleCounts.Add(new SettleCount("电商首购B级", "201/300单", "201元")); settleCounts.Add(new SettleCount("电商首购C级", "202/300单", "202元")); settleCounts.Add(new SettleCount("今日汇总", "603/900单", "603元")); //settleCounts.Add(new SettleCount("电商首购A级", "200/300单", "200元")); //settleCounts.Add(new SettleCount("电商首购A级", "200/300单", "200元")); list.Add(new ProjectCountPageOutput((long)(Id != 0 ? Id : 416237348180038), "2023-05-02", "", settleCounts)); List settleCounts1 = new List(); settleCounts1.Add(new SettleCount("电商首购A级", "200/300单", "200元")); settleCounts1.Add(new SettleCount("电商首购B级", "199/300单", "199元")); settleCounts1.Add(new SettleCount("电商首购C级", "198/300单", "198元")); settleCounts1.Add(new SettleCount("今日汇总", "597/900单", "597元")); //settleCounts.Add(new SettleCount("电商首购A级", "200/300单", "200元")); //settleCounts.Add(new SettleCount("电商首购A级", "200/300单", "200元")); list.Add(new ProjectCountPageOutput((long)(Id != 0 ? Id : 416237348180038), "2023-05-01", "", settleCounts1)); var total = list.Count; var data = new PageOutput() { List = list, Total = total }; return data; } /// /// 判断字符串是否是手机号 /// /// /// private static bool IsPhoneNumber(string str_handset) { return System.Text.RegularExpressions.Regex.IsMatch(str_handset, @"^1[3456789]\d{9}$"); } } }