StoreMachineApplyOperateController.cs 45 KB

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