using System; using System.Collections.Generic; using System.Linq; using System.Data; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Authorization; using System.Web; using MySystem.MainModels; using LitJson; using Library; namespace MySystem.Areas.Api.Controllers.v1 { [Area("Api")] [Route("Api/v1/[controller]/[action]")] public class StoreStockChangeController : BaseController { public StoreStockChangeController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString(); } #region 首页-仓库管理-整箱划拨 [Authorize] public JsonResult TransferWhole(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = TransferWholeDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson TransferWholeDo(string value) { JsonData data = JsonMapper.ToObject(value); int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString())); int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库 int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人 string SnNo = data["SnNo"].ToString(); //首台SN编号 Dictionary Obj = new Dictionary(); if (string.IsNullOrEmpty(SnNo)) { return new AppResultJson() { Status = "-1", Info = "请选择机具" }; } StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse(); string[] SnIdList = SnNo.Split(','); string SnNos = ""; //划拨的机具号(多个) Orders order = maindb.Orders.FirstOrDefault(m => m.Id == OrderId); if (order != null) { if (order.Status == 2) { return new AppResultJson() { Status = "-1", Info = "该订单已处理,请勿重复操作" }; } int ApplyType = 0; // 申请类型,1-机具SN,2-200兑换码,3-300券 List SourceSnNos = new List(); if (order.Sort > 0) { MachineApply Apply = maindb.MachineApply.FirstOrDefault(m => m.Id == order.Sort); if (Apply != null) { Apply.Status = 1; Apply.QueryCount = order.Id; ApplyType = Apply.Sort; 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; // int OpId = 0; DateTime RecycEndDate = DateTime.Now.AddDays(360); if (SourceSnNos.Count > SnIndex) { string SourceSnNo = SourceSnNos[SnIndex]; if (ApplyType <= 1) { MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSnNo) ?? new MachineForSnNo(); PosMachinesTwo spos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo(); RecycEndDate = spos.RecycEndDate == null ? RecycEndDate = DateTime.Now.AddDays(360) : spos.RecycEndDate.Value; LeaderUserId = spos.LeaderUserId; // OpId = spos.OpId; } else if (ApplyType > 1) { PosCoupons coupon = maindb.PosCoupons.FirstOrDefault(m => m.ExchangeCode == SourceSnNo) ?? new PosCoupons(); 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"); } // OpId = coupon.OpId; } } } PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum) ?? new PosMachinesTwo(); //扣减分仓所关联的运营中心总机具数 if (pos.OpId > 0) { var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == pos.OpId) ?? new OpModels.SysAdmin(); if (sysAdmin.Id > 0) { sysAdmin.TotalMachineCount -= 1; opdb.SaveChanges(); } } SnNos += pos.PosSn + ","; Users toUser = UsersDbconn.Instance.Get(ToUserId) ?? new Users(); StoreStockChange query = maindb.StoreStockChange.Add(new StoreStockChange() { CreateDate = DateTime.Now, StoreId = StoreId, //仓库 BrandId = pos.BrandId, //产品类型 ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称 ChangeNo = ChangeNo, //变更单号 TransType = 10, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 1, //库存操作方向 DeviceType = pos.DeviceType, //设备类型 FromUserId = store.UserId, //出货人 FromDate = DateTime.Now, //出库时间 ToUserId = ToUserId, //收货人 ToStoreId = StoreId, //退货收货仓库 OpId = pos.OpId }).Entity; UserStoreChange userstore = maindb.UserStoreChange.Add(new UserStoreChange() { CreateDate = DateTime.Now, UserId = store.UserId, //创客 BrandId = pos.BrandId, //产品类型 ChangeRecordNo = ChangeNo, //变更记录单号 TransType = 0, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 0, //库存操作方向 DeviceVendor = pos.DeviceName, //设备厂商 DeviceType = pos.DeviceKind, //设备类型 DeviceModel = pos.DeviceType, //设备型号 ToUserId = ToUserId, //收货创客 ToDate = DateTime.Now, //入库时间 SourceStoreId = pos.SourceStoreId, //源仓库 SnStatus = 1, //SN状态 BindStatus = (int)pos.BindingState, //绑定状态 BindMerchantId = pos.BindMerchantId, //绑定商户 ActiveStatus = (int)pos.ActivationState, //激活状态 ActRewardUserId = pos.BuyUserId, //激活奖励创客 BrandType = pos.DeviceType, //品牌类型 }).Entity; StoreChangeHistory history = maindb.StoreChangeHistory.Add(new StoreChangeHistory() { CreateDate = DateTime.Now, UserId = store.UserId, //创客 BrandId = pos.BrandId, //产品类型 ChangeRecordNo = ChangeNo, //变更记录单号 TransType = 2, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 1, //库存操作方向 DeviceVendor = pos.DeviceName, //设备厂商 DeviceModel = pos.DeviceKind, //设备型号 DeviceType = pos.DeviceType, //设备类型 ToUserId = ToUserId, //收货创客 FromUserId = store.UserId, //出货创客 FromDate = DateTime.Now, //出库时间 SourceStoreId = pos.SourceStoreId, //源仓库 StoreId = store.Id, //仓库 OpId = pos.OpId }).Entity; maindb.SaveChanges(); PublicFunction.StatUserMachineData(ToUserId, pos.BrandId, 1); store.LaveNum -= 1; store.OutNum += 1; pos.OrderId = OrderId; pos.BuyUserId = ToUserId; pos.UserId = ToUserId; pos.TransferTime = DateTime.Now; pos.RecycEndDate = RecycEndDate; // 循环结束时间 pos.PosSnType = order.QueryCount; //机具类型,0-兑换机,1-循环机 pos.LeaderUserId = LeaderUserId; // pos.OpId = OpId; maindb.SaveChanges(); SnIndex += 1; } order.Status = 2; order.SendStatus = 1; order.SendDate = DateTime.Now; order.SnNos = SnNos.TrimEnd(','); maindb.SaveChanges(); //扣减分仓所关联的运营和中心总机具数 if (store.OpId > 0) { var count = SnIdList.Count(); var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == store.OpId) ?? new OpModels.SysAdmin(); if (sysAdmin.Id > 0) { sysAdmin.TotalMachineCount -= count; opdb.SaveChanges(); } } string SendData = "{\"Kind\":\"4\",\"Data\":{\"StoreId\":\"" + StoreId + "\",\"SnIds\":\"" + SnNo + "\"}}"; //只给对应分仓增加可用额度 RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); // if(ApplyType > 1) // { // // 兑换成机具将向运营中心返还对应机具额度 // foreach(int OpId in couponIds.Keys) // { // string[] datalist = couponIds[OpId].Split(','); // decimal OperateAmount = 200 + int.Parse(datalist[2]); // if(datalist[1] == "2") OperateAmount = 300 + int.Parse(datalist[2]); // string OperateData = "{\"UserId\":\"" + OpId + "\",\"DataId\":\"" + datalist[0] + "\",\"Kind\":\"1\",\"Amount\":\"" + OperateAmount + "\"}"; // RedisDbconn.Instance.AddList("OperateAmountQueue", OperateData); // } // } } maindb.Dispose(); return new AppResultJson() { Status = "1", Info = "", Data = Obj }; } #endregion #region 首页-仓库管理-逐台划拨 [Authorize] public JsonResult TransferOne(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = TransferOneDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson TransferOneDo(string value) { JsonData data = JsonMapper.ToObject(value); int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString())); int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库 int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人 string SnIds = data["SnIds"].ToString(); //SN的Id集合 Dictionary Obj = new Dictionary(); if (string.IsNullOrEmpty(SnIds)) { return new AppResultJson() { Status = "-1", Info = "请选择机具" }; } StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse(); string[] SnIdList = SnIds.Split(','); string SnNos = ""; //划拨的机具号(多个) Orders order = maindb.Orders.FirstOrDefault(m => m.Id == OrderId); if (order != null) { if (order.Status == 2) { return new AppResultJson() { Status = "-1", Info = "该订单已处理,请勿重复操作" }; } int ApplyType = 0; // 申请类型,1-机具SN,2-200兑换码,3-300券 List SourceSnNos = new List(); if (order.Sort > 0) { MachineApply Apply = maindb.MachineApply.FirstOrDefault(m => m.Id == order.Sort); if (Apply != null) { Apply.Status = 1; Apply.QueryCount = order.Id; ApplyType = Apply.Sort; 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); DateTime RecycEndDate = DateTime.Now.AddDays(360); int LeaderUserId = 0; // int OpId = 0; if (SourceSnNos.Count > SnIndex) { string SourceSnNo = SourceSnNos[SnIndex]; if (ApplyType <= 1) { MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSnNo) ?? new MachineForSnNo(); PosMachinesTwo spos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo(); RecycEndDate = spos.RecycEndDate == null ? RecycEndDate = DateTime.Now.AddDays(360) : spos.RecycEndDate.Value; LeaderUserId = spos.LeaderUserId; // OpId = spos.OpId; } else if (ApplyType > 1) { PosCoupons coupon = maindb.PosCoupons.FirstOrDefault(m => m.ExchangeCode == SourceSnNo) ?? new PosCoupons(); 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"); } } } } PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum) ?? new PosMachinesTwo(); //扣减分仓所关联的运营中心总机具数 if (pos.OpId > 0) { var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == pos.OpId) ?? new OpModels.SysAdmin(); if (sysAdmin.Id > 0) { sysAdmin.TotalMachineCount -= 1; opdb.SaveChanges(); } } if (StoreId == 0) { StoreId = pos.StoreId; } SnNos += pos.PosSn + ","; Users toUser = UsersDbconn.Instance.Get(ToUserId) ?? new Users(); StoreStockChange query = maindb.StoreStockChange.Add(new StoreStockChange() { CreateDate = DateTime.Now, StoreId = StoreId, //仓库 BrandId = pos.BrandId, //产品类型 ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称 ChangeNo = ChangeNo, //变更单号 TransType = 11, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 1, //库存操作方向 DeviceType = pos.DeviceType, //设备类型 FromUserId = store.UserId, //出货人 FromDate = DateTime.Now, //出库时间 ToUserId = ToUserId, //收货人 ToStoreId = StoreId, //退货收货仓库 OpId = pos.OpId }).Entity; UserStoreChange userstore = maindb.UserStoreChange.Add(new UserStoreChange() { CreateDate = DateTime.Now, UserId = store.UserId, //创客 BrandId = pos.BrandId, //产品类型 ChangeRecordNo = ChangeNo, //变更记录单号 TransType = 0, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 0, //库存操作方向 DeviceVendor = pos.DeviceName, //设备厂商 DeviceType = pos.DeviceKind, //设备类型 DeviceModel = pos.DeviceType, //设备型号 ToUserId = ToUserId, //收货创客 ToDate = DateTime.Now, //入库时间 SourceStoreId = pos.SourceStoreId, //源仓库 SnStatus = 1, //SN状态 BindStatus = (int)pos.BindingState, //绑定状态 BindMerchantId = pos.BindMerchantId, //绑定商户 ActiveStatus = (int)pos.ActivationState, //激活状态 ActRewardUserId = pos.BuyUserId, //激活奖励创客 BrandType = pos.DeviceType, //品牌类型 }).Entity; StoreChangeHistory history = maindb.StoreChangeHistory.Add(new StoreChangeHistory() { CreateDate = DateTime.Now, UserId = store.UserId, //创客 BrandId = pos.BrandId, //产品类型 ChangeRecordNo = ChangeNo, //变更记录单号 TransType = 2, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 1, //库存操作方向 DeviceVendor = pos.DeviceName, //设备厂商 DeviceModel = pos.DeviceKind, //设备型号 DeviceType = pos.DeviceType, //设备类型 ToUserId = ToUserId, //收货创客 FromUserId = store.UserId, //出货创客 FromDate = DateTime.Now, //出库时间 SourceStoreId = pos.SourceStoreId, //源仓库 StoreId = store.Id, //仓库 OpId = pos.OpId }).Entity; maindb.SaveChanges(); PublicFunction.StatUserMachineData(ToUserId, pos.BrandId, 1); store.LaveNum -= 1; store.OutNum += 1; pos.OrderId = OrderId; pos.BuyUserId = ToUserId; pos.UserId = ToUserId; pos.TransferTime = DateTime.Now; pos.RecycEndDate = RecycEndDate; // 循环结束时间 pos.PosSnType = order.QueryCount; pos.LeaderUserId = LeaderUserId; //机子无标记就赋运营中心的值 // if ((pos.OpId == 0 && ApplyType > 1) || ApplyType <= 1) // { // pos.OpId = OpId; // } maindb.SaveChanges(); SnIndex += 1; } order.Status = 2; order.SendStatus = 1; order.SendDate = DateTime.Now; order.SnNos = SnNos.TrimEnd(','); maindb.SaveChanges(); string SendData = "{\"Kind\":\"4\",\"Data\":{\"StoreId\":\"" + StoreId + "\",\"SnIds\":\"" + SnIds + "\"}}"; RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); // if(ApplyType > 1) // { // // 兑换成机具将向运营中心返还对应机具额度 // foreach(int OpId in couponIds.Keys) // { // string[] datalist = couponIds[OpId].Split(','); // decimal OperateAmount = 200 + int.Parse(datalist[2]); // if(datalist[1] == "2") OperateAmount = 300 + int.Parse(datalist[2]); // string OperateData = "{\"UserId\":\"" + OpId + "\",\"DataId\":\"" + datalist[0] + "\",\"Kind\":\"1\",\"Amount\":\"" + OperateAmount + "\"}"; // RedisDbconn.Instance.AddList("OperateAmountQueue", OperateData); // } // } } maindb.Dispose(); return new AppResultJson() { Status = "1", Info = "", Data = Obj }; } #endregion #region 首页-仓库管理-售后单-划拨 [Authorize] public JsonResult TransferForChange(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = TransferForChangeDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson TransferForChangeDo(string value) { JsonData data = JsonMapper.ToObject(value); int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString())); int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库 string SnIds = data["SnIds"].ToString(); //SN的Id集合 Dictionary Obj = new Dictionary(); if (string.IsNullOrEmpty(SnIds)) { return new AppResultJson() { Status = "-1", Info = "请选择机具" }; } int CheckCount = maindb.MachineChange.Count(m => m.OutStoreId == StoreId && m.AuditResult == 0); if (CheckCount >= 10) { return new AppResultJson() { Status = "-1", Info = "待审核订单超过10单,请等待管理员审核" }; } StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse(); string[] SnIdList = SnIds.Split(','); string SnNos = ""; //划拨的机具号(多个) Orders order = maindb.Orders.FirstOrDefault(m => m.Id == OrderId); if (order != null) { if (order.Status == 2) { return new AppResultJson() { Status = "-1", Info = "该订单已处理,请勿重复操作" }; } int ToUserId = order.UserId; int ChangeId = 0; List SourceSnNos = new List(); if (order.Sort > 0) { MachineChange Apply = maindb.MachineChange.FirstOrDefault(m => m.Id == order.Sort); if (Apply != null) { 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]; MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSnNo) ?? new MachineForSnNo(); PosMachinesTwo spos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId) ?? new PosMachinesTwo(); RecycEndDate = spos.RecycEndDate == null ? RecycEndDate = DateTime.Now.AddDays(360) : spos.RecycEndDate.Value; } PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum) ?? new PosMachinesTwo(); //扣减分仓所关联的运营中心总机具数 if (pos.OpId > 0) { var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == pos.OpId) ?? new OpModels.SysAdmin(); if (sysAdmin.Id > 0) { sysAdmin.TotalMachineCount -= 1; opdb.SaveChanges(); } } PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo(); SnNos += pos.PosSn + ","; Users toUser = UsersDbconn.Instance.Get(ToUserId) ?? new Users(); StoreStockChange query = maindb.StoreStockChange.Add(new StoreStockChange() { CreateDate = DateTime.Now, StoreId = StoreId, //仓库 BrandId = pos.BrandId, //产品类型 ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称 ChangeNo = ChangeNo, //变更单号 TransType = 11, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 1, //库存操作方向 DeviceType = pos.DeviceType, //设备类型 FromUserId = store.UserId, //出货人 FromDate = DateTime.Now, //出库时间 ToUserId = ToUserId, //收货人 ToStoreId = StoreId, //退货收货仓库 }).Entity; UserStoreChange userstore = maindb.UserStoreChange.Add(new UserStoreChange() { CreateDate = DateTime.Now, UserId = store.UserId, //创客 BrandId = pos.BrandId, //产品类型 ChangeRecordNo = ChangeNo, //变更记录单号 TransType = 0, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 0, //库存操作方向 DeviceVendor = pos.DeviceName, //设备厂商 DeviceType = pos.DeviceKind, //设备类型 DeviceModel = pos.DeviceType, //设备型号 ToUserId = ToUserId, //收货创客 ToDate = DateTime.Now, //入库时间 SourceStoreId = pos.SourceStoreId, //源仓库 SnStatus = 1, //SN状态 BindStatus = (int)pos.BindingState, //绑定状态 BindMerchantId = pos.BindMerchantId, //绑定商户 ActiveStatus = (int)pos.ActivationState, //激活状态 ActRewardUserId = pos.BuyUserId, //激活奖励创客 BrandType = pos.DeviceType, //品牌类型 }).Entity; StoreChangeHistory history = maindb.StoreChangeHistory.Add(new StoreChangeHistory() { CreateDate = DateTime.Now, UserId = store.UserId, //创客 BrandId = pos.BrandId, //产品类型 ChangeRecordNo = ChangeNo, //变更记录单号 TransType = 2, //交易类型 SnNo = pos.PosSn, //SN编号 SnType = pos.PosSnType, //SN机具类型 StockOpDirect = 1, //库存操作方向 DeviceVendor = pos.DeviceName, //设备厂商 DeviceModel = pos.DeviceKind, //设备型号 DeviceType = pos.DeviceType, //设备类型 ToUserId = ToUserId, //收货创客 FromUserId = store.UserId, //出货创客 FromDate = DateTime.Now, //出库时间 SourceStoreId = pos.SourceStoreId, //源仓库 StoreId = store.Id, //仓库 }).Entity; maindb.SaveChanges(); PublicFunction.StatUserMachineData(ToUserId, pos.BrandId, 1); store.LaveNum -= 1; store.OutNum += 1; pos.OrderId = OrderId; pos.BuyUserId = ToUserId; pos.UserId = ToUserId; pos.TransferTime = DateTime.Now; pos.RecycEndDate = RecycEndDate; // 循环结束时间 pos.PosSnType = order.QueryCount; maindb.SaveChanges(); SnIndex += 1; string content = "{"; //执行机具数据同步 content += "\"OldSn\":\"" + SourceSnNo + "\","; content += "\"NewSn\":\"" + pos.PosSn + "\","; content += "\"MerNo\":\"" + merchant.KqMerNo + "\","; content += "\"ChangeId\":\"" + ChangeId + "\""; content += "}"; contents.Add(content); } order.Status = 2; order.SendStatus = 1; order.SendDate = DateTime.Now; order.SnNos = SnNos.TrimEnd(','); maindb.SaveChanges(); foreach (string content in contents) { RedisDbconn.Instance.AddList("ChangePosTimerQueue", content); } string SendData = "{\"Kind\":\"4\",\"Data\":{\"StoreId\":\"" + StoreId + "\",\"SnIds\":\"" + SnIds + "\"}}"; RedisDbconn.Instance.AddList("StoreApplyQueue", SendData); } maindb.Dispose(); return new AppResultJson() { Status = "1", Info = "", Data = Obj }; } #endregion #region 首页-仓库管理-售后单-划拨验证 [Authorize] public JsonResult TransferForCheck(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = TransferForCheckDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson TransferForCheckDo(string value) { JsonData data = JsonMapper.ToObject(value); int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库 int CheckCount = maindb.MachineChange.Count(m => m.OutStoreId == StoreId && m.AuditResult == 0); if (CheckCount >= 10) { return new AppResultJson() { Status = "-1", Info = "待审核订单超过10单,请等待管理员审核" }; } return new AppResultJson() { Status = "1", Info = "" }; } #endregion #region 首页-仓库管理-售后单-驳回 [Authorize] public JsonResult RefuseForChange(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = RefuseForChangeDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson RefuseForChangeDo(string value) { JsonData data = JsonMapper.ToObject(value); int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString())); int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库 Orders order = maindb.Orders.FirstOrDefault(m => m.Id == OrderId && m.StoreId == StoreId); if (order != null) { order.Status = -1; MachineChange change = maindb.MachineChange.FirstOrDefault(m => m.Id == order.Sort); if (change != null) { change.AuditResult = 2; } maindb.SaveChanges(); maindb.Dispose(); return new AppResultJson() { Status = "1", Info = "" }; } maindb.Dispose(); return new AppResultJson() { Status = "-1", Info = "" }; } #endregion #region 创客-首页-仓库管理-划拨记录-拨入 [Authorize] public JsonResult In(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = InDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> InDo(string value) { JsonData data = JsonMapper.ToObject(value); string SearchKey = data["SearchKey"].ToString(); int ToStoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //退货收货仓库 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); IQueryable query = maindb.StoreStockChange.Where(m => m.ToStoreId == ToStoreId); if (!string.IsNullOrEmpty(SearchKey)) { query = query.Where(m => m.SnNo == SearchKey); } if (PageNum == 1) { query = query.Take(PageSize); } else { int skipNum = PageSize * (PageNum - 1); query = query.Skip(skipNum).Take(PageSize); } query = query.OrderByDescending(m => m.Id); foreach (var subdata in query.ToList()) { Dictionary curData = new Dictionary(); curData.Add("StoreId", subdata.StoreId); //仓库 Dictionary StoreInfo = new Dictionary(); StoreHouse StoreHouseData = maindb.StoreHouse.FirstOrDefault(m => m.Id == subdata.StoreId) ?? new StoreHouse(); StoreInfo.Add("StoreName", StoreHouseData.StoreName); //仓库名称 curData.Add("StoreInfo", StoreInfo); curData.Add("SnNo", subdata.SnNo); //SN编号 curData.Add("FromUserId", subdata.FromUserId); //出货人 Dictionary UserInfo = new Dictionary(); Users UsersData = maindb.Users.FirstOrDefault(m => m.Id == subdata.FromUserId) ?? new Users(); UserInfo.Add("RealName", UsersData.RealName); //真实姓名 UserInfo.Add("MakerCode", UsersData.MakerCode); //创客编号 UserInfo.Add("Mobile", UsersData.Mobile); //手机号 curData.Add("UserInfo", UserInfo); curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate dataList.Add(curData); } return dataList; } #endregion #region 创客-首页-仓库管理-划拨记录-拨出 [Authorize] public JsonResult Out(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = OutDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> OutDo(string value) { JsonData data = JsonMapper.ToObject(value); string SearchKey = data["SearchKey"].ToString(); int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); IQueryable query = maindb.StoreStockChange.Where(m => m.StoreId == StoreId && m.ToUserId > 0); if (!string.IsNullOrEmpty(SearchKey)) { query = query.Where(m => m.SnNo == SearchKey); } if (PageNum == 1) { query = query.Take(PageSize); } else { int skipNum = PageSize * (PageNum - 1); query = query.Skip(skipNum).Take(PageSize); } query = query.OrderByDescending(m => m.Id); foreach (var subdata in query.ToList()) { Dictionary curData = new Dictionary(); curData.Add("ChangeNo", subdata.ChangeNo); //变更单号 curData.Add("SnNo", subdata.SnNo); //SN编号 curData.Add("ToUserId", subdata.ToUserId); //收货人 Dictionary UserInfo = new Dictionary(); Users UsersData = maindb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new Users(); UserInfo.Add("RealName", UsersData.RealName); //真实姓名 UserInfo.Add("MakerCode", UsersData.MakerCode); //创客编号 UserInfo.Add("Mobile", UsersData.Mobile); //手机号 curData.Add("UserInfo", UserInfo); curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate dataList.Add(curData); } return dataList; } #endregion #region 创客-首页-仓库管理-出货记录-按天 [Authorize] public JsonResult ForDate(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = ForDateDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> ForDateDo(string value) { JsonData data = JsonMapper.ToObject(value); int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库 // int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型 string Month = data["Month"].ToString(); //月份 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); DataTable dt = OtherMySqlConn.dtable("SELECT DATE_FORMAT(CreateDate,'%Y%m%d') date,COUNT(0) count FROM StoreStockChange WHERE StoreId = '" + StoreId + "' AND TransType in (2,10,11) AND DATE_FORMAT(CreateDate,'%Y%m') = '" + Month + "' GROUP BY DATE_FORMAT(CreateDate,'%Y%m%d') ORDER BY DATE_FORMAT(CreateDate,'%Y%m%d') DESC"); foreach (DataRow item in dt.Rows) { Dictionary curData = new Dictionary(); curData.Add("Date", item["date"]); //时间 curData.Add("ActTotal", Convert.ToInt32(function.CheckInt(item["count"].ToString()))); //总激活 List> snList = new List>(); DataTable dts = OtherMySqlConn.dtable("SELECT DATE_FORMAT(CreateDate,'%Y%m%d') date,SnNo FROM StoreStockChange WHERE StoreId = '" + StoreId + "' AND TransType in (2,10,11) AND DATE_FORMAT(CreateDate,'%Y%m%d') = '" + item["date"] + "'"); foreach (DataRow items in dts.Rows) { Dictionary sn = new Dictionary(); sn.Add("Date", items["date"]); //时间 sn.Add("Sn", items["SnNo"]); //Sn snList.Add(sn); } curData.Add("SnList", snList); dataList.Add(curData); } dataList = dataList.Skip((PageNum - 1) * PageSize).Take(PageSize).ToList();//分页的重点 return dataList; } #endregion #region 创客-首页-仓库管理-出货记录-按月 [Authorize] public JsonResult ForMonth(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = ForMonthDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> ForMonthDo(string value) { JsonData data = JsonMapper.ToObject(value); int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库 // int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); DataTable dt = OtherMySqlConn.dtable("SELECT DATE_FORMAT(CreateDate,'%Y%m') date,COUNT(0) count FROM StoreStockChange WHERE StoreId = '" + StoreId + "' AND TransType in (2,10,11) GROUP BY DATE_FORMAT(CreateDate,'%Y%m') ORDER BY DATE_FORMAT(CreateDate,'%Y%m') DESC"); foreach (DataRow item in dt.Rows) { Dictionary curData = new Dictionary(); curData.Add("Date", item["date"]); //时间 curData.Add("ActTotal", Convert.ToInt32(function.CheckInt(item["count"].ToString()))); //总激活 dataList.Add(curData); } dataList = dataList.Skip((PageNum - 1) * PageSize).Take(PageSize).ToList();//分页的重点 return dataList; } #endregion #region 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 请求的参数(json字符串) /// 要签名的字段 /// private string CheckSign(string value, string[] signField) { JsonData json = JsonMapper.ToObject(value); Dictionary dic = new Dictionary(); for (int i = 0; i < signField.Length; i++) { dic.Add(signField[i], json[signField[i]].ToString()); } string sign = json["sign"].ToString(); //客户端签名字符串 return new Sign().sign(dic, sign); } #endregion } }