MachineApplyController.cs 32 KB

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