123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705 |
- 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<BaseController> logger, IOptions<Setting> 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<Dictionary<string, object>> dataList = ListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- // var date = DateTime.Now.AddDays(-30);
- IQueryable<PreSendStockDetail> 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<string, object> curData = new Dictionary<string, object>();
- // 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<string, object> Obj = new Dictionary<string, object>();
- 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 = "<div class='f16'>您的预发机 SN:<br/>" + query.SnNo + "<br/>已被" + storeHouse.StoreName + " 撤回!</div>", //内容
- 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 = "<div class='f16'>已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:<br/>" + query.SnNo + "</div>", //内容
- 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<string, object> Obj = new Dictionary<string, object>();
- List<PreSendStockDetail> LPD = new List<PreSendStockDetail>();
- 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<string, object> Obj = new Dictionary<string, object>();
- 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 + ",<br/>";
- }
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = ToUserId, //创客
- Title = "预发货确认通知", //标题
- Content = "<div class='f16'>已确认接收来自:<br/>" + StoreName + " 的 " + count + " 台 预发货机具<br/>SN:" + Sn + "<br/>*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。</div>", //内容
- Summary = "已确认接收来自: " + StoreName + " 的 " + count + " 台 预发货机具",
- CreateDate = DateTime.Now,
- }));
- List<int> FromUserList = new List<int>();
- 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 + ",<br/>";
- sum += 1;
- }
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = sub, //创客
- Title = "预发货确认通知", //标题
- Content = "<div class='f16'>创客:" + toUser.MakerCode + " " + toUser.RealName + " 已确认接收来自您的:<br/>" + FStoreName + " 的 " + sum + " 台 预发货机具<br/>SN:" + FSn + "<br/>*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。</div>", //内容
- 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 + ",<br/>";
- }
- 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 = "<div class='f16'>已拒绝接收来自:<br/>" + StoreName + " 的 " + count + " 台 预发货机具<br/>SN:" + Sn + "<br/>*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。</div>", //内容
- Summary = "已拒绝接收来自: " + StoreName + " 的 " + count + " 台 预发货机具",
- CreateDate = DateTime.Now,
- }));
- List<int> FromUserList = new List<int>();
- 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 + ",<br/>";
- sum += 1;
- }
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = sub, //创客
- Title = "预发货拒绝通知", //标题
- Content = "<div class='f16'>创客:" + toUser.MakerCode + " " + toUser.RealName + " 已拒绝接收来自您的:<br/>" + FStoreName + " 的 " + sum + " 台 预发货机具<br/>SN:" + FSn + "<br/>*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。</div>", //内容
- 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<string, object> dataList = WaitConfirmsDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public Dictionary<string, object> 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<string, object> dataList = new Dictionary<string, object>();
- List<Dictionary<string, object>> storeList = new List<Dictionary<string, object>>();
- List<Dictionary<string, object>> pssdList = new List<Dictionary<string, object>>();
- IQueryable<PreSendStockDetail> 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<string, object> ob = new Dictionary<string, object>();
- ob.Add("StoreId", StoreId);
- ob.Add("StoreName", StoreName);
- storeList.Add(ob);
- }
- dataList.Add("StoreList", storeList);
- OtherMySqlConn.connstr = "";
- foreach (var subdata in mydata)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- 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<string, object> Obj = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = SnListDo(value, out Obj);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Obj });
- }
- public List<Dictionary<string, object>> SnListDo(string value, out Dictionary<string, object> 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- var userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
- // var date = DateTime.Now.AddDays(-30);
- List<KqProducts> brandList = maindb.KqProducts.ToList();
- foreach (var items in brandList)
- {
- List<PreSendStockDetail> mydata = maindb.PreSendStockDetail.Where(m => m.ToUserId == UserId && m.Status == 1 && m.ApplyFlag == 0 && m.BrandId == items.Id).ToList();
- if (mydata.Count > 0)
- {
- Dictionary<string, object> brandInfo = new Dictionary<string, object>();
- KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == items.Id);
- brandInfo.Add("Id", items.Id);//产品类型Id
- brandInfo.Add("Name", items.Name);//产品类型名称
- List<Dictionary<string, object>> snList = new List<Dictionary<string, object>>();
- foreach (var subdata in mydata)
- {
- // var TimeOut = 0;
- var CreateDate = Convert.ToDateTime(subdata.CreateDate).ToString("yyyy/MM/dd hh:mm:ss");
- Dictionary<string, object> curData = new Dictionary<string, object>();
- // 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<string, object> Obj = new Dictionary<string, object>();
- Obj.Add("ThisMonthPreAmount", userAccount.ThisMonthPreAmount);//本月预发额度
- Obj.Add("ValidPreAmount", userAccount.ValidPreAmount);//可用预发额度
- Other = Obj;
- return dataList;
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- 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
- }
- }
|