MachineApplyController.cs 31 KB

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