PreSendStockDetailController.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.Extensions.Options;
  9. using Microsoft.AspNetCore.Authorization;
  10. using System.Web;
  11. using MySystem.MainModels;
  12. using LitJson;
  13. using Library;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/pos/[controller]/[action]")]
  18. public class PreSendStockDetailController : BaseController
  19. {
  20. public PreSendStockDetailController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  23. }
  24. #region 创客-首页-客小爽产品-机具管理-机具申请-预发机列表
  25. [Authorize]
  26. public JsonResult List(string value)
  27. {
  28. value = DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. List<Dictionary<string, object>> dataList = ListDo(value);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  32. }
  33. public List<Dictionary<string, object>> ListDo(string value)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  37. int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人
  38. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  39. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  40. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  41. // var date = DateTime.Now.AddDays(-30);
  42. IQueryable<PreSendStockDetail> query = maindb.PreSendStockDetail.Where(m => m.ToUserId == ToUserId && m.Status == 1 && m.ApplyFlag == 0);
  43. if (!string.IsNullOrEmpty(data["BrandId"].ToString()))
  44. {
  45. query = query.Where(m => m.BrandId == BrandId);
  46. }
  47. int TotalCount = query.Count();
  48. query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  49. if (PageNum == 1)
  50. {
  51. query = query.Take(PageSize);
  52. }
  53. else
  54. {
  55. int skipNum = PageSize * (PageNum - 1);
  56. query = query.Skip(skipNum).Take(PageSize);
  57. }
  58. var mydata = query.ToList();
  59. foreach (var subdata in mydata)
  60. {
  61. var CreateDate = Convert.ToDateTime(subdata.CreateDate).ToString("yyyy/MM/dd hh:mm:ss");
  62. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == subdata.SnId) ?? new PosMachinesTwo();
  63. // var TimeOut = 0;
  64. Dictionary<string, object> curData = new Dictionary<string, object>();
  65. // if (subdata.CreateDate <= date && subdata.AuthFlag == 1)
  66. // {
  67. // TimeOut = 1;
  68. // curData.Add("TimeOut", TimeOut); //是否超时
  69. // }
  70. // else
  71. // {
  72. // curData.Add("TimeOut", TimeOut); //是否超时
  73. // }
  74. curData.Add("SnId", subdata.SnId); //机具Id
  75. curData.Add("SnNo", subdata.SnNo); //机具SN编号
  76. curData.Add("Id", subdata.Id); //ID
  77. curData.Add("FromStoreId", subdata.FromStoreId); //出货仓库Id
  78. StoreHouse StoreHouseData = maindb.StoreHouse.FirstOrDefault(m => m.Id == subdata.FromStoreId) ?? new StoreHouse();
  79. curData.Add("StoreName", StoreHouseData.StoreName); //出货仓库名称
  80. curData.Add("isGrant", subdata.AuthFlag); //占用小分仓额度标记
  81. curData.Add("CreateDate", CreateDate); //是否超时
  82. dataList.Add(curData);
  83. }
  84. return dataList;
  85. }
  86. #endregion
  87. #region 创客-首页-仓库管理-小分仓-撤回
  88. [Authorize]
  89. public JsonResult Cancel(string value)
  90. {
  91. value = DesDecrypt(value);
  92. JsonData data = JsonMapper.ToObject(value);
  93. AppResultJson result = CancelDo(value);
  94. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  95. }
  96. public AppResultJson CancelDo(string value)
  97. {
  98. JsonData data = JsonMapper.ToObject(value);
  99. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
  100. Dictionary<string, object> Obj = new Dictionary<string, object>();
  101. PreSendStockDetail query = new PreSendStockDetail();
  102. int SnId = int.Parse(function.CheckInt(data["SnId"].ToString()));//记录Id
  103. RedisDbconn.Instance.GetLock("CheckCancelPos:" + UserId + ":" + function.MD5_16(SnId.ToString()));
  104. query = maindb.PreSendStockDetail.FirstOrDefault(m => m.FromUserId == UserId && m.Id == SnId);
  105. var userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  106. var tuserAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == query.ToUserId) ?? new UserAccount();
  107. KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == query.BrandId);
  108. var date = DateTime.Now.AddDays(-30);
  109. var amount = 0;
  110. if (query != null)
  111. {
  112. PosMachinesTwo posMachinesTwo = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId) ?? new PosMachinesTwo();
  113. StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == query.FromStoreId) ?? new StoreHouse();
  114. PosMachinesTwo pm = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId);
  115. var brandInfo = maindb.KqProducts.FirstOrDefault(m => m.Id == posMachinesTwo.BrandId);
  116. if (brandInfo.Name.Contains("电签"))
  117. {
  118. amount = 200;
  119. }
  120. if (brandInfo.Name.Contains("大POS"))
  121. {
  122. amount = 300;
  123. }
  124. if (pm != null)
  125. {
  126. if (pm.BindingState == 1)
  127. {
  128. return new AppResultJson() { Status = "-1", Info = "机具已绑定,不可撤回!请创客申请机具后补录!" };
  129. }
  130. SmallStoreHouse smallStoreHouse = maindb.SmallStoreHouse.FirstOrDefault(m => m.UserId == query.ToUserId);
  131. posMachinesTwo.PreUserId = 0;
  132. query.UpdateDate = DateTime.Now;
  133. query.Status = -1;
  134. query.CancelFlag = 1;
  135. storeHouse.LaveNum += 1;
  136. // //增加分仓所关联运营中心的总机具数
  137. // if (storeHouse.OpId > 0)
  138. // {
  139. // var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == storeHouse.OpId) ?? new OpModels.SysAdmin();
  140. // if (sysAdmin.Id > 0)
  141. // {
  142. // sysAdmin.TotalMachineCount += 1;
  143. // opdb.SaveChanges();
  144. // }
  145. // }
  146. smallStoreHouse.UpdateDate = DateTime.Now;
  147. smallStoreHouse.LaveNum += 1;
  148. smallStoreHouse.TotalNum -= 1;
  149. if (query.CreateDate <= date)
  150. {
  151. //撤回占用小分仓额度的增加接收创客的小分仓可用额度
  152. if (query.AuthFlag == 1 && tuserAccount.SmallStoreDeposit >= amount)
  153. {
  154. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  155. tuserAccount.SmallStoreDeposit -= amount;
  156. tuserAccount.ValidPreAmount += amount;//增加小分仓可用额度
  157. var add = maindb.UserAccountRecord.Add(new UserAccountRecord()
  158. {
  159. CreateDate = DateTime.Now,
  160. Remark = "小分仓押金退还",
  161. ChangeType = 66,
  162. BeforeBalanceAmount = userAccount.SmallStoreDeposit + amount, //变更前小分仓押金
  163. AfterBalanceAmount = userAccount.SmallStoreDeposit, //变更后小分仓押金
  164. ChangeAmount = amount,//变动金额
  165. UserId = tuserAccount.Id,
  166. }).Entity;
  167. maindb.SaveChanges();
  168. }
  169. }
  170. else
  171. {
  172. //撤回占用小分仓额度的增加接收创客的小分仓可用额度
  173. if (query.AuthFlag == 1)
  174. {
  175. tuserAccount.ValidPreAmount += amount;//增加小分仓可用额度
  176. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  177. }
  178. }
  179. string text = string.Format("创客-首页-仓库管理-小分仓-撤回,UserId: '" + UserId + "',ToUserId: '" + smallStoreHouse.UserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + 1 + "',Time'" + DateTime.Now + "'");
  180. function.WriteLog(text, "smallstorehouse");//小分仓记录日志
  181. if (smallStoreHouse.LaveNum > 10 || smallStoreHouse.TotalNum < 0)
  182. {
  183. RedisDbconn.Instance.ReleaseLock("CheckCancelPos:" + UserId + ":" + function.MD5_16(SnId.ToString()));
  184. return new AppResultJson() { Status = "-1", Info = "*库存已重置,不可撤回!", Data = Obj };
  185. }
  186. maindb.SaveChanges();
  187. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  188. {
  189. UserId = query.ToUserId, //收货创客
  190. Title = "预发机撤回通知", //标题
  191. Content = "<div class='f16'>您的预发机 SN:<br/>" + query.SnNo + "<br/>已被" + storeHouse.StoreName + " 撤回!</div>", //内容
  192. Summary = "您的预发机: " + kqProducts.Name + " sn:" + query.SnNo + "已被 " + storeHouse.StoreName + " 撤回!",
  193. CreateDate = DateTime.Now,
  194. }));
  195. var toUser = maindb.Users.FirstOrDefault(m => m.Id == query.ToUserId);
  196. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  197. {
  198. UserId = query.FromUserId, //收货创客
  199. Title = "预发机撤回通知", //标题
  200. Content = "<div class='f16'>已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:<br/>" + query.SnNo + "</div>", //内容
  201. Summary = "已撤回创客:" + toUser.MakerCode + " " + toUser.RealName + " 的预发机 SN:" + query.SnNo + "",
  202. CreateDate = DateTime.Now,
  203. }));
  204. }
  205. RedisDbconn.Instance.ReleaseLock("CheckCancelPos:" + UserId + ":" + function.MD5_16(SnId.ToString()));
  206. }
  207. return new AppResultJson() { Status = "1", Info = "撤回成功", Data = Obj };
  208. }
  209. #endregion
  210. #region 创客-首页-仓库管理-小分仓-确认发货
  211. [Authorize]
  212. public JsonResult Send(string value)
  213. {
  214. value = DesDecrypt(value);
  215. JsonData data = JsonMapper.ToObject(value);
  216. AppResultJson result = SendDo(value);
  217. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  218. }
  219. public AppResultJson SendDo(string value)
  220. {
  221. JsonData data = JsonMapper.ToObject(value);
  222. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //发货人Id
  223. int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人Id
  224. int FromStoreId = int.Parse(function.CheckInt(data["FromStoreId"].ToString())); //出货仓库Id
  225. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型Id
  226. string SnIds = data["SnIds"].ToString(); //机具Id
  227. // Users user = maindb.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  228. // if (!user.ParentNav.Contains("," + UserId + ","))
  229. // {
  230. // return new AppResultJson() { Status = "-1", Info = "收货创客不在您的操作权限内,请检查收货创客编号是否正确" };
  231. // }
  232. if (ToUserId <= 0)
  233. {
  234. return new AppResultJson() { Status = "-1", Info = "收货创客不存在,请检查收货创客编号是否正确" };
  235. }
  236. //分割SN
  237. string[] strids = SnIds.Split(',');
  238. var count = strids.ToList().Count();
  239. Dictionary<string, object> Obj = new Dictionary<string, object>();
  240. List<PreSendStockDetail> LPD = new List<PreSendStockDetail>();
  241. SmallStoreHouse smallStoreHouse = maindb.SmallStoreHouse.FirstOrDefault(m => m.UserId == ToUserId);
  242. //判断是否符合预发货规范(总库存数<=10)
  243. if (smallStoreHouse.LaveNum > 0 && smallStoreHouse.TotalNum < 10)
  244. {
  245. if (smallStoreHouse.LaveNum - count < 0 || smallStoreHouse.TotalNum + count > 10)
  246. {
  247. return new AppResultJson() { Status = "-1", Info = "*发货失败,发货后该创客预发机超过10台" };
  248. }
  249. //循环添加到数据库
  250. foreach (var item in strids)
  251. {
  252. PreSendStockDetail preSendStockDetail = maindb.PreSendStockDetail.FirstOrDefault(m => m.FromUserId == UserId && m.Status >= 0 && m.Status <= 1 && m.SnId == Convert.ToInt32(item));
  253. if (preSendStockDetail != null)
  254. {
  255. return new AppResultJson() { Status = "-1", Info = "*发货失败,请勿重复提交" };
  256. }
  257. PreSendStockDetail pd = new PreSendStockDetail();
  258. PosMachinesTwo posMachinesTwo = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == Convert.ToInt32(item));
  259. posMachinesTwo.PreUserId = ToUserId;
  260. pd.CreateDate = DateTime.Now; //创建时间
  261. pd.FromUserId = UserId;//发货人Id
  262. pd.ToUserId = ToUserId; //收货人Id
  263. pd.SourceStoreId = 0; //源仓库Id
  264. pd.BrandId = BrandId; //产品类型Id
  265. pd.SnNo = posMachinesTwo.PosSn; //机具SN
  266. pd.FromStoreId = FromStoreId; //出货仓库Id
  267. pd.ToStoreId = smallStoreHouse.Id; //收货仓库Id
  268. pd.StoreId = smallStoreHouse.Id; //仓库Id
  269. pd.SnId = Convert.ToInt32(item);
  270. LPD.Add(pd);
  271. }
  272. smallStoreHouse.LaveNum -= count;
  273. smallStoreHouse.TotalNum += count;
  274. string text = string.Format("创客-首页-仓库管理-小分仓-确认发货,UserId: '" + UserId + "',ToUserId: '" + ToUserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum:'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + count + "',Time'" + DateTime.Now + "'");
  275. function.WriteLog(text, "smallstorehouse");//小分仓记录日志
  276. StoreHouse storeHouse = maindb.StoreHouse.First(m => m.Id == FromStoreId);
  277. storeHouse.UpdateDate = DateTime.Now;
  278. storeHouse.LaveNum -= count;
  279. // //扣减分仓所关联运营中心的总机具数
  280. // if (storeHouse.OpId > 0)
  281. // {
  282. // var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == storeHouse.OpId) ?? new OpModels.SysAdmin();
  283. // if (sysAdmin.Id > 0)
  284. // {
  285. // sysAdmin.TotalMachineCount -= count;
  286. // opdb.SaveChanges();
  287. // }
  288. // }
  289. maindb.PreSendStockDetail.AddRange(LPD);
  290. function.WriteLog("");//小分仓记录日志
  291. maindb.SaveChanges();
  292. }
  293. else
  294. {
  295. return new AppResultJson() { Status = "-1", Info = "*发货失败,该创客已有10台预发机" };
  296. }
  297. return new AppResultJson() { Status = "1", Info = "发货成功", Data = Obj };
  298. }
  299. #endregion
  300. #region 创客-首页-仓库管理-小分仓-预发货确认反馈
  301. [Authorize]
  302. public JsonResult Confirm(string value)
  303. {
  304. value = DesDecrypt(value);
  305. JsonData data = JsonMapper.ToObject(value);
  306. AppResultJson result = ConfirmDo(value);
  307. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  308. }
  309. public AppResultJson ConfirmDo(string value)
  310. {
  311. JsonData data = JsonMapper.ToObject(value);
  312. int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人
  313. string Ids = data["Ids"].ToString(); //反馈的记录Id列表
  314. int Status = int.Parse(function.CheckInt(data["Status"].ToString())); //状态
  315. Dictionary<string, object> Obj = new Dictionary<string, object>();
  316. Users toUser = new Users();
  317. PreSendStockDetail query = new PreSendStockDetail();
  318. //获取小分仓额度
  319. var amount = 0;
  320. decimal totalAmount = 0;
  321. var userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == ToUserId) ?? new UserAccount();
  322. if (userAccount.Id > 0)
  323. {
  324. totalAmount = userAccount.ValidPreAmount;//小分仓额度
  325. }
  326. //分割SN
  327. string[] strids = Ids.Split(',');
  328. var count = strids.ToList().Count();
  329. foreach (var item in strids)
  330. {
  331. bool check = maindb.PreSendStockDetail.Any(m => m.Id == Convert.ToInt32(item) && m.Status == -1);
  332. if(check)
  333. {
  334. return new AppResultJson() { Status = "-1", Info = "机具已退回仓库,操作失败", Data = Obj };
  335. }
  336. }
  337. //同意
  338. if (Status == 1)
  339. {
  340. string StoreName = "";
  341. string Sn = "";
  342. foreach (var item in strids)
  343. {
  344. query = maindb.PreSendStockDetail.FirstOrDefault(m => m.Id == Convert.ToInt32(item));
  345. var fuserAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == query.FromUserId) ?? new UserAccount();
  346. PosMachinesTwo posMachinesTwo = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId);
  347. var brandInfo = maindb.KqProducts.FirstOrDefault(m => m.Id == posMachinesTwo.BrandId);
  348. if (brandInfo.Name.Contains("电签"))
  349. {
  350. amount = 200;
  351. }
  352. if (brandInfo.Name.Contains("大POS"))
  353. {
  354. amount = 300;
  355. }
  356. totalAmount -= amount;
  357. StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == query.FromStoreId) ?? new StoreHouse();
  358. if (query != null)
  359. {
  360. query.UpdateDate = DateTime.Now; //修改时间
  361. query.Status = Status;//状态(-1 撤回,0 初始,1 同意,2 拒绝)
  362. //小分仓额度减掉机子占用的额度 >=0
  363. if (totalAmount >= 0 && userAccount.ValidPreAmount >= amount)
  364. {
  365. query.AuthFlag = 1;//添加小分仓额度标记
  366. fuserAccount.ValidAmount += amount;//增加预发机来源分仓可用额度
  367. userAccount.ValidPreAmount -= amount;//扣减小分仓可用额度
  368. }
  369. maindb.SaveChanges();
  370. }
  371. if (!StoreName.Contains(storeHouse.StoreName))
  372. {
  373. StoreName += storeHouse.StoreName + ',';
  374. }
  375. Sn += query.SnNo + ",<br/>";
  376. }
  377. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  378. {
  379. UserId = ToUserId, //创客
  380. Title = "预发货确认通知", //标题
  381. Content = "<div class='f16'>已确认接收来自:<br/>" + StoreName + " 的 " + count + " 台 预发货机具<br/>SN:" + Sn + "<br/>*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。</div>", //内容
  382. Summary = "已确认接收来自: " + StoreName + " 的 " + count + " 台 预发货机具",
  383. CreateDate = DateTime.Now,
  384. }));
  385. List<int> FromUserList = new List<int>();
  386. DataTable dts = OtherMySqlConn.dtable("SELECT FromUserId FROM PreSendStockDetail WHERE Id IN(" + Ids + ") GROUP BY FromUserId");
  387. foreach (DataRow items in dts.Rows)
  388. {
  389. int FromUserId = int.Parse(items["FromUserId"].ToString());
  390. FromUserList.Add(FromUserId);
  391. }
  392. foreach (var sub in FromUserList)
  393. {
  394. string FStoreName = "";
  395. string FSn = "";
  396. int sum = 0;
  397. toUser = maindb.Users.FirstOrDefault(m => m.Id == ToUserId);
  398. DataTable dt = OtherMySqlConn.dtable("SELECT FromStoreId,SnId FROM PreSendStockDetail WHERE Id IN(" + Ids + ") AND FromUserId=" + sub + " GROUP BY FromStoreId,SnId");
  399. foreach (DataRow item in dt.Rows)
  400. {
  401. int FromStoreId = int.Parse(item["FromStoreId"].ToString());
  402. int SnId = int.Parse(item["SnId"].ToString());
  403. StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId);
  404. var pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId);
  405. if (!FStoreName.Contains(storeHouse.StoreName))
  406. {
  407. FStoreName += storeHouse.StoreName + ',';
  408. }
  409. FSn += pos.PosSn + ",<br/>";
  410. sum += 1;
  411. }
  412. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  413. {
  414. UserId = sub, //创客
  415. Title = "预发货确认通知", //标题
  416. Content = "<div class='f16'>创客:" + toUser.MakerCode + " " + toUser.RealName + " 已确认接收来自您的:<br/>" + FStoreName + " 的 " + sum + " 台 预发货机具<br/>SN:" + FSn + "<br/>*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。</div>", //内容
  417. Summary = "创客:" + toUser.MakerCode + " " + toUser.RealName + " 已确认接收来自您的: " + FStoreName + " 的 " + sum + " 台 预发货机具",
  418. CreateDate = DateTime.Now,
  419. }));
  420. }
  421. }
  422. //拒绝
  423. else if (Status == 2)
  424. {
  425. string StoreName = "";
  426. string Sn = "";
  427. foreach (var item in strids)
  428. {
  429. query = maindb.PreSendStockDetail.FirstOrDefault(m => m.Id == Convert.ToInt32(item));
  430. StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == query.FromStoreId) ?? new StoreHouse();
  431. storeHouse.LaveNum += 1;
  432. // //增加分仓所关联运营中心的总机具数
  433. // if (storeHouse.OpId > 0)
  434. // {
  435. // var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.UserId == storeHouse.OpId) ?? new OpModels.SysAdmin();
  436. // if (sysAdmin.Id > 0)
  437. // {
  438. // sysAdmin.TotalMachineCount += 1;
  439. // opdb.SaveChanges();
  440. // }
  441. // }
  442. maindb.SaveChanges();
  443. PosMachinesTwo posMachinesTwo = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == query.SnId);
  444. if (query != null)
  445. {
  446. query.UpdateDate = DateTime.Now; //修改时间
  447. query.Status = Status;//状态(-1 撤回,0 初始,1 同意,2 拒绝)
  448. posMachinesTwo.PreUserId = 0;
  449. maindb.SaveChanges();
  450. }
  451. if (!StoreName.Contains(storeHouse.StoreName))
  452. {
  453. StoreName += storeHouse.StoreName + ',';
  454. }
  455. Sn += query.SnNo + ",<br/>";
  456. }
  457. SmallStoreHouse smallStoreHouse = maindb.SmallStoreHouse.FirstOrDefault(m => m.UserId == ToUserId);
  458. smallStoreHouse.LaveNum += count;
  459. smallStoreHouse.TotalNum -= count;
  460. string text = string.Format("创客-首页-仓库管理-小分仓-预发货确认反馈(拒绝),UserId: '" + query.FromUserId + "',ToUserId: '" + ToUserId + "',LaveNum:'" + smallStoreHouse.LaveNum + "',TotalNum'" + smallStoreHouse.TotalNum + "',ChangeCount:'" + count + "',Time'" + DateTime.Now + "'");
  461. function.WriteLog(text, "smallstorehouse");//小分仓记录日志
  462. maindb.SaveChanges();
  463. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  464. {
  465. UserId = ToUserId, //创客
  466. Title = "预发货拒绝通知", //标题
  467. Content = "<div class='f16'>已拒绝接收来自:<br/>" + StoreName + " 的 " + count + " 台 预发货机具<br/>SN:" + Sn + "<br/>*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。</div>", //内容
  468. Summary = "已拒绝接收来自: " + StoreName + " 的 " + count + " 台 预发货机具",
  469. CreateDate = DateTime.Now,
  470. }));
  471. List<int> FromUserList = new List<int>();
  472. DataTable dts = OtherMySqlConn.dtable("SELECT FromUserId FROM PreSendStockDetail WHERE Id IN(" + strids + ") GROUP BY FromUserId");
  473. foreach (DataRow items in dts.Rows)
  474. {
  475. int FromUserId = int.Parse(items["FromUserId"].ToString());
  476. FromUserList.Add(FromUserId);
  477. }
  478. foreach (var sub in FromUserList)
  479. {
  480. string FStoreName = "";
  481. string FSn = "";
  482. int sum = 0;
  483. toUser = maindb.Users.FirstOrDefault(m => m.Id == ToUserId);
  484. DataTable dt = OtherMySqlConn.dtable("SELECT FromStoreId,SnId FROM PreSendStockDetail WHERE Id IN(" + strids + ") AND FromUserId=" + sub + " GROUP BY FromStoreId,SnId");
  485. foreach (DataRow item in dt.Rows)
  486. {
  487. int FromStoreId = int.Parse(item["FromStoreId"].ToString());
  488. int SnId = int.Parse(item["SnId"].ToString());
  489. StoreHouse storeHouse = maindb.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId);
  490. var pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId);
  491. if (!FStoreName.Contains(storeHouse.StoreName))
  492. {
  493. FStoreName += storeHouse.StoreName + ',';
  494. }
  495. FSn += pos.PosSn + ",<br/>";
  496. sum += 1;
  497. }
  498. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  499. {
  500. UserId = sub, //创客
  501. Title = "预发货拒绝通知", //标题
  502. Content = "<div class='f16'>创客:" + toUser.MakerCode + " " + toUser.RealName + " 已拒绝接收来自您的:<br/>" + FStoreName + " 的 " + sum + " 台 预发货机具<br/>SN:" + FSn + "<br/>*注:请仔细核对SN后确认,确认接收机具后若出现机具丢失等问题,则需承担相应损失。</div>", //内容
  503. Summary = "创客:" + toUser.MakerCode + " " + toUser.RealName + " 已拒绝接收来自您的: " + FStoreName + " 的 " + sum + " 台 预发货机具",
  504. CreateDate = DateTime.Now,
  505. }));
  506. }
  507. }
  508. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  509. }
  510. #endregion
  511. #region 创客-首页-仓库管理-小分仓-预发货确认查询
  512. [Authorize]
  513. public JsonResult WaitConfirms(string value)
  514. {
  515. value = DesDecrypt(value);
  516. JsonData data = JsonMapper.ToObject(value);
  517. Dictionary<string, object> dataList = WaitConfirmsDo(value);
  518. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  519. }
  520. public Dictionary<string, object> WaitConfirmsDo(string value)
  521. {
  522. JsonData data = JsonMapper.ToObject(value);
  523. int ToUserId = int.Parse(function.CheckInt(data["ToUserId"].ToString())); //收货人Id
  524. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  525. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  526. Dictionary<string, object> dataList = new Dictionary<string, object>();
  527. List<Dictionary<string, object>> storeList = new List<Dictionary<string, object>>();
  528. List<Dictionary<string, object>> pssdList = new List<Dictionary<string, object>>();
  529. IQueryable<PreSendStockDetail> query = maindb.PreSendStockDetail.Where(m => m.Status == 0 && m.ToUserId == ToUserId);
  530. int TotalCount = query.Count();
  531. query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
  532. if (PageNum == 1)
  533. {
  534. query = query.Take(PageSize);
  535. }
  536. else
  537. {
  538. int skipNum = PageSize * (PageNum - 1);
  539. query = query.Skip(skipNum).Take(PageSize);
  540. }
  541. var mydata = query.ToList();
  542. if (mydata.Count() == 0)
  543. {
  544. return dataList;
  545. }
  546. OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  547. 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");
  548. foreach (DataRow item in dt.Rows)
  549. {
  550. var StoreId = item["StoreId"];//仓库Id
  551. var StoreName = item["StoreName"];//仓库名称
  552. Dictionary<string, object> ob = new Dictionary<string, object>();
  553. ob.Add("StoreId", StoreId);
  554. ob.Add("StoreName", StoreName);
  555. storeList.Add(ob);
  556. }
  557. dataList.Add("StoreList", storeList);
  558. OtherMySqlConn.connstr = "";
  559. foreach (var subdata in mydata)
  560. {
  561. Dictionary<string, object> curData = new Dictionary<string, object>();
  562. curData.Add("SnNo", subdata.SnNo); //机具编号
  563. curData.Add("SnId", subdata.SnId); //机具Id
  564. curData.Add("Id", subdata.Id); //记录Id
  565. pssdList.Add(curData);
  566. }
  567. dataList.Add("SnList", pssdList);
  568. return dataList;
  569. }
  570. #endregion
  571. #region 创客-我的-小分仓-机具Sn列表
  572. [Authorize]
  573. public JsonResult SnList(string value)
  574. {
  575. value = DesDecrypt(value);
  576. JsonData data = JsonMapper.ToObject(value);
  577. Dictionary<string, object> Obj = new Dictionary<string, object>();
  578. List<Dictionary<string, object>> dataList = SnListDo(value, out Obj);
  579. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Obj });
  580. }
  581. public List<Dictionary<string, object>> SnListDo(string value, out Dictionary<string, object> Other)
  582. {
  583. JsonData data = JsonMapper.ToObject(value);
  584. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));//出货创客Id
  585. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  586. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  587. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  588. var userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  589. // var date = DateTime.Now.AddDays(-30);
  590. List<KqProducts> brandList = maindb.KqProducts.ToList();
  591. foreach (var items in brandList)
  592. {
  593. List<PreSendStockDetail> mydata = maindb.PreSendStockDetail.Where(m => m.ToUserId == UserId && m.Status == 1 && m.ApplyFlag == 0 && m.BrandId == items.Id).ToList();
  594. if (mydata.Count > 0)
  595. {
  596. Dictionary<string, object> brandInfo = new Dictionary<string, object>();
  597. KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == items.Id);
  598. brandInfo.Add("Id", items.Id);//产品类型Id
  599. brandInfo.Add("Name", items.Name);//产品类型名称
  600. List<Dictionary<string, object>> snList = new List<Dictionary<string, object>>();
  601. foreach (var subdata in mydata)
  602. {
  603. // var TimeOut = 0;
  604. var CreateDate = Convert.ToDateTime(subdata.CreateDate).ToString("yyyy/MM/dd hh:mm:ss");
  605. Dictionary<string, object> curData = new Dictionary<string, object>();
  606. // if (subdata.CreateDate <= date && subdata.AuthFlag == 1)
  607. // {
  608. // TimeOut = 1;
  609. // curData.Add("TimeOut", TimeOut); //是否超时
  610. // }
  611. // else
  612. // {
  613. // curData.Add("TimeOut", TimeOut); //是否超时
  614. // }
  615. curData.Add("SnNo", subdata.SnNo); //机具SN
  616. curData.Add("isGrant", subdata.AuthFlag); //占用小分仓额度标记
  617. curData.Add("CreateDate", CreateDate); //是否超时
  618. snList.Add(curData);
  619. }
  620. brandInfo.Add("SnList", snList);
  621. dataList.Add(brandInfo);
  622. }
  623. }
  624. Dictionary<string, object> Obj = new Dictionary<string, object>();
  625. Obj.Add("ThisMonthPreAmount", userAccount.ThisMonthPreAmount);//本月预发额度
  626. Obj.Add("ValidPreAmount", userAccount.ValidPreAmount);//可用预发额度
  627. Other = Obj;
  628. return dataList;
  629. }
  630. #endregion
  631. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  632. /// <summary>
  633. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  634. /// </summary>
  635. /// <param name="value">请求的参数(json字符串)</param>
  636. /// <param name="signField">要签名的字段</param>
  637. /// <returns></returns>
  638. private string CheckSign(string value, string[] signField)
  639. {
  640. JsonData json = JsonMapper.ToObject(value);
  641. Dictionary<string, string> dic = new Dictionary<string, string>();
  642. for (int i = 0; i < signField.Length; i++)
  643. {
  644. dic.Add(signField[i], json[signField[i]].ToString());
  645. }
  646. string sign = json["sign"].ToString(); //客户端签名字符串
  647. return new Sign().sign(dic, sign);
  648. }
  649. #endregion
  650. }
  651. }