StoreMachineApplysOperateController.cs 38 KB

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