StoreMachineApplyController.cs 38 KB

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