StoreMachineApplyOperateController.cs 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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.UserId;
  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("SeoKeyword", data.SeoKeyword);
  262. Fields.Add("SeoDescription", data.SeoDescription);
  263. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, data.Id);
  264. AddSysLog(data.Id.ToString(), "OpStoreMachineApply", "update");
  265. db.SaveChanges();
  266. return "success";
  267. }
  268. #endregion
  269. #region 删除分仓机具申请记录信息
  270. /// <summary>
  271. /// 删除分仓机具申请记录信息
  272. /// </summary>
  273. /// <returns></returns>
  274. public string Delete(string Id)
  275. {
  276. string[] idlist = Id.Split(new char[] { ',' });
  277. AddSysLog(Id, "StoreMachineApply", "del");
  278. foreach (string subid in idlist)
  279. {
  280. int id = int.Parse(subid);
  281. Dictionary<string, object> Fields = new Dictionary<string, object>();
  282. Fields.Add("Status", -1);
  283. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
  284. }
  285. db.SaveChanges();
  286. return "success";
  287. }
  288. #endregion
  289. #region 开启
  290. /// <summary>
  291. /// 开启
  292. /// </summary>
  293. /// <returns></returns>
  294. public string Open(string Id)
  295. {
  296. string[] idlist = Id.Split(new char[] { ',' });
  297. AddSysLog(Id, "StoreMachineApply", "open");
  298. foreach (string subid in idlist)
  299. {
  300. int id = int.Parse(subid);
  301. Dictionary<string, object> Fields = new Dictionary<string, object>();
  302. Fields.Add("Status", 1);
  303. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
  304. }
  305. db.SaveChanges();
  306. return "success";
  307. }
  308. #endregion
  309. #region 关闭
  310. /// <summary>
  311. /// 关闭
  312. /// </summary>
  313. /// <returns></returns>
  314. public string Close(string Id)
  315. {
  316. string[] idlist = Id.Split(new char[] { ',' });
  317. AddSysLog(Id, "StoreMachineApplyOperate", "close");
  318. foreach (string subid in idlist)
  319. {
  320. int id = int.Parse(subid);
  321. Dictionary<string, object> Fields = new Dictionary<string, object>();
  322. Fields.Add("Status", 2);
  323. var query = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == id);
  324. string[] amountlist = query.SeoTitle.Split(',');
  325. decimal ValidAmount = decimal.Parse(amountlist[0]);
  326. decimal TotalAmt = decimal.Parse(amountlist[1]);
  327. decimal ValidForGetAmount = decimal.Parse(amountlist[2]);
  328. var users = opdb.UserAccount.FirstOrDefault(m => m.Status == 0 && m.UserId == query.UserId) ?? new UserAccount();
  329. if (users.Id > 0)
  330. {
  331. var amountRecord = opdb.AmountRecord.Add(new AmountRecord()
  332. {
  333. CreateDate = DateTime.Now,
  334. CreateMan = SysUserName + "-" + SysRealName,
  335. SeoDescription = "机具申请驳回",
  336. OperateType = 1,//增加
  337. BeforeAmount = users.ValidAmount + users.TotalAmt + users.ValidForGetAmount,
  338. AfterAmount = users.ValidAmount + users.TotalAmt + users.ValidForGetAmount + query.UseAmount,
  339. UseAmount = query.UseAmount,
  340. UserId = query.UserId,
  341. ApplyId = query.Id,
  342. }).Entity;
  343. users.ValidAmount += ValidAmount;
  344. users.TotalAmt += TotalAmt;
  345. users.ValidForGetAmount += ValidForGetAmount;
  346. opdb.SaveChanges();
  347. }
  348. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
  349. }
  350. db.SaveChanges();
  351. return "success";
  352. }
  353. #endregion
  354. #region 排序
  355. /// <summary>
  356. /// 排序
  357. /// </summary>
  358. /// <param name="Id"></param>
  359. public string Sort(int Id, int Sort)
  360. {
  361. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Sort("StoreMachineApply", Sort, Id);
  362. AddSysLog(Id.ToString(), "StoreMachineApply", "sort");
  363. return "success";
  364. }
  365. #endregion
  366. #region 导入数据
  367. /// <summary>
  368. /// 导入数据
  369. /// </summary>
  370. /// <param name="ExcelData"></param>
  371. public string Import(string ExcelData)
  372. {
  373. ExcelData = HttpUtility.UrlDecode(ExcelData);
  374. JsonData list = JsonMapper.ToObject(ExcelData);
  375. for (int i = 1; i < list.Count; i++)
  376. {
  377. JsonData dr = list[i];
  378. opdb.StoreMachineApply.Add(new StoreMachineApply()
  379. {
  380. CreateDate = DateTime.Now,
  381. UpdateDate = DateTime.Now,
  382. });
  383. db.SaveChanges();
  384. }
  385. AddSysLog("0", "OpStoreMachineApply", "Import");
  386. return "success";
  387. }
  388. #endregion
  389. #region 导出Excel
  390. /// <summary>
  391. /// 导出Excel
  392. /// </summary>
  393. /// <returns></returns>
  394. public JsonResult ExportExcel(StoreMachineApply data, string BrandIdSelect, string UserIdRealName, string UserIdMakerCode)
  395. {
  396. Dictionary<string, string> Fields = new Dictionary<string, string>();
  397. Fields.Add("CreateDate", "3"); //时间
  398. Fields.Add("ApplyNo", "1"); //申请单号
  399. Fields.Add("SendMode", "1"); //发货方式
  400. string condition = " and Status>-1";
  401. //品牌
  402. if (!string.IsNullOrEmpty(BrandIdSelect))
  403. {
  404. condition += " and BrandId=" + BrandIdSelect;
  405. }
  406. //创客真实姓名
  407. if (!string.IsNullOrEmpty(UserIdRealName))
  408. {
  409. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  410. }
  411. //创客编号
  412. if (!string.IsNullOrEmpty(UserIdMakerCode))
  413. {
  414. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  415. }
  416. 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);
  417. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  418. foreach (Dictionary<string, object> dic in diclist)
  419. {
  420. //品牌
  421. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  422. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  423. //运营中心
  424. int OpId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  425. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Id == OpId) ?? new SysAdmin();
  426. // Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  427. dic["MakerName"] = sysAdmin.MakerName;
  428. dic["MakerCode"] = sysAdmin.MakerCode;
  429. dic["OpCode"] = sysAdmin.OpCode;
  430. dic.Remove("OpId");
  431. }
  432. Dictionary<string, object> result = new Dictionary<string, object>();
  433. result.Add("Status", "1");
  434. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  435. result.Add("Obj", diclist);
  436. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  437. ReturnFields.Add("BrandId", "品牌");
  438. ReturnFields.Add("ApplyNo", "申请单号");
  439. ReturnFields.Add("ApplyNum", "申请台数");
  440. ReturnFields.Add("SendNum", "发货台数");
  441. ReturnFields.Add("UseAmount", "使用额度");
  442. ReturnFields.Add("SendMode", "发货方式");
  443. ReturnFields.Add("ErpCode", "快递单号");
  444. ReturnFields.Add("MakerName", "创客真实姓名");
  445. ReturnFields.Add("MakerName", "创客编号");
  446. ReturnFields.Add("OpCode", "运营中心编号");
  447. result.Add("Fields", ReturnFields);
  448. AddSysLog("0", "OpStoreMachineApply", "ExportExcel");
  449. return Json(result);
  450. }
  451. #endregion
  452. #region 审核发货
  453. public IActionResult AuditSend(string right, int Id = 0)
  454. {
  455. ViewBag.RightInfo = RightInfo;
  456. ViewBag.right = right;
  457. StoreMachineApply editData = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  458. ViewBag.data = editData;
  459. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status == 0 && m.UserId == editData.UserId) ?? new SysAdmin();
  460. ViewBag.OpCode = sysAdmin.OpCode;
  461. ViewBag.MakerCode = sysAdmin.MakerCode;
  462. ViewBag.MakerName = sysAdmin.MakerName;
  463. return View();
  464. }
  465. #endregion
  466. #region 审核发货
  467. [HttpPost]
  468. public string AuditSend(StoreMachineApply data, string ExcelData)
  469. {
  470. Dictionary<string, object> Fields = new Dictionary<string, object>();
  471. Fields.Add("ApplyNum", data.ApplyNum); //申请数
  472. Fields.Add("SendNum", data.ApplyNum); //发货数
  473. Fields.Add("ErpCode", data.ErpCode); //快递单号
  474. Fields.Add("SendMode", data.SendMode); //发货方式
  475. Fields.Add("SeoKeyword", data.SeoKeyword); //申请描述
  476. Fields.Add("Status", 1);
  477. AddSysLog(data.Id.ToString(), "StoreMachineApply", "AuditSend");
  478. Dictionary<string, object> Obj = new Dictionary<string, object>();
  479. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  480. List<SendInfo> sendInfos = new List<SendInfo>();
  481. List<CheckSendInfo> checksendInfos = new List<CheckSendInfo>();
  482. StoreMachineApply apply = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == data.Id) ?? new StoreMachineApply();
  483. string[] amountlist = apply.SeoTitle.Split(',');
  484. decimal ValidAmount = decimal.Parse(amountlist[0]);
  485. decimal TotalAmt = decimal.Parse(amountlist[1]);
  486. decimal ValidForGetAmount = decimal.Parse(amountlist[2]);
  487. JsonData ApplyList = JsonMapper.ToObject(apply.SendSn);
  488. decimal ApplyAmount = 0;
  489. decimal Amount = 0;
  490. for (int i = 0; i < ApplyList.Count; i++)
  491. {
  492. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  493. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  494. //自动匹配品牌
  495. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  496. if (brandInfo.Name.Contains("电签"))
  497. {
  498. ApplyAmount += num * 100;
  499. }
  500. if (brandInfo.Name.Contains("大POS"))
  501. {
  502. ApplyAmount += num * 150;
  503. }
  504. }
  505. Amount = apply.UseAmount - ApplyAmount;
  506. Models.StoreHouse tostore = new Models.StoreHouse();
  507. Models.StoreHouse fromstore = new Models.StoreHouse();
  508. var BrandId = 0;
  509. var FromStoreId = 0;
  510. string error = "";
  511. if (string.IsNullOrEmpty(ExcelData))
  512. {
  513. return "Warning|" + "请选择要导入的数据";
  514. }
  515. ExcelData = HttpUtility.UrlDecode(ExcelData);
  516. JsonData list = JsonMapper.ToObject(ExcelData);
  517. //判断各品牌发货数量是否符合
  518. if (list.Count - 1 > apply.ApplyNum)
  519. {
  520. return "Warning|" + "机具发货数量过多!";
  521. }
  522. if (list.Count - 1 < apply.ApplyNum)
  523. {
  524. return "Warning|" + "机具发货数量不足!";
  525. }
  526. for (int index = 1; index < list.Count; index++)
  527. {
  528. JsonData dr = list[index];
  529. string itemJson = dr.ToJson();
  530. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  531. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  532. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  533. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  534. BrandId = Convert.ToInt32(Brand);
  535. if (BrandId == 1) FromStoreId = 7;
  536. if (BrandId == 2) FromStoreId = 721;
  537. if (BrandId == 3) FromStoreId = 697;
  538. if (BrandId == 4) FromStoreId = 774;
  539. if (BrandId == 5) FromStoreId = 775;
  540. if (BrandId == 6) FromStoreId = 871;
  541. if (BrandId == 7) FromStoreId = 1047;
  542. if (BrandId == 8) FromStoreId = 4831;
  543. if (BrandId == 9) FromStoreId = 4832;
  544. if (BrandId == 10) FromStoreId = 5512;
  545. if (BrandId == 11) FromStoreId = 5513;
  546. if (BrandId == 12) FromStoreId = 0;
  547. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandId);
  548. if (items == null)
  549. {
  550. CheckSendInfo rows = new CheckSendInfo()
  551. {
  552. BrandId = BrandId,
  553. Num = 1
  554. };
  555. checksendInfos.Add(rows);
  556. }
  557. else
  558. {
  559. items.Num += 1;
  560. }
  561. }
  562. for (int i = 0; i < ApplyList.Count; i++)
  563. {
  564. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  565. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  566. if (BrandIds == 1) FromStoreId = 7;
  567. if (BrandIds == 2) FromStoreId = 721;
  568. if (BrandIds == 3) FromStoreId = 697;
  569. if (BrandIds == 4) FromStoreId = 774;
  570. if (BrandIds == 5) FromStoreId = 775;
  571. if (BrandIds == 6) FromStoreId = 871;
  572. if (BrandIds == 7) FromStoreId = 1047;
  573. if (BrandIds == 8) FromStoreId = 4831;
  574. if (BrandIds == 9) FromStoreId = 4832;
  575. if (BrandId == 10) FromStoreId = 5512;
  576. if (BrandId == 11) FromStoreId = 5513;
  577. if (BrandId == 12) FromStoreId = 0;
  578. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  579. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandIds) ?? new CheckSendInfo();
  580. if (items.Num > num)
  581. {
  582. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量过多!";
  583. }
  584. if (items.Num < num)
  585. {
  586. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量不足!";
  587. }
  588. }
  589. List<string> PosSnList = new List<string>();
  590. for (int index = 1; index < list.Count; index++)
  591. {
  592. JsonData dr = list[index];
  593. string itemJson = dr.ToJson();
  594. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  595. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  596. BrandId = Convert.ToInt32(Brand);
  597. if (BrandId == 1) FromStoreId = 7;
  598. if (BrandId == 2) FromStoreId = 721;
  599. if (BrandId == 3) FromStoreId = 697;
  600. if (BrandId == 4) FromStoreId = 774;
  601. if (BrandId == 5) FromStoreId = 775;
  602. if (BrandId == 6) FromStoreId = 871;
  603. if (BrandId == 7) FromStoreId = 1047;
  604. if (BrandId == 8) FromStoreId = 4831;
  605. if (BrandId == 9) FromStoreId = 4832;
  606. if (BrandId == 10) FromStoreId = 5512;
  607. if (BrandId == 11) FromStoreId = 5513;
  608. if (BrandId == 12) FromStoreId = 0;
  609. Models.MachineForSnNo posInfo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new Models.MachineForSnNo();
  610. 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();
  611. if (pos.BindingState == 1 || pos.ActivationState == 1)
  612. {
  613. error += "以下操作失败" + SnNo + ',' + "该机具已绑定或已激活" + '\n';
  614. }
  615. if (posInfo.SnId > 0)
  616. {
  617. if (pos.Id > 0)
  618. {
  619. if (pos.BrandId != BrandId)
  620. {
  621. error += "以下操作失败" + SnNo + ',' + "该机具品牌填写错误" + '\n';
  622. }
  623. }
  624. if (PosSnList.Contains(SnNo))
  625. {
  626. error += "以下操作失败" + SnNo + ',' + "该机具重复发货" + '\n';
  627. }
  628. PosSnList.Add(SnNo);
  629. }
  630. else
  631. {
  632. error += "以下操作失败" + SnNo + ',' + "未找到该机具或者该机具不符合发货条件" + '\n';
  633. }
  634. }
  635. if (!string.IsNullOrEmpty(error))
  636. {
  637. return "Warning|" + error;
  638. }
  639. Dictionary<string, int> storeData = new Dictionary<string, int>();
  640. Dictionary<string, int> toStoreData = new Dictionary<string, int>();
  641. var amount = 0;
  642. for (int index = 1; index < list.Count; index++)
  643. {
  644. JsonData dr = list[index];
  645. string itemJson = dr.ToJson();
  646. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  647. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  648. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  649. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  650. BrandId = Convert.ToInt32(Brand);
  651. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandId);
  652. if (brandInfo != null)
  653. {
  654. if (brandInfo.Name.Contains("电签"))
  655. {
  656. amount = 100;
  657. }
  658. if (brandInfo.Name.Contains("大POS"))
  659. {
  660. amount = 150;
  661. }
  662. }
  663. if (BrandId == 1) FromStoreId = 7;
  664. if (BrandId == 2) FromStoreId = 721;
  665. if (BrandId == 3) FromStoreId = 697;
  666. if (BrandId == 4) FromStoreId = 774;
  667. if (BrandId == 5) FromStoreId = 775;
  668. if (BrandId == 6) FromStoreId = 871;
  669. if (BrandId == 7) FromStoreId = 1047;
  670. if (BrandId == 8) FromStoreId = 4831;
  671. if (BrandId == 9) FromStoreId = 4832;
  672. if (BrandId == 10) FromStoreId = 5512;
  673. if (BrandId == 11) FromStoreId = 5513;
  674. if (BrandId == 12) FromStoreId = 0;
  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. // //额度标记
  765. // if (ValidAmount >= amount)
  766. // {
  767. // ValidAmount -= amount;
  768. // // machine.OpReserveKind = 3;
  769. // }
  770. // else if (TotalAmt >= amount)
  771. // {
  772. // TotalAmt -= amount;
  773. // // machine.OpReserveKind = 1;
  774. // }
  775. // else if (ValidForGetAmount >= amount)
  776. // {
  777. // ValidForGetAmount -= amount;
  778. // // machine.OpReserveKind = 2;
  779. // }
  780. if (ValidAmount >= amount)
  781. {
  782. ValidAmount -= amount;
  783. machine.OpReserve3 = amount;
  784. machine.OpReserve1 = 0;
  785. machine.OpReserve2 = 0;
  786. }
  787. else
  788. {
  789. if (TotalAmt >= amount)
  790. {
  791. TotalAmt -= amount - ValidAmount;
  792. machine.OpReserve3 = ValidAmount;
  793. machine.OpReserve1 = amount - ValidAmount;
  794. machine.OpReserve2 = 0;
  795. }
  796. else
  797. {
  798. if (ValidForGetAmount >= amount)
  799. {
  800. ValidForGetAmount -= amount - TotalAmt;
  801. machine.OpReserve3 = 0;
  802. machine.OpReserve1 = TotalAmt;
  803. machine.OpReserve2 = amount - TotalAmt;
  804. }
  805. }
  806. }
  807. db.SaveChanges();
  808. }
  809. }
  810. else
  811. {
  812. return "总仓无该机具";
  813. }
  814. }
  815. foreach (var item in sendInfos)
  816. {
  817. //出货仓库数据调整
  818. Models.StoreHouse storeCH = db.StoreHouse.FirstOrDefault(m => m.Id == item.FromStoreId) ?? new Models.StoreHouse();
  819. Models.StoreBalance balance = db.StoreBalance.Add(new Models.StoreBalance()
  820. {
  821. CreateDate = DateTime.Now,
  822. StoreId = storeCH.Id, //仓库
  823. TransType = 1, //交易类型
  824. BrandId = BrandId, //产品类型
  825. OpStoreNum = item.Num, //操作库存数
  826. OpSymbol = "-", //操作符
  827. BeforeTotalNum = storeCH.TotalNum, //操作前总库存数
  828. AfterTotalNum = storeCH.TotalNum - item.Num, //操作后总库存数
  829. BeforeLaveNum = storeCH.LaveNum, //操作前剩余库存数
  830. AfterLaveNum = storeCH.LaveNum - item.Num, //操作后剩余库存数
  831. BeforeOutNum = storeCH.OutNum, //操作前出库数
  832. AfterOutNum = storeCH.OutNum + item.Num, //操作后出库数
  833. }).Entity;
  834. string ChangeNo1 = "CS";
  835. int StoreStockChangeId1 = balance.Id;
  836. string StoreStockChangeId1String = StoreStockChangeId1.ToString();
  837. for (int i = 0; i < 18 - StoreStockChangeId1.ToString().Length; i++)
  838. {
  839. StoreStockChangeId1String = "0" + StoreStockChangeId1String;
  840. }
  841. ChangeNo1 += StoreStockChangeId1String;
  842. balance.TransRecordNo = ChangeNo1; //交易流水编号
  843. storeCH.LaveNum -= item.Num;
  844. storeCH.OutNum += item.Num;
  845. //收货仓库数据调整
  846. Models.StoreHouse storeSH = db.StoreHouse.FirstOrDefault(m => m.Id == item.ToStoreId) ?? new Models.StoreHouse();
  847. balance = db.StoreBalance.Add(new Models.StoreBalance()
  848. {
  849. CreateDate = DateTime.Now,
  850. StoreId = storeSH.Id, //仓库
  851. TransType = 0, //交易类型
  852. BrandId = BrandId, //产品类型
  853. OpStoreNum = item.Num, //操作库存数
  854. OpSymbol = "+", //操作符
  855. BeforeTotalNum = storeSH.TotalNum, //操作前总库存数
  856. AfterTotalNum = storeSH.TotalNum + item.Num, //操作后总库存数
  857. BeforeLaveNum = storeSH.LaveNum, //操作前剩余库存数
  858. AfterLaveNum = storeSH.LaveNum + item.Num, //操作后剩余库存数
  859. BeforeOutNum = storeSH.OutNum, //操作前出库数
  860. AfterOutNum = storeSH.OutNum, //操作后出库数
  861. }).Entity;
  862. string ChangeNo2 = "CS";
  863. int StoreStockChangeId2 = balance.Id;
  864. string StoreStockChangeId2String = StoreStockChangeId2.ToString();
  865. for (int i = 0; i < 18 - StoreStockChangeId2.ToString().Length; i++)
  866. {
  867. StoreStockChangeId2String = "0" + StoreStockChangeId2String;
  868. }
  869. ChangeNo2 += StoreStockChangeId2String;
  870. balance.TransRecordNo = ChangeNo2; //交易流水编号
  871. storeSH.TotalNum += item.Num;
  872. storeSH.LaveNum += item.Num;
  873. var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.Status == 0 && m.UserId == storeSH.UserId) ?? new SysAdmin();
  874. if (sysAdmin.Id > 0)
  875. {
  876. sysAdmin.TotalMachineCount += item.Num;
  877. opdb.SaveChanges();
  878. }
  879. }
  880. apply.SeoTitle = SysUserName + '-' + SysRealName;//添加操作人信息
  881. apply.UseAmount = ApplyAmount;
  882. db.SaveChanges();
  883. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, data.Id);
  884. string SendData = "{\"Kind\":\"2\",\"Data\":{\"UserId\":\"" + apply.UserId + "\",\"Amount\":\"" + Amount + "\",\"OperateType\":\"1\"}}";
  885. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  886. return "success";
  887. }
  888. #endregion
  889. //发货信息实体类
  890. private class SendInfo
  891. {
  892. public int FromStoreId { get; set; }
  893. public int ToStoreId { get; set; }
  894. public int BrandId { get; set; }
  895. public int Num { get; set; }
  896. }
  897. //检查发货信息实体类
  898. private class CheckSendInfo
  899. {
  900. public int BrandId { get; set; }
  901. public int Num { get; set; }
  902. }
  903. }
  904. }