MachineApplyController.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * 机具申请订单
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class MachineApplyController : BaseController
  23. {
  24. public MachineApplyController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 机具申请订单列表
  29. /// <summary>
  30. /// 根据条件查询机具申请订单列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(MachineApply data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询机具申请订单列表
  41. /// <summary>
  42. /// 机具申请订单列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(MachineApply data, string MakerCode, string RealName, string StoreNo, string StoreName, string StoreMakerCode, string StatusSelect, string SendStatusSelect, string StoreTypeSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("ApplyNo", "1"); //申请单号
  49. Fields.Add("BrandId", "1"); //品牌
  50. Fields.Add("ApplyTime", "3"); //申请时间
  51. Fields.Add("ExpressNo", "1"); //快递单号
  52. Fields.Add("DeliveryType", "0"); //提货类型
  53. Fields.Add("StoreManager", "1"); //仓库联系人
  54. Fields.Add("SendDate", "3"); //发货时间
  55. Fields.Add("TopUserId", "0"); //顶级创客
  56. Fields.Add("SwapSnExpand", "1"); //兑换SN
  57. Fields.Add("SendSn", "1"); //发货SN
  58. string condition = " and Status>-1";
  59. //创客编号
  60. if (!string.IsNullOrEmpty(MakerCode))
  61. {
  62. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  63. }
  64. //创客名称
  65. if (!string.IsNullOrEmpty(RealName))
  66. {
  67. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  68. }
  69. //仓库编号
  70. if (!string.IsNullOrEmpty(StoreNo))
  71. {
  72. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  73. }
  74. //仓库名称
  75. if (!string.IsNullOrEmpty(StoreName))
  76. {
  77. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  78. }
  79. //仓库归属创客编号
  80. if (!string.IsNullOrEmpty(StoreMakerCode))
  81. {
  82. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + StoreMakerCode + "')";
  83. }
  84. //订单状态
  85. if(!string.IsNullOrEmpty(StatusSelect))
  86. {
  87. condition += " and Status=" + StatusSelect;
  88. }
  89. //发货状态
  90. if(!string.IsNullOrEmpty(SendStatusSelect))
  91. {
  92. condition += " and SendStatus=" + SendStatusSelect;
  93. }
  94. //仓库类型
  95. if(!string.IsNullOrEmpty(StoreTypeSelect))
  96. {
  97. condition += " and StoreType=" + StoreTypeSelect;
  98. }
  99. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("MachineApply", Fields, "Id desc", "0", page, limit, condition);
  100. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  101. foreach (Dictionary<string, object> dic in diclist)
  102. {
  103. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  104. //发货仓库
  105. int StoreId = int.Parse(dic["StoreId"].ToString());
  106. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  107. dic["StoreInfo"] = store.StoreNo + "<br />" + store.StoreName;
  108. //仓库联系人信息
  109. dic["StoreContact"] = dic["StoreManagerMobile"].ToString() + "<br />" + dic["StoreManager"].ToString();
  110. //仓库归属信息
  111. int StoreUserId = int.Parse(dic["StoreUserId"].ToString());
  112. Users storeUser = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  113. int StoreType = int.Parse(dic["StoreType"].ToString());
  114. string StoreTypeName = "";
  115. if(StoreType == 0) StoreTypeName = "总仓";
  116. if(StoreType == 1) StoreTypeName = "分仓";
  117. dic["StoreUser"] = storeUser.MakerCode + "<br />" + StoreTypeName;
  118. //创客信息
  119. int UserId = int.Parse(dic["UserId"].ToString());
  120. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  121. dic["UserInfo"] = puser.MakerCode + "<br />" + puser.RealName;
  122. //顶级创客
  123. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  124. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  125. dic["TopUserInfo"] = tuser.MakerCode + "<br />" + tuser.RealName;
  126. //收件人姓名-联系电话
  127. dic["StoreContact"] = dic["RealName"].ToString() + "<br />" + dic["Mobile"].ToString();
  128. //订单状态
  129. int Status = int.Parse(dic["Status"].ToString());
  130. if(Status == 0) dic["Status"] = "待审核";
  131. if(Status == 1) dic["Status"] = "申请成功";
  132. if(Status == 2) dic["Status"] = "申请失败";
  133. //提货方式
  134. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  135. if(DeliveryType == 0) dic["DeliveryType"] = "";
  136. if(DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  137. if(DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  138. //发货状态
  139. int SendStatus = int.Parse(dic["SendStatus"].ToString());
  140. if(SendStatus == 0) dic["SendStatus"] = "未发货";
  141. if(SendStatus == 1) dic["SendStatus"] = "已发货";
  142. //快递单号-快递名称
  143. dic["ExpressInfo"] = dic["ExpressName"].ToString() + "<br />" + dic["ExpressNo"].ToString();
  144. }
  145. Dictionary<string, object> other = new Dictionary<string, object>();
  146. other.Add("ApplyCount", 0);
  147. other.Add("SendCount", 0);
  148. obj.Add("other", other);
  149. return Json(obj);
  150. }
  151. #endregion
  152. #region 增加机具申请订单
  153. /// <summary>
  154. /// 增加或修改机具申请订单信息
  155. /// </summary>
  156. /// <returns></returns>
  157. public IActionResult Add(string right)
  158. {
  159. ViewBag.RightInfo = RightInfo;
  160. ViewBag.right = right;
  161. return View();
  162. }
  163. #endregion
  164. #region 增加机具申请订单
  165. /// <summary>
  166. /// 增加或修改机具申请订单信息
  167. /// </summary>
  168. /// <returns></returns>
  169. [HttpPost]
  170. public string Add(MachineApply data)
  171. {
  172. Dictionary<string, object> Fields = new Dictionary<string, object>();
  173. Fields.Add("SeoTitle", data.SeoTitle);
  174. Fields.Add("SeoKeyword", data.SeoKeyword);
  175. Fields.Add("SeoDescription", data.SeoDescription);
  176. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("MachineApply", Fields, 0);
  177. AddSysLog(data.Id.ToString(), "MachineApply", "add");
  178. db.SaveChanges();
  179. return "success";
  180. }
  181. #endregion
  182. #region 修改机具申请订单
  183. /// <summary>
  184. /// 增加或修改机具申请订单信息
  185. /// </summary>
  186. /// <returns></returns>
  187. public IActionResult Edit(string right, int Id = 0)
  188. {
  189. ViewBag.RightInfo = RightInfo;
  190. ViewBag.right = right;
  191. MachineApply editData = db.MachineApply.FirstOrDefault(m => m.Id == Id) ?? new MachineApply();
  192. ViewBag.data = editData;
  193. Users user = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  194. ViewBag.MakerCode = user.MakerCode;
  195. ViewBag.RealName = user.RealName;
  196. int Status = editData.Status;
  197. if(Status == 0) ViewBag.Status = "待审核";
  198. if(Status == 1) ViewBag.Status = "申请成功";
  199. if(Status == 2) ViewBag.Status = "申请失败";
  200. int AuditResult = editData.AuditResult;
  201. if(AuditResult == 0) ViewBag.AuditResult = "未通过";
  202. if(AuditResult == 1) ViewBag.AuditResult = "通过";
  203. //邮寄方式
  204. int DeliveryType = editData.DeliveryType;
  205. if(DeliveryType == 1) ViewBag.DeliveryType = "邮寄到付";
  206. if(DeliveryType == 2) ViewBag.DeliveryType = "上门自提";
  207. //发货状态
  208. int SendStatus = editData.SendStatus;
  209. if(SendStatus == 0) ViewBag.SendStatus = "未发货";
  210. if(SendStatus == 1) ViewBag.SendStatus = "已发货";
  211. return View();
  212. }
  213. #endregion
  214. #region 修改机具申请订单
  215. /// <summary>
  216. /// 增加或修改机具申请订单信息
  217. /// </summary>
  218. /// <returns></returns>
  219. [HttpPost]
  220. public string Edit(MachineApply data)
  221. {
  222. Dictionary<string, object> Fields = new Dictionary<string, object>();
  223. Fields.Add("SeoTitle", data.SeoTitle);
  224. Fields.Add("SeoKeyword", data.SeoKeyword);
  225. Fields.Add("SeoDescription", data.SeoDescription);
  226. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, data.Id);
  227. AddSysLog(data.Id.ToString(), "MachineApply", "update");
  228. db.SaveChanges();
  229. return "success";
  230. }
  231. #endregion
  232. #region 删除机具申请订单信息
  233. /// <summary>
  234. /// 删除机具申请订单信息
  235. /// </summary>
  236. /// <returns></returns>
  237. public string Delete(string Id)
  238. {
  239. string[] idlist = Id.Split(new char[] { ',' });
  240. AddSysLog(Id, "MachineApply", "del");
  241. foreach (string subid in idlist)
  242. {
  243. int id = int.Parse(subid);
  244. Dictionary<string, object> Fields = new Dictionary<string, object>();
  245. Fields.Add("Status", -1);
  246. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, id);
  247. }
  248. db.SaveChanges();
  249. return "success";
  250. }
  251. #endregion
  252. #region 取消机具申请订单
  253. /// <summary>
  254. /// 取消机具申请订单
  255. /// </summary>
  256. /// <returns></returns>
  257. public string Cancel(int Id)
  258. {
  259. AddSysLog(Id, "MachineApply", "cancel");
  260. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.Id == Id);
  261. if (apply != null)
  262. {
  263. Orders order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount);
  264. if (order != null)
  265. {
  266. string SwapSnExpand = apply.SwapSnExpand;
  267. if (!string.IsNullOrEmpty(SwapSnExpand))
  268. {
  269. string[] list = SwapSnExpand.TrimEnd('\n').Split('\n');
  270. if (apply.Sort > 0)
  271. {
  272. int Kind = apply.Sort - 1;
  273. string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  274. int CouponCount = 0;
  275. foreach (string sub in list)
  276. {
  277. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == sub && m.UserId == order.UserId && m.IsUse == 1);
  278. if (coupon != null)
  279. {
  280. coupon.IsUse = 0;
  281. coupon.IsLock = 0;
  282. coupon.UseDate = DateTime.Parse("1900-01-01");
  283. PosCouponRecord query = db.PosCouponRecord.Add(new PosCouponRecord()
  284. {
  285. QueryCount = Kind,
  286. CreateDate = DateTime.Now,
  287. ChangeKind = 1,
  288. OrderNo = ChangeRecordNo,
  289. ToUserId = order.UserId,
  290. FromUserId = order.UserId,
  291. PosCouponId = coupon.Id,
  292. }).Entity;
  293. CouponCount += 1;
  294. }
  295. }
  296. if (CouponCount > 0)
  297. {
  298. PosCouponForUser forUser = db.PosCouponForUser.FirstOrDefault(m => m.Id == order.UserId);
  299. if (forUser == null)
  300. {
  301. forUser = db.PosCouponForUser.Add(new PosCouponForUser()
  302. {
  303. Id = order.UserId,
  304. }).Entity;
  305. db.SaveChanges();
  306. }
  307. int BeforeOut = forUser.OutNum;
  308. int BeforeTotal = forUser.TotalNum;
  309. int BeforeStock = forUser.StockNum;
  310. forUser.StockNum += CouponCount;
  311. int AfterOut = forUser.OutNum;
  312. int AfterTotal = forUser.TotalNum;
  313. int AfterStock = forUser.StockNum;
  314. PosCouponOrders stat = db.PosCouponOrders.Add(new PosCouponOrders()
  315. {
  316. QueryCount = Kind,
  317. CreateDate = DateTime.Now,
  318. ChangeKind = 1,
  319. ChangeCount = CouponCount,
  320. AfterOut = AfterOut,
  321. AfterTotal = AfterTotal,
  322. AfterStock = AfterStock,
  323. BeforeOut = BeforeOut,
  324. BeforeTotal = BeforeTotal,
  325. BeforeStock = BeforeStock,
  326. OrderNo = ChangeRecordNo,
  327. ToUserId = order.UserId,
  328. FromUserId = order.UserId,
  329. }).Entity;
  330. }
  331. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(apply) + "#cut#" + Newtonsoft.Json.JsonConvert.SerializeObject(order) + "#cut#" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "机具申请订单取消日志");
  332. db.MachineApply.Remove(apply);
  333. db.Orders.Remove(order);
  334. db.SaveChanges();
  335. }
  336. else
  337. {
  338. foreach (string sub in list)
  339. {
  340. string SourcePosSn = sub.Split(':')[0];
  341. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourcePosSn) ?? new MachineForSnNo();
  342. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  343. if (pos != null)
  344. {
  345. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(apply) + "#cut#" + Newtonsoft.Json.JsonConvert.SerializeObject(order) + "#cut#" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "机具申请订单取消日志");
  346. pos.IsPurchase = 0;
  347. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  348. }
  349. }
  350. db.MachineApply.Remove(apply);
  351. db.Orders.Remove(order);
  352. db.SaveChanges();
  353. }
  354. }
  355. }
  356. }
  357. return "success";
  358. }
  359. #endregion
  360. #region 开启
  361. /// <summary>
  362. /// 开启
  363. /// </summary>
  364. /// <returns></returns>
  365. public string Open(string Id)
  366. {
  367. string[] idlist = Id.Split(new char[] { ',' });
  368. AddSysLog(Id, "MachineApply", "open");
  369. foreach (string subid in idlist)
  370. {
  371. int id = int.Parse(subid);
  372. Dictionary<string, object> Fields = new Dictionary<string, object>();
  373. Fields.Add("Status", 1);
  374. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, id);
  375. }
  376. db.SaveChanges();
  377. return "success";
  378. }
  379. #endregion
  380. #region 关闭
  381. /// <summary>
  382. /// 关闭
  383. /// </summary>
  384. /// <returns></returns>
  385. public string Close(string Id)
  386. {
  387. string[] idlist = Id.Split(new char[] { ',' });
  388. AddSysLog(Id, "MachineApply", "close");
  389. foreach (string subid in idlist)
  390. {
  391. int id = int.Parse(subid);
  392. Dictionary<string, object> Fields = new Dictionary<string, object>();
  393. Fields.Add("Status", 0);
  394. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, id);
  395. }
  396. db.SaveChanges();
  397. return "success";
  398. }
  399. #endregion
  400. #region 排序
  401. /// <summary>
  402. /// 排序
  403. /// </summary>
  404. /// <param name="Id"></param>
  405. public string Sort(int Id, int Sort)
  406. {
  407. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("MachineApply", Sort, Id);
  408. AddSysLog(Id.ToString(), "MachineApply", "sort");
  409. return "success";
  410. }
  411. #endregion
  412. #region 导入数据
  413. /// <summary>
  414. /// 导入数据
  415. /// </summary>
  416. /// <param name="ExcelData"></param>
  417. public string Import(string ExcelData)
  418. {
  419. ExcelData = HttpUtility.UrlDecode(ExcelData);
  420. JsonData list = JsonMapper.ToObject(ExcelData);
  421. for (int i = 1; i < list.Count; i++)
  422. {
  423. JsonData dr = list[i];
  424. db.MachineApply.Add(new MachineApply()
  425. {
  426. CreateDate = DateTime.Now,
  427. UpdateDate = DateTime.Now,
  428. });
  429. db.SaveChanges();
  430. }
  431. AddSysLog("0", "MachineApply", "Import");
  432. return "success";
  433. }
  434. #endregion
  435. #region 导出Excel
  436. /// <summary>
  437. /// 导出Excel
  438. /// </summary>
  439. /// <returns></returns>
  440. public JsonResult ExportExcel(MachineApply data, string MakerCode, string RealName, string StoreNo, string StoreName, string StoreMakerCode, string StatusSelect, string SendStatusSelect, string StoreTypeSelect)
  441. {
  442. Dictionary<string, string> Fields = new Dictionary<string, string>();
  443. Fields.Add("ApplyNo", "1"); //申请单号
  444. Fields.Add("BrandId", "1"); //品牌
  445. Fields.Add("ApplyTime", "3"); //申请时间
  446. Fields.Add("ExpressNo", "1"); //快递单号
  447. Fields.Add("DeliveryType", "0"); //提货类型
  448. Fields.Add("StoreManager", "1"); //仓库联系人
  449. Fields.Add("SendDate", "3"); //发货时间
  450. Fields.Add("TopUserId", "0"); //顶级创客
  451. Fields.Add("SwapSnExpand", "1"); //兑换SN
  452. Fields.Add("SendSn", "1"); //发货SN
  453. string condition = " and Status>-1";
  454. //创客编号
  455. if (!string.IsNullOrEmpty(MakerCode))
  456. {
  457. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  458. }
  459. //创客名称
  460. if (!string.IsNullOrEmpty(RealName))
  461. {
  462. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  463. }
  464. //仓库编号
  465. if (!string.IsNullOrEmpty(StoreNo))
  466. {
  467. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  468. }
  469. //仓库名称
  470. if (!string.IsNullOrEmpty(RealName))
  471. {
  472. condition += " and StoreId in (select StoreId from StoreForName where Name='" + RealName + "')";
  473. }
  474. //仓库归属创客编号
  475. if (!string.IsNullOrEmpty(StoreMakerCode))
  476. {
  477. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + StoreMakerCode + "')";
  478. }
  479. //订单状态
  480. if(!string.IsNullOrEmpty(StatusSelect))
  481. {
  482. condition += " and Status=" + StatusSelect;
  483. }
  484. //发货状态
  485. if(!string.IsNullOrEmpty(SendStatusSelect))
  486. {
  487. condition += " and SendStatus=" + SendStatusSelect;
  488. }
  489. //仓库类型
  490. if(!string.IsNullOrEmpty(StoreTypeSelect))
  491. {
  492. condition += " and StoreType=" + StoreTypeSelect;
  493. }
  494. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("MachineApply", Fields, "Id desc", "0", 1, 20000, condition, "ApplyNo,UserId,TopUserId,BrandId,Areas,Address,RealName,Mobile,ApplyDeviceName,ApplyDeviceNum,ApplyTime,SendStatus,ExpressNo,ExpressName,DeliveryType,StoreId,StoreName,StoreManager,StoreManagerMobile,Remark,StoreUserId,SendDate,StoreType,Status", false);
  495. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  496. foreach (Dictionary<string, object> dic in diclist)
  497. {
  498. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  499. //发货仓库
  500. int StoreId = int.Parse(dic["StoreId"].ToString());
  501. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  502. dic["StoreNo"] = store.StoreNo;
  503. dic["StoreName"] = store.StoreName;
  504. //仓库归属信息
  505. int StoreUserId = int.Parse(dic["StoreUserId"].ToString());
  506. Users storeUser = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  507. dic["StoreMakerCode"] = storeUser.MakerCode;
  508. int StoreType = int.Parse(dic["StoreType"].ToString());
  509. if(StoreType == 0) dic["StoreType"] = "总仓";
  510. if(StoreType == 1) dic["StoreType"] = "分仓";
  511. //创客信息
  512. int UserId = int.Parse(dic["UserId"].ToString());
  513. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  514. dic["MakerCode"] = puser.MakerCode;
  515. dic["MakerName"] = puser.RealName;
  516. //顶级创客
  517. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  518. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  519. dic["TopMakerCode"] = tuser.MakerCode;
  520. dic["TopRealName"] = tuser.RealName;
  521. //订单状态
  522. int Status = int.Parse(dic["Status"].ToString());
  523. if(Status == 0) dic["Status"] = "待审核";
  524. if(Status == 1) dic["Status"] = "申请成功";
  525. if(Status == 2) dic["Status"] = "申请失败";
  526. //提货方式
  527. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  528. if(DeliveryType == 0) dic["DeliveryType"] = "";
  529. if(DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  530. if(DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  531. //发货状态
  532. int SendStatus = int.Parse(dic["SendStatus"].ToString());
  533. if(SendStatus == 0) dic["SendStatus"] = "未发货";
  534. if(SendStatus == 1) dic["SendStatus"] = "已发货";
  535. dic.Remove("UserId");
  536. dic.Remove("TopUserId");
  537. dic.Remove("StoreId");
  538. dic.Remove("StoreUserId");
  539. }
  540. Dictionary<string, object> result = new Dictionary<string, object>();
  541. result.Add("Status", "1");
  542. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  543. result.Add("Obj", diclist);
  544. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  545. ReturnFields.Add("ApplyNo", "申请单号");
  546. ReturnFields.Add("StoreNo", "发货仓库编号");
  547. ReturnFields.Add("StoreName", "发货仓库名称");
  548. ReturnFields.Add("StoreMakerCode", "仓库归属创客编号");
  549. ReturnFields.Add("StoreRealName", "仓库归属创客名称");
  550. ReturnFields.Add("MakerCode", "创客编号");
  551. ReturnFields.Add("MakerName", "创客名称");
  552. ReturnFields.Add("StoreType", "仓库类型");
  553. ReturnFields.Add("StoreManager", "仓库联系人");
  554. ReturnFields.Add("StoreManagerMobile", "仓库联系人手机号");
  555. ReturnFields.Add("BrandId", "产品类型");
  556. ReturnFields.Add("Areas", "收货所在地区");
  557. ReturnFields.Add("Address", "收货详细地址");
  558. ReturnFields.Add("RealName", "收件人姓名");
  559. ReturnFields.Add("Mobile", "收件人手机号");
  560. ReturnFields.Add("ApplyDeviceName", "申请机具名称");
  561. ReturnFields.Add("ApplyDeviceNum", "申请机具数量");
  562. ReturnFields.Add("Status", "订单状态");
  563. ReturnFields.Add("ApplyTime", "申请时间");
  564. ReturnFields.Add("SendStatus", "发货状态");
  565. ReturnFields.Add("SendDate", "发货时间");
  566. ReturnFields.Add("ExpressNo", "快递单号");
  567. ReturnFields.Add("ExpressName", "快递名称");
  568. ReturnFields.Add("DeliveryType", "提货类型");
  569. ReturnFields.Add("Remark", "订单备注");
  570. result.Add("Fields", ReturnFields);
  571. AddSysLog("0", "MachineApply", "ExportExcel");
  572. return Json(result);
  573. }
  574. #endregion
  575. #region 审核发货
  576. public IActionResult AuditSend(string right, int Id = 0)
  577. {
  578. ViewBag.RightInfo = RightInfo;
  579. ViewBag.right = right;
  580. MachineApply editData = db.MachineApply.FirstOrDefault(m => m.Id == Id) ?? new MachineApply();
  581. ViewBag.data = editData;
  582. return View();
  583. }
  584. #endregion
  585. #region 审核发货
  586. [HttpPost]
  587. public string AuditSend(MachineApply data)
  588. {
  589. Dictionary<string, object> Fields = new Dictionary<string, object>();
  590. Fields.Add("ExpressNo", data.ExpressNo);
  591. Fields.Add("ExpressName", data.ExpressName);
  592. Fields.Add("StoreId", data.StoreId);
  593. Fields.Add("AuditResult", data.AuditResult);
  594. Fields.Add("SendSn", data.SendSn);
  595. Fields.Add("SendStatus", 1);
  596. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, data.Id);
  597. AddSysLog(data.Id.ToString(), "MachineApply", "AuditSend");
  598. db.SaveChanges();
  599. return "success";
  600. }
  601. #endregion
  602. }
  603. }