StoreMachineApplyController.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /*
  2. * 分仓机具申请记录
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  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 UserIdRealName, string UserIdMakerCode, string CreateDateData, string StatusSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("ApplyNo", "1"); //申请单号
  49. Fields.Add("SendMode", "1"); //发货方式
  50. string condition = " and Status>-1";
  51. if (!string.IsNullOrEmpty(CreateDateData))
  52. {
  53. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  54. string start = datelist[0];
  55. string end = datelist[1];
  56. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  57. }
  58. //创客真实姓名
  59. if (!string.IsNullOrEmpty(UserIdRealName))
  60. {
  61. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  62. }
  63. //创客编号
  64. if (!string.IsNullOrEmpty(UserIdMakerCode))
  65. {
  66. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  67. }
  68. if (!string.IsNullOrEmpty(StatusSelect))
  69. {
  70. condition += " and Status=" + StatusSelect + "";
  71. }
  72. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreMachineApply", Fields, "Id desc", "0", page, limit, condition);
  73. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  74. foreach (Dictionary<string, object> dic in diclist)
  75. {
  76. //品牌
  77. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  78. int Status = int.Parse(dic["Status"].ToString());
  79. if (Status == 0) dic["StatusName"] = "待配货";
  80. if (Status == 1) dic["StatusName"] = "已发货";
  81. if (Status == 2) dic["StatusName"] = "已驳回";
  82. //创客
  83. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  84. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  85. dic["UserIdRealName"] = userid_Users.RealName;
  86. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  87. dic.Remove("UserId");
  88. }
  89. return Json(obj);
  90. }
  91. #endregion
  92. #region 增加分仓机具申请记录
  93. /// <summary>
  94. /// 增加或修改分仓机具申请记录信息
  95. /// </summary>
  96. /// <returns></returns>
  97. public IActionResult Add(string right)
  98. {
  99. ViewBag.RightInfo = RightInfo;
  100. ViewBag.right = right;
  101. return View();
  102. }
  103. #endregion
  104. #region 增加分仓机具申请记录
  105. /// <summary>
  106. /// 增加或修改分仓机具申请记录信息
  107. /// </summary>
  108. /// <returns></returns>
  109. [HttpPost]
  110. public string Add(StoreMachineApply data)
  111. {
  112. Dictionary<string, object> Fields = new Dictionary<string, object>();
  113. Fields.Add("BrandId", data.BrandId); //品牌
  114. Fields.Add("ApplyNo", data.ApplyNo); //申请单号
  115. Fields.Add("ApplyNum", data.ApplyNum); //申请台数
  116. Fields.Add("SendNum", data.SendNum); //发货台数
  117. Fields.Add("UseAmount", data.UseAmount); //使用额度
  118. Fields.Add("SendMode", data.SendMode); //发货方式
  119. Fields.Add("ErpCode", data.ErpCode); //快递单号
  120. Fields.Add("SendSn", data.SendSn); //发货SN数据
  121. Fields.Add("UserId", data.UserId); //创客
  122. Fields.Add("SeoTitle", data.SeoTitle);
  123. Fields.Add("SeoKeyword", data.SeoKeyword);
  124. Fields.Add("SeoDescription", data.SeoDescription);
  125. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreMachineApply", Fields, 0);
  126. AddSysLog(data.Id.ToString(), "StoreMachineApply", "add");
  127. db.SaveChanges();
  128. return "success";
  129. }
  130. #endregion
  131. #region 修改分仓机具申请记录
  132. /// <summary>
  133. /// 增加或修改分仓机具申请记录信息
  134. /// </summary>
  135. /// <returns></returns>
  136. public IActionResult Edit(string right, int Id = 0)
  137. {
  138. ViewBag.RightInfo = RightInfo;
  139. ViewBag.right = right;
  140. StoreMachineApply editData = db.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  141. ViewBag.data = editData;
  142. Users users = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  143. ViewBag.UserId = users.Id;
  144. ViewBag.RealName = users.RealName;
  145. ViewBag.UseAmount = editData.UseAmount;
  146. JsonData SendSnList = new JsonData();
  147. SendSnList = JsonMapper.ToObject(editData.SendSn);//申请数据
  148. List<Dictionary<string, object>> KsProductList = new List<Dictionary<string, object>>();
  149. for (int i = 0; i < SendSnList.Count; i++)
  150. {
  151. int BrandId = Convert.ToInt32(SendSnList[i]["BrandId"].ToString());
  152. int Num = Convert.ToInt32(SendSnList[i]["ApplyNum"].ToString());
  153. List<KqProducts> products = db.KqProducts.Where(m => m.Id == BrandId).ToList();
  154. foreach (KqProducts product in products)
  155. {
  156. Dictionary<string, object> item = new Dictionary<string, object>();
  157. item.Add("BrandId", BrandId); //商品Id
  158. item.Add("Name", product.Name); //商品名称
  159. item.Add("Num", Num); //商品数量
  160. KsProductList.Add(item);
  161. }
  162. }
  163. ViewBag.KsProductList = KsProductList;
  164. return View();
  165. }
  166. #endregion
  167. #region 修改分仓机具申请记录
  168. /// <summary>
  169. /// 增加或修改分仓机具申请记录信息
  170. /// </summary>
  171. /// <returns></returns>
  172. [HttpPost]
  173. public string Edit(StoreMachineApply data)
  174. {
  175. Dictionary<string, object> Fields = new Dictionary<string, object>();
  176. Fields.Add("SendSn", data.SendSn); //发货SN数据
  177. JsonData SendSnList = new JsonData();
  178. SendSnList = JsonMapper.ToObject(data.SendSn);//申请数据
  179. int ApplyNum = 0;
  180. for (int i = 0; i < SendSnList.Count; i++)
  181. {
  182. int num = Convert.ToInt32(SendSnList[i]["ApplyNum"].ToString());
  183. ApplyNum += num;
  184. }
  185. Fields.Add("BrandId", data.BrandId); //品牌
  186. Fields.Add("ApplyNo", data.ApplyNo); //申请单号
  187. Fields.Add("ApplyNum", ApplyNum); //申请台数
  188. Fields.Add("SendNum", data.SendNum); //发货台数
  189. Fields.Add("UseAmount", data.UseAmount); //使用额度
  190. Fields.Add("SendMode", data.SendMode); //发货方式
  191. Fields.Add("ErpCode", data.ErpCode); //快递单号
  192. Fields.Add("UserId", data.UserId); //创客
  193. Fields.Add("SeoTitle", SysUserName + '-' + SysRealName);
  194. Fields.Add("SeoKeyword", data.SeoKeyword);
  195. Fields.Add("SeoDescription", data.SeoDescription);
  196. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, data.Id);
  197. AddSysLog(data.Id.ToString(), "StoreMachineApply", "update");
  198. db.SaveChanges();
  199. return "success";
  200. }
  201. #endregion
  202. #region 删除分仓机具申请记录信息
  203. /// <summary>
  204. /// 删除分仓机具申请记录信息
  205. /// </summary>
  206. /// <returns></returns>
  207. public string Delete(string Id)
  208. {
  209. string[] idlist = Id.Split(new char[] { ',' });
  210. AddSysLog(Id, "StoreMachineApply", "del");
  211. foreach (string subid in idlist)
  212. {
  213. int id = int.Parse(subid);
  214. Dictionary<string, object> Fields = new Dictionary<string, object>();
  215. Fields.Add("Status", -1);
  216. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  217. }
  218. db.SaveChanges();
  219. return "success";
  220. }
  221. #endregion
  222. #region 开启
  223. /// <summary>
  224. /// 开启
  225. /// </summary>
  226. /// <returns></returns>
  227. public string Open(string Id)
  228. {
  229. string[] idlist = Id.Split(new char[] { ',' });
  230. AddSysLog(Id, "StoreMachineApply", "open");
  231. foreach (string subid in idlist)
  232. {
  233. int id = int.Parse(subid);
  234. Dictionary<string, object> Fields = new Dictionary<string, object>();
  235. Fields.Add("Status", 1);
  236. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  237. }
  238. db.SaveChanges();
  239. return "success";
  240. }
  241. #endregion
  242. #region 关闭
  243. /// <summary>
  244. /// 关闭
  245. /// </summary>
  246. /// <returns></returns>
  247. public string Close(string Id)
  248. {
  249. string[] idlist = Id.Split(new char[] { ',' });
  250. AddSysLog(Id, "StoreMachineApply", "close");
  251. foreach (string subid in idlist)
  252. {
  253. int id = int.Parse(subid);
  254. Dictionary<string, object> Fields = new Dictionary<string, object>();
  255. Fields.Add("Status", 2);
  256. var query = db.StoreMachineApply.FirstOrDefault(m => m.Id == id);
  257. var users = db.UserAccount.FirstOrDefault(m => m.Id == query.UserId);
  258. users.ValidAmount += query.UseAmount;
  259. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  260. }
  261. db.SaveChanges();
  262. return "success";
  263. }
  264. #endregion
  265. #region 排序
  266. /// <summary>
  267. /// 排序
  268. /// </summary>
  269. /// <param name="Id"></param>
  270. public string Sort(int Id, int Sort)
  271. {
  272. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreMachineApply", Sort, Id);
  273. AddSysLog(Id.ToString(), "StoreMachineApply", "sort");
  274. return "success";
  275. }
  276. #endregion
  277. #region 导入数据
  278. /// <summary>
  279. /// 导入数据
  280. /// </summary>
  281. /// <param name="ExcelData"></param>
  282. public string Import(string ExcelData)
  283. {
  284. ExcelData = HttpUtility.UrlDecode(ExcelData);
  285. JsonData list = JsonMapper.ToObject(ExcelData);
  286. for (int i = 1; i < list.Count; i++)
  287. {
  288. JsonData dr = list[i];
  289. db.StoreMachineApply.Add(new StoreMachineApply()
  290. {
  291. CreateDate = DateTime.Now,
  292. UpdateDate = DateTime.Now,
  293. });
  294. db.SaveChanges();
  295. }
  296. AddSysLog("0", "StoreMachineApply", "Import");
  297. return "success";
  298. }
  299. #endregion
  300. #region 导出Excel
  301. /// <summary>
  302. /// 导出Excel
  303. /// </summary>
  304. /// <returns></returns>
  305. public JsonResult ExportExcel(StoreMachineApply data, string BrandIdSelect, string UserIdRealName, string UserIdMakerCode)
  306. {
  307. Dictionary<string, string> Fields = new Dictionary<string, string>();
  308. Fields.Add("CreateDate", "3"); //时间
  309. Fields.Add("ApplyNo", "1"); //申请单号
  310. Fields.Add("SendMode", "1"); //发货方式
  311. string condition = " and Status>-1";
  312. //品牌
  313. if (!string.IsNullOrEmpty(BrandIdSelect))
  314. {
  315. condition += " and BrandId=" + BrandIdSelect;
  316. }
  317. //创客真实姓名
  318. if (!string.IsNullOrEmpty(UserIdRealName))
  319. {
  320. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  321. }
  322. //创客编号
  323. if (!string.IsNullOrEmpty(UserIdMakerCode))
  324. {
  325. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  326. }
  327. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreMachineApply", Fields, "Id desc", "0", 1, 20000, condition, "BrandId,ApplyNo,ApplyNum,SendNum,UseAmount,SendMode,ErpCode,UserId", false);
  328. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  329. foreach (Dictionary<string, object> dic in diclist)
  330. {
  331. //品牌
  332. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  333. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  334. //创客
  335. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  336. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  337. dic["UserIdRealName"] = userid_Users.RealName;
  338. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  339. dic.Remove("UserId");
  340. }
  341. Dictionary<string, object> result = new Dictionary<string, object>();
  342. result.Add("Status", "1");
  343. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  344. result.Add("Obj", diclist);
  345. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  346. ReturnFields.Add("BrandId", "品牌");
  347. ReturnFields.Add("ApplyNo", "申请单号");
  348. ReturnFields.Add("ApplyNum", "申请台数");
  349. ReturnFields.Add("SendNum", "发货台数");
  350. ReturnFields.Add("UseAmount", "使用额度");
  351. ReturnFields.Add("SendMode", "发货方式");
  352. ReturnFields.Add("ErpCode", "快递单号");
  353. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  354. ReturnFields.Add("UserIdMakerCode", "创客编号");
  355. result.Add("Fields", ReturnFields);
  356. AddSysLog("0", "StoreMachineApply", "ExportExcel");
  357. return Json(result);
  358. }
  359. #endregion
  360. #region 审核发货
  361. public IActionResult AuditSend(string right, int Id = 0)
  362. {
  363. ViewBag.RightInfo = RightInfo;
  364. ViewBag.right = right;
  365. StoreMachineApply editData = db.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  366. ViewBag.data = editData;
  367. Users users = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  368. ViewBag.MakerCode = users.MakerCode;
  369. ViewBag.RealName = users.RealName;
  370. return View();
  371. }
  372. #endregion
  373. #region 审核发货
  374. [HttpPost]
  375. public string AuditSend(StoreMachineApply data, string ExcelData)
  376. {
  377. Dictionary<string, object> Fields = new Dictionary<string, object>();
  378. Fields.Add("ApplyNum", data.ApplyNum); //申请数
  379. Fields.Add("SendNum", data.ApplyNum); //发货数
  380. Fields.Add("ErpCode", data.ErpCode); //快递单号
  381. Fields.Add("SendMode", data.SendMode); //发货方式
  382. Fields.Add("SeoKeyword", data.SeoKeyword); //申请描述
  383. Fields.Add("Status", 1);
  384. AddSysLog(data.Id.ToString(), "StoreMachineApply", "AuditSend");
  385. Dictionary<string, object> Obj = new Dictionary<string, object>();
  386. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  387. List<SendInfo> sendInfos = new List<SendInfo>();
  388. List<CheckSendInfo> checksendInfos = new List<CheckSendInfo>();
  389. StoreMachineApply apply = db.StoreMachineApply.FirstOrDefault(m => m.Id == data.Id) ?? new StoreMachineApply();
  390. JsonData ApplyList = JsonMapper.ToObject(apply.SendSn);
  391. decimal ApplyAmount = 0;
  392. decimal Amount = 0;
  393. for (int i = 0; i < ApplyList.Count; i++)
  394. {
  395. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  396. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  397. //自动匹配品牌
  398. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  399. if (brandInfo.Name.Contains("电签"))
  400. {
  401. ApplyAmount += num * 200;
  402. }
  403. if (brandInfo.Name.Contains("大POS"))
  404. {
  405. ApplyAmount += num * 300;
  406. }
  407. }
  408. Amount = apply.UseAmount - ApplyAmount;
  409. StoreHouse tostore = new StoreHouse();
  410. StoreHouse fromstore = new StoreHouse();
  411. var BrandId = 0;
  412. var FromStoreId = 0;
  413. string error = "";
  414. if (string.IsNullOrEmpty(ExcelData))
  415. {
  416. return "Warning|" + "请选择要导入的数据";
  417. }
  418. ExcelData = HttpUtility.UrlDecode(ExcelData);
  419. JsonData list = JsonMapper.ToObject(ExcelData);
  420. //判断各品牌发货数量是否符合
  421. if (list.Count - 1 > apply.ApplyNum)
  422. {
  423. return "Warning|" + "机具发货数量过多!";
  424. }
  425. if (list.Count - 1 < apply.ApplyNum)
  426. {
  427. return "Warning|" + "机具发货数量不足!";
  428. }
  429. for (int index = 1; index < list.Count; index++)
  430. {
  431. JsonData dr = list[index];
  432. string itemJson = dr.ToJson();
  433. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  434. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  435. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  436. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  437. BrandId = Convert.ToInt32(Brand);
  438. if (BrandId == 1) FromStoreId = 7;
  439. if (BrandId == 2) FromStoreId = 721;
  440. if (BrandId == 3) FromStoreId = 697;
  441. if (BrandId == 4) FromStoreId = 774;
  442. if (BrandId == 5) FromStoreId = 775;
  443. if (BrandId == 6) FromStoreId = 871;
  444. if (BrandId == 7) FromStoreId = 1047;
  445. if (BrandId == 8) FromStoreId = 4831;
  446. if (BrandId == 9) FromStoreId = 4832;
  447. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandId);
  448. if (items == null)
  449. {
  450. CheckSendInfo rows = new CheckSendInfo()
  451. {
  452. BrandId = BrandId,
  453. Num = 1
  454. };
  455. checksendInfos.Add(rows);
  456. }
  457. else
  458. {
  459. items.Num += 1;
  460. }
  461. }
  462. for (int i = 0; i < ApplyList.Count; i++)
  463. {
  464. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  465. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  466. if (BrandIds == 1) FromStoreId = 7;
  467. if (BrandIds == 2) FromStoreId = 721;
  468. if (BrandIds == 3) FromStoreId = 697;
  469. if (BrandIds == 4) FromStoreId = 774;
  470. if (BrandIds == 5) FromStoreId = 775;
  471. if (BrandIds == 6) FromStoreId = 871;
  472. if (BrandIds == 7) FromStoreId = 1047;
  473. if (BrandIds == 8) FromStoreId = 4831;
  474. if (BrandIds == 9) FromStoreId = 4832;
  475. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  476. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandIds) ?? new CheckSendInfo();
  477. if (items.Num > num)
  478. {
  479. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量过多!";
  480. }
  481. if (items.Num < num)
  482. {
  483. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量不足!";
  484. }
  485. }
  486. List<string> PosSnList = new List<string>();
  487. for (int index = 1; index < list.Count; index++)
  488. {
  489. JsonData dr = list[index];
  490. string itemJson = dr.ToJson();
  491. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  492. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  493. BrandId = Convert.ToInt32(Brand);
  494. MachineForSnNo posInfo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  495. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posInfo.SnId) ?? new PosMachinesTwo();
  496. if (posInfo.SnId > 0)
  497. {
  498. if (pos.Id > 0)
  499. {
  500. if (pos.BrandId != BrandId)
  501. {
  502. error += "以下操作失败" + SnNo + ',' + "该机具品牌填写错误" + '\n';
  503. }
  504. }
  505. if (BrandId == 1) FromStoreId = 7;
  506. if (BrandId == 2) FromStoreId = 721;
  507. if (BrandId == 3) FromStoreId = 697;
  508. if (BrandId == 4) FromStoreId = 774;
  509. if (BrandId == 5) FromStoreId = 775;
  510. if (BrandId == 6) FromStoreId = 871;
  511. if (BrandId == 7) FromStoreId = 1047;
  512. if (BrandId == 8) FromStoreId = 4831;
  513. if (BrandId == 9) FromStoreId = 4832;
  514. if (PosSnList.Contains(SnNo))
  515. {
  516. error += "以下操作失败" + SnNo + ',' + "该机具重复发货" + '\n';
  517. }
  518. PosSnList.Add(SnNo);
  519. }
  520. else
  521. {
  522. error += "以下操作失败" + SnNo + ',' + "未找到该机具" + '\n';
  523. }
  524. }
  525. if (!string.IsNullOrEmpty(error))
  526. {
  527. return "Warning|" + error;
  528. }
  529. Dictionary<string, int> storeData = new Dictionary<string, int>();
  530. Dictionary<string, int> toStoreData = new Dictionary<string, int>();
  531. for (int index = 1; index < list.Count; index++)
  532. {
  533. JsonData dr = list[index];
  534. string itemJson = dr.ToJson();
  535. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  536. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  537. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  538. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  539. BrandId = Convert.ToInt32(Brand);
  540. if (BrandId == 1) FromStoreId = 7;
  541. if (BrandId == 2) FromStoreId = 721;
  542. if (BrandId == 3) FromStoreId = 697;
  543. if (BrandId == 4) FromStoreId = 774;
  544. if (BrandId == 5) FromStoreId = 775;
  545. if (BrandId == 6) FromStoreId = 871;
  546. if (BrandId == 7) FromStoreId = 1047;
  547. if (BrandId == 8) FromStoreId = 4831;
  548. if (BrandId == 9) FromStoreId = 4832;
  549. tostore = db.StoreHouse.FirstOrDefault(m => m.UserId == apply.UserId && m.BrandId == BrandId.ToString() && m.Status > -1);
  550. SendInfo item = sendInfos.FirstOrDefault(m => m.FromStoreId == FromStoreId && m.ToStoreId == tostore.Id && m.BrandId == BrandId);
  551. if (item == null)
  552. {
  553. SendInfo row = new SendInfo()
  554. {
  555. FromStoreId = FromStoreId,
  556. ToStoreId = tostore.Id,
  557. BrandId = BrandId,
  558. Num = 1
  559. };
  560. sendInfos.Add(row);
  561. }
  562. else
  563. {
  564. item.Num += 1;
  565. }
  566. apply.SeoDescription = function.CheckString(SnNo) + ',';
  567. fromstore = db.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId);
  568. tostore = db.StoreHouse.FirstOrDefault(m => m.UserId == apply.UserId && m.BrandId == BrandId.ToString() && m.Status > -1);
  569. MachineForSnNo machinefor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  570. PosMachinesTwo machine = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machinefor.SnId && m.BuyUserId == 0 && m.UserId == 0) ?? new PosMachinesTwo();
  571. if (machine.Id > 0)
  572. {
  573. if (machine.BrandId != BrandId)
  574. {
  575. return machine.PosSn + "与表格里填写的品牌不一致";
  576. }
  577. else
  578. {
  579. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  580. {
  581. CreateDate = DateTime.Now,
  582. CreateMan = SysUserName,
  583. Sort = data.Id,//库存变动关联申请记录表
  584. StoreId = FromStoreId, //出货仓库
  585. BrandId = BrandId, //产品类型
  586. ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
  587. BizBatchNo = BatchNo, //业务批次号
  588. TransType = 1, //交易类型
  589. SnNo = SnNo, //SN编号
  590. StockOpDirect = 1, //库存操作方向
  591. SnStatus = 1, //SN状态
  592. DeviceVendor = machine.DeviceName, //设备厂商
  593. DeviceModel = machine.DeviceKind, //设备型号
  594. DeviceType = machine.DeviceType, //设备类型
  595. FromUserId = fromstore.UserId, //出货人
  596. FromDate = DateTime.Now, //出库时间
  597. FromRemark = OutNote, //出库备注
  598. ToUserId = tostore.UserId, //收货人
  599. ToStoreId = fromstore.Id, //退货收货仓库
  600. SourceStoreId = machine.SourceStoreId, //源仓库编号
  601. BrandType = machine.DeviceType, //品牌类型
  602. }).Entity;
  603. string ChangeNo = "CS";
  604. int StoreStockChangeId = stockchange.Id;
  605. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  606. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  607. {
  608. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  609. }
  610. ChangeNo += StoreStockChangeIdString;
  611. stockchange.ChangeNo = ChangeNo; //交易流水编号
  612. machine.StoreId = tostore.Id;
  613. db.StoreChangeHistory.Add(new StoreChangeHistory()
  614. {
  615. CreateDate = DateTime.Now,
  616. UserId = fromstore.UserId, //创客
  617. BrandId = BrandId, //产品类型
  618. ChangeRecordNo = ChangeNo, //变更记录单号
  619. BizBatchNo = BatchNo, //业务批次号
  620. TransType = 1, //交易类型
  621. SnNo = SnNo, //SN编号
  622. SnType = machine.PosSnType, //SN机具类型
  623. StockOpDirect = 1, //库存操作方向
  624. DeviceVendor = machine.DeviceName, //设备厂商
  625. DeviceModel = machine.DeviceKind, //设备型号
  626. DeviceType = machine.DeviceType, //设备类型
  627. FromUserId = fromstore.UserId, //出货创客
  628. FromDate = DateTime.Now, //出库时间
  629. FromRemark = OutNote, //出库备注
  630. SourceStoreId = machine.SourceStoreId, //源仓库
  631. StoreId = fromstore.Id, //仓库
  632. ToUserId = tostore.UserId,//收货创客
  633. });
  634. //修改机具所属仓库
  635. machine.StoreId = tostore.Id;
  636. machine.UpdateDate = DateTime.Now;
  637. }
  638. }
  639. else
  640. {
  641. return "总仓无该机具";
  642. }
  643. }
  644. foreach (var item in sendInfos)
  645. {
  646. //出货仓库数据调整
  647. StoreHouse storeCH = db.StoreHouse.FirstOrDefault(m => m.Id == item.FromStoreId) ?? new StoreHouse();
  648. StoreBalance balance = db.StoreBalance.Add(new StoreBalance()
  649. {
  650. CreateDate = DateTime.Now,
  651. StoreId = storeCH.Id, //仓库
  652. TransType = 1, //交易类型
  653. BrandId = BrandId, //产品类型
  654. OpStoreNum = item.Num, //操作库存数
  655. OpSymbol = "-", //操作符
  656. BeforeTotalNum = storeCH.TotalNum, //操作前总库存数
  657. AfterTotalNum = storeCH.TotalNum - item.Num, //操作后总库存数
  658. BeforeLaveNum = storeCH.LaveNum, //操作前剩余库存数
  659. AfterLaveNum = storeCH.LaveNum - item.Num, //操作后剩余库存数
  660. BeforeOutNum = storeCH.OutNum, //操作前出库数
  661. AfterOutNum = storeCH.OutNum + item.Num, //操作后出库数
  662. }).Entity;
  663. string ChangeNo1 = "CS";
  664. int StoreStockChangeId1 = balance.Id;
  665. string StoreStockChangeId1String = StoreStockChangeId1.ToString();
  666. for (int i = 0; i < 18 - StoreStockChangeId1.ToString().Length; i++)
  667. {
  668. StoreStockChangeId1String = "0" + StoreStockChangeId1String;
  669. }
  670. ChangeNo1 += StoreStockChangeId1String;
  671. balance.TransRecordNo = ChangeNo1; //交易流水编号
  672. storeCH.LaveNum -= item.Num;
  673. storeCH.OutNum += item.Num;
  674. //收货仓库数据调整
  675. StoreHouse storeSH = db.StoreHouse.FirstOrDefault(m => m.Id == item.ToStoreId) ?? new StoreHouse();
  676. balance = db.StoreBalance.Add(new StoreBalance()
  677. {
  678. CreateDate = DateTime.Now,
  679. StoreId = storeSH.Id, //仓库
  680. TransType = 0, //交易类型
  681. BrandId = BrandId, //产品类型
  682. OpStoreNum = item.Num, //操作库存数
  683. OpSymbol = "+", //操作符
  684. BeforeTotalNum = storeSH.TotalNum, //操作前总库存数
  685. AfterTotalNum = storeSH.TotalNum + item.Num, //操作后总库存数
  686. BeforeLaveNum = storeSH.LaveNum, //操作前剩余库存数
  687. AfterLaveNum = storeSH.LaveNum + item.Num, //操作后剩余库存数
  688. BeforeOutNum = storeSH.OutNum, //操作前出库数
  689. AfterOutNum = storeSH.OutNum, //操作后出库数
  690. }).Entity;
  691. string ChangeNo2 = "CS";
  692. int StoreStockChangeId2 = balance.Id;
  693. string StoreStockChangeId2String = StoreStockChangeId2.ToString();
  694. for (int i = 0; i < 18 - StoreStockChangeId2.ToString().Length; i++)
  695. {
  696. StoreStockChangeId2String = "0" + StoreStockChangeId2String;
  697. }
  698. ChangeNo2 += StoreStockChangeId2String;
  699. balance.TransRecordNo = ChangeNo2; //交易流水编号
  700. storeSH.TotalNum += item.Num;
  701. storeSH.LaveNum += item.Num;
  702. }
  703. apply.SeoTitle = SysUserName + '-' + SysRealName;//添加操作人信息
  704. apply.UseAmount = ApplyAmount;
  705. db.SaveChanges();
  706. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, data.Id);
  707. string SendData = "{\"Kind\":\"2\",\"Data\":{\"UserId\":\"" + apply.UserId + "\",\"Amount\":\"" + Amount + "\",\"OperateType\":\"1\"}}";
  708. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  709. return "success";
  710. }
  711. #endregion
  712. //发货信息实体类
  713. private class SendInfo
  714. {
  715. public int FromStoreId { get; set; }
  716. public int ToStoreId { get; set; }
  717. public int BrandId { get; set; }
  718. public int Num { get; set; }
  719. }
  720. //检查发货信息实体类
  721. private class CheckSendInfo
  722. {
  723. public int BrandId { get; set; }
  724. public int Num { get; set; }
  725. }
  726. }
  727. }