MachineApplyController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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. //恢复仓库申请订单数量
  404. store.ApplyNum -= list.Length;
  405. db.SaveChanges();
  406. }
  407. }
  408. }
  409. }
  410. return "success";
  411. }
  412. #endregion
  413. #region 开启
  414. /// <summary>
  415. /// 开启
  416. /// </summary>
  417. /// <returns></returns>
  418. public string Open(string Id)
  419. {
  420. string[] idlist = Id.Split(new char[] { ',' });
  421. AddSysLog(Id, "MachineApply", "open");
  422. foreach (string subid in idlist)
  423. {
  424. int id = int.Parse(subid);
  425. Dictionary<string, object> Fields = new Dictionary<string, object>();
  426. Fields.Add("Status", 1);
  427. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, id);
  428. }
  429. db.SaveChanges();
  430. return "success";
  431. }
  432. #endregion
  433. #region 关闭
  434. /// <summary>
  435. /// 关闭
  436. /// </summary>
  437. /// <returns></returns>
  438. public string Close(string Id)
  439. {
  440. string[] idlist = Id.Split(new char[] { ',' });
  441. AddSysLog(Id, "MachineApply", "close");
  442. foreach (string subid in idlist)
  443. {
  444. int id = int.Parse(subid);
  445. Dictionary<string, object> Fields = new Dictionary<string, object>();
  446. Fields.Add("Status", 0);
  447. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, id);
  448. }
  449. db.SaveChanges();
  450. return "success";
  451. }
  452. #endregion
  453. #region 排序
  454. /// <summary>
  455. /// 排序
  456. /// </summary>
  457. /// <param name="Id"></param>
  458. public string Sort(int Id, int Sort)
  459. {
  460. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("MachineApply", Sort, Id);
  461. AddSysLog(Id.ToString(), "MachineApply", "sort");
  462. return "success";
  463. }
  464. #endregion
  465. #region 导入数据
  466. /// <summary>
  467. /// 导入数据
  468. /// </summary>
  469. /// <param name="ExcelData"></param>
  470. public string Import(string ExcelData)
  471. {
  472. ExcelData = HttpUtility.UrlDecode(ExcelData);
  473. JsonData list = JsonMapper.ToObject(ExcelData);
  474. for (int i = 1; i < list.Count; i++)
  475. {
  476. JsonData dr = list[i];
  477. db.MachineApply.Add(new MachineApply()
  478. {
  479. CreateDate = DateTime.Now,
  480. UpdateDate = DateTime.Now,
  481. });
  482. db.SaveChanges();
  483. }
  484. AddSysLog("0", "MachineApply", "Import");
  485. return "success";
  486. }
  487. #endregion
  488. #region 导出Excel
  489. /// <summary>
  490. /// 导出Excel
  491. /// </summary>
  492. /// <returns></returns>
  493. public JsonResult ExportExcel(MachineApply data, string MakerCode, string RealName, string StoreNo, string StoreName, string StoreMakerCode, string StatusSelect, string SendStatusSelect, string StoreTypeSelect)
  494. {
  495. Dictionary<string, string> Fields = new Dictionary<string, string>();
  496. Fields.Add("ApplyNo", "1"); //申请单号
  497. Fields.Add("BrandId", "1"); //品牌
  498. Fields.Add("ApplyTime", "3"); //申请时间
  499. Fields.Add("ExpressNo", "1"); //快递单号
  500. Fields.Add("DeliveryType", "0"); //提货类型
  501. Fields.Add("StoreManager", "1"); //仓库联系人
  502. Fields.Add("SendDate", "3"); //发货时间
  503. Fields.Add("TopUserId", "0"); //顶级创客
  504. Fields.Add("SwapSnExpand", "1"); //兑换SN
  505. Fields.Add("SendSn", "1"); //发货SN
  506. string condition = " and Status>-1";
  507. //创客编号
  508. if (!string.IsNullOrEmpty(MakerCode))
  509. {
  510. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  511. }
  512. //创客名称
  513. if (!string.IsNullOrEmpty(RealName))
  514. {
  515. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  516. }
  517. //仓库编号
  518. if (!string.IsNullOrEmpty(StoreNo))
  519. {
  520. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  521. }
  522. //仓库名称
  523. if (!string.IsNullOrEmpty(RealName))
  524. {
  525. condition += " and StoreId in (select StoreId from StoreForName where Name='" + RealName + "')";
  526. }
  527. //仓库归属创客编号
  528. if (!string.IsNullOrEmpty(StoreMakerCode))
  529. {
  530. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + StoreMakerCode + "')";
  531. }
  532. //订单状态
  533. if (!string.IsNullOrEmpty(StatusSelect))
  534. {
  535. condition += " and Status=" + StatusSelect;
  536. }
  537. //发货状态
  538. if (!string.IsNullOrEmpty(SendStatusSelect))
  539. {
  540. condition += " and SendStatus=" + SendStatusSelect;
  541. }
  542. //仓库类型
  543. if (!string.IsNullOrEmpty(StoreTypeSelect))
  544. {
  545. condition += " and StoreType=" + StoreTypeSelect;
  546. }
  547. 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);
  548. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  549. foreach (Dictionary<string, object> dic in diclist)
  550. {
  551. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  552. //发货仓库
  553. int StoreId = int.Parse(dic["StoreId"].ToString());
  554. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  555. dic["StoreNo"] = store.StoreNo;
  556. dic["StoreName"] = store.StoreName;
  557. //仓库归属信息
  558. int StoreUserId = int.Parse(dic["StoreUserId"].ToString());
  559. Users storeUser = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  560. dic["StoreMakerCode"] = storeUser.MakerCode;
  561. int StoreType = int.Parse(dic["StoreType"].ToString());
  562. if (StoreType == 0) dic["StoreType"] = "总仓";
  563. if (StoreType == 1) dic["StoreType"] = "分仓";
  564. //创客信息
  565. int UserId = int.Parse(dic["UserId"].ToString());
  566. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  567. dic["MakerCode"] = puser.MakerCode;
  568. dic["MakerName"] = puser.RealName;
  569. //顶级创客
  570. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  571. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  572. dic["TopMakerCode"] = tuser.MakerCode;
  573. dic["TopRealName"] = tuser.RealName;
  574. //订单状态
  575. int Status = int.Parse(dic["Status"].ToString());
  576. if (Status == 0) dic["Status"] = "待审核";
  577. if (Status == 1) dic["Status"] = "申请成功";
  578. if (Status == 2) dic["Status"] = "申请失败";
  579. //提货方式
  580. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  581. if (DeliveryType == 0) dic["DeliveryType"] = "";
  582. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  583. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  584. //发货状态
  585. int SendStatus = int.Parse(dic["SendStatus"].ToString());
  586. if (SendStatus == 0) dic["SendStatus"] = "未发货";
  587. if (SendStatus == 1) dic["SendStatus"] = "已发货";
  588. dic.Remove("UserId");
  589. dic.Remove("TopUserId");
  590. dic.Remove("StoreId");
  591. dic.Remove("StoreUserId");
  592. }
  593. Dictionary<string, object> result = new Dictionary<string, object>();
  594. result.Add("Status", "1");
  595. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  596. result.Add("Obj", diclist);
  597. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  598. ReturnFields.Add("ApplyNo", "申请单号");
  599. ReturnFields.Add("StoreNo", "发货仓库编号");
  600. ReturnFields.Add("StoreName", "发货仓库名称");
  601. ReturnFields.Add("StoreMakerCode", "仓库归属创客编号");
  602. ReturnFields.Add("StoreRealName", "仓库归属创客名称");
  603. ReturnFields.Add("MakerCode", "创客编号");
  604. ReturnFields.Add("MakerName", "创客名称");
  605. ReturnFields.Add("StoreType", "仓库类型");
  606. ReturnFields.Add("StoreManager", "仓库联系人");
  607. ReturnFields.Add("StoreManagerMobile", "仓库联系人手机号");
  608. ReturnFields.Add("BrandId", "产品类型");
  609. ReturnFields.Add("Areas", "收货所在地区");
  610. ReturnFields.Add("Address", "收货详细地址");
  611. ReturnFields.Add("RealName", "收件人姓名");
  612. ReturnFields.Add("Mobile", "收件人手机号");
  613. ReturnFields.Add("ApplyDeviceName", "申请机具名称");
  614. ReturnFields.Add("ApplyDeviceNum", "申请机具数量");
  615. ReturnFields.Add("Status", "订单状态");
  616. ReturnFields.Add("ApplyTime", "申请时间");
  617. ReturnFields.Add("SendStatus", "发货状态");
  618. ReturnFields.Add("SendDate", "发货时间");
  619. ReturnFields.Add("ExpressNo", "快递单号");
  620. ReturnFields.Add("ExpressName", "快递名称");
  621. ReturnFields.Add("DeliveryType", "提货类型");
  622. ReturnFields.Add("Remark", "订单备注");
  623. result.Add("Fields", ReturnFields);
  624. AddSysLog("0", "MachineApply", "ExportExcel");
  625. return Json(result);
  626. }
  627. #endregion
  628. #region 审核发货
  629. public IActionResult AuditSend(string right, int Id = 0)
  630. {
  631. ViewBag.RightInfo = RightInfo;
  632. ViewBag.right = right;
  633. MachineApply editData = db.MachineApply.FirstOrDefault(m => m.Id == Id) ?? new MachineApply();
  634. ViewBag.data = editData;
  635. return View();
  636. }
  637. #endregion
  638. #region 审核发货
  639. [HttpPost]
  640. public string AuditSend(MachineApply data)
  641. {
  642. Dictionary<string, object> Fields = new Dictionary<string, object>();
  643. Fields.Add("ExpressNo", data.ExpressNo);
  644. Fields.Add("ExpressName", data.ExpressName);
  645. Fields.Add("StoreId", data.StoreId);
  646. Fields.Add("AuditResult", data.AuditResult);
  647. Fields.Add("SendSn", data.SendSn);
  648. Fields.Add("SendStatus", 1);
  649. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, data.Id);
  650. AddSysLog(data.Id.ToString(), "MachineApply", "AuditSend");
  651. db.SaveChanges();
  652. return "success";
  653. }
  654. #endregion
  655. }
  656. }