Commit 8e443eba authored by liudong1993's avatar liudong1993
parents 9da335cf bf783e16
...@@ -237,5 +237,37 @@ namespace REBORN.Common ...@@ -237,5 +237,37 @@ namespace REBORN.Common
return new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("ViewFileSiteUrl").Value; return new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("ViewFileSiteUrl").Value;
} }
} }
/// <summary>
/// 出库申请币种
/// </summary>
public static string OutCurrencyId
{
get
{
return new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("OutCurrencyId").Value;
}
}
/// <summary>
/// 财务单据请求参数Key
/// </summary>
public static string FinanceKey
{
get
{
return new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("FinanceKey").Value;
}
}
/// <summary>
/// 生成付款成本财务单据
/// </summary>
public static string PaymentFinanceApi
{
get
{
return new ConfigurationBuilder().Add(new JsonConfigurationSource { Path = "appsettings.json" }).Build().GetSection("PaymentFinanceApi").Value;
}
}
} }
} }
\ No newline at end of file
...@@ -229,6 +229,34 @@ namespace REBORN.Common ...@@ -229,6 +229,34 @@ namespace REBORN.Common
#endregion #endregion
#region AES加密算法 #region AES加密算法
/// <summary>
/// AES 加密
/// </summary>
/// <param name="str">明文(待加密)</param>
/// <param name="key">密文</param>
/// <returns></returns>
public static string AesEncrypt(string str, string key)
{
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
RijndaelManaged rm = new RijndaelManaged
{
Key = Encoding.UTF8.GetBytes(key),
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
ICryptoTransform cTransform = rm.CreateEncryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
/// <summary> /// <summary>
/// AES加密 /// AES加密
/// </summary> /// </summary>
......
using REBORN.Common.AOP;
using System;
using System.Collections.Generic;
using System.Text;
namespace Property.Model.Entity.Mall
{
/// <summary>
/// 商品订单明细表实体
/// </summary>
[Serializable]
[DB(ConnectionName = "MallConnection")]
public class RB_Goods_OrderDetail
{
/// <summary>
/// Id
/// </summary>
public int Id
{
get;
set;
}
/// <summary>
/// 订单id
/// </summary>
public int? OrderId
{
get;
set;
}
/// <summary>
/// 商品id
/// </summary>
public int? GoodsId
{
get;
set;
}
/// <summary>
/// 订单类型 枚举
/// </summary>
public int OrderType
{
get;
set;
}
/// <summary>
/// 商品名称
/// </summary>
public string GoodsName
{
get;
set;
}
/// <summary>
/// 封面图
/// </summary>
public string CoverImage
{
get;
set;
}
/// <summary>
/// 规格
/// </summary>
public string Specification
{
get;
set;
}
/// <summary>
/// 规格key
/// </summary>
public string SpecificationSort { get; set; }
/// <summary>
/// 货号
/// </summary>
public string ProductCode
{
get;
set;
}
/// <summary>
/// 单价
/// </summary>
public decimal? Unit_Price
{
get;
set;
}
/// <summary>
/// 数量
/// </summary>
public int? Number
{
get;
set;
}
/// <summary>
/// 原价 (=单价*数量)
/// </summary>
public decimal? Original_Price
{
get;
set;
}
/// <summary>
/// 最终价格(不包含运费)
/// </summary>
public decimal? Final_Price
{
get;
set;
}
/// <summary>
/// 折扣
/// </summary>
public decimal? DiscountRate
{
get;
set;
}
/// <summary>
/// 是否商品单独会员价购买 1是 2否
/// </summary>
public int? IsMemberPrice
{
get;
set;
}
/// <summary>
/// 商户号
/// </summary>
public int TenantId
{
get;
set;
}
/// <summary>
/// 小程序id
/// </summary>
public int MallBaseId
{
get;
set;
}
/// <summary>
/// CreateDate
/// </summary>
public DateTime? CreateDate
{
get;
set;
}
/// <summary>
/// UpdateDate
/// </summary>
public DateTime? UpdateDate
{
get;
set;
}
/// <summary>
/// 成本价
/// </summary>
public decimal? CostMoney { get; set; }
/// <summary>
/// 是否评论 1是 2否
/// </summary>
public int? IsComment { get; set; }
/// <summary>
/// 运费
/// </summary>
public decimal? FreightMoney { get; set; }
/// <summary>
/// 使用积分数量
/// </summary>
public int? IntegralNumber { get; set; }
/// <summary>
/// 积分抵扣金额
/// </summary>
public decimal? IntegralMoney { get; set; }
/// <summary>
/// 优惠券使用金额
/// </summary>
public decimal? CouponMoney { get; set; }
/// <summary>
/// 运费成本
/// </summary>
public decimal? FreightCostMoney { get; set; }
/// <summary>
/// 供应商id
/// </summary>
public int SupplierId { get; set; }
/// <summary>
/// 成本单据ID
/// </summary>
public int CostFinanceId { get; set; }
/// <summary>
/// 积分赠送
/// </summary>
public int? IntegralGoodsPresent { get; set; }
}
}
...@@ -134,9 +134,9 @@ namespace Property.Model.Entity.Mall ...@@ -134,9 +134,9 @@ namespace Property.Model.Entity.Mall
} }
/// <summary> /// <summary>
/// 供应商id /// 出库单id
/// </summary> /// </summary>
public int SupplierId public int StockInId
{ {
get; get;
set; set;
......
...@@ -14,6 +14,11 @@ namespace Property.Model.Entity.Mall ...@@ -14,6 +14,11 @@ namespace Property.Model.Entity.Mall
{ {
/// <summary>
/// 入库单id
/// </summary>
public int StockInId { get; set; }
/// <summary> /// <summary>
/// 物料id /// 物料id
/// </summary> /// </summary>
......
using Property.Model.Entity.Mall; using DapperExtensions.Lambda;
using Newtonsoft.Json.Linq;
using Property.Model.Entity;
using Property.Model.Entity.Mall;
using Property.Model.Extend;
using Property.Model.Extend.Mall; using Property.Model.Extend.Mall;
using Property.Repository; using Property.Repository;
using Property.Repository.Mall; using Property.Repository.Mall;
using REBORN.Common;
using REBORN.Common.Enum;
using REBORN.Common.Plugin;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -21,12 +28,16 @@ namespace Property.Module.Mall ...@@ -21,12 +28,16 @@ namespace Property.Module.Mall
/// 出库申请仓储层 /// 出库申请仓储层
/// </summary> /// </summary>
private readonly RB_WarehouseOut_ApplyRepository warehouseOutApplyRepository = new RB_WarehouseOut_ApplyRepository(); private readonly RB_WarehouseOut_ApplyRepository warehouseOutApplyRepository = new RB_WarehouseOut_ApplyRepository();
private readonly RB_WarehouseOut_FinanceRepository warehouseOutFinanceRepository = new RB_WarehouseOut_FinanceRepository();
private readonly RB_WarehouseOut_GoodsDetailRepository warehouseOutGoodsDetailRepository = new RB_WarehouseOut_GoodsDetailRepository();
/// <summary> /// <summary>
/// 小程序仓储 /// 小程序仓储
/// </summary> /// </summary>
private readonly RB_MiniProgramRepository miniProgramRepository = new RB_MiniProgramRepository(); private readonly RB_MiniProgramRepository miniProgramRepository = new RB_MiniProgramRepository();
private readonly RB_Goods_OrderDetailRepository goodsOrderDetailRepository = new RB_Goods_OrderDetailRepository();
/// <summary> /// <summary>
/// 商户仓储 /// 商户仓储
...@@ -35,6 +46,27 @@ namespace Property.Module.Mall ...@@ -35,6 +46,27 @@ namespace Property.Module.Mall
private readonly Rb_employeeRepository employeeRepository = new Rb_employeeRepository(); private readonly Rb_employeeRepository employeeRepository = new Rb_employeeRepository();
/// <summary>
/// 库存表
/// </summary>
private readonly RB_Supplies_InventoryRepository supplies_InventoryRepository = new RB_Supplies_InventoryRepository();
/// <summary>
/// 库存明细表
/// </summary>
private readonly RB_Supplies_InventoryDetailRepository supplies_InventoryDetailRepository = new RB_Supplies_InventoryDetailRepository();
/// <summary>
/// 出库单
/// </summary>
private readonly RB_Supplies_StockOutRepository supplies_StockOutRepository = new RB_Supplies_StockOutRepository();
/// <summary>
/// 出库单明细
/// </summary>
private readonly RB_Supplies_StockOutDetailRepository supplies_StockOutDetailRepository = new RB_Supplies_StockOutDetailRepository();
/// <summary> /// <summary>
/// 出库申请列表 /// 出库申请列表
/// </summary> /// </summary>
...@@ -185,5 +217,223 @@ namespace Property.Module.Mall ...@@ -185,5 +217,223 @@ namespace Property.Module.Mall
/// <summary>
/// 保存出库单
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public bool SetStockOutInfo(RB_WarehouseOut_Apply_Extend applyModel, RB_Supplies_StockOut_Extend demodel, List<RB_WarehouseOut_Goods_Extend> financeList,int RB_Department_Id)
{
var trans = supplies_StockOutRepository.DbTransaction;
try
{
int Id = supplies_StockOutRepository.Insert(demodel, trans);
if (Id > 0)
{
#region 生成财务单据
var detailList = financeList.Select(x => new
{
CostTypeId = 213,
Number = x.Number,
OriginalMoney = (x.CostMoney ?? 0) * (x.Number ?? 0),
UnitPrice = (x.CostMoney ?? 0),
Remark = x.GoodsName + x.OrderNo
});
var financeObj = new
{
CreateBy = demodel.CreateBy,
IsPublic = 0,// supplierModel.ClientBankAccount.AccountType, //financeConfigurineModel.AccountType,
ClientType = 10,
ClientID = 3134,
CurrencyId = Config.OutCurrencyId,
WBMoney = financeList.Sum(x => (x.CostMoney ?? 0) * (x.Number ?? 0)),
RB_Branch_Id = demodel.RB_Branch_Id,
PayDate = System.DateTime.Now.ToString("yyyy-MM-dd"),
TemplateId = 128,
OrderSource = 16,
OtherType = 16,
Remark = System.DateTime.Now.ToString("yyyy年MM月dd日") + "生成财务单据",
detailList,
RB_Depart_Id = RB_Department_Id,
ReFinanceId = Id
};
string sign = EncryptionHelper.AesEncrypt(JsonHelper.Serialize(financeObj), Config.FinanceKey);
var resultInfo = new
{
msg = sign,
};
string apiResult = HttpHelper.HttpPost(Config.PaymentFinanceApi, JsonHelper.Serialize(resultInfo), "");
JObject parmsJob = JObject.Parse(apiResult);
string resultCode = parmsJob.GetStringValue("resultCode");
int frid = parmsJob.GetInt("data", 0);
#endregion
if (resultCode == "1" && frid > 0)//新增记录
{
applyModel.WarehouseOutFinanceModel.FinanceId = frid;
applyModel.WarehouseOutFinanceModel.StockInId = Id;
financeList.ForEach(x => x.WarehouseId = applyModel.WarehouseId);
financeList.ForEach(x => x.StockInId = Id);
applyModel.WarehouseOutGoodsDetailList.ForEach(x => x.StockOutId = Id);
//更新申请单的出库状态
Dictionary<string, object> filesApply = new Dictionary<string, object>() {
{ nameof(RB_WarehouseOut_Apply.OutStatus),applyModel.OutStatus}
};
List<WhereHelper> wheresApply = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_WarehouseOut_Apply.ID),
FiledValue=applyModel.ID,
OperatorEnum=OperatorEnum.Equal
}
};
warehouseOutApplyRepository.Update(filesApply, wheresApply, trans);
//更新已出库的商品信息
foreach (var item in applyModel.WarehouseOutGoodsList)
{
Dictionary<string, object> filesApplyGoods = new Dictionary<string, object>() {
{ nameof(RB_WarehouseOut_Goods.IsOut),1},
{ nameof(RB_WarehouseOut_Goods.CostMoney),item.CostMoney}
};
List<WhereHelper> wheresApplyGoods = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_WarehouseOut_Goods.ID),
FiledValue=item.ID,
OperatorEnum=OperatorEnum.Equal
}
};
warehouseOutRepository.Update(filesApplyGoods, wheresApplyGoods, trans);
//更新订单商品的财务id与成本价
decimal costMoney = 0;
var nowGoods = financeList.Where(x => x.OrderGoodsId == item.OrderGoodsId);
if (nowGoods != null && nowGoods.Any())
{
costMoney = (nowGoods.Sum(x => x.CostMoney ?? 0) / nowGoods.Sum(x => x.Number ?? 0));
//更新申请单的出库状态
Dictionary<string, object> filesGoods = new Dictionary<string, object>() {
{nameof(RB_Goods_OrderDetail.CostFinanceId),frid},
{ nameof(RB_Goods_OrderDetail.CostMoney),Math.Round(costMoney, 2, MidpointRounding.AwayFromZero)}
};
List<WhereHelper> wheresGoods = new List<WhereHelper>() { new WhereHelper()
{
FiledName=nameof(RB_Goods_OrderDetail.Id),
FiledValue=item.OrderGoodsId,
OperatorEnum=OperatorEnum.Equal
}
};
goodsOrderDetailRepository.Update(filesGoods, wheresGoods);
}
}
//新增申请单的财务单据
warehouseOutFinanceRepository.Insert(applyModel.WarehouseOutFinanceModel, trans);
warehouseOutGoodsDetailRepository.InsertBatch(applyModel.WarehouseOutGoodsDetailList, trans);
}
//编码自动生成
string BMStr = Id.ToString();
if (BMStr.Length < 5)
{
switch (BMStr.Length)
{
case 1:
BMStr = "0000" + BMStr; break;
case 2:
BMStr = "000" + BMStr; break;
case 3:
BMStr = "00" + BMStr; break;
case 4:
BMStr = "0" + BMStr; break;
}
}
BMStr = "CK" + DateTime.Now.ToString("yyyyMMdd") + BMStr;
Dictionary<string, object> files = new Dictionary<string, object>() {
{ nameof(RB_Supplies_StockOut.StockOutNum),BMStr}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Supplies_StockOut.Id),
FiledValue=Id,
OperatorEnum=OperatorEnum.Equal
}
};
supplies_StockOutRepository.Update(files, wheres, trans);
//新增明细
foreach (var item in demodel.DetailList)
{
var ilist = supplies_InventoryRepository.GetList(new RB_Supplies_Inventory_Extend() { RB_Group_Id = demodel.RB_Group_Id, WarehouseId = demodel.WarehouseId, SuppliesId = item.SuppliesId });
decimal Price = 0;
if (ilist.Any())
{
var iModel = ilist.FirstOrDefault();
Price = Math.Round((iModel.Money ?? 0) / (iModel.Number ?? 1), 2, MidpointRounding.AwayFromZero) * (item.Number ?? 0);
}
supplies_StockOutDetailRepository.Insert(new RB_Supplies_StockOutDetail()
{
CreateBy = demodel.CreateBy,
CreateDate = demodel.CreateDate,
Number = item.Number,
Money = Price,
RB_Branch_Id = demodel.RB_Branch_Id,
Id = 0,
RB_Group_Id = demodel.RB_Group_Id,
Remark = item.Remark,
Status = 0,
StockOutId = Id,
SuppliesId = item.SuppliesId,
UpdateBy = demodel.UpdateBy,
UpdateDate = demodel.UpdateDate
}, trans);
//新增库存表数据
if (ilist.Any() && demodel.StockOutState == StockOutStatusEnum.StockOut)
{
var iModel = ilist.FirstOrDefault();
iModel.Number -= item.Number;//减少库存
iModel.Money -= Price;
if (iModel.Money < 0)
{
iModel.Money = 0;
}
var iflag = supplies_InventoryRepository.Update(iModel, trans);
if (iflag)
{
//增加库存明细
supplies_InventoryDetailRepository.Insert(new RB_Supplies_InventoryDetail()
{
CreateBy = demodel.CreateBy,
CreateDate = DateTime.Now,
InventoryId = iModel.Id,
Number = item.Number,
Money = Price,
RB_Branch_Id = demodel.RB_Branch_Id,
RB_Group_Id = demodel.RB_Group_Id,
Status = 0,
Type = 2,
Id = 0,
Description = "减少库存-出库"
}, trans);
}
}
}
}
supplies_StockOutRepository.DBSession.Commit();
return Id > 0;
}
catch (Exception ex)
{
supplies_StockOutRepository.DBSession.Rollback("WarehouseOut.SetStockOutInfo");
LogHelper.Write(ex, "WarehouseOut.SetStockOutInfo");
return false;
}
}
} }
} }
using Property.Model.Entity.Mall;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Property.Repository.Mall
{
/// <summary>
/// 商品订单明细仓储层
/// </summary>
public class RB_Goods_OrderDetailRepository : RepositoryBase<RB_Goods_OrderDetail>
{
/// <summary>
/// 获取订单明细列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="count"></param>
/// <param name="dmodel"></param>
/// <returns></returns>
public List<RB_Goods_OrderDetail> GetOrderDetailList(RB_Goods_OrderDetail dmodel)
{
string where = $" 1=1 ";
if (dmodel.TenantId > 0)
{
where += $@" and a.{nameof(RB_Goods_OrderDetail.TenantId)}={dmodel.TenantId}";
}
if (dmodel.MallBaseId > 0)
{
where += $@" and a.{nameof(RB_Goods_OrderDetail.MallBaseId)}={dmodel.MallBaseId}";
}
if (dmodel.OrderId > 0)
{
where += $@" and a.{nameof(RB_Goods_OrderDetail.OrderId)}={dmodel.OrderId}";
}
if (dmodel.OrderType > 0)
{
where += $@" and a.{nameof(RB_Goods_OrderDetail.OrderType)}={(int)dmodel.OrderType}";
}
if (dmodel.IsComment > 0)
{
where += $@" and a.{nameof(RB_Goods_OrderDetail.IsComment)}={(int)dmodel.IsComment}";
}
if (!string.IsNullOrEmpty(dmodel.GoodsName))
{
where += $@" and a.{nameof(RB_Goods_OrderDetail.GoodsName)} like '%{dmodel.GoodsName}%'";
}
if (!string.IsNullOrEmpty(dmodel.ProductCode))
{
where += $@" and a.{nameof(RB_Goods_OrderDetail.ProductCode)} like '%{dmodel.ProductCode}%'";
}
string sql = $@"SELECT a.*,b.`Name` as SupplierName FROM rb_goods_orderdetail as a LEFT JOIN rb_supplier as b on a.SupplierId=b.ID where {where} order by a.Id asc";
return Get<RB_Goods_OrderDetail>(sql).ToList();
}
}
}
using Property.Model.Entity.Mall;
using Property.Model.Extend.Mall;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Property.Repository.Mall
{
public class RB_WarehouseOut_FinanceRepository : RepositoryBase<RB_WarehouseOut_Finance>
{
/// <summary>
/// 表名称
/// </summary>
public string TableName { get { return nameof(RB_WarehouseOut_Finance); } }
/// <summary>
/// 出库申请列表
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">每页显示条数</param>
/// <param name="rowCount">总条数</param>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_WarehouseOut_Finance> GetApplyPageList(int pageIndex, int pageSize, out long rowCount, RB_WarehouseOut_Finance query)
{
StringBuilder builder = new StringBuilder();
builder.Append(@$" select a.* from {TableName} as a where a.Status=0 ");
if (query != null)
{
if (query.ID > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_Finance.ID)}={query.ID}");
}
if (query.TenantId > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_Finance.TenantId)}={query.TenantId}");
}
if (query.MallBaseId > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_Finance.MallBaseId)}={query.MallBaseId}");
}
if (query.RB_Group_Id > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_Finance.RB_Group_Id)}={query.RB_Group_Id}");
}
if (query.RB_Branch_Id > -1)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_Finance.RB_Branch_Id)}={query.RB_Branch_Id}");
}
}
return GetPage<RB_WarehouseOut_Finance>(pageIndex, pageSize, out rowCount, builder.ToString()).ToList();
}
/// <summary>
/// 出库申请列表
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_WarehouseOut_Finance> GetApplyList(RB_WarehouseOut_Finance query)
{
StringBuilder builder = new StringBuilder();
builder.Append($" select * from {TableName} as a where a.Status=0 ");
if (query != null)
{
if (query.ID > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_Finance.ID)}={query.ID}");
}
if (query.TenantId > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_Finance.TenantId)}={query.TenantId}");
}
if (query.MallBaseId > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_Finance.MallBaseId)}={query.MallBaseId}");
}
}
return Get<RB_WarehouseOut_Finance>(builder.ToString()).ToList();
}
}
}
using Property.Model.Entity.Mall;
using Property.Model.Extend.Mall;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Property.Repository.Mall
{
public class RB_WarehouseOut_GoodsDetailRepository : RepositoryBase<RB_WarehouseOut_GoodsDetail>
{
/// <summary>
/// 表名称
/// </summary>
public string TableName { get { return nameof(RB_WarehouseOut_GoodsDetail); } }
/// <summary>
/// 出库申请列表
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">每页显示条数</param>
/// <param name="rowCount">总条数</param>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_WarehouseOut_GoodsDetail> GetApplyPageList(int pageIndex, int pageSize, out long rowCount, RB_WarehouseOut_GoodsDetail query)
{
StringBuilder builder = new StringBuilder();
builder.Append(@$" select a.* from {TableName} as a where a.Status=0 ");
if (query != null)
{
if (query.ID > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_GoodsDetail.ID)}={query.ID}");
}
if (query.TenantId > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_GoodsDetail.TenantId)}={query.TenantId}");
}
if (query.MallBaseId > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_GoodsDetail.MallBaseId)}={query.MallBaseId}");
}
}
return GetPage<RB_WarehouseOut_GoodsDetail>(pageIndex, pageSize, out rowCount, builder.ToString()).ToList();
}
/// <summary>
/// 出库申请列表
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_WarehouseOut_GoodsDetail> GetApplyList(RB_WarehouseOut_GoodsDetail query)
{
StringBuilder builder = new StringBuilder();
builder.Append($" select * from {TableName} as a where a.Status=0 ");
if (query != null)
{
if (query.ID > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_GoodsDetail.ID)}={query.ID}");
}
if (query.TenantId > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_GoodsDetail.TenantId)}={query.TenantId}");
}
if (query.MallBaseId > 0)
{
builder.Append($" AND a.{nameof(RB_WarehouseOut_GoodsDetail.MallBaseId)}={query.MallBaseId}");
}
}
return Get<RB_WarehouseOut_GoodsDetail>(builder.ToString()).ToList();
}
}
}
...@@ -53,9 +53,9 @@ namespace Property.Repository.Mall ...@@ -53,9 +53,9 @@ namespace Property.Repository.Mall
{ {
builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.GoodsName)} like '%{query.GoodsName}%'"); builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.GoodsName)} like '%{query.GoodsName}%'");
} }
if (query.SupplierId > 0) if (query.StockInId > 0)
{ {
builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.SupplierId)}={query.SupplierId}"); builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.StockInId)}={query.StockInId}");
} }
if (!string.IsNullOrWhiteSpace(query.OrderGoodsIds)) if (!string.IsNullOrWhiteSpace(query.OrderGoodsIds))
{ {
...@@ -98,9 +98,9 @@ namespace Property.Repository.Mall ...@@ -98,9 +98,9 @@ namespace Property.Repository.Mall
{ {
builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.GoodsName)} like '%{query.GoodsName}%'"); builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.GoodsName)} like '%{query.GoodsName}%'");
} }
if (query.SupplierId > 0) if (query.StockInId > 0)
{ {
builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.SupplierId)}={query.SupplierId}"); builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.StockInId)}={query.StockInId}");
} }
} }
return Get<RB_WarehouseOut_Goods_Extend>(builder.ToString()).ToList(); return Get<RB_WarehouseOut_Goods_Extend>(builder.ToString()).ToList();
...@@ -142,9 +142,9 @@ namespace Property.Repository.Mall ...@@ -142,9 +142,9 @@ namespace Property.Repository.Mall
{ {
builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.GoodsName)} like '%{query.GoodsName}%'"); builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.GoodsName)} like '%{query.GoodsName}%'");
} }
if (query.SupplierId > 0) if (query.StockInId > 0)
{ {
builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.SupplierId)}={query.SupplierId}"); builder.Append($" AND a.{nameof(RB_WarehouseOut_Goods_Extend.StockInId)}={query.StockInId}");
} }
} }
return Get<RB_WarehouseOut_Goods_Extend>(builder.ToString()).ToList(); return Get<RB_WarehouseOut_Goods_Extend>(builder.ToString()).ToList();
......
...@@ -4,6 +4,7 @@ using System.Linq; ...@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Property.Model.Extend; using Property.Model.Extend;
using Property.Model.Extend.Mall; using Property.Model.Extend.Mall;
using Property.Module.FixedAssets; using Property.Module.FixedAssets;
...@@ -161,33 +162,151 @@ namespace Property.WebApi.Controllers.Mall ...@@ -161,33 +162,151 @@ namespace Property.WebApi.Controllers.Mall
{ {
return ApiResult.ParamIsNull("请选择仓库"); return ApiResult.ParamIsNull("请选择仓库");
} }
RB_Supplies_StockOut_Extend demodel = new RB_Supplies_StockOut_Extend();//出库申请表,等会儿组装
if (applyModel.WarehouseOutGoodsDetailList == null && !applyModel.WarehouseOutGoodsDetailList.Any()) if (applyModel.WarehouseOutGoodsDetailList == null && !applyModel.WarehouseOutGoodsDetailList.Any())
{ {
return ApiResult.ParamIsNull("请选择您要出库的商品"); return ApiResult.Failed("请选择您要出库的商品");
} }
applyModel.WarehouseOutGoodsDetailList.ForEach(x => x.ApplyId = applyModel.ID);//将申请赋值给出库商品详情表 //查询之前的申请信息
applyModel.WarehouseOutGoodsDetailList.ForEach(x => x.WarehouseId = applyModel.WarehouseId);//将申请赋值给出库商品详情表 var oldModel = warehouseOutModule.GetApplyEntity(applyModel.ID).RefMapperTo<RB_WarehouseOut_Apply_Extend>();
if (oldModel != null)
{
oldModel.WarehouseOutGoodsList = new List<RB_WarehouseOut_Goods_Extend>();
oldModel.WarehouseOutGoodsList = warehouseOutModule.GetWarehouseOutList(new RB_WarehouseOut_Goods_Extend { ApplyId = applyModel.ID });
}
if (oldModel.ApplyStatus != 2)
{
return ApiResult.Failed("出库申请单未通过,请勿操作出库");
}
if (oldModel.OutStatus == 2)
{
return ApiResult.Failed("出库单中的商品已全部出库");
}
//判断此次商品是否已出库与数量是否相等
applyModel.WarehouseOutGoodsList = new List<RB_WarehouseOut_Goods_Extend>();
var goodsList = applyModel.WarehouseOutGoodsDetailList.GroupBy(x => x.OrderGoodsId);
oldModel.RB_Group_Id = userInfo.RB_Group_id;
oldModel.RB_Branch_Id = -1;
oldModel.WarehouseId = applyModel.WarehouseId;
var wareHouseGoodsList = warehouseOutModule.GetOuGoodsByWarehouseId(oldModel);
foreach (var item in goodsList)
{
var oldOrderGoods = oldModel.WarehouseOutGoodsList.Where(x => x.OrderGoodsId == item.Key).FirstOrDefault();
applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).ToList().ForEach(x => x.OrderId = oldOrderGoods.OrderId);
applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).ToList().ForEach(x => x.GoodsId = oldOrderGoods.GoodsId);
applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).ToList().ForEach(x => x.GoodsName = oldOrderGoods.GoodsName);
applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).ToList().ForEach(x => x.Specification = oldOrderGoods.Specification);
applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).ToList().ForEach(x => x.SpecificationSort = oldOrderGoods.SpecificationSort);
applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).ToList().ForEach(x => x.ProductCode = oldOrderGoods.ProductCode);
applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).ToList().ForEach(x => x.TenantId = oldOrderGoods.TenantId);
applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).ToList().ForEach(x => x.MallBaseId = oldOrderGoods.MallBaseId);
if (oldOrderGoods == null)
{
var nowOrderGoods = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key).FirstOrDefault();
return ApiResult.Failed("商品不属于出库单,请核实后再出库");
}
else if (oldOrderGoods.IsOut == 1)
{
return ApiResult.Failed("订单号:" + oldOrderGoods.OrderNo + "商品名称:" + oldOrderGoods.GoodsName + "申请单中已出库");
}
var nowGoodsList = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key);
int goodsCount = nowGoodsList.Count();
if (oldOrderGoods.Number != goodsCount)
{
return ApiResult.Failed("订单号:" + oldOrderGoods.OrderNo + "商品名称:" + oldOrderGoods.GoodsName + "必须一起出库");
}
if (!wareHouseGoodsList.Any(x => x.OrderGoodsId == item.Key))
{
return ApiResult.Failed("订单号:" + oldOrderGoods.OrderNo + "商品名称:" + oldOrderGoods.GoodsName + "没在当前仓库");
}
oldOrderGoods.CostMoney = nowGoodsList.Sum(x => x.CostMoney ?? 0);
applyModel.WarehouseOutGoodsList.Add(oldOrderGoods);
}
if (oldModel.WarehouseOutGoodsList.Where(x => x.IsOut == 0).Count() == wareHouseGoodsList.Count())
{
applyModel.OutStatus = 2;
}
else if (oldModel.WarehouseOutGoodsList.Where(x => x.IsOut == 0).Count() > wareHouseGoodsList.Count())
{
applyModel.OutStatus = 1;
}
else
{
return ApiResult.Failed("已出库的商品类别数大于出库单的商品类别数");
}
//判断出库商品是否是同一个仓库
#region 出库记录信息 主要是针对电商
applyModel.WarehouseOutGoodsDetailList.ForEach(x => x.ApplyId = applyModel.ID);//将申请赋值给出库商品详情表
applyModel.WarehouseOutGoodsDetailList.ForEach(x => x.WarehouseId = applyModel.WarehouseId);//将申请赋值给出库商品详情表
applyModel.WarehouseOutFinanceModel = new Model.Entity.Mall.RB_WarehouseOut_Finance();//财务id ,后面更新出库id与财务id applyModel.WarehouseOutFinanceModel = new Model.Entity.Mall.RB_WarehouseOut_Finance();//财务id ,后面更新出库id与财务id
applyModel.WarehouseOutFinanceModel.ApplyId = applyModel.ID; applyModel.WarehouseOutFinanceModel.ApplyId = applyModel.ID;
applyModel.WarehouseOutFinanceModel.Status = 0; applyModel.WarehouseOutFinanceModel.Status = 0;
applyModel.WarehouseOutFinanceModel.TenantId = applyModel.TenantId; applyModel.WarehouseOutFinanceModel.TenantId = oldModel.TenantId;
applyModel.WarehouseOutFinanceModel.MallBaseId = applyModel.MallBaseId; applyModel.WarehouseOutFinanceModel.MallBaseId = oldModel.MallBaseId;
applyModel.WarehouseOutFinanceModel.CreateDate = NowStr; applyModel.WarehouseOutFinanceModel.CreateDate = NowStr;
applyModel.WarehouseOutFinanceModel.CreateBy = userInfo.EmployeeId; applyModel.WarehouseOutFinanceModel.CreateBy = userInfo.EmployeeId;
applyModel.WarehouseOutFinanceModel.RB_Branch_Id = applyModel.RB_Branch_Id; applyModel.WarehouseOutFinanceModel.RB_Branch_Id = oldModel.RB_Branch_Id;
applyModel.WarehouseOutFinanceModel.RB_Group_Id = applyModel.RB_Group_Id; applyModel.WarehouseOutFinanceModel.RB_Group_Id = oldModel.RB_Group_Id;
#endregion
#region 出库记录信息
RB_Supplies_StockOut_Extend demodel = new RB_Supplies_StockOut_Extend();//出库申请表,等会儿组装
demodel.WarehouseId = applyModel.WarehouseId; demodel.WarehouseId = applyModel.WarehouseId;
demodel.EmployeeId = applyModel.CreateBy; demodel.EmployeeId = applyModel.CreateBy;
demodel.CreateBy = userInfo.EmployeeId; demodel.CreateBy = userInfo.EmployeeId;
demodel.StockOutDate = NowStr; demodel.StockOutDate = NowStr;
demodel.StockOutState = REBORN.Common.Enum.StockOutStatusEnum.StockOut;
demodel.Remark = "电商订单商品出库";
demodel.Status = 0;
demodel.RB_Branch_Id = userInfo.RB_Branch_id;
demodel.RB_Group_Id = userInfo.RB_Group_id;
demodel.CreateDate = NowStr;
demodel.UpdateBy = userInfo.EmployeeId;
demodel.UpdateDate = NowStr;
UserInfo userInfoLQR = CacheManager.User.UserReidsCache.GetUserLoginInfo(oldModel.CreateBy.ToString());
demodel.DepartmentId = userInfoLQR.RB_Department_Id;
demodel.BranchId = userInfoLQR.RB_Branch_id;
demodel.DetailList = new List<RB_Supplies_StockOutDetail_Extend>();
foreach (var item in applyModel.WarehouseOutGoodsDetailList.GroupBy(x => x.MaterialId))
{
RB_Supplies_StockOutDetail_Extend stockOutDetailModel = new RB_Supplies_StockOutDetail_Extend
{
Id = 0,
StockOutId = 0,
SuppliesId = item.Key,
Number = applyModel.WarehouseOutGoodsDetailList.Where(x => x.MaterialId == item.Key).Count(),
Remark = "电商订单商品出库",
Status = 0,
RB_Branch_Id = userInfo.RB_Branch_id,
RB_Group_Id = userInfo.RB_Group_id,
CreateBy = userInfo.EmployeeId,
CreateDate = NowStr,
UpdateBy = userInfo.EmployeeId,
UpdateDate = NowStr,
Money = applyModel.WarehouseOutGoodsDetailList.Where(x => x.MaterialId == item.Key).Sum(x => x.CostMoney ?? 0),
};
demodel.DetailList.Add(stockOutDetailModel);
}
if (demodel.DetailList == null || !demodel.DetailList.Any()) if (demodel.DetailList == null || !demodel.DetailList.Any())
{ {
return ApiResult.ParamIsNull("请选择物料"); return ApiResult.ParamIsNull("请选择物料");
...@@ -226,25 +345,44 @@ namespace Property.WebApi.Controllers.Mall ...@@ -226,25 +345,44 @@ namespace Property.WebApi.Controllers.Mall
{ {
return ApiResult.Failed("请选择耗材"); return ApiResult.Failed("请选择耗材");
} }
demodel.Status = 0;
demodel.RB_Branch_Id = userInfo.RB_Branch_id;
demodel.RB_Group_Id = userInfo.RB_Group_id;
demodel.CreateBy = userInfo.EmployeeId;
demodel.CreateDate = DateTime.Now;
demodel.UpdateBy = userInfo.EmployeeId;
demodel.UpdateDate = DateTime.Now;
var emodel = CacheManager.User.UserReidsCache.GetEmployee(demodel.EmployeeId);
demodel.BranchId = emodel.RB_Branch_id;//暂时这么赋值 看是否需要前端自行选择
demodel.DepartmentId = emodel.RB_Department_Id;
//验证库存是否足够 //验证库存是否足够
if (!suppliesModule.ValidateStockOutInsert(demodel)) if (!suppliesModule.ValidateStockOutInsert(demodel))
{ {
return ApiResult.Failed("库存不足无法出库,请核实后再试"); return ApiResult.Failed("库存不足无法出库,请核实后再试");
} }
bool flag = suppliesModule.SetStockOutInfo(demodel); #endregion
#region 组装财务单据需要的数据
List<RB_WarehouseOut_Goods_Extend> financeList = new List<RB_WarehouseOut_Goods_Extend>();
foreach (var item in applyModel.WarehouseOutGoodsDetailList.GroupBy(x => new { x.OrderGoodsId, x.CostMoney }))
{
RB_WarehouseOut_Goods_Extend warehouseOutModel = new RB_WarehouseOut_Goods_Extend
{
ApplyId = applyModel.ID,
ID = 0,
OrderId = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key.OrderGoodsId).FirstOrDefault()?.OrderId ?? 0,
GoodsId = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key.OrderGoodsId).FirstOrDefault()?.GoodsId ?? 0,
Status = 0,
IsOut = 1,
OrderGoodsId = item.Key.OrderGoodsId,
OrderNo = "",
GoodsName = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key.OrderGoodsId).FirstOrDefault()?.GoodsName,
Specification = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key.OrderGoodsId).FirstOrDefault()?.Specification,
SpecificationSort = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key.OrderGoodsId).FirstOrDefault()?.SpecificationSort,
ProductCode = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key.OrderGoodsId).FirstOrDefault()?.ProductCode,
Number = applyModel.WarehouseOutGoodsDetailList.Where(x => x.OrderGoodsId == item.Key.OrderGoodsId && x.CostMoney == item.Key.CostMoney).Count(),
TenantId = applyModel.TenantId,
MallBaseId = applyModel.MallBaseId,
CostMoney = item.Key.CostMoney ?? 0
};
financeList.Add(warehouseOutModel);
}
#endregion
bool flag = warehouseOutModule.SetStockOutInfo(applyModel, demodel, financeList, userInfo.RB_Department_Id);
if (flag) if (flag)
{ {
return ApiResult.Success(); return ApiResult.Success();
......
...@@ -28,6 +28,12 @@ ...@@ -28,6 +28,12 @@
"ViewFileSiteUrl": "http://192.168.2.214:8130", "ViewFileSiteUrl": "http://192.168.2.214:8130",
"ImKey": "b612b31e837c79c68f141aeb719d2b20", "ImKey": "b612b31e837c79c68f141aeb719d2b20",
"ImSecret": "66000451fb72", "ImSecret": "66000451fb72",
"FinanceKey": "FinanceMallInsertToERPViitto2020",
"OutCurrencyId": 1,
"PaymentFinanceApi": "http://testapi.oytour.com/api/Mall/InsertFinanceBatchForMallOut",
"ExpendDirector": 1756, //财务支出创建人
"ExpendBranchId": 49, //财务支出创建人公司
"ExpendDepartment": 331,
"RedisSetting": { "RedisSetting": {
"RedisServer": "192.168.2.214", "RedisServer": "192.168.2.214",
"RedisPort": "6379", "RedisPort": "6379",
......
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