StoreMachineApplyController.cs 31 KB

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