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/pos/[controller]/[action]")] public class PreSendStockDetailController : BaseController { public PreSendStockDetailController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString(); } #region 创客-首页-客小爽产品-机具管理-机具申请-预发机列表 [Authorize] public JsonResult List(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = ListDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> ListDo(string value) { JsonData data = JsonMapper.ToObject(value); int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型 int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); // var date = DateTime.Now.AddDays(-30); IQueryable query = maindb.PreSendStockDetail.Where(m => m.ToUserId == ToUserId && m.Status == 1 && m.ApplyFlag == 0); if (!string.IsNullOrEmpty(data["BrandId"].ToString())) { query = query.Where(m => m.BrandId == BrandId); } int TotalCount = query.Count(); query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id); if (PageNum == 1) { query = query.Take(PageSize); } else { int skipNum = PageSize * (PageNum - 1); query = query.Skip(skipNum).Take(PageSize); } var mydata = query.ToList(); foreach (var subdata in mydata) { var CreateDate = Convert.ToDateTime(subdata.CreateDate).ToString("yyyy/MM/dd hh:mm:ss"); PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == subdata.SnId) ?? new PosMachinesTwo(); // var TimeOut = 0; Dictionary curData = new Dictionary(); // if (subdata.CreateDate <= date && subdata.AuthFlag == 1) // { // TimeOut = 1; // curData.Add("TimeOut", TimeOut); //是否超时 // } // else // { // curData.Add("TimeOut", TimeOut); //是否超时 // } curData.Add("SnId", subdata.SnId); //机具Id curData.Add("SnNo", subdata.SnNo); //机具SN编号 curData.Add("Id", subdata.Id); //ID curData.Add("FromStoreId", subdata.FromStoreId); //出货仓库Id StoreHouse StoreHouseData = maindb.StoreHouse.FirstOrDefault(m => m.Id == subdata.FromStoreId) ?? new StoreHouse(); curData.Add("StoreName", StoreHouseData.StoreName); //出货仓库名称 curData.Add("isGrant", subdata.AuthFlag); //占用小分仓额度标记 curData.Add("CreateDate", CreateDate); //是否超时 dataList.Add(curData); } return dataList; } #endregion #region 创客-首页-仓库管理-小分仓-撤回 [Authorize] public JsonResult Cancel(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = CancelDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson CancelDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id Dictionary Obj = new Dictionary(); PreSendStockDetail query = new PreSendStockDetail(); int SnId = int.Parse(function.CheckInt(data["SnId"].ToString()));//记录Id RedisDbconn.Instance.GetLock("CheckCancelPos:" + UserId + ":" + function.MD5_16(SnId.ToString())); query = maindb.PreSendStockDetail.FirstOrDefault(m => m.FromUserId == UserId && m.Id == SnId); var userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount(); var tuserAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == query.ToUserId) ?? new UserAccount(); KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == query.BrandId); var date = DateTime.Now.AddDays(-30); var amount = 0; if (query != null) { PosMachinesTwo posMachinesTwo = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId) ?? new PosMachinesTwo(); StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == query.FromStoreId) ?? new StoreHouse(); PosMachinesTwo pm = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId); var brandInfo = maindb.KqProducts.FirstOrDefault(m => m.Id == posMachinesTwo.BrandId); if (brandInfo.Name.Contains("电签")) { amount = 200; } if (brandInfo.Name.Contains("大POS")) { amount = 300; } if (pm != null) { if (pm.BindingState == 1) { return new AppResultJson() { Status = "-1", Info = "机具已绑定,不可撤回!请创客申请机具后补录!" }; } SmallStoreHouse smallStoreHouse = maindb.SmallStoreHouse.FirstOrDefault(m => m.UserId == query.ToUserId); posMachinesTwo.PreUserId = 0; query.UpdateDate = DateTime.Now; query.Status = -1; query.CancelFlag = 1; storeHouse.LaveNum += 1; // //增加分仓所关联运营中心的总机具数 // if (storeHouse.OpId > 0) // { // var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == storeHouse.OpId) ?? new OpModels.SysAdmin(); // if (sysAdmin.Id > 0) // { // sysAdmin.TotalMachineCount += 1; // opdb.SaveChanges(); // } // } smallStoreHouse.UpdateDate = DateTime.Now; smallStoreHouse.LaveNum += 1; smallStoreHouse.TotalNum -= 1; if (query.CreateDate <= date) { //撤回占用小分仓额度的增加接收创客的小分仓可用额度 if (query.AuthFlag == 1 && tuserAccount.SmallStoreDeposit >= amount) { userAccount.ValidAmount -= amount;//扣减分仓可用额度 tuserAccount.SmallStoreDeposit -= amount; tuserAccount.ValidPreAmount += amount;//增加小分仓可用额度 var add = maindb.UserAccountRecord.Add(new UserAccountRecord() { CreateDate = DateTime.Now, Remark = "小分仓押金退还", ChangeType = 66, BeforeBalanceAmount = userAccount.SmallStoreDeposit + amount, //变更前小分仓押金 AfterBalanceAmount = userAccount.SmallStoreDeposit, //变更后小分仓押金 ChangeAmount = amount,//变动金额 UserId = tuserAccount.Id, }).Entity; maindb.SaveChanges(); } } else { //撤回占用小分仓额度的增加接收创客的小分仓可用额度 if (query.AuthFlag == 1) { tuserAccount.ValidPreAmount += amount;//增加小分仓可用额度 userAccount.ValidAmount -= amount;//扣减分仓可用额度 } } 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) { RedisDbconn.Instance.ReleaseLock("CheckCancelPos:" + UserId + ":" + function.MD5_16(SnId.ToString())); return new AppResultJson() { Status = "-1", Info = "*库存已重置,不可撤回!", Data = Obj }; } maindb.SaveChanges(); RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal() { UserId = query.ToUserId, //收货创客 Title = "预发机撤回通知", //标题 Content = "
您的预发机 SN:
" + query.SnNo + "
已被" + storeHouse.StoreName + " 撤回!
", //内容 Summary = "您的预发机: " + kqProducts.Name + " sn:" + query.SnNo + "已被 " + storeHouse.StoreName + " 撤回!", CreateDate = DateTime.Now, })); var toUser = maindb.Users.FirstOrDefault(m => m.Id == query.ToUserId); RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal() { UserId = query.FromUserId, //收货创客 Title = "预发机撤回通知", //标题 Content = "
已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:
" + query.SnNo + "
", //内容 Summary = "已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:" + query.SnNo + "", CreateDate = DateTime.Now, })); } RedisDbconn.Instance.ReleaseLock("CheckCancelPos:" + UserId + ":" + function.MD5_16(SnId.ToString())); } return new AppResultJson() { Status = "1", Info = "撤回成功", Data = Obj }; } #endregion #region 创客-首页-仓库管理-小分仓-确认发货 [Authorize] public JsonResult Send(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = SendDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson SendDo(string value) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //发货人Id int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人Id int FromStoreId = int.Parse(function.CheckInt(data["FromStoreId"].ToString())); //出货仓库Id int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型Id string SnIds = data["SnIds"].ToString(); //机具Id // Users user = maindb.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users(); // if (!user.ParentNav.Contains("," + UserId + ",")) // { // return new AppResultJson() { Status = "-1", Info = "收货创客不在您的操作权限内,请检查收货创客编号是否正确" }; // } if (ToUserId <= 0) { return new AppResultJson() { Status = "-1", Info = "收货创客不存在,请检查收货创客编号是否正确" }; } //分割SN string[] strids = SnIds.Split(','); var count = strids.ToList().Count(); Dictionary Obj = new Dictionary(); List LPD = new List(); SmallStoreHouse smallStoreHouse = maindb.SmallStoreHouse.FirstOrDefault(m => m.UserId == ToUserId); //判断是否符合预发货规范(总库存数<=10) if (smallStoreHouse.LaveNum > 0 && smallStoreHouse.TotalNum < 10) { if (smallStoreHouse.LaveNum - count < 0 || smallStoreHouse.TotalNum + count > 10) { return new AppResultJson() { Status = "-1", Info = "*发货失败,发货后该创客预发机超过10台" }; } //循环添加到数据库 foreach (var item in strids) { PreSendStockDetail preSendStockDetail = maindb.PreSendStockDetail.FirstOrDefault(m => m.FromUserId == UserId && m.Status >= 0 && m.Status <= 1 && m.SnId == Convert.ToInt32(item)); if (preSendStockDetail != null) { return new AppResultJson() { Status = "-1", Info = "*发货失败,请勿重复提交" }; } PreSendStockDetail pd = new PreSendStockDetail(); PosMachinesTwo posMachinesTwo = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == Convert.ToInt32(item)); posMachinesTwo.PreUserId = ToUserId; pd.CreateDate = DateTime.Now; //创建时间 pd.FromUserId = UserId;//发货人Id pd.ToUserId = ToUserId; //收货人Id pd.SourceStoreId = 0; //源仓库Id pd.BrandId = BrandId; //产品类型Id pd.SnNo = posMachinesTwo.PosSn; //机具SN pd.FromStoreId = FromStoreId; //出货仓库Id pd.ToStoreId = smallStoreHouse.Id; //收货仓库Id pd.StoreId = smallStoreHouse.Id; //仓库Id pd.SnId = Convert.ToInt32(item); LPD.Add(pd); } 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");//小分仓记录日志 StoreHouse storeHouse = maindb.StoreHouse.First(m => m.Id == FromStoreId); storeHouse.UpdateDate = DateTime.Now; storeHouse.LaveNum -= count; // //扣减分仓所关联运营中心的总机具数 // if (storeHouse.OpId > 0) // { // var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == storeHouse.OpId) ?? new OpModels.SysAdmin(); // if (sysAdmin.Id > 0) // { // sysAdmin.TotalMachineCount -= count; // opdb.SaveChanges(); // } // } maindb.PreSendStockDetail.AddRange(LPD); function.WriteLog("");//小分仓记录日志 maindb.SaveChanges(); } else { return new AppResultJson() { Status = "-1", Info = "*发货失败,该创客已有10台预发机" }; } return new AppResultJson() { Status = "1", Info = "发货成功", Data = Obj }; } #endregion #region 创客-首页-仓库管理-小分仓-预发货确认反馈 [Authorize] public JsonResult Confirm(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); AppResultJson result = ConfirmDo(value); return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data }); } public AppResultJson ConfirmDo(string value) { JsonData data = JsonMapper.ToObject(value); int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人 string Ids = data["Ids"].ToString(); //反馈的记录Id列表 int Status = int.Parse(function.CheckInt(data["Status"].ToString())); //状态 Dictionary Obj = new Dictionary(); Users toUser = new Users(); PreSendStockDetail query = new PreSendStockDetail(); //获取小分仓额度 var amount = 0; decimal totalAmount = 0; var userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == ToUserId) ?? new UserAccount(); if (userAccount.Id > 0) { totalAmount = userAccount.ValidPreAmount;//小分仓额度 } //分割SN string[] strids = Ids.Split(','); var count = strids.ToList().Count(); foreach (var item in strids) { bool check = maindb.PreSendStockDetail.Any(m => m.Id == Convert.ToInt32(item) && m.Status == -1); if(check) { return new AppResultJson() { Status = "-1", Info = "机具已退回仓库,操作失败", Data = Obj }; } } //同意 if (Status == 1) { string StoreName = ""; string Sn = ""; foreach (var item in strids) { query = maindb.PreSendStockDetail.FirstOrDefault(m => m.Id == Convert.ToInt32(item)); var fuserAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == query.FromUserId) ?? new UserAccount(); PosMachinesTwo posMachinesTwo = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId); var brandInfo = maindb.KqProducts.FirstOrDefault(m => m.Id == posMachinesTwo.BrandId); if (brandInfo.Name.Contains("电签")) { amount = 200; } if (brandInfo.Name.Contains("大POS")) { amount = 300; } totalAmount -= amount; StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == query.FromStoreId) ?? new StoreHouse(); if (query != null) { query.UpdateDate = DateTime.Now; //修改时间 query.Status = Status;//状态(-1 撤回,0 初始,1 同意,2 拒绝) //小分仓额度减掉机子占用的额度 >=0 if (totalAmount >= 0 && userAccount.ValidPreAmount >= amount) { query.AuthFlag = 1;//添加小分仓额度标记 fuserAccount.ValidAmount += amount;//增加预发机来源分仓可用额度 userAccount.ValidPreAmount -= amount;//扣减小分仓可用额度 } maindb.SaveChanges(); } if (!StoreName.Contains(storeHouse.StoreName)) { StoreName += storeHouse.StoreName + ','; } Sn += query.SnNo + ",
"; } RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal() { UserId = ToUserId, //创客 Title = "预发货确认通知", //标题 Content = "
已确认接收来自:
" + StoreName + " 的 " + count + " 台 预发货机具
SN:" + Sn + "
*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。
", //内容 Summary = "已确认接收来自: " + StoreName + " 的 " + count + " 台 预发货机具", CreateDate = DateTime.Now, })); List FromUserList = new List(); DataTable dts = OtherMySqlConn.dtable("SELECT FromUserId FROM PreSendStockDetail WHERE Id IN(" + Ids + ") GROUP BY FromUserId"); foreach (DataRow items in dts.Rows) { int FromUserId = int.Parse(items["FromUserId"].ToString()); FromUserList.Add(FromUserId); } foreach (var sub in FromUserList) { string FStoreName = ""; string FSn = ""; int sum = 0; toUser = maindb.Users.FirstOrDefault(m => m.Id == ToUserId); DataTable dt = OtherMySqlConn.dtable("SELECT FromStoreId,SnId FROM PreSendStockDetail WHERE Id IN(" + Ids + ") AND FromUserId=" + sub + " GROUP BY FromStoreId,SnId"); foreach (DataRow item in dt.Rows) { int FromStoreId = int.Parse(item["FromStoreId"].ToString()); int SnId = int.Parse(item["SnId"].ToString()); StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId); var pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId); if (!FStoreName.Contains(storeHouse.StoreName)) { FStoreName += storeHouse.StoreName + ','; } FSn += pos.PosSn + ",
"; sum += 1; } RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal() { UserId = sub, //创客 Title = "预发货确认通知", //标题 Content = "
创客:" + toUser.MakerCode + " " + toUser.RealName + " 已确认接收来自您的:
" + FStoreName + " 的 " + sum + " 台 预发货机具
SN:" + FSn + "
*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。
", //内容 Summary = "创客:" + toUser.MakerCode + " " + toUser.RealName + " 已确认接收来自您的: " + FStoreName + " 的 " + sum + " 台 预发货机具", CreateDate = DateTime.Now, })); } } //拒绝 else if (Status == 2) { string StoreName = ""; string Sn = ""; foreach (var item in strids) { query = maindb.PreSendStockDetail.FirstOrDefault(m => m.Id == Convert.ToInt32(item)); StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == query.FromStoreId) ?? new StoreHouse(); storeHouse.LaveNum += 1; // //增加分仓所关联运营中心的总机具数 // if (storeHouse.OpId > 0) // { // var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == storeHouse.OpId) ?? new OpModels.SysAdmin(); // if (sysAdmin.Id > 0) // { // sysAdmin.TotalMachineCount += 1; // opdb.SaveChanges(); // } // } maindb.SaveChanges(); PosMachinesTwo posMachinesTwo = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId); if (query != null) { query.UpdateDate = DateTime.Now; //修改时间 query.Status = Status;//状态(-1 撤回,0 初始,1 同意,2 拒绝) posMachinesTwo.PreUserId = 0; maindb.SaveChanges(); } if (!StoreName.Contains(storeHouse.StoreName)) { StoreName += storeHouse.StoreName + ','; } Sn += query.SnNo + ",
"; } SmallStoreHouse smallStoreHouse = maindb.SmallStoreHouse.FirstOrDefault(m => m.UserId == ToUserId); smallStoreHouse.LaveNum += count; smallStoreHouse.TotalNum -= count; string text = string.Format("创客-首页-仓库管理-小分仓-预发货确认反馈(拒绝),UserId: '" + query.FromUserId + "',ToUserId: '" + ToUserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + count + "',Time'" + DateTime.Now + "'"); function.WriteLog(text, "smallstorehouse");//小分仓记录日志 maindb.SaveChanges(); RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal() { UserId = ToUserId, //创客 Title = "预发货拒绝通知", //标题 Content = "
已拒绝接收来自:
" + StoreName + " 的 " + count + " 台 预发货机具
SN:" + Sn + "
*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。
", //内容 Summary = "已拒绝接收来自: " + StoreName + " 的 " + count + " 台 预发货机具", CreateDate = DateTime.Now, })); List FromUserList = new List(); DataTable dts = OtherMySqlConn.dtable("SELECT FromUserId FROM PreSendStockDetail WHERE Id IN(" + strids + ") GROUP BY FromUserId"); foreach (DataRow items in dts.Rows) { int FromUserId = int.Parse(items["FromUserId"].ToString()); FromUserList.Add(FromUserId); } foreach (var sub in FromUserList) { string FStoreName = ""; string FSn = ""; int sum = 0; toUser = maindb.Users.FirstOrDefault(m => m.Id == ToUserId); DataTable dt = OtherMySqlConn.dtable("SELECT FromStoreId,SnId FROM PreSendStockDetail WHERE Id IN(" + strids + ") AND FromUserId=" + sub + " GROUP BY FromStoreId,SnId"); foreach (DataRow item in dt.Rows) { int FromStoreId = int.Parse(item["FromStoreId"].ToString()); int SnId = int.Parse(item["SnId"].ToString()); StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId); var pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId); if (!FStoreName.Contains(storeHouse.StoreName)) { FStoreName += storeHouse.StoreName + ','; } FSn += pos.PosSn + ",
"; sum += 1; } RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal() { UserId = sub, //创客 Title = "预发货拒绝通知", //标题 Content = "
创客:" + toUser.MakerCode + " " + toUser.RealName + " 已拒绝接收来自您的:
" + FStoreName + " 的 " + sum + " 台 预发货机具
SN:" + FSn + "
*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。
", //内容 Summary = "创客:" + toUser.MakerCode + " " + toUser.RealName + " 已拒绝接收来自您的: " + FStoreName + " 的 " + sum + " 台 预发货机具", CreateDate = DateTime.Now, })); } } return new AppResultJson() { Status = "1", Info = "", Data = Obj }; } #endregion #region 创客-首页-仓库管理-小分仓-预发货确认查询 [Authorize] public JsonResult WaitConfirms(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); Dictionary dataList = WaitConfirmsDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public Dictionary WaitConfirmsDo(string value) { JsonData data = JsonMapper.ToObject(value); int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人Id int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); Dictionary dataList = new Dictionary(); List> storeList = new List>(); List> pssdList = new List>(); IQueryable query = maindb.PreSendStockDetail.Where(m => m.Status == 0 && m.ToUserId == ToUserId); int TotalCount = query.Count(); query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id); if (PageNum == 1) { query = query.Take(PageSize); } else { int skipNum = PageSize * (PageNum - 1); query = query.Skip(skipNum).Take(PageSize); } var mydata = query.ToList(); if (mydata.Count() == 0) { return dataList; } OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString(); DataTable dt = OtherMySqlConn.dtable("select b.Id StoreId,b.StoreName StoreName from(select FromStoreId from PreSendStockDetail where ToUserId='" + ToUserId + "' and Status=0 GROUP BY FromStoreId)a left join StoreHouse b on a.FromStoreId = b.Id"); foreach (DataRow item in dt.Rows) { var StoreId = item["StoreId"];//仓库Id var StoreName = item["StoreName"];//仓库名称 Dictionary ob = new Dictionary(); ob.Add("StoreId", StoreId); ob.Add("StoreName", StoreName); storeList.Add(ob); } dataList.Add("StoreList", storeList); OtherMySqlConn.connstr = ""; foreach (var subdata in mydata) { Dictionary curData = new Dictionary(); curData.Add("SnNo", subdata.SnNo); //机具编号 curData.Add("SnId", subdata.SnId); //机具Id curData.Add("Id", subdata.Id); //记录Id pssdList.Add(curData); } dataList.Add("SnList", pssdList); return dataList; } #endregion #region 创客-我的-小分仓-机具Sn列表 [Authorize] public JsonResult SnList(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); Dictionary Obj = new Dictionary(); List> dataList = SnListDo(value, out Obj); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Obj }); } public List> SnListDo(string value, out Dictionary Other) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));//出货创客Id int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); var userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount(); // var date = DateTime.Now.AddDays(-30); List brandList = maindb.KqProducts.ToList(); foreach (var items in brandList) { List mydata = maindb.PreSendStockDetail.Where(m => m.ToUserId == UserId && m.Status == 1 && m.ApplyFlag == 0 && m.BrandId == items.Id).ToList(); if (mydata.Count > 0) { Dictionary brandInfo = new Dictionary(); KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == items.Id); brandInfo.Add("Id", items.Id);//产品类型Id brandInfo.Add("Name", items.Name);//产品类型名称 List> snList = new List>(); foreach (var subdata in mydata) { // var TimeOut = 0; var CreateDate = Convert.ToDateTime(subdata.CreateDate).ToString("yyyy/MM/dd hh:mm:ss"); Dictionary curData = new Dictionary(); // if (subdata.CreateDate <= date && subdata.AuthFlag == 1) // { // TimeOut = 1; // curData.Add("TimeOut", TimeOut); //是否超时 // } // else // { // curData.Add("TimeOut", TimeOut); //是否超时 // } curData.Add("SnNo", subdata.SnNo); //机具SN curData.Add("isGrant", subdata.AuthFlag); //占用小分仓额度标记 curData.Add("CreateDate", CreateDate); //是否超时 snList.Add(curData); } brandInfo.Add("SnList", snList); dataList.Add(brandInfo); } } Dictionary Obj = new Dictionary(); Obj.Add("ThisMonthPreAmount", userAccount.ThisMonthPreAmount);//本月预发额度 Obj.Add("ValidPreAmount", userAccount.ValidPreAmount);//可用预发额度 Other = Obj; 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 } }