StoreMachineApplyOperateController.cs 44 KB

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