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.
101 lines
5.6 KiB
101 lines
5.6 KiB
using BBWYB.Common.Log;
|
|
using BBWYB.Common.Models;
|
|
using BBWYB.Server.Model;
|
|
using BBWYB.Server.Model.Db;
|
|
using BBWYB.Server.Model.Dto;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace BBWYB.Server.Business
|
|
{
|
|
public class PurchaserBusiness : BaseBusiness, IDenpendency
|
|
{
|
|
public PurchaserBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator) : base(fsql, nLogManager, idGenerator)
|
|
{
|
|
|
|
}
|
|
|
|
public ListResponse<string> QueryPurchaserNameList(string keywords)
|
|
{
|
|
if (string.IsNullOrEmpty(keywords))
|
|
throw new BusinessException("关键字不能为空");
|
|
var list = fsql.Select<Purchaser>().Where(p => p.Name.Contains(keywords)).Distinct().ToList(x => x.Name);
|
|
return new ListResponse<string> { Items = list, TotalCount = list.Count() };
|
|
}
|
|
|
|
public ListResponse<string> QueryPurchaserLocationList(string keywords)
|
|
{
|
|
if (string.IsNullOrEmpty(keywords))
|
|
throw new BusinessException("关键字不能为空");
|
|
var list = fsql.Select<Purchaser>().Where(p => p.Location.Contains(keywords)).Distinct().ToList(x => x.Location);
|
|
return new ListResponse<string> { Items = list, TotalCount = list.Count() };
|
|
}
|
|
|
|
public ListResponse<PurchaserResponse> QueryPurchaserList(QueryPurchaserRequest request)
|
|
{
|
|
if (request.PageSize > 20)
|
|
request.PageSize = 20;
|
|
var purchaserList = fsql.Select<Purchaser>()
|
|
.WhereIf(!string.IsNullOrEmpty(request.Spu), p => fsql.Select<PurchaseSchemeProduct>()
|
|
.Where(psp1 => psp1.PurchaserId == p.Id &&
|
|
psp1.ProductId == request.Spu)
|
|
.Any())
|
|
.WhereIf(!string.IsNullOrEmpty(request.Sku), p => fsql.Select<PurchaseSchemeProduct>()
|
|
.Where(psp2 => psp2.PurchaserId == p.Id &&
|
|
psp2.SkuId == request.Sku)
|
|
.Any())
|
|
.WhereIf(request.PurchaserNameList != null && request.PurchaserNameList.Count() > 0, p => request.PurchaserNameList.Contains(p.Name))
|
|
.WhereIf(request.CategoryIdList != null && request.CategoryIdList.Count() > 0, p => fsql.Select<Purchaser_ExtendedInfo_Relation>()
|
|
.Where(per => per.PurchaserId == p.Id &&
|
|
request.CategoryIdList.Contains(per.ExtendedInfoId.Value)).Any())
|
|
.WhereIf(request.LocationList != null && request.LocationList.Count() > 0, p => request.LocationList.Contains(p.Location))
|
|
.Page(request.PageIndex, request.PageSize)
|
|
.Count(out var count)
|
|
.ToList<PurchaserResponse>();
|
|
return new ListResponse<PurchaserResponse>()
|
|
{
|
|
Items = purchaserList,
|
|
TotalCount = count
|
|
};
|
|
}
|
|
|
|
public ListResponse<PurchaserExtendedInfoResponse> QueryPurchaserCategoryList(QueryPurchaserExtendedRequest request)
|
|
{
|
|
var list = fsql.Select<PurchaserExtendedInfo>()
|
|
.WhereIf(request.Type != null, x => x.Type == request.Type)
|
|
.WhereIf(!string.IsNullOrEmpty(request.Keywords), x => x.Name.Contains(request.Keywords))
|
|
.Count(out var count)
|
|
.ToList<PurchaserExtendedInfoResponse>();
|
|
return new ListResponse<PurchaserExtendedInfoResponse> { Items = list, TotalCount = count };
|
|
}
|
|
|
|
public void EditPurchaserExtendedInfo(EditPurchaserExtendedInfoRequest request)
|
|
{
|
|
var insertRelationList = new List<Purchaser_ExtendedInfo_Relation>();
|
|
insertRelationList.AddRange(request.CategoryIdList.Select(x => new Purchaser_ExtendedInfo_Relation()
|
|
{
|
|
Id = idGenerator.NewLong(),
|
|
PurchaserId = request.PurchaserId,
|
|
ExtendedType = Enums.PurchaserBasicInfoType.主营类目,
|
|
ExtendedInfoId = x
|
|
}));
|
|
|
|
insertRelationList.AddRange(request.TagIdList.Select(x => new Purchaser_ExtendedInfo_Relation()
|
|
{
|
|
Id = idGenerator.NewLong(),
|
|
PurchaserId = request.PurchaserId,
|
|
ExtendedType = Enums.PurchaserBasicInfoType.标签,
|
|
ExtendedInfoId = x
|
|
}));
|
|
|
|
fsql.Transaction(() =>
|
|
{
|
|
fsql.Delete<Purchaser_ExtendedInfo_Relation>().Where(r => r.PurchaserId == request.PurchaserId).ExecuteAffrows();
|
|
fsql.Update<Purchaser>(request.PurchaserId).Set(p => p.ManagmentMode, request.ManagmentMode).ExecuteAffrows();
|
|
if (insertRelationList.Count() > 0)
|
|
fsql.Insert(insertRelationList).ExecuteAffrows();
|
|
|
|
});
|
|
|
|
}
|
|
}
|
|
}
|
|
|