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.
360 lines
12 KiB
360 lines
12 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;
|
|
using Coldairarrow.IBusiness;
|
|
|
|
namespace Coldairarrow.Business.HuiYan
|
|
{
|
|
public class itemlabelsBusiness : BaseBusiness<itemlabels>, IitemlabelsBusiness, ITransientDependency
|
|
{
|
|
IteamitemsBusiness iteamitemsBusiness;
|
|
readonly IOperator _operator;
|
|
public itemlabelsBusiness(IDbAccessor db, IteamitemsBusiness _iteamitemsBusiness, IOperator @operator)
|
|
: base(db)
|
|
{
|
|
iteamitemsBusiness = _iteamitemsBusiness;
|
|
_operator = @operator;
|
|
}
|
|
|
|
|
|
#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,
|
|
GoodsUrl=b.GoodsUrl
|
|
};
|
|
|
|
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 == _operator.TeamId || c.HasFilter ==true);
|
|
|
|
var list = q.Where(where).ToListAsync().Result;
|
|
|
|
return Success(list);
|
|
}
|
|
|
|
public AjaxResult GetAlbbLabelByShopIds(List<string>ids)
|
|
{
|
|
var list= Db.GetIQueryable<albbitemlabels>().Where(c => ids.Contains(c.ShopId));
|
|
|
|
return Success(list);
|
|
}
|
|
|
|
public AjaxResult SetItemLabel(ItemLabelDto model)
|
|
{
|
|
bool isAddItem = false;
|
|
var item= Db.GetIQueryable<items>().FirstOrDefault(c => c.GoodsId == model.ItemId&&c.Platform==(int)model.Platform);
|
|
|
|
if (item == null)
|
|
{
|
|
item = new items()
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
CreatorId = string.Empty,
|
|
Deleted = false,
|
|
GoodsId = model.ItemId,
|
|
Id = IdHelper.GetId(),
|
|
HasFilter = model.Status == ItemLabelStatus.Filter,
|
|
Platform = (int)model.Platform
|
|
};
|
|
|
|
item.GoodsUrl = string.Empty;
|
|
switch (model.Platform)
|
|
{
|
|
case ItemPlatform.Taobao:
|
|
item.GoodsUrl = $"https://item.taobao.com/item.htm?id={item.GoodsId}";
|
|
break;
|
|
case ItemPlatform.Jd:
|
|
item.GoodsUrl = $"https://item.jd.com/{item.GoodsId}.html";
|
|
break;
|
|
case ItemPlatform.ALBB:
|
|
item.GoodsUrl = $"https://detail.1688.com/offer/{item.GoodsId}.html";
|
|
break;
|
|
}
|
|
|
|
|
|
int row = Db.Insert(item);
|
|
|
|
if (row <= 0)
|
|
return Error("添加失败!");
|
|
|
|
isAddItem = true;
|
|
}
|
|
|
|
////判断是否阿里巴巴合作
|
|
//if (model.Status == ItemLabelStatus.Cooperation)
|
|
//{
|
|
// return SetAlbbCooperation(item);
|
|
//}
|
|
|
|
var where = LinqHelper.True<itemlabels>().And(c => c.ItemsId == item.Id);
|
|
|
|
//团队筛选
|
|
where = where.And(c=>c.TeamId==_operator.TeamId);
|
|
|
|
var label = GetIQueryable().FirstOrDefault(where);
|
|
|
|
bool isCanel = false;
|
|
|
|
var result = Db.RunTransaction(() =>
|
|
{
|
|
int row = 0;
|
|
bool hasAdded = false;
|
|
|
|
//新增
|
|
if (label == null)
|
|
{
|
|
label = new itemlabels()
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
Deleted = false,
|
|
Id = IdHelper.GetId(),
|
|
ItemsId = item.Id,
|
|
CreatorId =_operator.UserId,
|
|
TeamId =_operator.TeamId,
|
|
UserId = _operator.UserId
|
|
};
|
|
|
|
switch (model.Status)
|
|
{
|
|
case ItemLabelStatus.Screening:
|
|
label.IsScreening = true;
|
|
break;
|
|
case ItemLabelStatus.Filter:
|
|
label.IsFilter = true;
|
|
break;
|
|
case ItemLabelStatus.Added:
|
|
label.IsAdded = true;
|
|
break;
|
|
case ItemLabelStatus.Competing:
|
|
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 ItemLabelStatus.Screening:
|
|
if (label.IsFilter)
|
|
throw new Exception("该商品已被过滤!");
|
|
if (data.IsScreening)
|
|
{
|
|
data.IsScreening = false;
|
|
isCanel = true;
|
|
}
|
|
else
|
|
data.IsScreening = true;
|
|
break;
|
|
case ItemLabelStatus.Filter:
|
|
if (label.IsScreening)
|
|
throw new Exception("该商品已被筛选!");
|
|
if (data.IsFilter)
|
|
{
|
|
data.IsFilter = false;
|
|
isCanel = true;
|
|
}
|
|
else
|
|
data.IsFilter = true;
|
|
break;
|
|
case ItemLabelStatus.Added:
|
|
//加入产品库同时也勾选筛选
|
|
if (data.IsAdded) {
|
|
data.IsAdded = false;
|
|
|
|
isCanel = true;
|
|
}
|
|
else
|
|
data.IsAdded = true;
|
|
break;
|
|
case ItemLabelStatus.Competing:
|
|
if (data.IsCompeting) {
|
|
data.IsCompeting = false;
|
|
isCanel = true;
|
|
}
|
|
else
|
|
data.IsCompeting = true;
|
|
break;
|
|
}
|
|
});
|
|
|
|
if (row <= 0)
|
|
throw new Exception("标签设置失败!");
|
|
}
|
|
|
|
//设置集团过滤
|
|
if (model.Status == ItemLabelStatus.Filter&& !isAddItem)
|
|
{
|
|
Db.Update<items>(c => c.Id == item.Id, (i) => { i.HasFilter = true; });
|
|
}
|
|
|
|
//判断是否添加产品库
|
|
if (model.Status== ItemLabelStatus.Added&&!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,
|
|
GoodsUrl=item.GoodsUrl
|
|
}).Success)
|
|
{
|
|
throw new Exception("添加产品库失败!");
|
|
}
|
|
}
|
|
|
|
//删除产品库
|
|
if (model.Status == ItemLabelStatus.Added && isCanel)
|
|
{
|
|
iteamitemsBusiness.RemoveItem(model.ItemId);
|
|
}
|
|
});
|
|
|
|
if (result.Success)
|
|
return Success(new { isCanel },"操作成功!");
|
|
|
|
return Error(result.ex.Message);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置阿里巴巴合作
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public AjaxResult SetAlbbCooperation(string shopId)
|
|
{
|
|
bool isCanel = false;
|
|
|
|
int count= Db.GetIQueryable<albbitemlabels>().Count(c => c.ShopId == shopId);
|
|
|
|
if (count > 0)
|
|
{
|
|
isCanel = true;
|
|
|
|
Db.Delete<albbitemlabels>(c => c.ShopId == shopId);
|
|
|
|
return Success(new { isCanel });
|
|
}
|
|
|
|
int row= Db.Insert<albbitemlabels>(new albbitemlabels()
|
|
{
|
|
CreateTime = DateTime.Now,
|
|
CreatorId = _operator.UserId,
|
|
Deleted = false,
|
|
Id = IdHelper.GetId(),
|
|
ShopId = shopId
|
|
});
|
|
|
|
if (row > 0)
|
|
return Success(new { isCanel });
|
|
else
|
|
{
|
|
return Error();
|
|
}
|
|
}
|
|
|
|
public AjaxResult GetItemsByJpLabels(int type)
|
|
{
|
|
Expression<Func<itemlabels, items, ItemlabelInfoDto>> select = (a, b) => new ItemlabelInfoDto
|
|
{
|
|
GoodsId = b.GoodsId,
|
|
HasFilter = b.HasFilter,
|
|
Platform = b.Platform,
|
|
GoodsUrl=b.GoodsUrl
|
|
};
|
|
|
|
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);
|
|
|
|
var where = LinqHelper.True<ItemlabelInfoDto>().And(c => c.Platform == (int)ItemPlatform.Jd && c.TeamId == _operator.TeamId && c.IsCompeting == true);
|
|
|
|
var list = q.Where(where).ToList();
|
|
|
|
return Success(list);
|
|
}
|
|
|
|
}
|
|
}
|