StoreMachineApplyController.cs 38 KB

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