MachineApplyController.cs 30 KB

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