using Library; using MySystem.Models.Main; using MySystem.Service.Main; using System; using System.Collections.Generic; using System.Linq; namespace MySystem { /// /// 预发货库存明细工具类 /// public class PreSendStockDetailUtil { public static List LPD = new List(); public static List LPos = new List(); #region 创客-首页-仓库管理-小分仓-确认发货 /// /// 创客-首页-仓库管理-小分仓-确认发货 /// /// 发货人Id /// 收货人Id /// 出货仓库Id /// 产品类型Id /// 机具Id /// public static string SendDo(int UserId, int ToUserId, int FromStoreId, int BrandId, string SnIds) { //分割SN string[] strids = SnIds.Split(','); var count = strids.ToList().Count(); var smallStoreHouse = SmallStoreHouseService.Query("UserId='" + ToUserId + "'"); //判断是否符合预发货规范(总库存数<=10) if (smallStoreHouse.LaveNum > 0 && smallStoreHouse.TotalNum < 10) { if (smallStoreHouse.LaveNum - count < 0 || smallStoreHouse.TotalNum + count > 10) { return "*发货失败,发货后该创客预发机超过10台"; } //循环添加到数据库 foreach (var item in strids) { var preSendStockDetail = PreSendStockDetailService.Query("FromUserId='" + UserId + "' and Status>=0 and Status<=1 and SnId='" + item + "'"); if (preSendStockDetail.Id > 0) { return "*发货失败,请勿重复提交"; } var posMachinesTwo = PosMachinesTwoService.Query(int.Parse(item)); posMachinesTwo.PreUserId = ToUserId; //赋值机具预发机所属人信息 PosMachinesTwoUtil.SetPosMachinesTwoValue(posMachinesTwo.Id, ToUserId); //赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货) SetPreSendStockDetailValue(UserId, ToUserId, posMachinesTwo.SourceStoreId, BrandId, posMachinesTwo.PosSn, FromStoreId, smallStoreHouse.Id, smallStoreHouse.Id, Convert.ToInt32(item)); } //修改机具预发机所属人标记 PosMachinesTwoUtil.EditPosPreUserIdValue(LPos); //修改小仓库库存(创客-首页-仓库管理-小分仓-确认发货) SmallStoreHouseUtil.EditStoreStock(smallStoreHouse.Id, smallStoreHouse.LaveNum -= count, smallStoreHouse.TotalNum += count); string text = string.Format("创客-首页-仓库管理-小分仓-确认发货,UserId: '" + UserId + "',ToUserId: '" + ToUserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + count + "',Time'" + DateTime.Now + "'"); function.WriteLog(text, "smallstorehouse");//小分仓记录日志 var storeHouse = StoreHouseService.Query(FromStoreId); //修改仓库剩余库存数 StoreHouseUtil.EditStoreLaveNum(storeHouse.Id, storeHouse.LaveNum -= count); //添加预发货库存明细 AddPreSendStockDetail(LPD); } else { return "*发货失败,该创客已有10台预发机"; } return "success"; } #endregion #region 创客-首页-仓库管理-小分仓-撤回 /// /// 创客-首页-仓库管理-小分仓-撤回 /// /// 发货人Id /// 记录Id public static string CancelDo(int UserId, int Id) { RedisDbconn.Instance.Set("SmallStoreCancel:" + UserId, "wait"); RedisDbconn.Instance.SetExpire("SmallStoreCancel:" + UserId, 300); var query = PreSendStockDetailService.Query("FromUserId='" + UserId + "' and Id='" + Id + "'"); var userAccount = UserAccountService.Query(UserId); var tuserAccount = UserAccountService.Query(query.ToUserId); var brandInfo = KqProductsService.Query(query.BrandId); var date = DateTime.Now.AddDays(-30); var amount = 0; if (query.Id > 0) { var posMachinesTwo = PosMachinesTwoService.Query(query.SnId); var storeHouse = StoreHouseService.Query(query.FromStoreId); var pm = PosMachinesTwoService.Query(query.SnId); if (brandInfo.Kind == 1) { amount = 200; } if (brandInfo.Kind == 2) { amount = 300; } if (pm != null) { if (pm.BindingState == 1) { return "机具已绑定,不可撤回!请创客申请机具后补录!"; } var smallStoreHouse = SmallStoreHouseService.Query("UserId='" + query.ToUserId + "'"); //赋值机具预发机所属人信息 PosMachinesTwoUtil.SetPosMachinesTwoValue(posMachinesTwo.Id, 0); //修改机具预发机所属人标记 PosMachinesTwoUtil.EditPosPreUserIdValue(LPos); //修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回) EditPreSendStockDetail(query.Id, -1, 1); //修改仓库剩余库存数 StoreHouseUtil.EditStoreLaveNum(storeHouse.Id, storeHouse.LaveNum += 1); //修改小仓库库存 SmallStoreHouseUtil.EditStoreStock(smallStoreHouse.Id, smallStoreHouse.LaveNum += 1, smallStoreHouse.TotalNum -= 1); if (query.CreateDate <= date) { //撤回占用小分仓额度的增加接收创客的小分仓可用额度 if (query.AuthFlag == 1 && tuserAccount.SmallStoreDeposit >= amount) { //扣减分仓可用额度 Dictionary userAccountData = new Dictionary(); userAccountData.Add("ValidAmount", userAccount.ValidAmount -= amount); UserAccountService.Edit(userAccountData, userAccount.Id); //增加小分仓可用额度 Dictionary tuserAccountData = new Dictionary(); tuserAccountData.Add("SmallStoreDeposit", tuserAccount.SmallStoreDeposit -= amount); tuserAccountData.Add("ValidPreAmount", tuserAccount.ValidPreAmount += amount); UserAccountService.Edit(tuserAccountData, userAccount.Id); //预发机撤回退还小分仓押金 UserAccountRecordUtil.AddRecordForCanclePos("小分仓押金退还", 66, tuserAccount.SmallStoreDeposit + amount, tuserAccount.SmallStoreDeposit, amount, tuserAccount.Id); } } else { //撤回占用小分仓额度的增加接收创客的小分仓可用额度 if (query.AuthFlag == 1) { //扣减分仓可用额度 Dictionary userAccountData = new Dictionary(); userAccountData.Add("ValidAmount", userAccount.ValidAmount -= amount); UserAccountService.Edit(userAccountData, userAccount.Id); //增加小分仓可用额度 Dictionary tuserAccountData = new Dictionary(); tuserAccountData.Add("ValidPreAmount", tuserAccount.ValidPreAmount += amount); UserAccountService.Edit(tuserAccountData, userAccount.Id); } } string text = string.Format("创客-首页-仓库管理-小分仓-撤回,UserId: '" + UserId + "',ToUserId: '" + smallStoreHouse.UserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + 1 + "',Time'" + DateTime.Now + "'"); function.WriteLog(text, "smallstorehouse");//小分仓记录日志 if (smallStoreHouse.LaveNum > 10 || smallStoreHouse.TotalNum < 0) { return "*库存已重置,不可撤回!"; } BaseClass.SendPersonalMsg(query.ToUserId, 0, "预发机撤回通知", "
您的预发机 SN:
" + query.SnNo + "
已被" + storeHouse.StoreName + " 撤回!
", "您的预发机: " + brandInfo.Name + " sn:" + query.SnNo + "已被 " + storeHouse.StoreName + " 撤回!"); var toUser = UsersService.Query(query.ToUserId); BaseClass.SendPersonalMsg(query.FromUserId, 0, "预发机撤回通知", "
已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:
" + query.SnNo + "
", "已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:" + query.SnNo + ""); } } RedisDbconn.Instance.SetExpire("SmallStoreCancel:" + UserId, 1); return "success"; } #endregion #region 赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货) /// /// 赋值预发货库存明细(创客-首页-仓库管理-小分仓-确认发货) /// public static void SetPreSendStockDetailValue(int FromUserId, int ToUserId, int SourceStoreId, int BrandId, string SnNo, int FromStoreId, int ToStoreId, int StoreId, int SnId) { PreSendStockDetail pd = new PreSendStockDetail(); pd.CreateDate = DateTime.Now; //创建时间 pd.FromUserId = FromUserId;//发货人Id pd.ToUserId = ToUserId; //收货人Id pd.SourceStoreId = SourceStoreId; //源仓库Id pd.BrandId = BrandId; //产品类型Id pd.SnNo = SnNo; //机具SN pd.FromStoreId = FromStoreId; //出货仓库Id pd.ToStoreId = ToStoreId; //收货仓库Id pd.StoreId = ToStoreId; //仓库Id pd.SnId = SnId; LPD.Add(pd); } #endregion #region 添加预发货库存明细(创客-首页-仓库管理-小分仓-确认发货) /// /// 添加预发货库存明细(创客-首页-仓库管理-小分仓-确认发货) /// public static void AddPreSendStockDetail(List pds) { foreach (var item in pds) { Dictionary query = new Dictionary(); query.Add("FromUserId", item.FromUserId);//发货人Id query.Add("ToUserId", item.ToUserId); //收货人Id query.Add("SourceStoreId", item.SourceStoreId); //源仓库Id query.Add("BrandId", item.BrandId); //产品类型Id query.Add("SnNo", item.SnNo); //机具SN query.Add("FromStoreId", item.FromStoreId); //出货仓库Id query.Add("ToStoreId", item.ToStoreId); //收货仓库Id query.Add("StoreId", item.StoreId); //仓库Id query.Add("SnId", item.SnId); PreSendStockDetailService.Add(query); } } #endregion #region 修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回) /// /// 修改预发货库存明细(创客-首页-仓库管理-小分仓-撤回) /// /// 记录Id /// 状态 /// 撤回标记 public static void EditPreSendStockDetail(int Id, int Status, int CancelFlag) { Dictionary query = new Dictionary(); query.Add("Status", Status); query.Add("CancelFlag", CancelFlag); PreSendStockDetailService.Edit(query, Id); } #endregion } }