using Library; using MySystem.Service.Main; using System; using System.Collections.Generic; namespace MySystem { /// /// 仓库库存变动工具类 /// public class StoreStockChangeUtil { #region 首页-仓库管理-整箱/逐台划拨 /// /// 首页-仓库管理-整箱/逐台划拨 /// /// 订单Id /// 仓库Id /// 收获创客Id /// 机具SN的Id集合 public static string TransferWholeOrOneDo(int OrderId, int StoreId, int ToUserId, string SnIds) { var store = StoreHouseService.Query(StoreId); string[] SnIdList = SnIds.Split(','); string SnNos = ""; //划拨的机具号(多个) var order = OrdersService.Query(OrderId); if (order.Id > 0) { if (order.Status == 2) { return "该订单已处理,请勿重复操作"; } int ApplyType = 0; // 申请类型,1-机具SN,2-200兑换码,3-300券 List SourceSnNos = new List(); if (order.Sort > 0) { var Apply = MachineApplyService.Query(order.Sort); if (Apply.Id > 0) { ApplyType = Apply.Sort; Dictionary File = new Dictionary(); File.Add("Status", 1); File.Add("QueryCount", order.Id); MachineApplyService.Edit(File, Apply.Id); if (!string.IsNullOrEmpty(Apply.SwapSnExpand)) { string[] SwapSnExpands = Apply.SwapSnExpand.Split('\n'); foreach (string sub in SwapSnExpands) { if (!string.IsNullOrEmpty(sub)) { SourceSnNos.Add(sub.Split(':')[0]); } } } } } Dictionary couponIds = new Dictionary(); int SnIndex = 0; foreach (string SnId in SnIdList) { string ChangeNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); int SnIdNum = int.Parse(SnId); int LeaderUserId = 0; DateTime RecycEndDate = DateTime.Now.AddDays(360); if (SourceSnNos.Count > SnIndex) { string SourceSnNo = SourceSnNos[SnIndex]; if (ApplyType <= 1) { var forSnNo = MachineForSnNoService.Query("SnNo='" + SourceSnNo + "'"); var spos = PosMachinesTwoService.Query(forSnNo.SnId); RecycEndDate = spos.RecycEndDate == null ? RecycEndDate = DateTime.Now.AddDays(360) : spos.RecycEndDate.Value; LeaderUserId = spos.LeaderUserId; } else if (ApplyType > 1) { var coupon = PosCouponsService.Query("ExchangeCode='" + SourceSnNo + "'"); LeaderUserId = coupon.LeaderUserId; if (coupon.OpId > 0) { if (couponIds.ContainsKey(coupon.OpId)) { string[] datas = couponIds[coupon.OpId].Split(','); int Num = int.Parse(datas[2]) + 1; couponIds[coupon.OpId] = datas[0] + "," + datas[1] + "," + Num; } else { couponIds.Add(coupon.OpId, coupon.Id + "," + coupon.QueryCount + ",1"); } } } } var pos = PosMachinesTwoService.Query(SnIdNum); //扣减分仓所关联的运营中心总机具数 if (pos.OpId > 0) { var sysAdmin = MySystem.Service.Operate.SysAdminService.Query("QueryCount=1 and UserId='" + pos.OpId + "'"); if (sysAdmin.Id > 0) { sysAdmin.TotalMachineCount -= 1; Dictionary File = new Dictionary(); File.Add("TotalMachineCount", sysAdmin.TotalMachineCount); MySystem.Service.Operate.SysAdminService.Edit(File, sysAdmin.Id); } } SnNos += pos.PosSn + ","; AddForTransfer(StoreId, pos.BrandId, KqProductsService.Query(pos.BrandId).Name, ChangeNo, 10, pos.PosSn, pos.PosSnType, 1, pos.DeviceType, store.UserId, DateTime.Now, ToUserId, StoreId, pos.OpId); UserStoreChangeUtil.AddForTransfer(store.UserId, pos.BrandId, ChangeNo, 0, pos.PosSn, pos.PosSnType, 0, pos.DeviceName, pos.DeviceKind, pos.DeviceType, ToUserId, DateTime.Now, pos.SourceStoreId, 1, (int)pos.BindingState, pos.BindMerchantId, (int)pos.ActivationState, pos.BuyUserId, pos.DeviceType); StoreChangeHistoryUtil.AddForTransfer(store.UserId, pos.BrandId, ChangeNo, 2, pos.PosSn, pos.PosSnType, 1, pos.DeviceName, pos.DeviceKind, pos.DeviceType, ToUserId, store.UserId, DateTime.Now, pos.SourceStoreId, store.Id, pos.OpId); PublicFunction.StatUserMachineData(ToUserId, pos.BrandId, 1); StoreHouseUtil.EditStoreStock(store.Id, store.LaveNum -= 1, store.OutNum += 1); PosMachinesTwoUtil.EditPosInfo(pos.Id, OrderId, ToUserId, ToUserId, DateTime.Now, RecycEndDate, order.QueryCount, LeaderUserId); } OrdersUtil.EditOrdersInfo(order.Id, 2, 1, DateTime.Now, SnNos.TrimEnd(',')); string SendData = "{\"Kind\":\"4\",\"Data\":{\"StoreId\":\"" + StoreId + "\",\"SnIds\":\"" + SnIds + "\"}}"; RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); } return "success"; } #endregion #region 首页-仓库管理-售后单划拨 /// /// 首页-仓库管理-售后单划拨 /// /// 订单Id /// 仓库Id /// 收获创客Id /// 机具SN的Id集合 public static string TransferForChangeDo(int OrderId, int StoreId, string SnIds) { int CheckCount = MachineChangeService.Count("OutStoreId='" + StoreId + "' and AuditResult=0"); if (CheckCount >= 10) { return "待审核订单超过10单,请等待管理员审核"; } var store = StoreHouseService.Query(StoreId); string[] SnIdList = SnIds.Split(','); string SnNos = ""; //划拨的机具号(多个) var order = OrdersService.Query(OrderId); if (order.Id > 0) { if (order.Status == 2) { return "该订单已处理,请勿重复操作"; } int ToUserId = order.UserId; int ChangeId = 0; List SourceSnNos = new List(); if (order.Sort > 0) { var Apply = MachineChangeService.Query(order.Sort); if (Apply.Id > 0) { Apply.Status = 1; if (!string.IsNullOrEmpty(Apply.ChangeSnExpand)) { string[] ChangeSnExpand = Apply.ChangeSnExpand.Split('\n'); foreach (string sub in ChangeSnExpand) { if (!string.IsNullOrEmpty(sub)) { SourceSnNos.Add(sub.Split(':')[0]); } } } ChangeId = Apply.Id; } } int SnIndex = 0; List contents = new List(); foreach (string SnId in SnIdList) { string ChangeNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); int SnIdNum = int.Parse(SnId); DateTime RecycEndDate = DateTime.Now.AddDays(360); string SourceSnNo = ""; if (SourceSnNos.Count > SnIndex) { SourceSnNo = SourceSnNos[SnIndex]; var forSnNo = MachineForSnNoService.Query("SnNo='" + SourceSnNo + "'"); var spos = PosMachinesTwoService.Query(forSnNo.SnId); RecycEndDate = spos.RecycEndDate == null ? RecycEndDate = DateTime.Now.AddDays(360) : spos.RecycEndDate.Value; } var pos = PosMachinesTwoService.Query(SnIdNum); //扣减分仓所关联的运营中心总机具数 if (pos.OpId > 0) { var sysAdmin = MySystem.Service.Operate.SysAdminService.Query("QueryCount=1 and UserId='" + pos.OpId + "'"); if (sysAdmin.Id > 0) { sysAdmin.TotalMachineCount -= 1; Dictionary File = new Dictionary(); File.Add("TotalMachineCount", sysAdmin.TotalMachineCount); MySystem.Service.Operate.SysAdminService.Edit(File, sysAdmin.Id); } } var merchant = PosMerchantInfoService.Query(pos.BindMerchantId); SnNos += pos.PosSn + ","; AddForTransfer(StoreId, pos.BrandId, KqProductsService.Query(pos.BrandId).Name, ChangeNo, 11, pos.PosSn, pos.PosSnType, 1, pos.DeviceType, store.UserId, DateTime.Now, ToUserId, StoreId, pos.OpId); UserStoreChangeUtil.AddForTransfer(store.UserId, pos.BrandId, ChangeNo, 0, pos.PosSn, pos.PosSnType, 0, pos.DeviceName, pos.DeviceKind, pos.DeviceType, ToUserId, DateTime.Now, pos.SourceStoreId, 1, (int)pos.BindingState, pos.BindMerchantId, (int)pos.ActivationState, pos.BuyUserId, pos.DeviceType); StoreChangeHistoryUtil.AddForTransfer(store.UserId, pos.BrandId, ChangeNo, 2, pos.PosSn, pos.PosSnType, 1, pos.DeviceName, pos.DeviceKind, pos.DeviceType, ToUserId, store.UserId, DateTime.Now, pos.SourceStoreId, store.Id, pos.OpId); PublicFunction.StatUserMachineData(ToUserId, pos.BrandId, 1); StoreHouseUtil.EditStoreStock(store.Id, store.LaveNum -= 1, store.OutNum += 1); PosMachinesTwoUtil.EditPosInfo(pos.Id, OrderId, ToUserId, ToUserId, DateTime.Now, RecycEndDate, order.QueryCount, 0); string content = "{"; //执行机具数据同步 content += "\"OldSn\":\"" + SourceSnNo + "\","; content += "\"NewSn\":\"" + pos.PosSn + "\","; content += "\"MerNo\":\"" + merchant.KqMerNo + "\","; content += "\"ChangeId\":\"" + ChangeId + "\""; content += "}"; contents.Add(content); } OrdersUtil.EditOrdersInfo(order.Id, 2, 1, DateTime.Now, SnNos.TrimEnd(',')); foreach (string content in contents) { RedisDbconn.Instance.AddList("ChangePosTimerQueue", content); } string SendData = "{\"Kind\":\"4\",\"Data\":{\"StoreId\":\"" + StoreId + "\",\"SnIds\":\"" + SnIds + "\"}}"; RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); } return "success"; } #endregion #region 添加仓库库存变动记录(仓库出货) /// /// 添加仓库库存变动记录(仓库出货) /// /// 仓库 /// 产品类型 /// 产品名称 /// 变更单号 /// 交易类型 /// SN编号 /// SN机具类型 /// 库存操作方向 /// 设备类型 /// 出货人 /// 出库时间 /// 收货人 /// 退货收货仓库 /// 运营中心创客Id public static void AddForTransfer(int StoreId, int BrandId, string ProductName, string ChangeNo, int TransType, string SnNo, int SnType, int StockOpDirect, string DeviceType, int FromUserId, DateTime? FromDate, int ToUserId, int ToStoreId, int OpId) { Dictionary query = new Dictionary(); query.Add("StoreId", StoreId);//仓库 query.Add("BrandId", BrandId);//产品类型 query.Add("ProductName", ProductName);//产品名称 query.Add("ChangeNo", ChangeNo);//变更单号 query.Add("TransType", TransType);//交易类型 query.Add("SnNo", SnNo);//SN编号 query.Add("SnType", SnType);//SN机具类型 query.Add("StockOpDirect", 1);//库存操作方向 query.Add("DeviceType", DeviceType);//设备类型 query.Add("FromUserId", FromUserId);//出货人 query.Add("FromDate", FromDate);//出库时间 query.Add("ToUserId", ToUserId);//收货人 query.Add("ToStoreId", ToStoreId);//退货收货仓库 query.Add("OpId", OpId);//运营中心创客Id StoreStockChangeService.Add(query); } #endregion } }