StoreMachineApplyController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. using System;
  2. using System.Web;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.AspNetCore.Http;
  9. using Microsoft.Extensions.Logging;
  10. using Microsoft.Extensions.Options;
  11. using MySystem.Models;
  12. using Library;
  13. using LitJson;
  14. using MySystemLib;
  15. /// <summary>
  16. /// 机具申请记录
  17. /// </summary>
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class StoreMachineApplyController : BaseController
  23. {
  24. public StoreMachineApplyController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 机具申请记录列表
  29. /// <summary>
  30. /// 机具申请记录列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(StoreMachineApply data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询机具申请记录列表
  41. /// <summary>
  42. /// 机具申请记录列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(StoreMachineApply data, string MakerCode, string RealName, string StoreNo, string StoreName, string StoreMakerCode, string StatusSelect, string SendStatusSelect, string StoreTypeSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("ApplyNo", "1"); //申请单号
  49. Fields.Add("BrandId", "1"); //品牌
  50. Fields.Add("ApplyTime", "3"); //申请时间
  51. Fields.Add("ExpressNo", "1"); //快递单号
  52. string condition = " and Status>-1";
  53. //创客编号
  54. if (!string.IsNullOrEmpty(MakerCode))
  55. {
  56. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  57. }
  58. //创客名称
  59. if (!string.IsNullOrEmpty(RealName))
  60. {
  61. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  62. }
  63. //仓库编号
  64. if (!string.IsNullOrEmpty(StoreNo))
  65. {
  66. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  67. }
  68. //仓库名称
  69. if (!string.IsNullOrEmpty(StoreName))
  70. {
  71. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  72. }
  73. //仓库归属创客编号
  74. if (!string.IsNullOrEmpty(StoreMakerCode))
  75. {
  76. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + StoreMakerCode + "')";
  77. }
  78. //订单状态
  79. if (!string.IsNullOrEmpty(StatusSelect))
  80. {
  81. condition += " and Status=" + StatusSelect;
  82. }
  83. //发货状态
  84. if (!string.IsNullOrEmpty(SendStatusSelect))
  85. {
  86. condition += " and SendStatus=" + SendStatusSelect;
  87. }
  88. //仓库类型
  89. if (!string.IsNullOrEmpty(StoreTypeSelect))
  90. {
  91. condition += " and StoreType=" + StoreTypeSelect;
  92. }
  93. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreMachineApply", Fields, "Id desc", "0", page, limit, condition);
  94. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  95. foreach (Dictionary<string, object> dic in diclist)
  96. {
  97. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  98. //申请仓库信息
  99. int StoreId = int.Parse(dic["StoreId"].ToString());
  100. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  101. dic["StoreInfo"] = store.StoreNo + "<br />" + store.StoreName;
  102. //仓库收货地址
  103. dic["StoreAddressInfo"] = store.Areas + "<br />" + store.Address;
  104. //仓库联系人信息
  105. //dic["StoreContact"] = dic["StoreManagerMobile"].ToString() + "<br />" + dic["StoreManager"].ToString();
  106. //仓库归属信息
  107. // int StoreUserId = int.Parse(dic["StoreUserId"].ToString());
  108. // Users storeUser = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  109. // int StoreType = int.Parse(dic["StoreType"].ToString());
  110. // string StoreTypeName = "";
  111. // if(StoreType == 0) StoreTypeName = "总仓";
  112. // if(StoreType == 1) StoreTypeName = "分仓";
  113. // dic["StoreUser"] = storeUser.MakerCode + "<br />" + StoreTypeName;
  114. //创客信息
  115. int UserId = int.Parse(dic["UserId"].ToString());
  116. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  117. dic["UserInfo"] = puser.MakerCode + "<br />" + puser.RealName;
  118. //顶级创客
  119. // int TopUserId = int.Parse(dic["TopUserId"].ToString());
  120. // Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  121. // dic["TopUserInfo"] = tuser.MakerCode + "<br />" + tuser.RealName;
  122. //申请状态
  123. int Status = int.Parse(dic["Status"].ToString());
  124. if (Status == 0) dic["Status"] = "待审核";
  125. if (Status == 1) dic["Status"] = "申请成功";
  126. if (Status == 2) dic["Status"] = "申请失败";
  127. }
  128. Dictionary<string, object> other = new Dictionary<string, object>();
  129. other.Add("ApplyNum", 0);
  130. other.Add("SendNum", 0);
  131. obj.Add("other", other);
  132. return Json(obj);
  133. }
  134. #endregion
  135. #region 增加机具申请记录
  136. /// <summary>
  137. /// 增加或修改机具申请记录信息
  138. /// </summary>
  139. /// <returns></returns>
  140. public IActionResult Add(string right)
  141. {
  142. ViewBag.RightInfo = RightInfo;
  143. ViewBag.right = right;
  144. return View();
  145. }
  146. #endregion
  147. #region 增加机具申请记录
  148. /// <summary>
  149. /// 增加或修改机具申请记录信息
  150. /// </summary>
  151. /// <returns></returns>
  152. [HttpPost]
  153. public string Add(StoreMachineApply data)
  154. {
  155. Dictionary<string, object> Fields = new Dictionary<string, object>();
  156. Fields.Add("SeoTitle", data.SeoTitle);
  157. Fields.Add("SeoKeyword", data.SeoKeyword);
  158. Fields.Add("SeoDescription", data.SeoDescription);
  159. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreMachineApply", Fields, 0);
  160. AddSysLog(data.Id.ToString(), "StoreMachineApply", "add");
  161. db.SaveChanges();
  162. return "success";
  163. }
  164. #endregion
  165. #region 修改机具申请记录信息
  166. /// <summary>
  167. /// 增加或修改机具申请记录信息
  168. /// </summary>
  169. /// <returns></returns>
  170. public IActionResult Edit(string right, int Id = 0)
  171. {
  172. ViewBag.RightInfo = RightInfo;
  173. ViewBag.right = right;
  174. StoreMachineApply editData = db.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  175. ViewBag.data = editData;
  176. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == editData.BrandId);
  177. ViewBag.BrandName = kqProducts.Name;
  178. Users user = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  179. ViewBag.MakerCode = user.MakerCode;
  180. ViewBag.RealName = user.RealName;
  181. int Status = editData.Status;
  182. if (Status == 0) ViewBag.Status = "待审核";
  183. if (Status == 1) ViewBag.Status = "申请成功";
  184. if (Status == 2) ViewBag.Status = "申请失败";
  185. return View();
  186. }
  187. #endregion
  188. #region 修改机具申请记录
  189. /// <summary>
  190. /// 增加或修改机具申请记录信息
  191. /// </summary>
  192. /// <returns></returns>
  193. [HttpPost]
  194. public string Edit(StoreMachineApply data)
  195. {
  196. Dictionary<string, object> Fields = new Dictionary<string, object>();
  197. Fields.Add("ApplyNo", data.ApplyNo); //申请单号
  198. // Fields.Add("BrandId", data.BrandId); //产品Id
  199. Fields.Add("ApplyNum", data.ApplyNum); //申请箱数
  200. Fields.Add("SendNum", data.SendNum); //发货箱数
  201. // Fields.Add("UserId", data.UserId); //创客ID
  202. Fields.Add("Status", data.Status); //申请状态
  203. Fields.Add("SwapSnExpand", data.SwapSnExpand);//已发货机具SN
  204. Fields.Add("SeoDescription", data.SeoDescription); //申请描述
  205. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, data.Id);
  206. AddSysLog(data.Id.ToString(), "StoreMachineApply", "update");
  207. db.SaveChanges();
  208. return "success";
  209. }
  210. #endregion
  211. #region 删除机具申请记录信息
  212. /// <summary>
  213. /// 删除机具申请记录信息
  214. /// </summary>
  215. /// <returns></returns>
  216. public string Delete(string Id)
  217. {
  218. string[] idlist = Id.Split(new char[] { ',' });
  219. AddSysLog(Id, "StoreMachineApply", "del");
  220. foreach (string subid in idlist)
  221. {
  222. int id = int.Parse(subid);
  223. Dictionary<string, object> Fields = new Dictionary<string, object>();
  224. Fields.Add("Status", -1);
  225. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  226. }
  227. db.SaveChanges();
  228. return "success";
  229. }
  230. #endregion
  231. #region 取消机具申请记录信息
  232. /// <summary>
  233. /// 取消机具申请记录信息
  234. /// </summary>
  235. /// <returns></returns>
  236. public string Cancel(int Id)
  237. {
  238. StoreMachineApply storeMachineApply = db.StoreMachineApply.FirstOrDefault(m => m.Id == Id);
  239. Orders order = db.Orders.FirstOrDefault(m => m.Id == storeMachineApply.OrderId);
  240. if (storeMachineApply != null && order != null)
  241. {
  242. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(storeMachineApply) + "#cut#" + Newtonsoft.Json.JsonConvert.SerializeObject(order) + "#cut#" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "机具申请订单取消日志");
  243. db.StoreMachineApply.Remove(storeMachineApply);
  244. db.Orders.Remove(order);
  245. db.SaveChanges();
  246. }
  247. AddSysLog(Id, "StoreMachineApply", "cancel");
  248. AddSysLog(Id, "Orders", "cancel");
  249. return "success";
  250. }
  251. #endregion
  252. #region 开启
  253. /// <summary>
  254. /// 开启
  255. /// </summary>
  256. /// <returns></returns>
  257. public string Open(string Id)
  258. {
  259. string[] idlist = Id.Split(new char[] { ',' });
  260. AddSysLog(Id, "StoreMachineApply", "open");
  261. foreach (string subid in idlist)
  262. {
  263. int id = int.Parse(subid);
  264. Dictionary<string, object> Fields = new Dictionary<string, object>();
  265. Fields.Add("Status", 1);
  266. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  267. }
  268. db.SaveChanges();
  269. return "success";
  270. }
  271. #endregion
  272. #region 关闭
  273. /// <summary>
  274. /// 关闭
  275. /// </summary>
  276. /// <returns></returns>
  277. public string Close(string Id)
  278. {
  279. string[] idlist = Id.Split(new char[] { ',' });
  280. AddSysLog(Id, "StoreMachineApply", "close");
  281. foreach (string subid in idlist)
  282. {
  283. int id = int.Parse(subid);
  284. Dictionary<string, object> Fields = new Dictionary<string, object>();
  285. Fields.Add("Status", 0);
  286. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  287. }
  288. db.SaveChanges();
  289. return "success";
  290. }
  291. #endregion
  292. #region 排序
  293. /// <summary>
  294. /// 排序
  295. /// </summary>
  296. /// <param name="Id"></param>
  297. public string Sort(int Id, int Sort)
  298. {
  299. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreMachineApply", Sort, Id);
  300. AddSysLog(Id.ToString(), "StoreMachineApply", "sort");
  301. return "success";
  302. }
  303. #endregion
  304. #region 导入数据
  305. public IActionResult Import(string right, string ExcelKind)
  306. {
  307. ViewBag.RightInfo = RightInfo;
  308. ViewBag.right = right;
  309. ViewBag.ExcelKind = ExcelKind;
  310. return View();
  311. }
  312. /// <summary>
  313. /// 导入数据
  314. /// </summary>
  315. /// <param name="ExcelData"></param>
  316. [HttpPost]
  317. public string ImportPost(string ExcelData)
  318. {
  319. // // RedisDbconn.Instance.AddList("ExcelImport", ExcelPath + "#cut#" + Kind);
  320. // string key = function.MD5_16(Guid.NewGuid().ToString());
  321. // RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#" + Kind + "#cut#" + key);
  322. // return "success|" + key;
  323. ExcelData = HttpUtility.UrlDecode(ExcelData);
  324. JsonData list = JsonMapper.ToObject(ExcelData);
  325. for (int i = 1; i < list.Count; i++)
  326. {
  327. JsonData dr = list[i];
  328. // string SwapSnExpand = dr[0].ToString();
  329. var temp = dr[0].ToString();
  330. temp = temp.Substring(1);
  331. temp = temp.Substring(0, temp.Length - 1);
  332. var SwapSnExpand = temp.Split(",,");
  333. // StoreMachineApply storeMachineApply = db.StoreMachineApply.FirstOrDefault(m => m.MakerCode == MakerCode);
  334. // if (UserCode != null)
  335. // {
  336. // Users User = db.Users.FirstOrDefault(m => m.Id == UserCode.UserId);
  337. // if (User != null)
  338. // {
  339. // User.SettleAmount = decimal.Parse(function.CheckInt(SettleAmount));
  340. // }
  341. // }
  342. }
  343. db.SaveChanges();
  344. return "success";
  345. }
  346. #endregion
  347. #region 导出Excel
  348. /// <summary>
  349. /// 导出Excel
  350. /// </summary>
  351. /// <returns></returns>
  352. public JsonResult ExportExcel(StoreMachineApply data, string MakerCode, string RealName, string StoreNo, string StoreName, string StoreMakerCode, string StatusSelect, string SendStatusSelect, string StoreTypeSelect)
  353. {
  354. Dictionary<string, string> Fields = new Dictionary<string, string>();
  355. Fields.Add("ApplyNo", "1"); //申请单号
  356. Fields.Add("BrandId", "1"); //品牌
  357. Fields.Add("ApplyTime", "3"); //申请时间
  358. Fields.Add("ExpressNo", "1"); //快递单号
  359. string condition = " and Status>-1";
  360. //创客编号
  361. if (!string.IsNullOrEmpty(MakerCode))
  362. {
  363. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  364. }
  365. //创客名称
  366. if (!string.IsNullOrEmpty(RealName))
  367. {
  368. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  369. }
  370. //仓库编号
  371. if (!string.IsNullOrEmpty(StoreNo))
  372. {
  373. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  374. }
  375. //仓库名称
  376. if (!string.IsNullOrEmpty(RealName))
  377. {
  378. condition += " and StoreId in (select StoreId from StoreForName where Name='" + RealName + "')";
  379. }
  380. //仓库归属创客编号
  381. if (!string.IsNullOrEmpty(StoreMakerCode))
  382. {
  383. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + StoreMakerCode + "')";
  384. }
  385. //订单状态
  386. if (!string.IsNullOrEmpty(StatusSelect))
  387. {
  388. condition += " and Status=" + StatusSelect;
  389. }
  390. //发货状态
  391. if (!string.IsNullOrEmpty(SendStatusSelect))
  392. {
  393. condition += " and SendStatus=" + SendStatusSelect;
  394. }
  395. //仓库类型
  396. if (!string.IsNullOrEmpty(StoreTypeSelect))
  397. {
  398. condition += " and StoreType=" + StoreTypeSelect;
  399. }
  400. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("MachineApply", Fields, "Id desc", "0", 1, 20000, condition, "ApplyNo,UserId,TopUserId,BrandId,Areas,Address,RealName,Mobile,ApplyDeviceName,ApplyDeviceNum,ApplyTime,SendStatus,ExpressNo,ExpressName,DeliveryType,StoreId,StoreName,StoreManager,StoreManagerMobile,Remark,StoreUserId,SendDate,StoreType,Status", false);
  401. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  402. foreach (Dictionary<string, object> dic in diclist)
  403. {
  404. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  405. //申请仓库信息
  406. int StoreId = int.Parse(dic["StoreId"].ToString());
  407. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  408. dic["StoreInfo"] = store.StoreNo + "<br />" + store.StoreName;
  409. //仓库联系人信息
  410. //dic["StoreContact"] = dic["StoreManagerMobile"].ToString() + "<br />" + dic["StoreManager"].ToString();
  411. //仓库归属信息
  412. // int StoreUserId = int.Parse(dic["StoreUserId"].ToString());
  413. // Users storeUser = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  414. // int StoreType = int.Parse(dic["StoreType"].ToString());
  415. // string StoreTypeName = "";
  416. // if(StoreType == 0) StoreTypeName = "总仓";
  417. // if(StoreType == 1) StoreTypeName = "分仓";
  418. // dic["StoreUser"] = storeUser.MakerCode + "<br />" + StoreTypeName;
  419. //创客信息
  420. int UserId = int.Parse(dic["UserId"].ToString());
  421. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  422. dic["UserInfo"] = puser.MakerCode + "<br />" + puser.RealName;
  423. //顶级创客
  424. // int TopUserId = int.Parse(dic["TopUserId"].ToString());
  425. // Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  426. // dic["TopUserInfo"] = tuser.MakerCode + "<br />" + tuser.RealName;
  427. //申请状态
  428. int Status = int.Parse(dic["Status"].ToString());
  429. if (Status == 0) dic["Status"] = "待审核";
  430. if (Status == 1) dic["Status"] = "申请成功";
  431. if (Status == 2) dic["Status"] = "申请失败";
  432. dic.Remove("BrandId");
  433. dic.Remove("StoreInfo");
  434. dic.Remove("UserInfo");
  435. dic.Remove("Status");
  436. }
  437. Dictionary<string, object> result = new Dictionary<string, object>();
  438. result.Add("Status", "1");
  439. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  440. result.Add("Obj", diclist);
  441. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  442. ReturnFields.Add("ApplyNo", "申请单号");
  443. ReturnFields.Add("BrandId", "产品类型");
  444. ReturnFields.Add("StoreId", "申请仓库");
  445. ReturnFields.Add("StoreMakerCode", "仓库归属创客编号");
  446. ReturnFields.Add("StoreRealName", "仓库归属创客名称");
  447. ReturnFields.Add("MakerCode", "创客编号");
  448. ReturnFields.Add("MakerName", "创客名称");
  449. ReturnFields.Add("Status", "申请状态");
  450. ReturnFields.Add("ApplyTime", "申请时间");
  451. ReturnFields.Add("ApplyNum", "申请箱数");
  452. ReturnFields.Add("SendNum", "发货箱数");
  453. ReturnFields.Add("SwapSnExpand", "已发货SN号");
  454. ReturnFields.Add("SeoDescription", "申请描述");
  455. result.Add("Fields", ReturnFields);
  456. AddSysLog("0", "StoreMachineApply", "ExportExcel");
  457. return Json(result);
  458. }
  459. #endregion
  460. #region 审核发货
  461. public IActionResult AuditSend(string right, int Id = 0)
  462. {
  463. ViewBag.RightInfo = RightInfo;
  464. ViewBag.right = right;
  465. StoreMachineApply editData = db.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  466. ViewBag.data = editData;
  467. Users users = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  468. StoreHouse storeHouse = db.StoreHouse.FirstOrDefault(m => m.Id == editData.StoreId) ?? new StoreHouse();
  469. ViewBag.MakerCode = users.MakerCode;
  470. ViewBag.RealName = users.RealName;
  471. return View();
  472. }
  473. #endregion
  474. #region 审核发货
  475. [HttpPost]
  476. public string AuditSend(StoreMachineApply data, string ExcelData)
  477. {
  478. Dictionary<string, object> Fields = new Dictionary<string, object>();
  479. Fields.Add("ApplyNum", data.ApplyNum); //申请箱数
  480. Fields.Add("SendNum", data.SendNum); //发货箱数
  481. Fields.Add("SeoDescription", data.SeoDescription); //申请描述
  482. Fields.Add("Status", data.Status);
  483. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, data.Id);
  484. AddSysLog(data.Id.ToString(), "StoreMachineApply", "AuditSend");
  485. StoreMachineApply apply = db.StoreMachineApply.FirstOrDefault(m=>m.Id == data.Id) ?? new StoreMachineApply();
  486. StoreHouse tostore = db.StoreHouse.FirstOrDefault(m=>m.Id == apply.StoreId) ?? new StoreHouse();
  487. int BrandId = apply.BrandId.Value;
  488. var FromStoreId = 0;
  489. if (BrandId==1)
  490. {
  491. FromStoreId=7;
  492. }
  493. else if (BrandId==2)
  494. {
  495. FromStoreId=721;
  496. }
  497. else if (BrandId==3)
  498. {
  499. FromStoreId=697;
  500. }
  501. else if (BrandId==4)
  502. {
  503. FromStoreId=774;
  504. }
  505. else if (BrandId==5)
  506. {
  507. FromStoreId=775;
  508. }
  509. else if (BrandId==6)
  510. {
  511. FromStoreId=871;
  512. }
  513. else if (BrandId==7)
  514. {
  515. FromStoreId=0;
  516. }
  517. ExcelData = HttpUtility.UrlDecode(ExcelData);
  518. JsonData list = JsonMapper.ToObject(ExcelData);
  519. Dictionary<string, int> storeData = new Dictionary<string, int>();
  520. Dictionary<string, int> toStoreData = new Dictionary<string, int>();
  521. for (int i = 1; i < list.Count; i++)
  522. {
  523. JsonData dr = list[i];
  524. string itemJson = dr.ToJson();
  525. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  526. string BatchNo = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  527. string OutNote = itemJson.Contains("\"C\"") ? dr["B"].ToString() : "";
  528. StoreMachineApply storeMachineApply = db.StoreMachineApply.FirstOrDefault(m=>m.Id == data.Id);
  529. if (storeMachineApply != null)
  530. {
  531. storeMachineApply.SwapSnExpand = function.CheckString(SnNo)+',';
  532. }
  533. MachineForSnNo machinefor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  534. PosMachinesTwo machine = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machinefor.SnId && m.StoreId != apply.StoreId && m.BuyUserId == 0 && m.UserId == 0) ?? new PosMachinesTwo();
  535. if (machine.Id > 0)
  536. {
  537. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  538. {
  539. CreateDate = DateTime.Now,
  540. StoreId = FromStoreId, //出货仓库
  541. BrandId = BrandId, //产品类型
  542. ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
  543. BizBatchNo = BatchNo, //业务批次号
  544. TransType = 1, //交易类型
  545. SnNo = SnNo, //SN编号
  546. StockOpDirect = 1, //库存操作方向
  547. SnStatus = 1, //SN状态
  548. DeviceVendor = machine.DeviceName, //设备厂商
  549. DeviceModel = machine.DeviceKind, //设备型号
  550. DeviceType = machine.DeviceType, //设备类型
  551. FromUserId = tostore.UserId, //出货人
  552. FromDate = DateTime.Now, //出库时间
  553. FromRemark = OutNote, //出库备注
  554. ToUserId = tostore.UserId, //收货人
  555. ToStoreId = tostore.Id, //退货收货仓库
  556. SourceStoreId = machine.SourceStoreId, //源仓库编号
  557. BrandType = machine.DeviceType, //品牌类型
  558. }).Entity;
  559. db.SaveChanges();
  560. string ChangeNo = "SC";
  561. int StoreStockChangeId = stockchange.Id;
  562. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  563. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  564. {
  565. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  566. }
  567. ChangeNo += StoreStockChangeIdString;
  568. stockchange.ChangeNo = ChangeNo; //交易流水编号
  569. machine.StoreId = tostore.Id;
  570. db.StoreChangeHistory.Add(new StoreChangeHistory()
  571. {
  572. CreateDate = DateTime.Now,
  573. UserId = tostore.UserId, //创客
  574. BrandId = BrandId, //产品类型
  575. ChangeRecordNo = ChangeNo, //变更记录单号
  576. BizBatchNo = BatchNo, //业务批次号
  577. TransType = 1, //交易类型
  578. SnNo = SnNo, //SN编号
  579. SnType = machine.PosSnType, //SN机具类型
  580. StockOpDirect = 1, //库存操作方向
  581. DeviceVendor = machine.DeviceName, //设备厂商
  582. DeviceModel = machine.DeviceKind, //设备型号
  583. DeviceType = machine.DeviceType, //设备类型
  584. FromUserId = tostore.UserId, //出货创客
  585. FromDate = DateTime.Now, //出库时间
  586. FromRemark = OutNote, //出库备注
  587. SourceStoreId = machine.SourceStoreId, //源仓库
  588. StoreId = tostore.Id, //仓库
  589. });
  590. db.StoreChangeHistory.Add(new StoreChangeHistory()
  591. {
  592. CreateDate = DateTime.Now,
  593. UserId = tostore.UserId, //创客
  594. BrandId = BrandId, //产品类型
  595. ChangeRecordNo = ChangeNo, //变更记录单号
  596. BizBatchNo = BatchNo, //业务批次号
  597. TransType = 1, //交易类型
  598. SnNo = SnNo, //SN编号
  599. SnType = machine.PosSnType, //SN机具类型
  600. StockOpDirect = 0, //库存操作方向
  601. DeviceVendor = machine.DeviceName, //设备厂商
  602. DeviceModel = machine.DeviceKind, //设备型号
  603. DeviceType = machine.DeviceType, //设备类型
  604. ToUserId = tostore.UserId, //收货创客
  605. ToStoreId = tostore.Id, //创客退货收货仓库
  606. ToDate = DateTime.Now, //入库时间
  607. ToRemark = OutNote, //入库备注
  608. SourceStoreId = machine.SourceStoreId, //源仓库
  609. StoreId = tostore.Id, //仓库
  610. });
  611. db.SaveChanges();
  612. }
  613. }
  614. db.SaveChanges();
  615. int StoreId = FromStoreId;
  616. int OpStoreNum = list.Count - 1;
  617. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  618. StoreBalance balance = db.StoreBalance.Add(new StoreBalance()
  619. {
  620. CreateDate = DateTime.Now,
  621. StoreId = StoreId, //仓库
  622. TransType = 1, //交易类型
  623. BrandId = BrandId, //产品类型
  624. OpStoreNum = OpStoreNum, //操作库存数
  625. OpSymbol = "-", //操作符
  626. BeforeTotalNum = store.TotalNum, //操作前总库存数
  627. AfterTotalNum = store.TotalNum, //操作后总库存数
  628. BeforeLaveNum = store.LaveNum, //操作前剩余库存数
  629. AfterLaveNum = store.LaveNum - OpStoreNum, //操作后剩余库存数
  630. BeforeOutNum = store.OutNum, //操作前出库数
  631. AfterOutNum = store.OutNum + OpStoreNum, //操作后出库数
  632. }).Entity;
  633. db.SaveChanges();
  634. string ChangeNo1 = "SC";
  635. int StoreStockChangeId1 = balance.Id;
  636. string StoreStockChangeId1String = StoreStockChangeId1.ToString();
  637. for (int i = 0; i < 18 - StoreStockChangeId1.ToString().Length; i++)
  638. {
  639. StoreStockChangeId1String = "0" + StoreStockChangeId1String;
  640. }
  641. ChangeNo1 += StoreStockChangeId1String;
  642. balance.TransRecordNo = ChangeNo1; //交易流水编号
  643. store.LaveNum -= OpStoreNum;
  644. store.OutNum += OpStoreNum;
  645. db.SaveChanges();
  646. StoreId = tostore.Id;
  647. balance = db.StoreBalance.Add(new StoreBalance()
  648. {
  649. CreateDate = DateTime.Now,
  650. StoreId = StoreId, //仓库
  651. TransType = 0, //交易类型
  652. BrandId = BrandId, //产品类型
  653. OpStoreNum = OpStoreNum, //操作库存数
  654. OpSymbol = "+", //操作符
  655. BeforeTotalNum = store.TotalNum, //操作前总库存数
  656. AfterTotalNum = store.TotalNum + OpStoreNum, //操作后总库存数
  657. BeforeLaveNum = store.LaveNum, //操作前剩余库存数
  658. AfterLaveNum = store.LaveNum + OpStoreNum, //操作后剩余库存数
  659. BeforeOutNum = store.OutNum, //操作前出库数
  660. AfterOutNum = store.OutNum, //操作后出库数
  661. }).Entity;
  662. db.SaveChanges();
  663. string ChangeNo2 = "SC";
  664. int StoreStockChangeId2 = balance.Id;
  665. string StoreStockChangeId2String = StoreStockChangeId2.ToString();
  666. for (int i = 0; i < 18 - StoreStockChangeId2.ToString().Length; i++)
  667. {
  668. StoreStockChangeId2String = "0" + StoreStockChangeId2String;
  669. }
  670. ChangeNo2 += StoreStockChangeId2String;
  671. balance.TransRecordNo = ChangeNo2; //交易流水编号
  672. store.TotalNum += OpStoreNum;
  673. store.LaveNum += OpStoreNum;
  674. db.SaveChanges();
  675. if (data.Status == 1)
  676. {
  677. return "success";
  678. }
  679. else
  680. {
  681. return "false";
  682. }
  683. }
  684. #endregion
  685. }
  686. }