MachineApplyController.cs 31 KB

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