/// <summary> /// 修改一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > ModifyAsync(ErpSkuLoss parm) { var res = new ApiResult <string>() { data = "1", statusCode = (int)ApiEnum.Error }; try { //根据条形码,查询条形码信息 var skuModel = ErpGoodsSkuDb.GetSingle(m => m.Code == parm.SkuGuid); if (skuModel == null) { res.message = "条形码不存在~"; return(await Task.Run(() => res)); } var oldLoss = ErpSkuLossDb.GetSingle(m => m.Guid == parm.Guid); if (oldLoss == null) { res.message = "报损信息不存在~"; return(await Task.Run(() => res)); } //判断库存数量是否满足报损数量 if (oldLoss.Counts < parm.Counts) { res.message = "数量不能大于原报损数量~"; return(await Task.Run(() => res)); } //修改原报损数量 oldLoss.Counts -= parm.Counts; //减少库存 skuModel.StockSum += parm.Counts; //事务,保证数据一致性 var result = Db.Ado.UseTran(() => { //执行添加报损信息 Db.Updateable(oldLoss).ExecuteCommand(); //修改条形码库存 Db.Updateable(skuModel).ExecuteCommand(); }); res.statusCode = (int)ApiEnum.Status; if (!result.IsSuccess) { res.message = result.ErrorMessage; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 获得一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <ErpGoodsSku> > GetByGuidAsync(string parm) { var model = ErpGoodsSkuDb.GetSingle(m => m.Code == parm); var res = new ApiResult <ErpGoodsSku> { statusCode = 200, data = model ?? new ErpGoodsSku() { } }; return(await Task.Run(() => res)); }
/// <summary> /// 添加一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpInOutLog parm) { var res = new ApiResult <string>() { statusCode = 200 }; try { //判断条形码是否存在 var skuModel = ErpGoodsSkuDb.GetSingle(m => m.Code == parm.GoodsSku && !m.IsDel); if (skuModel == null) { res.statusCode = (int)ApiEnum.ParameterError; res.message = "该条形码不存在~"; return(await Task.Run(() => res)); } if (parm.Types == 2) { //出库 需要判断库存是否足够 if (skuModel.StockSum < parm.GoodsSum) { res.statusCode = (int)ApiEnum.ParameterError; res.message = "库存不足,只剩下" + skuModel.StockSum + "件~"; return(await Task.Run(() => res)); } } parm.Guid = Guid.NewGuid().ToString(); parm.GoodsGuid = skuModel.Guid; //开启事务 Db.Ado.BeginTran(); if (parm.Types == 1) { //更新该条形码的库存 ErpGoodsSkuDb.Update(m => new ErpGoodsSku() { StockSum = m.StockSum + parm.GoodsSum }, m => m.Guid == parm.GoodsGuid); } else { //更新平台的库存,减少 ErpGoodsSkuDb.Update(m => new ErpGoodsSku() { StockSum = m.StockSum - parm.GoodsSum }, m => m.Guid == parm.GoodsGuid); //增加到店铺条形码表中 var shopSku = ErpShopSkuDb.GetSingle(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == parm.GoodsGuid); if (shopSku != null) { //修改,增加库存 ErpShopSkuDb.Update(m => new ErpShopSku() { Stock = m.Stock + parm.GoodsSum, UpdateDate = DateTime.Now }, m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == parm.GoodsGuid); } else { //增加一条库存 var shopSkuModel = new ErpShopSku() { SkuGuid = skuModel.Guid, SkuCode = skuModel.Code, ShopGuid = parm.ShopGuid, Stock = parm.GoodsSum }; ErpShopSkuDb.Insert(shopSkuModel); } } ErpInOutLogDb.Insert(parm); Db.Ado.CommitTran(); } catch (Exception ex) { Db.Ado.CommitTran(); res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 添加一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpBackGoods parm) { var res = new ApiResult <string>() { data = "1", statusCode = (int)ApiEnum.Error }; try { DateTime dayTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00"); parm.Guid = Guid.NewGuid().ToString(); //查询今天退货数量 var dayCount = ErpBackGoodsDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime)); parm.Number = "BO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount); //根据条形码查询唯一编号 var goodSku = ErpGoodsSkuDb.GetSingle(m => m.Code == parm.GoodsGuid); if (goodSku != null) { parm.GoodsGuid = goodSku.Guid; } else { res.message = "商品不存在~"; return(await Task.Run(() => res)); } //判断退货商品,金额是否大于订单金额, 以及商品数量,是否大于订单出售数量 var orderModel = ErpSaleOrderDb.GetSingle(m => m.Number == parm.OrderNumber); if (orderModel == null) { res.message = "订单不存在~"; return(await Task.Run(() => res)); } //跨月不允许退货 if (orderModel.AddDate.Month != DateTime.Now.Month) { res.message = "跨月不允许退货~"; return(await Task.Run(() => res)); } //查询活动,是否买一赠一活动,如果是,需要单独处理下 var activityModel = new ErpShopActivity(); if (!string.IsNullOrEmpty(orderModel.ActivityGuid)) { activityModel = ErpShopActivityDb.GetSingle(m => m.Guid == orderModel.ActivityGuid); } //if (parm.BackMoney>orderModel.RealMoney) //{ // res.message = "退货金额不能大于订单金额~"; // return await Task.Run(() => res); //} //判断是否存在 var egbCount = ErpBackGoodsDb.Count(m => m.ShopGuid == parm.ShopGuid && m.GoodsGuid == parm.GoodsGuid && m.OrderNumber == parm.OrderNumber); if (egbCount > 0) { //买一增一,最多可以退货2次 if (activityModel != null && activityModel.Method == 3) { if (egbCount > 1) { res.message = "该退货信息已存在~"; return(await Task.Run(() => res)); } } else { res.message = "该退货信息已存在~"; return(await Task.Run(() => res)); } } //根据订单查询商品数量是否满足 var orderGoodsModel = new ErpSaleOrderGoods(); if (activityModel != null && activityModel.Method == 3) { //如果是买一赠一,第一次差=0的,第二次差!=0的 if (egbCount == 0) { orderGoodsModel = ErpSaleOrderGoodsDb.GetSingle(m => m.OrderNumber == parm.OrderNumber && m.GoodsGuid == parm.GoodsGuid && m.ShopGuid == parm.ShopGuid && m.Money == 0); } else { orderGoodsModel = ErpSaleOrderGoodsDb.GetSingle(m => m.OrderNumber == parm.OrderNumber && m.GoodsGuid == parm.GoodsGuid && m.ShopGuid == parm.ShopGuid && m.Money != 0); } } else { orderGoodsModel = ErpSaleOrderGoodsDb.GetSingle(m => m.OrderNumber == parm.OrderNumber && m.GoodsGuid == parm.GoodsGuid && m.ShopGuid == parm.ShopGuid); } if (orderGoodsModel == null) { res.message = "该商品在该订单号中不存在~"; return(await Task.Run(() => res)); } if (orderGoodsModel.Counts < parm.BackCount) { res.message = "退货商品数量不能大于订单购买数量~"; return(await Task.Run(() => res)); } //获取订单销售的金额 客户端不需要手动输入, 注意需要判断下是否买一赠一活动 parm.BackMoney = orderGoodsModel.Money; //构建积分变动记录 var result = Db.Ado.UseTran(() => { //修改加盟商条形码里面的库存 退货=加盟商库存增加 Db.Updateable <ErpShopSku>() .UpdateColumns(m => new ErpShopSku() { Stock = m.Stock + parm.BackCount, Sale = m.Sale - parm.BackCount }) .Where(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == goodSku.Guid) .ExecuteCommand(); //根据商品编号,修改平台的销售数量 Db.Updateable <ErpGoodsSku>().UpdateColumns(m => new ErpGoodsSku() { SaleSum = m.SaleSum - parm.BackCount }) .Where(m => m.Guid == goodSku.Guid).ExecuteCommand(); //修改订单-商品详情表中的退货数量 增加 orderGoodsModel.BackCounts = orderGoodsModel.BackCounts + parm.BackCount; Db.Updateable(orderGoodsModel).ExecuteCommand(); //增加一条退货信息 Db.Insertable(parm).ExecuteCommand(); //判断是否存在用户信息 if (!string.IsNullOrEmpty(orderModel.UserGuid)) { var pointLogModel = new ErpUserPointLog() { Guid = Guid.NewGuid().ToString(), UserGuid = orderModel.UserGuid, OperateGuid = parm.Guid, Types = 1, Point = orderGoodsModel.Money != 0?Convert.ToInt32((orderGoodsModel.Money / orderGoodsModel.Counts) / 10):0, Summary = "[减少]-退货积分变更" }; Db.Insertable(pointLogModel).ExecuteCommand(); //用户积分减少 Db.Updateable <ErpShopUser>().UpdateColumns(m => m.Points == m.Points - pointLogModel.Point) .Where(m => m.Guid == orderModel.UserGuid).ExecuteCommand(); } }); res.statusCode = (int)ApiEnum.Status; if (!result.IsSuccess) { res.statusCode = (int)ApiEnum.Error; res.message = result.ErrorMessage; } } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 添加一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpBackGoods parm) { var res = new ApiResult <string>() { data = "1", statusCode = (int)ApiEnum.Error }; try { DateTime dayTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00"); parm.Guid = Guid.NewGuid().ToString(); //查询今天退货数量 var dayCount = ErpBackGoodsDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime)); parm.Number = "BO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount); //根据条形码查询唯一编号 var goodSku = ErpGoodsSkuDb.GetSingle(m => m.Code == parm.GoodsGuid); if (goodSku != null) { parm.GoodsGuid = goodSku.Guid; } else { res.message = "商品不存在~"; return(await Task.Run(() => res)); } //判断退货商品,金额是否大于订单金额, 以及商品数量,是否大于订单出售数量 var orderModel = ErpSaleOrderDb.GetSingle(m => m.Number == parm.OrderNumber); if (orderModel == null) { res.message = "订单不存在~"; return(await Task.Run(() => res)); } if (parm.BackMoney > orderModel.RealMoney) { res.message = "退货金额不能大于订单金额~"; return(await Task.Run(() => res)); } //判断是否存在 var isExt = ErpBackGoodsDb.IsAny(m => m.ShopGuid == parm.ShopGuid && m.GoodsGuid == parm.GoodsGuid && m.OrderNumber == parm.OrderNumber); if (isExt) { res.message = "该退货信息已存在~"; return(await Task.Run(() => res)); } //根据订单查询商品数量是否满足 var orderGoodsModel = ErpSaleOrderGoodsDb.GetSingle(m => m.OrderNumber == parm.OrderNumber && m.GoodsGuid == parm.GoodsGuid && m.ShopGuid == parm.ShopGuid); if (orderGoodsModel == null) { res.message = "该商品在该订单号中不存在~"; return(await Task.Run(() => res)); } if (orderGoodsModel.Counts < parm.BackCount) { res.message = "退货商品数量不能大于订单购买数量~"; return(await Task.Run(() => res)); } var result = Db.Ado.UseTran(() => { //修改加盟商条形码里面的库存 退货=加盟商库存增加 Db.Updateable <ErpShopSku>() .UpdateColumns(m => new ErpShopSku() { Stock = m.Stock + parm.BackCount, Sale = m.Sale - parm.BackCount }) .Where(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == goodSku.Guid) .ExecuteCommand(); //根据商品编号,修改平台的销售数量 Db.Updateable <ErpGoodsSku>().UpdateColumns(m => new ErpGoodsSku() { SaleSum = m.SaleSum - parm.BackCount }) .Where(m => m.Guid == goodSku.Guid).ExecuteCommand(); //修改订单-商品详情表中的退货数量 增加 orderGoodsModel.BackCounts = orderGoodsModel.BackCounts + parm.BackCount; Db.Updateable(orderGoodsModel).ExecuteCommand(); //增加一条退货信息 Db.Insertable(parm).ExecuteCommand(); }); res.statusCode = (int)ApiEnum.Status; if (!result.IsSuccess) { res.statusCode = (int)ApiEnum.Error; res.message = result.ErrorMessage; } } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 修改一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > ModifyStatusAsync(ErpReturnGoods parm) { var res = new ApiResult <string>() { data = "1", statusCode = (int)ApiEnum.Error }; try { var model = ErpReturnGoodsDb.GetSingle(m => m.Guid == parm.Guid); if (model != null) { //查询加盟商库存中,该条商品的信息 var shopGoods = ErpShopSkuDb.GetSingle(m => m.ShopGuid == model.ShopGuid && m.SkuGuid == model.GoodsGuid); //查询平台 该条商品的信息 var platformGoods = ErpGoodsSkuDb.GetSingle(m => m.Guid == model.GoodsGuid); //查询返货订单信息 var returnOrderModel = ErpReturnOrderDb.GetSingle(m => m.Guid == model.OrderGuid); if (model.Status == 1) { //如果状态修改为非正常 需要增加加盟商库存 减少平台库存 model.Status = 2; //加盟商增加 shopGoods.Stock += model.ReturnCount; //需要判断平台库存是否足够 if (platformGoods.StockSum < model.ReturnCount) { res.message = "平台库存不足!"; return(await Task.Run(() => res)); } //平台库存减少 platformGoods.StockSum -= model.ReturnCount; //减少返货订单总数 returnOrderModel.GoodsSum -= model.ReturnCount; } else { //如果状态修改为非正常 需要减少加盟商库存 增加平台库存 model.Status = 1; //需要判断加盟商库存是否足够 if (shopGoods.Stock < model.ReturnCount) { res.message = "加盟商库存不足!"; return(await Task.Run(() => res)); } //加盟商减少 shopGoods.Stock -= model.ReturnCount; //平台库存增加 platformGoods.StockSum += model.ReturnCount; //增加返货订单总数 returnOrderModel.GoodsSum += model.ReturnCount; } var result = Db.Ado.UseTran(() => { //修改加盟商信息 Db.Updateable(shopGoods).ExecuteCommand(); //修改平台库存 Db.Updateable(platformGoods).ExecuteCommand(); //修改返货订单信息 Db.Updateable(returnOrderModel).ExecuteCommand(); //修改返货商品 Db.Updateable(model).ExecuteCommand(); }); if (!result.IsSuccess) { res.message = result.ErrorMessage; } res.statusCode = (int)ApiEnum.Status; } else { res.message = "没有查询到该条数据~"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }