StoreMachineApplyOperateController.cs 44 KB

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