Commit e44994cd by lizefeng

销量上限的多种模型

parent a445a0f0
......@@ -40,7 +40,7 @@ namespace AutoTurnOver.DB
public static dc_base_warehouse GetWareHouseByCode(string code)
{
var sql = "select * from dc_base_warehouse where is_enabled=1 and warehouse_code='" + code + "'";
var sql = "select * from dc_base_warehouse where warehouse_code='" + code + "'";
return _connection.QueryFirstOrDefault<dc_base_warehouse>(sql);
}
......
......@@ -133,23 +133,23 @@ namespace AutoTurnOver.DB
#endregion
#region 销量上限设置
#region 销量上限规则设置
/// <summary>
/// 获取销量上限设置分页列表
/// 获取销量上限规则设置分页列表
/// </summary>
/// <param name="m"></param>
/// <param name="offset"></param>
/// <param name="limit"></param>
/// <param name="total"></param>
/// <returns></returns>
public static List<dc_auto_config_sales_upper_limit> SalesUpperLimitList(Condition_ConfigPromotion m, int offset, int limit, ref int total)
public static List<dc_auto_config_sales_upper_limitDto> SalesUpperLimitList(Condition_ConfigPromotion m, int offset, int limit, ref int total)
{
var list = new List<dc_auto_config_sales_upper_limit>();
var list = new List<dc_auto_config_sales_upper_limitDto>();
try
{
var sql = @"select * from dc_auto_config_sales_upper_limit as dacp where dacp.bailun_sku!='common' ";
var sql = @"select * from dc_auto_config_sales_upper_limit as dacp ";
if (m.IsEffective == true)
{
......@@ -157,7 +157,7 @@ namespace AutoTurnOver.DB
}
if (!string.IsNullOrWhiteSpace(m.sku))
{
sql += " and dacp.bailun_sku like '%" + m.sku + "%'";
sql += " and dacp.variable_code like '%" + m.sku + "%'";
}
if (!string.IsNullOrWhiteSpace(m.warehousecode))
......@@ -167,7 +167,7 @@ namespace AutoTurnOver.DB
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_config_sales_upper_limit>(sql + " limit " + offset + "," + limit);
var obj = _connection.Query<dc_auto_config_sales_upper_limitDto>(sql + " limit " + offset + "," + limit);
return obj.AsList();
......@@ -180,14 +180,14 @@ namespace AutoTurnOver.DB
/// <summary>
/// 保存销量上限
/// 保存安全库存规则
/// </summary>
/// <param name="m">销售设置model</param>
/// <param name="username">当前操作人名称</param>
/// <returns></returns>
public static string SaveSalesUpperLimit(Models.dc_auto_config_sales_upper_limit m, string username)
{
var obj = _connection.QueryFirstOrDefault<Models.dc_auto_config_sales_upper_limit>("select * from dc_auto_config_safe_inventory where id=" + m.id);
var obj = _connection.QueryFirstOrDefault<Models.dc_auto_config_sales_upper_limit>("select * from dc_auto_config_sales_upper_limit where id=" + m.id);
if (obj == null)
{
obj = new dc_auto_config_sales_upper_limit
......@@ -197,21 +197,25 @@ namespace AutoTurnOver.DB
}
obj.id = m.id;
obj.bailun_sku = m.bailun_sku;
obj.sku_name = m.sku_name;
obj.variable_code = m.variable_code;
obj.variable_name = m.variable_name;
obj.bl_operator = username ?? "";
obj.gmt_modified = DateTime.Now;
obj.remark = m.remark;
obj.warehouse_code = m.warehouse_code;
obj.warehouse_name = m.warehouse_name;
obj.status = m.status;
obj.value_or_coefficient = m.value_or_coefficient;
obj.weighting_coefficient_fourteen = m.weighting_coefficient_fourteen;
obj.weighting_coefficient_seven = m.weighting_coefficient_seven;
obj.weighting_coefficient_thirty = m.weighting_coefficient_thirty;
obj.type = m.type;
obj.param = m.param;
// 检查该数据是否有存在
var oldData = _connection.QueryFirstOrDefault(" select * from dc_auto_config_sales_upper_limit where bailun_sku=@bailun_sku and warehouse_code=@warehouse_code and id!=@id ", new { m.bailun_sku, m.warehouse_code, m.id });
var oldData = _connection.QueryFirstOrDefault(" select * from dc_auto_config_sales_upper_limit where variable_code=@variable_code and warehouse_code=@warehouse_code and type=@type and id!=@id ", new { m.variable_code, m.warehouse_code, m.id, m.type });
if (oldData != null)
{
return $" variable_code:【{m.bailun_sku}】,仓库:【{m.warehouse_code}】 已经配置过了 ";
return $" variable_code:【{m.variable_code}】,仓库:【{m.variable_name}】 已经配置过了 ";
}
try
......@@ -240,7 +244,7 @@ namespace AutoTurnOver.DB
/// <summary>
/// 获取销量上限设置详情
/// 获取安全库存规则设置详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
......
......@@ -10,14 +10,12 @@ namespace AutoTurnOver.Models
public class dc_auto_config_sales_upper_limit
{
public int id { get; set; }
public DateTime gmt_create { get; set; }
public DateTime gmt_modified { get; set; }
public string bailun_sku { get; set; }
public string variable_code { get; set; }
public string sku_name { get; set; }
public string variable_name { get; set; }
public string warehouse_code { get; set; }
......@@ -33,8 +31,47 @@ namespace AutoTurnOver.Models
public int status { get; set; }
/// <summary>
/// 上限值,或上限倍数
/// 7 天加权
/// </summary>
public decimal weighting_coefficient_seven { get; set; }
/// <summary>
/// 14 天加权
/// </summary>
public int value_or_coefficient { get; set; }
public decimal weighting_coefficient_fourteen { get; set; }
/// <summary>
/// 30 天加权
/// </summary>
public decimal weighting_coefficient_thirty { get; set; }
/// <summary>
/// 手动指定安全库存
/// </summary>
public int param { get; set; }
/// <summary>
/// 类型
/// </summary>
public int type { get; set; }
}
public class dc_auto_config_sales_upper_limitDto: dc_auto_config_sales_upper_limit
{
public string typeStr
{
get
{
return ((Safe_UpperLimitType)(type)).ToString();
}
}
}
public enum Safe_UpperLimitType
{
仓库_SKU_定值 = 1,
仓库_分类_定值 = 2,
仓库_SKU_按历史计算 = 11
}
}
......@@ -126,23 +126,23 @@ namespace AutoTurnOver.Services
#endregion
#region 销量上限配置
#region 安全库存规则配置
/// <summary>
/// 获取销量上限设置分页列表
/// 获取安全库存规则设置分页列表
/// </summary>
/// <param name="m"></param>
/// <param name="offset"></param>
/// <param name="limit"></param>
/// <returns></returns>
public List<dc_auto_config_sales_upper_limit> SalesUpperLimitList(Condition_ConfigPromotion m, int offset, int limit, ref int total)
public List<dc_auto_config_sales_upper_limitDto> SalesUpperLimitList(Condition_ConfigPromotion m, int offset, int limit, ref int total)
{
return DB.db_config.SalesUpperLimitList(m, offset, limit, ref total);
}
/// <summary>
/// 保存销量上限
/// 保存安全库存规则
/// </summary>
/// <param name="m">销售设置model</param>
/// <param name="username">当前操作人</param>
......@@ -161,25 +161,80 @@ namespace AutoTurnOver.Services
}
m.warehouse_name = objWarehouse.warehouse_name;
var objProduct = DB.common.GetPrductBySku(m.bailun_sku);
if (objProduct == null)
if (m.type == (int)Safe_UpperLimitType.仓库_SKU_定值)
{
return "系统找不到该Sku。";
if (string.IsNullOrWhiteSpace(m.variable_code))
{
return "Sku不能为空!";
}
if (m.param <= 0)
{
return "安全库存必填";
}
}
m.sku_name = objProduct.sku_title_cn;
else if (m.type == (int)Safe_UpperLimitType.仓库_分类_定值)
{
if (string.IsNullOrWhiteSpace(m.variable_code))
{
return "请选择分类";
}
if (m.param <= 0)
{
return "安全库存必填";
}
var cID = 0;
if (!int.TryParse(m.variable_code, out cID))
{
return "请选择分类";
}
var cModel = ApiServices.GetCategoryById(cID);
m.variable_name = cModel.C_CNAME;
}
else if (m.type == (int)Safe_UpperLimitType.仓库_SKU_按历史计算)
{
if (string.IsNullOrWhiteSpace(m.variable_code))
{
return "Sku不能为空!";
}
if (m.weighting_coefficient_seven <= 0)
{
return "请填写7天权重";
}
if (m.weighting_coefficient_fourteen <= 0)
{
return "请填写14天权重";
}
if (m.weighting_coefficient_thirty <= 0)
{
return "请填写30天权重";
}
if (m.weighting_coefficient_thirty + m.weighting_coefficient_seven + m.weighting_coefficient_fourteen != 1)
{
return "三个权重加起来不等于 1";
}
}
if (m.value_or_coefficient <= 0)
if (m.type == 1 || m.type == 11 || m.type == 12)
{
return "销量上线不可小于0";
var objProduct = DB.common.GetPrductBySku(m.variable_code);
if (objProduct == null)
{
return "系统找不到该Sku。";
}
m.variable_name = objProduct.sku_title_cn;
}
return DB.db_config.SaveSalesUpperLimit(m, username);
}
/// <summary>
/// 获取销量上限设置详情
/// 获取安全库存规则设置详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
......
......@@ -108,7 +108,7 @@ namespace AutoTurnOver.Controllers
}
/// <summary>
/// 保存销量上限设置
/// 保存安全库存规则设置
/// </summary>
/// <returns></returns>
[HttpPost]
......@@ -120,7 +120,7 @@ namespace AutoTurnOver.Controllers
/// <summary>
/// 获取销量上限设置详情
/// 获取安全库存规则设置详情
/// </summary>
/// <param name="id">销售设置id</param>
/// <returns></returns>
......
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