You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
7.6 KiB
232 lines
7.6 KiB
using Coldairarrow.Entity.DTO;
|
|
using Coldairarrow.Entity.HuiYan;
|
|
using Coldairarrow.Util;
|
|
using EFCore.Sharding;
|
|
using LinqKit;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Dynamic.Core;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace Coldairarrow.Business.HuiYan
|
|
{
|
|
public class itemlabelsBusiness : BaseBusiness<itemlabels>, IitemlabelsBusiness, ITransientDependency
|
|
{
|
|
IteamitemsBusiness iteamitemsBusiness;
|
|
public itemlabelsBusiness(IDbAccessor db, IteamitemsBusiness _iteamitemsBusiness)
|
|
: base(db)
|
|
{
|
|
iteamitemsBusiness = _iteamitemsBusiness;
|
|
}
|
|
|
|
#region 外部接口
|
|
|
|
public async Task<PageResult<itemlabels>> GetDataListAsync(PageInput<ConditionDTO> input)
|
|
{
|
|
var q = GetIQueryable();
|
|
var where = LinqHelper.True<itemlabels>();
|
|
var search = input.Search;
|
|
|
|
//筛选
|
|
if (!search.Condition.IsNullOrEmpty() && !search.Keyword.IsNullOrEmpty())
|
|
{
|
|
var newWhere = DynamicExpressionParser.ParseLambda<itemlabels, bool>(
|
|
ParsingConfig.Default, false, $@"{search.Condition}.Contains(@0)", search.Keyword);
|
|
where = where.And(newWhere);
|
|
}
|
|
|
|
return await q.Where(where).GetPageResultAsync(input);
|
|
}
|
|
|
|
public async Task<itemlabels> GetTheDataAsync(string id)
|
|
{
|
|
return await GetEntityAsync(id);
|
|
}
|
|
|
|
public async Task AddDataAsync(itemlabels data)
|
|
{
|
|
await InsertAsync(data);
|
|
}
|
|
|
|
public async Task UpdateDataAsync(itemlabels data)
|
|
{
|
|
await UpdateAsync(data);
|
|
}
|
|
|
|
public async Task DeleteDataAsync(List<string> ids)
|
|
{
|
|
await DeleteAsync(ids);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 私有成员
|
|
|
|
#endregion
|
|
|
|
|
|
public AjaxResult GetLabelByItemIds(List<string> ids, ItemPlatform platform)
|
|
{
|
|
Expression<Func<itemlabels, items, ItemlabelInfoDto>> select = (a, b) => new ItemlabelInfoDto
|
|
{
|
|
GoodsId = b.GoodsId,
|
|
HasFilter = b.HasFilter,
|
|
Platform = b.Platform
|
|
};
|
|
|
|
select = select.BuildExtendSelectExpre();
|
|
|
|
var q_titem = GetIQueryable();
|
|
var q = from a in q_titem.AsExpandable()
|
|
join b in Db.GetIQueryable<items>() on a.ItemsId equals b.Id into ab
|
|
from b in ab.DefaultIfEmpty()
|
|
select @select.Invoke(a, b);
|
|
|
|
//查询这边还需要添加 (Teamid筛选,或者HasFilter=True) 的二选一查询
|
|
var where = LinqHelper.True<ItemlabelInfoDto>().And(c => c.Platform == (int)platform && ids.Contains(c.GoodsId));
|
|
|
|
//where = where.And(c => c.TeamId == "" || c.HasFilter ==true);
|
|
|
|
var list = q.Where(where).ToListAsync().Result;
|
|
|
|
return Success(list);
|
|
}
|
|
|
|
|
|
public AjaxResult SetItemLabel(ItemLabelDto model)
|
|
{
|
|
var item= Db.GetIQueryable<items>().FirstOrDefault(c => c.GoodsId == model.ItemId);
|
|
|
|
if (item == null)
|
|
{
|
|
item = new items()
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
CreatorId = string.Empty,
|
|
Deleted = false,
|
|
GoodsId = model.ItemId,
|
|
Id = IdHelper.GetId(),
|
|
HasFilter = model.Status == 1,
|
|
Platform = (int)model.Platform
|
|
};
|
|
|
|
int row = Db.Insert(item);
|
|
|
|
if (row <= 0)
|
|
return Error("添加失败!");
|
|
}
|
|
|
|
var where = LinqHelper.True<itemlabels>().And(c => c.ItemsId == item.Id);
|
|
|
|
//团队筛选
|
|
//where = where.And(c=>c.TeamId=="");
|
|
|
|
|
|
var result = Db.RunTransaction(() =>
|
|
{
|
|
int row = 0;
|
|
bool hasAdded = false;
|
|
|
|
var label = GetIQueryable().FirstOrDefault(where);
|
|
//新增
|
|
if (label == null)
|
|
{
|
|
label = new itemlabels()
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
Deleted = false,
|
|
Id = IdHelper.GetId(),
|
|
ItemsId = item.Id,
|
|
CreatorId = string.Empty,
|
|
TeamId = string.Empty,
|
|
UserId = string.Empty
|
|
};
|
|
|
|
switch (model.Status)
|
|
{
|
|
case 0:
|
|
label.IsScreening = true;
|
|
break;
|
|
case 1:
|
|
label.IsFilter = true;
|
|
break;
|
|
case 2:
|
|
label.IsAdded = true;
|
|
break;
|
|
case 3:
|
|
label.IsCompeting = true;
|
|
break;
|
|
}
|
|
row = Db.Insert<itemlabels>(label);
|
|
if (row <= 0)
|
|
throw new Exception("标签设置失败!");
|
|
}
|
|
//更新
|
|
else
|
|
{
|
|
hasAdded = label.IsAdded;
|
|
|
|
|
|
//更新状态
|
|
row = Db.Update<itemlabels>(c => c.Id == label.Id, (data) =>
|
|
{
|
|
switch (model.Status)
|
|
{
|
|
case 0:
|
|
if (label.IsFilter)
|
|
throw new Exception("该商品已被过滤!");
|
|
data.IsScreening = true;
|
|
break;
|
|
case 1:
|
|
if (label.IsScreening)
|
|
throw new Exception("该商品已被筛选!");
|
|
data.IsFilter = true;
|
|
break;
|
|
case 2:
|
|
data.IsAdded = true;
|
|
break;
|
|
case 3:
|
|
data.IsCompeting = true;
|
|
break;
|
|
}
|
|
});
|
|
if (row <= 0)
|
|
throw new Exception("标签设置失败!");
|
|
}
|
|
|
|
|
|
//设置集团过滤
|
|
if (model.Status == 1)
|
|
{
|
|
Db.Update<items>(c => c.Id == item.Id, (i) => { i.HasFilter = true; });
|
|
}
|
|
|
|
//判断是否添加产品库
|
|
if (model.Status==2&&!hasAdded)
|
|
{
|
|
if (!iteamitemsBusiness.AddItem(new TeamitemDto()
|
|
{
|
|
GoodsId = model.ItemId,
|
|
ItemId = item.Id,
|
|
ItemImg = model.Img,
|
|
Price = model.Price,
|
|
Platform = item.Platform,
|
|
Sales = model.Sales,
|
|
Title = model.Title
|
|
}).Success)
|
|
{
|
|
throw new Exception("添加产品库失败!");
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
if (result.Success)
|
|
return Success("操作成功!");
|
|
return Error(result.ex.Message);
|
|
}
|
|
}
|
|
}
|