username@email.com
2024-06-26 7f26cd7c3e492062418cdc7dbe9d7ce14cbe5f05
CoreCms.Net.Repository/Stock/CoreCmsStockRepository.cs
@@ -23,6 +23,7 @@
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Helper;
using SqlSugar;
using CoreCms.Net.Model.Entities.baifenbingfa.puhuo;
namespace CoreCms.Net.Repository
{
@@ -44,7 +45,7 @@
        /// </summary>
        /// <param name="entity">实体数据</param>
        /// <returns></returns>
        public async Task<AdminUiCallBack> InsertAsync(FMCreateStock entity)
        public async Task<AdminUiCallBack> InsertAsync(FMCreateStock entity, string username, CoreCmsDistribution distribution)
        {
            var jm = new AdminUiCallBack();
@@ -76,6 +77,10 @@
            {
                stockModel.id = await CreateCode(GlobalEnumVars.StockType.Out.ToString());
            }
            else if (entity.model.type == 3)
            {
                stockModel.id = await CreateCode(GlobalEnumVars.StockType.Out.ToString());
            }
            else
            {
                jm.msg = "单据类型错误";
@@ -85,7 +90,20 @@
            stockModel.memo = entity.model.memo;
            stockModel.createTime = DateTime.Now;
            stockModel.manager = entity.model.manager;
            stockModel.type = entity.model.type;
            if (entity.model.type == 3 )
            {
                if (stockModel.memo == "无")
                {
                    stockModel.memo = "";
                }
                stockModel.memo = distribution.name+ " 经销商铺货 " + stockModel.memo;
                stockModel.type = 2;
            }
            else
            {
                stockModel.type = entity.model.type;
            }
            var logs = new List<CoreCmsStockLog>();
            var products = new List<CoreCmsProducts>();
@@ -116,7 +134,9 @@
                        name = good.name,
                        bn = good.bn,
                        isMarketable = good.isMarketable,
                        unit = good.unit
                        unit = good.unit,
                        distributionPrice = p.distributionPrice,
                        CategoryID = good.goodsCategoryId,
                    }).With(SqlWith.NoLock)
                    .MergeTable()
                    .Where(p => p.id == item.productId).FirstAsync();
@@ -136,6 +156,16 @@
                            return jm;
                        }
                    }
                    else if (entity.model.type == 3)
                    {
                        stock = product.stock - item.nums;
                        if (stock < 0)
                        {
                            jm.msg = $"第{index}个货品最大出库数量为:" + product.stock;
                            return jm;
                        }
                    }
                    product.nums = item.nums;
                    product.stock = stock;
                    products.Add(product);
@@ -160,6 +190,9 @@
                }
            }
            try
            {
                _unitOfWork.BeginTran();
@@ -172,6 +205,71 @@
                {
                    await DbClient.Insertable(logs).ExecuteCommandAsync();
                }
                //铺货
                if (entity.model.type == 3)
                {
                    if (products.Any() && distribution != null)
                    {
                        foreach (var products1 in products)
                        {
                            var puhuo = await DbClient.Queryable<Puhuo>().Where(x => x.isdelete == false && x.productsId == products1.id && x.distributionId == entity.model.distributionId).FirstAsync();
                            if (puhuo != null)
                            {
                                puhuo.nums = puhuo.nums + products1.nums;
                                puhuo.price = products1.distributionPrice;
                                puhuo.amount = products1.distributionPrice * new decimal(puhuo.nums);
                                puhuo.isdelete = false;
                                //entity.createBy = username;
                                puhuo.upDataBy = username;
                                //entity.createTime = DateTime.Now;
                                puhuo.upDataTime = DateTime.Now;
                                await DbClient.Updateable<Puhuo>(puhuo).ExecuteCommandAsync();
                            }
                            else
                            {
                                puhuo = new Puhuo();
                                puhuo.distributionId = entity.model.distributionId;
                                puhuo.distributionName = distribution.name;
                                puhuo.areaCode = distribution.areaCode;
                                puhuo.areaCodeName = distribution.areaName;
                                puhuo.CategoryId = products1.CategoryID??0;
                                //获取全部数据缓存
                                var categorie = await DbClient.Queryable<CoreCmsGoodsCategory>().Where(x => x.id == puhuo.CategoryId).FirstAsync(); ;
                                if (categorie != null)
                                {
                                    puhuo.CategoryName = categorie.name;
                                }
                                puhuo.goodsId = products1.goodsId;
                                puhuo.goodsName = products1.name;
                                puhuo.productsId = products1.id;
                                puhuo.productsName = products1.sn;
                                puhuo.spesDesc = products1.spesDesc;
                                puhuo.shoukuannums = 0;
                                puhuo.shoukuanamount = 0;
                                puhuo.nums = puhuo.nums + products1.nums;
                                puhuo.price = products1.distributionPrice;
                                puhuo.amount = products1.distributionPrice * new decimal(puhuo.nums);
                                puhuo.isdelete = false;
                                puhuo.createBy = username;
                                puhuo.upDataBy = username;
                                puhuo.createTime = DateTime.Now;
                                puhuo.upDataTime = DateTime.Now;
                                await DbClient.Insertable<Puhuo>(puhuo).ExecuteCommandAsync();
                            }
                        }
                    }
                }
                jm.code = bl ? 0 : 1;
                jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
                _unitOfWork.CommitTran();