|
|
|
using Coldairarrow.Entity.DTO;
|
|
|
|
using Coldairarrow.Entity.Enum;
|
|
|
|
using Coldairarrow.Entity.HuiYan;
|
|
|
|
using Coldairarrow.IBusiness;
|
|
|
|
using Coldairarrow.Util;
|
|
|
|
using EFCore.Sharding;
|
|
|
|
using LinqKit;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq.Dynamic.Core;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace Coldairarrow.Business.HuiYan
|
|
|
|
{
|
|
|
|
public class teamitemsBusiness : BaseBusiness<teamitems>, IteamitemsBusiness, ITransientDependency
|
|
|
|
{
|
|
|
|
readonly IOperator _operator;
|
|
|
|
public teamitemsBusiness(IDbAccessor db, IOperator @operator)
|
|
|
|
: base(db)
|
|
|
|
{
|
|
|
|
_operator = @operator;
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 外部接口
|
|
|
|
|
|
|
|
public async Task<PageResult<teamitems>> GetDataListAsync(PageInput<ConditionDTO> input)
|
|
|
|
{
|
|
|
|
var q = GetIQueryable();
|
|
|
|
var where = LinqHelper.True<teamitems>();
|
|
|
|
var search = input.Search;
|
|
|
|
|
|
|
|
//筛选
|
|
|
|
if (!search.Condition.IsNullOrEmpty() && !search.Keyword.IsNullOrEmpty())
|
|
|
|
{
|
|
|
|
var newWhere = DynamicExpressionParser.ParseLambda<teamitems, bool>(
|
|
|
|
ParsingConfig.Default, false, $@"{search.Condition}.Contains(@0)", search.Keyword);
|
|
|
|
where = where.And(newWhere);
|
|
|
|
}
|
|
|
|
|
|
|
|
return await q.Where(where).GetPageResultAsync(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<teamitems> GetTheDataAsync(string id)
|
|
|
|
{
|
|
|
|
return await GetEntityAsync(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task AddDataAsync(teamitems data)
|
|
|
|
{
|
|
|
|
await InsertAsync(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task UpdateDataAsync(teamitems data)
|
|
|
|
{
|
|
|
|
await UpdateAsync(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task DeleteDataAsync(List<string> ids)
|
|
|
|
{
|
|
|
|
await DeleteAsync(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 私有成员
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
public PageResult<TeamitemDto> GetItems(PageInput<ConditionDTO> input)
|
|
|
|
{
|
|
|
|
Expression<Func<teamitems, items, TeamitemDto>> select = (a, b) => new TeamitemDto
|
|
|
|
{
|
|
|
|
GoodsId = b.GoodsId,
|
|
|
|
HasFilter = b.HasFilter,
|
|
|
|
Platform = b.Platform,
|
|
|
|
GoodsUrl = b.GoodsUrl,
|
|
|
|
Extensions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TeamItemExtension>>(a.ExtensionJson)
|
|
|
|
};
|
|
|
|
|
|
|
|
var search = input.Search;
|
|
|
|
select = select.BuildExtendSelectExpre();
|
|
|
|
|
|
|
|
var q_titem = GetIQueryable();
|
|
|
|
var q = from a in q_titem.AsExpandable()
|
|
|
|
join b in Db.GetIQueryable<items>() on a.ItemId equals b.Id into ab
|
|
|
|
from b in ab.DefaultIfEmpty()
|
|
|
|
select @select.Invoke(a, b);
|
|
|
|
|
|
|
|
int state = int.Parse(search.Keyword);
|
|
|
|
|
|
|
|
//查询对应状态
|
|
|
|
var where = LinqHelper.True<TeamitemDto>();
|
|
|
|
if (state == 0)
|
|
|
|
{
|
|
|
|
where = where.And(c => c.State == state || c.State == (int)TeamItemState.已发布比价);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (state == 6)
|
|
|
|
{
|
|
|
|
where = where.And(c => c.State == state || c.State == (int)TeamItemState.待修改);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
where = where.And(c => c.State == state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
where = where.And(c => c.TeamId == _operator.TeamId);
|
|
|
|
|
|
|
|
input.SortField = "CreateTime";
|
|
|
|
input.SortType = "desc";
|
|
|
|
|
|
|
|
var list = q.Where(where).GetPageResultAsync(input).Result;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AjaxResult AddItem(TeamitemDto model)
|
|
|
|
{
|
|
|
|
model.Extensions = new List<TeamItemExtension>();
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
model.Extensions.Add(new TeamItemExtension() { Platform = model.Platform });
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.ItemId))
|
|
|
|
{
|
|
|
|
var item = Db.GetIQueryable<items>().FirstOrDefault(c => c.GoodsId == model.GoodsId);
|
|
|
|
if (item == null)
|
|
|
|
{
|
|
|
|
item = new items()
|
|
|
|
{
|
|
|
|
GoodsId = model.GoodsId,
|
|
|
|
GoodsUrl = model.GoodsUrl,
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
CreatorId = _operator.UserId,
|
|
|
|
Deleted = false,
|
|
|
|
HasFilter = false,
|
|
|
|
Id = IdHelper.GetId(),
|
|
|
|
Platform = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
item.GoodsUrl = string.Empty;
|
|
|
|
switch (model.Platform)
|
|
|
|
{
|
|
|
|
case (int)ItemPlatform.Taobao:
|
|
|
|
item.GoodsUrl = $"https://item.taobao.com/item.htm?id={item.GoodsId}";
|
|
|
|
break;
|
|
|
|
case (int)ItemPlatform.Jd:
|
|
|
|
item.GoodsUrl = $"https://item.jd.com/{item.GoodsId}.html";
|
|
|
|
break;
|
|
|
|
case (int)ItemPlatform.ALBB:
|
|
|
|
item.GoodsUrl = $"https://detail.1688.com/offer/{item.GoodsId}.html";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Db.Insert<items>(item) <= 0)
|
|
|
|
{
|
|
|
|
return Error("商品添加失败!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
model.ItemId = item.Id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//设置为初选
|
|
|
|
int row = Db.Insert<teamitems>(new teamitems()
|
|
|
|
{
|
|
|
|
State = 0,
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
CreatorId = _operator.UserId,
|
|
|
|
Deleted = false,
|
|
|
|
ExtensionJson = Newtonsoft.Json.JsonConvert.SerializeObject(model.Extensions),
|
|
|
|
Id = IdHelper.GetId(),
|
|
|
|
|
|
|
|
TeamId = _operator.TeamId,
|
|
|
|
UserId = _operator.UserId,
|
|
|
|
|
|
|
|
Price = model.Price,
|
|
|
|
ItemImg = model.ItemImg,
|
|
|
|
Sales = model.Sales,
|
|
|
|
Title = model.Title,
|
|
|
|
|
|
|
|
ItemId = model.ItemId
|
|
|
|
});
|
|
|
|
|
|
|
|
if (row <= 0)
|
|
|
|
return Error("商品信息添加失败!");
|
|
|
|
|
|
|
|
return Success();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AjaxResult RemoveItem(string goodsId)
|
|
|
|
{
|
|
|
|
var item = Db.GetIQueryable<items>().FirstOrDefault(c => c.GoodsId == goodsId);
|
|
|
|
|
|
|
|
int row= Db.Delete<teamitems>(c => c.ItemId == item.Id && c.TeamId == _operator.TeamId);
|
|
|
|
if (row > 0)
|
|
|
|
return Success();
|
|
|
|
return Error();
|
|
|
|
|
|
|
|
}
|
|
|
|
public AjaxResult SetItem(TeamitemDto model)
|
|
|
|
{
|
|
|
|
//if (!string.IsNullOrEmpty(model.RivalGoodsId))
|
|
|
|
//{
|
|
|
|
// if (model.RivalGoodsId.Contains("."))
|
|
|
|
// {
|
|
|
|
// model.RivalGoodsId = Regex.Match(model.RivalGoodsId + "&", "id=(.*?)&").Groups[1].Value;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
int row = Db.Update<teamitems>(c => c.Id == model.Id, (item) =>
|
|
|
|
{
|
|
|
|
item.ExtensionJson = Newtonsoft.Json.JsonConvert.SerializeObject(model.Extensions);
|
|
|
|
item.RivalGoodsId = model.RivalGoodsId;
|
|
|
|
item.RivalPLCount = model.RivalPLCount;
|
|
|
|
item.RivalPrice = model.RivalPrice;
|
|
|
|
item.RivalTitle = model.RivalTitle;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (row > 0)
|
|
|
|
return Success();
|
|
|
|
return Error("操作失败!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AjaxResult SetState(string id, int state)
|
|
|
|
{
|
|
|
|
//删除
|
|
|
|
if (state == -1)
|
|
|
|
{
|
|
|
|
return DeleteItem(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
var priceUserId = Db.GetIQueryable<teamitems>().FirstOrDefault(c => c.Id == id).PriceTaskUserId;
|
|
|
|
|
|
|
|
var result= Db.RunTransaction(() =>
|
|
|
|
{
|
|
|
|
int row = Db.Update<teamitems>(c => c.Id == id, (item) =>
|
|
|
|
{
|
|
|
|
item.State = state;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (row <= 0)
|
|
|
|
throw new Exception("任务状态设置失败!");
|
|
|
|
//同步更新比价任务状态
|
|
|
|
if ((Entity.Enum.TeamItemState)state == TeamItemState.待修改)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(priceUserId))
|
|
|
|
{
|
|
|
|
row = Db.Update<pricetasklog>(c => c.UserId == priceUserId && c.TeamItemId == id, (item) =>
|
|
|
|
{
|
|
|
|
item.State = PriceTaskState.待修改;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (row <= 0)
|
|
|
|
throw new Exception("比价任务设置失败!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(priceUserId))
|
|
|
|
{
|
|
|
|
if ((Entity.Enum.TeamItemState)state == TeamItemState.精选)
|
|
|
|
{
|
|
|
|
row = Db.Update<pricetasklog>(c => c.UserId == priceUserId && c.TeamItemId == id, (item) =>
|
|
|
|
{
|
|
|
|
item.State = PriceTaskState.比价完成;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (row <= 0)
|
|
|
|
throw new Exception("比价任务设置失败!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (result.Success)
|
|
|
|
{
|
|
|
|
return Success("更新成功");
|
|
|
|
}
|
|
|
|
return Error("操作失败!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AjaxResult DeleteItem(string id)
|
|
|
|
{
|
|
|
|
|
|
|
|
string itemId = Db.GetIQueryable<teamitems>().FirstOrDefault(c => c.Id == id)?.ItemId;
|
|
|
|
|
|
|
|
var result = Db.RunTransaction(() =>
|
|
|
|
{
|
|
|
|
var row = Db.Delete<teamitems>(c => c.Id == id);
|
|
|
|
|
|
|
|
if (row <= 0)
|
|
|
|
{
|
|
|
|
throw new Exception("操作失败!");
|
|
|
|
}
|
|
|
|
|
|
|
|
row = Db.Update<itemlabels>(c => c.ItemsId == itemId && c.TeamId == _operator.TeamId, (item) =>
|
|
|
|
{
|
|
|
|
//item.IsScreening = false;
|
|
|
|
item.IsAdded = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
//if (row <= 0)
|
|
|
|
//{
|
|
|
|
// throw new Exception($"删除失败!");
|
|
|
|
//}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (result.Success)
|
|
|
|
{
|
|
|
|
return Success();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Error(result.ex.Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|