Commit 8dcce85e authored by liudong1993's avatar liudong1993

商品采购

parent 210d19f4
......@@ -387,6 +387,25 @@ namespace Mall.Model.Entity.Product
/// 供应商id
/// </summary>
public int SupplierId { get; set; }
/// <summary>
/// 商品是否可代理 1是 2否
/// </summary>
public int? IsProxy { get; set; }
/// <summary>
/// 代理成本上浮类型 1百分比 2固定金额
/// </summary>
public int? ProxyType { get; set; }
/// <summary>
/// 价格上涨
/// </summary>
public decimal? ProxyRises { get; set; }
/// <summary>
/// 代理价格
/// </summary>
public decimal? ProxyMoney { get; set; }
/// <summary>
/// 是否是采购商品 1是 2否
/// </summary>
public int? IsProcurement { get; set; }
}
}
......@@ -22,6 +22,14 @@ namespace Mall.Model.Extend.Product
/// </summary>
public int? GoodsId { get; set; }
/// <summary>
/// 采购商品id
/// </summary>
public int? ProcurementGoodsId { get; set; }
/// <summary>
/// 其他商户
/// </summary>
public int? NotTenantId { get; set; }
/// <summary>
/// 商品购买的数量
/// </summary>
public int? GoodsBuyNum { get; set; }
......
......@@ -13,6 +13,9 @@ namespace Mall.Model.Extend.Product
[DB(ConnectionName = "DefaultConnection")]
public class RB_Goods_Proxy_Extend : RB_Goods_Proxy
{
/// <summary>
/// 商品ids
/// </summary>
public string GoodsIds { get; set; }
}
}
......@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Mall.Common;
using Mall.Common.API;
using Mall.Common.Plugin;
using Mall.Model.Entity.Product;
using Mall.Model.Entity.User;
......@@ -147,6 +148,13 @@ namespace Mall.Module.Product
/// 商品分销
/// </summary>
private readonly RB_MiniProgram_GoodPosterRepository miniProgram_GoodPosterRepository = new RB_MiniProgram_GoodPosterRepository();
/// <summary>
/// 商品代理
/// </summary>
private readonly RB_Goods_ProxyRepository goods_ProxyRepository = new RB_Goods_ProxyRepository();
#region 小程序接口
......@@ -3197,6 +3205,49 @@ namespace Mall.Module.Product
return list;
}
/// <summary>
/// 获取后台商品代理分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="demodel"></param>
/// <returns></returns>
public List<RB_Goods_Extend> GetProductGoodsProxyPageList(int pageIndex, int pageSize, out long count, RB_Goods_Extend demodel)
{
var list = goodsRepository.GetPageList(pageIndex, pageSize, out count, demodel);
if (list.Any())
{
//查询分类
string ids = string.Join(",", list.Select(x => x.Id));
var clist = goods_CategoryRepository.GetList(new RB_Goods_Category_Extend() { GoodsIds = ids, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
var olist = goods_OrderRepository.GetGoodsOrderNum(ids);
//查询商品是否已代理
var ProxyList = goods_ProxyRepository.GetList(new RB_Goods_Proxy_Extend() { GoodsIds = ids, ProxyTenantId = demodel.TenantId, ProxyMallBaseId = demodel.MallBaseId });
foreach (var item in list)
{
item.CategoryList = clist.Where(x => x.GoodsId == item.Id).ToList();
//轮播图
item.CoverImage = "";
if (!string.IsNullOrEmpty(item.CarouselImage) && item.CarouselImage != "[]")
{
List<string> CarouselIdList = JsonConvert.DeserializeObject<List<string>>(item.CarouselImage);
//封面图
item.CoverImage = CarouselIdList[0];
}
item.GoodsBuyNum = olist.Where(x => x.GoodsId == item.Id).FirstOrDefault()?.OrderNum ?? 0;
item.IsProcurement = 2;
item.ProcurementGoodsId = 0;
if (ProxyList.Where(x => x.GoodsId == item.Id).Any()) {
item.IsProcurement = 1;
item.ProcurementGoodsId = ProxyList.Where(x => x.GoodsId == item.Id).FirstOrDefault()?.GoodsId ?? 0;
}
}
}
return list;
}
/// <summary>
/// 获取后台商品列表
/// </summary>
......@@ -3299,6 +3350,23 @@ namespace Mall.Module.Product
/// <returns></returns>
public bool SetProductGoodsInfo(RB_Goods_Extend demodel)
{
if (demodel.Id > 0) {
var goodsModel = goodsRepository.GetEntity(demodel.Id);
if (goodsModel == null)
{
return false;
}
if (goodsModel.IsProcurement == 1)
{
//是采购的商品
if (demodel.CostPrice != goodsModel.CostPrice)
{
return false;
}
//验证 规格
}
}
var trans = goodsRepository.DbTransaction;
try
{
......@@ -3346,7 +3414,11 @@ namespace Mall.Module.Product
{ nameof(RB_Goods.EnjoyMember),demodel.EnjoyMember},
{ nameof(RB_Goods.SeparateSetMember),demodel.SeparateSetMember},
{ nameof(RB_Goods.IsQuickBuy),demodel.IsQuickBuy},
{ nameof(RB_Goods.SupplierId),demodel.SupplierId}
{ nameof(RB_Goods.SupplierId),demodel.SupplierId},
{ nameof(RB_Goods.IsProxy),demodel.IsProxy},
{ nameof(RB_Goods.ProxyType),demodel.ProxyType},
{ nameof(RB_Goods.ProxyRises),demodel.ProxyRises},
{ nameof(RB_Goods.ProxyMoney),demodel.ProxyMoney},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
......@@ -4436,6 +4508,148 @@ namespace Mall.Module.Product
#endregion
#region 商品代理
/// <summary>
/// 新增代理商品
/// </summary>
/// <param name="goodsId"></param>
/// <param name="tenantId"></param>
/// <param name="mallBaseId"></param>
/// <returns></returns>
public ApiResult SetProductGoodsProxy(int goodsId, int tenantId, int mallBaseId)
{
var plist = goods_ProxyRepository.GetList(new RB_Goods_Proxy_Extend() { GoodsId = goodsId, ProxyMallBaseId = mallBaseId, ProxyTenantId = tenantId });
if (plist.Any()) {
return ApiResult.Failed("该商品已存在采购");
}
var goodsModel = goodsRepository.GetEntity(goodsId);
if (goodsModel == null) {
return ApiResult.Failed("采购商品不存在");
}
if (goodsModel.IsProxy != 1) {
return ApiResult.Failed("采购商品不可代理");
}
if (goodsModel.IsProcurement == 1) {
return ApiResult.Failed("采购商品不可代理");
}
if (goodsModel.TenantId == tenantId) {
return ApiResult.Failed("不可采购同商户商品");
}
if ((goodsModel.ProxyMoney ?? 0) <= 0) {
return ApiResult.Failed("采购商品有误");
}
var trans = goodsRepository.DbTransaction;
try
{
//复制商品信息
int Id = goodsRepository.Insert(new RB_Goods()
{
Name = goodsModel.Name,
CarouselImage = goodsModel.CarouselImage,
VideoAddress = goodsModel.VideoAddress,
CustomShareTitles = goodsModel.CustomShareTitles,
CustomShareImage = goodsModel.CustomShareImage,
GoodsStatus = goodsModel.GoodsStatus,
InventoryNum = goodsModel.InventoryNum,
DefaultSpecificationName = goodsModel.DefaultSpecificationName,
IsCustomSpecification = goodsModel.IsCustomSpecification,
Sort = goodsModel.Sort,
SellingPrice = goodsModel.SellingPrice,
OriginalPrice = goodsModel.OriginalPrice,
Unit = goodsModel.Unit,
CostPrice = goodsModel.ProxyMoney,
IsGoodsNegotiable = goodsModel.IsGoodsNegotiable,
SalesNum = goodsModel.SalesNum,
GoodsNumbers = goodsModel.GoodsNumbers,
GoodsWeight = goodsModel.GoodsWeight,
IsDefaultService = 1,
GoodsService = "[]",
FreightId = 0,
FormsId = 0,
LimitBuyGoodsNum = goodsModel.LimitBuyGoodsNum,
LimitBuyOrderNum = goodsModel.LimitBuyOrderNum,
FullNumPinkage = goodsModel.FullNumPinkage,
FullMoneyPinkage = goodsModel.FullMoneyPinkage,
IsAreaBuy = 2,
IntegralPresent = goodsModel.IntegralPresent,
IntegralPresentType = goodsModel.IntegralPresentType,
PointsDeduction = goodsModel.PointsDeduction,
PointsDeductionType = goodsModel.PointsDeductionType,
IsMultipleDeduction = goodsModel.IsMultipleDeduction,
GoodsDetails = goodsModel.GoodsDetails,
Status = 0,
TenantId = tenantId,
MallBaseId = mallBaseId,
CreateDate = DateTime.Now,
UpdateDate = DateTime.Now,
SeparateDistribution = 2,
SeparateDistributionType = 1,
SeparateDistributionMoneyType = 1,
EnjoyMember = 2,
SeparateSetMember = 2,
IsQuickBuy = 2,
IsSellWell = 2,
GoodsType = goodsModel.GoodsType,
SupplierId = 0,
IsProxy = 2,
ProxyType = 1,
ProxyRises = 0,
ProxyMoney = 0,
IsProcurement = 1
}, trans);
if (Id > 0)
{
//复制规格
var slist = goods_SpecificationRepository.GetList(new RB_Goods_Specification_Extend() { GoodsId = goodsId });
var svlist = goods_SpecificationValueRepository.GetList(new RB_Goods_SpecificationValue_Extend() { GoodsId = goodsId });
foreach (var item in slist) {
goods_SpecificationRepository.Insert(new RB_Goods_Specification()
{
EnabledImage = item.EnabledImage,
CreateDate = DateTime.Now,
GoodsId = Id,
Id = 0,
MallBaseId = mallBaseId,
Name = item.Name,
Sort = item.Sort,
Status = 0,
TenantId = tenantId
}, trans);
}
foreach (var item in svlist) {
goods_SpecificationValueRepository.Insert(new RB_Goods_SpecificationValue()
{
TenantId = tenantId,
Status = 0,
Sort = item.Sort,
CreateDate = DateTime.Now,
GoodsId = Id,
Id = 0,
Image = item.Image,
MallBaseId = mallBaseId,
Name = item.Name,
SpecificationId = item.SpecificationId
}, trans);
}
}
goodsRepository.DBSession.Commit();
if (Id > 0)
return ApiResult.Success();
else
return ApiResult.Failed();
}
catch (Exception ex)
{
LogHelper.Write(ex, "SetProductGoodsProxy");
goodsRepository.DBSession.Rollback("SetProductGoodsProxy");
return ApiResult.Failed();
}
}
#endregion
#region 商品导入
/// <summary>
......@@ -4769,6 +4983,12 @@ namespace Mall.Module.Product
item.SeparateSetMember ??= 2;
item.GoodsType ??= Common.Enum.Goods.OrderTypeEnum.Mall;
item.IsProxy ??= 2;
item.ProxyType ??= 0;
item.ProxyRises ??= 0;
item.ProxyMoney ??= 0;
item.IsProcurement = 2;
item.Status = 0;
item.TenantId = tenantId;
item.MallBaseId = mallBaseId;
......
......@@ -27,6 +27,9 @@ namespace Mall.Repository.Product
if (dmodel.TenantId > 0) {
where += $@" and g.{nameof(RB_Goods_Extend.TenantId)}={dmodel.TenantId}";
}
if (dmodel.NotTenantId > 0) {
where += $@" and g.{nameof(RB_Goods_Extend.TenantId)}<>{dmodel.NotTenantId}";
}
if (dmodel.MallBaseId > 0) {
where += $@" and g.{nameof(RB_Goods_Extend.MallBaseId)}={dmodel.MallBaseId}";
}
......@@ -54,6 +57,12 @@ namespace Mall.Repository.Product
if (!string.IsNullOrEmpty(dmodel.EndTime)) {
where += $@" and g.{nameof(RB_Goods_Extend.CreateDate)} <='{dmodel.EndTime + " 23:59:59"}'";
}
if (dmodel.IsProcurement > 0) {
where += $@" and g.{nameof(RB_Goods_Extend.IsProcurement)}={dmodel.IsProcurement}";
}
if (dmodel.IsProxy > 0) {
where += $@" and g.{nameof(RB_Goods_Extend.IsProxy)}={dmodel.IsProxy}";
}
string sql = $@"select g.* from RB_Goods g
inner join rb_goods_category c on g.Id=c.GoodsId
......
using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.Product;
using Mall.Model.Extend.Product;
using System.Linq;
using Mall.Model.Entity.User;
namespace Mall.Repository.Product
{
/// <summary>
/// 商品代理仓储层
/// </summary>
public class RB_Goods_ProxyRepository : RepositoryBase<RB_Goods_Proxy>
{
/// <summary>
/// 获取列表
/// </summary>
/// <param name="dmodel"></param>
/// <returns></returns>
public List<RB_Goods_Proxy_Extend> GetList(RB_Goods_Proxy_Extend dmodel)
{
string where = $" 1=1 and Status =0";
if (dmodel.TenantId > 0)
{
where += $@" and {nameof(RB_Goods_Proxy.TenantId)}={dmodel.TenantId}";
}
if (dmodel.MallBaseId > 0)
{
where += $@" and {nameof(RB_Goods_Proxy.MallBaseId)}={dmodel.MallBaseId}";
}
if (dmodel.ProxyTenantId > 0)
{
where += $@" and {nameof(RB_Goods_Proxy.ProxyTenantId)}={dmodel.ProxyTenantId}";
}
if (dmodel.ProxyMallBaseId > 0)
{
where += $@" and {nameof(RB_Goods_Proxy.ProxyMallBaseId)}={dmodel.ProxyMallBaseId}";
}
if (dmodel.GoodsId > 0)
{
where += $@" and {nameof(RB_Goods_Proxy.GoodsId)}={dmodel.GoodsId}";
}
if (!string.IsNullOrEmpty(dmodel.GoodsIds))
{
where += $@" and {nameof(RB_Goods_Proxy.GoodsId)} in({dmodel.GoodsIds})";
}
if (dmodel.ProxyGoodsId > 0)
{
where += $@" and {nameof(RB_Goods_Proxy.ProxyGoodsId)}={dmodel.ProxyGoodsId}";
}
string sql = $@"SELECT * FROM RB_Goods_Proxy where {where} order by Id asc";
return Get<RB_Goods_Proxy_Extend>(sql).ToList();
}
}
}
......@@ -1091,6 +1091,8 @@ namespace Mall.WebApi.Controllers.MallBase
x.SalesNum,
x.GoodsBuyNum,
x.IsQuickBuy,
x.IsProxy,
x.IsProcurement,
x.GoodsStatus,
x.TenantId,
x.MallBaseId,
......@@ -1384,6 +1386,11 @@ namespace Mall.WebApi.Controllers.MallBase
model.SeparateSetMember,
model.IsQuickBuy,
model.SupplierId,
model.IsProxy,
model.ProxyType,
model.ProxyRises,
model.ProxyMoney,
model.IsProcurement,
CategoryList = model.CategoryList.Select(x=>new {
x.Id,
x.CategoryId,
......@@ -1859,6 +1866,25 @@ namespace Mall.WebApi.Controllers.MallBase
demodel.GoodsType ??= Common.Enum.Goods.OrderTypeEnum.Mall;
demodel.GoodsStatus ??= 2;
demodel.IsProxy ??= 2;
demodel.ProxyType ??= 1;
demodel.ProxyRises ??= 0;
demodel.ProxyMoney ??= 0;
demodel.IsProcurement = 2;//新增时
if (demodel.IsProxy == 1 && demodel.CostPrice > 0) {
decimal ProxyMoney = 0;
if (demodel.ProxyType == 1)
{
ProxyMoney = Math.Round((demodel.CostPrice ?? 0) * (1 + (demodel.ProxyRises ?? 0)), 2, MidpointRounding.AwayFromZero);
}
else {
ProxyMoney = (demodel.CostPrice ?? 0) + (demodel.ProxyRises ?? 0);
}
if (ProxyMoney != (demodel.ProxyMoney ?? 0)) {
return ApiResult.ParamIsNull("代理价格不正确");
}
}
bool flag = productModule.SetProductGoodsInfo(demodel);
if (flag)
{
......@@ -1939,6 +1965,63 @@ namespace Mall.WebApi.Controllers.MallBase
#endregion
#region 商品代理
/// <summary>
/// 商品代理分页列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetProductGoodsProxyPageList()
{
var parms = RequestParm;
ResultPageModel pagelist = JsonConvert.DeserializeObject<ResultPageModel>(parms.msg.ToString());
RB_Goods_Extend demodel = JsonConvert.DeserializeObject<RB_Goods_Extend>(parms.msg.ToString());
demodel.NotTenantId = parms.TenantId;
//demodel.MallBaseId = parms.MallBaseId;
demodel.IsProxy = 1;
demodel.IsProcurement = 2;
var list = productModule.GetProductGoodsProxyPageList(pagelist.pageIndex, pagelist.pageSize, out long count, demodel);
pagelist.count = Convert.ToInt32(count);
pagelist.pageData = list.Select(x => new
{
x.Id,
x.Name,
x.Sort,
x.CoverImage,
CategoryList = x.CategoryList.Select(y => new { y.Id, y.CategoryName }),
x.ProxyMoney,
x.InventoryNum,
SalesNum = (x.SalesNum ?? 0) + (x.GoodsBuyNum ?? 0),
x.IsProcurement,
x.ProcurementGoodsId,
x.GoodsStatus,
x.TenantId,
x.MallBaseId,
CreateDate = x.CreateDate.HasValue ? x.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""
});
return ApiResult.Success("", pagelist);
}
/// <summary>
/// 设置商品代理
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SetProductGoodsProxy() {
var req = RequestParm;
JObject parms = JObject.Parse(req.msg.ToString());
int GoodsId = parms.GetInt("GoodsId", 0);
if (GoodsId <= 0) {
return ApiResult.ParamIsNull("请传递商品id");
}
return productModule.SetProductGoodsProxy(GoodsId, req.TenantId, req.MallBaseId);
}
#endregion
#region 商品导入
/// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment