StoreMachineApplysOperateController.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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. var kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new KqProducts();
  450. FromStoreId = kqProducts.MainStoreId;
  451. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandId);
  452. if (items == null)
  453. {
  454. CheckSendInfo rows = new CheckSendInfo()
  455. {
  456. BrandId = BrandId,
  457. Num = 1
  458. };
  459. checksendInfos.Add(rows);
  460. }
  461. else
  462. {
  463. items.Num += 1;
  464. }
  465. }
  466. for (int i = 0; i < ApplyList.Count; i++)
  467. {
  468. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  469. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  470. var kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds) ?? new KqProducts();
  471. FromStoreId = kqProducts.MainStoreId;
  472. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  473. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandIds) ?? new CheckSendInfo();
  474. if (items.Num > num)
  475. {
  476. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量过多!";
  477. }
  478. if (items.Num < num)
  479. {
  480. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量不足!";
  481. }
  482. }
  483. List<string> PosSnList = new List<string>();
  484. for (int index = 1; index < list.Count; index++)
  485. {
  486. JsonData dr = list[index];
  487. string itemJson = dr.ToJson();
  488. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  489. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  490. BrandId = Convert.ToInt32(Brand);
  491. var kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new KqProducts();
  492. FromStoreId = kqProducts.MainStoreId;
  493. MachineForSnNo posInfo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  494. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posInfo.SnId && m.StoreId == FromStoreId && m.UserId == 0 && m.BuyUserId == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  495. if (pos.BindingState == 1 || pos.ActivationState == 1)
  496. {
  497. error += "以下操作失败" + SnNo + ',' + "该机具已绑定或已激活" + '\n';
  498. }
  499. if (posInfo.SnId > 0)
  500. {
  501. if (pos.Id > 0)
  502. {
  503. if (pos.BrandId != BrandId)
  504. {
  505. error += "以下操作失败" + SnNo + ',' + "该机具品牌填写错误" + '\n';
  506. }
  507. }
  508. if (PosSnList.Contains(SnNo))
  509. {
  510. error += "以下操作失败" + SnNo + ',' + "该机具重复发货" + '\n';
  511. }
  512. PosSnList.Add(SnNo);
  513. }
  514. else
  515. {
  516. error += "以下操作失败" + SnNo + ',' + "未找到该机具或者该机具不符合发货条件" + '\n';
  517. }
  518. }
  519. if (!string.IsNullOrEmpty(error))
  520. {
  521. return "Warning|" + error;
  522. }
  523. Dictionary<string, int> storeData = new Dictionary<string, int>();
  524. Dictionary<string, int> toStoreData = new Dictionary<string, int>();
  525. for (int index = 1; index < list.Count; index++)
  526. {
  527. JsonData dr = list[index];
  528. string itemJson = dr.ToJson();
  529. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  530. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  531. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  532. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  533. BrandId = Convert.ToInt32(Brand);
  534. var kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new KqProducts();
  535. FromStoreId = kqProducts.MainStoreId;
  536. tostore = db.StoreHouse.FirstOrDefault(m => m.Sort > 0 && m.UserId == apply.UserId && m.BrandId == BrandId.ToString() && m.Status == 1);
  537. SendInfo item = sendInfos.FirstOrDefault(m => m.FromStoreId == FromStoreId && m.ToStoreId == tostore.Id && m.BrandId == BrandId);
  538. if (item == null)
  539. {
  540. SendInfo row = new SendInfo()
  541. {
  542. FromStoreId = FromStoreId,
  543. ToStoreId = tostore.Id,
  544. BrandId = BrandId,
  545. Num = 1
  546. };
  547. sendInfos.Add(row);
  548. }
  549. else
  550. {
  551. item.Num += 1;
  552. }
  553. apply.SeoDescription = function.CheckString(SnNo) + ',';
  554. fromstore = db.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId);
  555. MachineForSnNo machinefor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  556. PosMachinesTwo machine = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machinefor.SnId && m.BuyUserId == 0 && m.UserId == 0) ?? new PosMachinesTwo();
  557. if (machine.Id > 0)
  558. {
  559. if (machine.BrandId != BrandId)
  560. {
  561. return machine.PosSn + "与表格里填写的品牌不一致";
  562. }
  563. else
  564. {
  565. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  566. {
  567. CreateDate = DateTime.Now,
  568. CreateMan = SysUserName,
  569. Sort = data.Id,//库存变动关联申请记录表
  570. StoreId = FromStoreId, //出货仓库
  571. BrandId = BrandId, //产品类型
  572. ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
  573. BizBatchNo = BatchNo, //业务批次号
  574. TransType = 1, //交易类型
  575. SnNo = SnNo, //SN编号
  576. StockOpDirect = 1, //库存操作方向
  577. SnStatus = 1, //SN状态
  578. DeviceVendor = machine.DeviceName, //设备厂商
  579. DeviceModel = machine.DeviceKind, //设备型号
  580. DeviceType = machine.DeviceType, //设备类型
  581. FromUserId = fromstore.UserId, //出货人
  582. FromDate = DateTime.Now, //出库时间
  583. FromRemark = OutNote, //出库备注
  584. ToUserId = tostore.UserId, //收货人
  585. ToStoreId = fromstore.Id, //退货收货仓库
  586. SourceStoreId = machine.SourceStoreId, //源仓库编号
  587. BrandType = machine.DeviceType, //品牌类型
  588. }).Entity;
  589. string ChangeNo = "CS";
  590. int StoreStockChangeId = stockchange.Id;
  591. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  592. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  593. {
  594. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  595. }
  596. ChangeNo += StoreStockChangeIdString;
  597. stockchange.ChangeNo = ChangeNo; //交易流水编号
  598. machine.StoreId = tostore.Id;
  599. db.StoreChangeHistory.Add(new StoreChangeHistory()
  600. {
  601. CreateDate = DateTime.Now,
  602. UserId = fromstore.UserId, //创客
  603. BrandId = BrandId, //产品类型
  604. ChangeRecordNo = ChangeNo, //变更记录单号
  605. BizBatchNo = BatchNo, //业务批次号
  606. TransType = 1, //交易类型
  607. SnNo = SnNo, //SN编号
  608. SnType = machine.PosSnType, //SN机具类型
  609. StockOpDirect = 1, //库存操作方向
  610. DeviceVendor = machine.DeviceName, //设备厂商
  611. DeviceModel = machine.DeviceKind, //设备型号
  612. DeviceType = machine.DeviceType, //设备类型
  613. FromUserId = fromstore.UserId, //出货创客
  614. FromDate = DateTime.Now, //出库时间
  615. FromRemark = OutNote, //出库备注
  616. SourceStoreId = machine.SourceStoreId, //源仓库
  617. StoreId = fromstore.Id, //仓库
  618. ToUserId = tostore.UserId,//收货创客
  619. });
  620. //修改机具所属仓库
  621. machine.StoreId = tostore.Id;
  622. machine.UpdateDate = DateTime.Now;
  623. db.SaveChanges();
  624. }
  625. }
  626. else
  627. {
  628. return "总仓无该机具";
  629. }
  630. }
  631. foreach (var item in sendInfos)
  632. {
  633. //出货仓库数据调整
  634. StoreHouse storeCH = db.StoreHouse.FirstOrDefault(m => m.Id == item.FromStoreId) ?? new StoreHouse();
  635. StoreBalance balance = db.StoreBalance.Add(new StoreBalance()
  636. {
  637. CreateDate = DateTime.Now,
  638. StoreId = storeCH.Id, //仓库
  639. TransType = 1, //交易类型
  640. BrandId = BrandId, //产品类型
  641. OpStoreNum = item.Num, //操作库存数
  642. OpSymbol = "-", //操作符
  643. BeforeTotalNum = storeCH.TotalNum, //操作前总库存数
  644. AfterTotalNum = storeCH.TotalNum - item.Num, //操作后总库存数
  645. BeforeLaveNum = storeCH.LaveNum, //操作前剩余库存数
  646. AfterLaveNum = storeCH.LaveNum - item.Num, //操作后剩余库存数
  647. BeforeOutNum = storeCH.OutNum, //操作前出库数
  648. AfterOutNum = storeCH.OutNum + item.Num, //操作后出库数
  649. }).Entity;
  650. string ChangeNo1 = "CS";
  651. int StoreStockChangeId1 = balance.Id;
  652. string StoreStockChangeId1String = StoreStockChangeId1.ToString();
  653. for (int i = 0; i < 18 - StoreStockChangeId1.ToString().Length; i++)
  654. {
  655. StoreStockChangeId1String = "0" + StoreStockChangeId1String;
  656. }
  657. ChangeNo1 += StoreStockChangeId1String;
  658. balance.TransRecordNo = ChangeNo1; //交易流水编号
  659. storeCH.LaveNum -= item.Num;
  660. storeCH.OutNum += item.Num;
  661. //收货仓库数据调整
  662. StoreHouse storeSH = db.StoreHouse.FirstOrDefault(m => m.Id == item.ToStoreId) ?? new StoreHouse();
  663. balance = db.StoreBalance.Add(new StoreBalance()
  664. {
  665. CreateDate = DateTime.Now,
  666. StoreId = storeSH.Id, //仓库
  667. TransType = 0, //交易类型
  668. BrandId = BrandId, //产品类型
  669. OpStoreNum = item.Num, //操作库存数
  670. OpSymbol = "+", //操作符
  671. BeforeTotalNum = storeSH.TotalNum, //操作前总库存数
  672. AfterTotalNum = storeSH.TotalNum + item.Num, //操作后总库存数
  673. BeforeLaveNum = storeSH.LaveNum, //操作前剩余库存数
  674. AfterLaveNum = storeSH.LaveNum + item.Num, //操作后剩余库存数
  675. BeforeOutNum = storeSH.OutNum, //操作前出库数
  676. AfterOutNum = storeSH.OutNum, //操作后出库数
  677. }).Entity;
  678. string ChangeNo2 = "CS";
  679. int StoreStockChangeId2 = balance.Id;
  680. string StoreStockChangeId2String = StoreStockChangeId2.ToString();
  681. for (int i = 0; i < 18 - StoreStockChangeId2.ToString().Length; i++)
  682. {
  683. StoreStockChangeId2String = "0" + StoreStockChangeId2String;
  684. }
  685. ChangeNo2 += StoreStockChangeId2String;
  686. balance.TransRecordNo = ChangeNo2; //交易流水编号
  687. storeSH.TotalNum += item.Num;
  688. storeSH.LaveNum += item.Num;
  689. }
  690. apply.SeoTitle = SysUserName + '-' + SysRealName;//添加操作人信息
  691. apply.UseAmount = ApplyAmount;
  692. db.SaveChanges();
  693. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, data.Id);
  694. string SendData = "{\"Kind\":\"2\",\"Data\":{\"UserId\":\"" + apply.UserId + "\",\"Amount\":\"" + Amount + "\",\"OperateType\":\"1\"}}";
  695. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  696. return "success";
  697. }
  698. #endregion
  699. //发货信息实体类
  700. private class SendInfo
  701. {
  702. public int FromStoreId { get; set; }
  703. public int ToStoreId { get; set; }
  704. public int BrandId { get; set; }
  705. public int Num { get; set; }
  706. }
  707. //检查发货信息实体类
  708. private class CheckSendInfo
  709. {
  710. public int BrandId { get; set; }
  711. public int Num { get; set; }
  712. }
  713. }
  714. }