MachineApplyController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. string key = function.MD5_16(apply.UserId + apply.OrderExpand);
  318. string[] list = SwapSnExpand.TrimEnd('\n').Split('\n');
  319. if (apply.Sort > 0)
  320. {
  321. int Kind = apply.Sort - 1;
  322. string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  323. int CouponCount = 0;
  324. foreach (string sub in list)
  325. {
  326. PosCoupons coupon = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == sub && m.UserId == order.UserId && m.IsUse == 1);
  327. if (coupon != null)
  328. {
  329. coupon.IsUse = 0;
  330. coupon.IsLock = 0;
  331. coupon.UseDate = DateTime.Parse("1900-01-01");
  332. PosCouponRecord query = db.PosCouponRecord.Add(new PosCouponRecord()
  333. {
  334. QueryCount = Kind,
  335. CreateDate = DateTime.Now,
  336. ChangeKind = 1,
  337. OrderNo = ChangeRecordNo,
  338. ToUserId = order.UserId,
  339. FromUserId = order.UserId,
  340. PosCouponId = coupon.Id,
  341. }).Entity;
  342. CouponCount += 1;
  343. }
  344. }
  345. if (CouponCount > 0)
  346. {
  347. PosCouponForUser forUser = db.PosCouponForUser.FirstOrDefault(m => m.Id == order.UserId);
  348. if (forUser == null)
  349. {
  350. forUser = db.PosCouponForUser.Add(new PosCouponForUser()
  351. {
  352. Id = order.UserId,
  353. }).Entity;
  354. db.SaveChanges();
  355. }
  356. int BeforeOut = forUser.OutNum;
  357. int BeforeTotal = forUser.TotalNum;
  358. int BeforeStock = forUser.StockNum;
  359. forUser.StockNum += CouponCount;
  360. int AfterOut = forUser.OutNum;
  361. int AfterTotal = forUser.TotalNum;
  362. int AfterStock = forUser.StockNum;
  363. PosCouponOrders stat = db.PosCouponOrders.Add(new PosCouponOrders()
  364. {
  365. QueryCount = Kind,
  366. CreateDate = DateTime.Now,
  367. ChangeKind = 1,
  368. ChangeCount = CouponCount,
  369. AfterOut = AfterOut,
  370. AfterTotal = AfterTotal,
  371. AfterStock = AfterStock,
  372. BeforeOut = BeforeOut,
  373. BeforeTotal = BeforeTotal,
  374. BeforeStock = BeforeStock,
  375. OrderNo = ChangeRecordNo,
  376. ToUserId = order.UserId,
  377. FromUserId = order.UserId,
  378. }).Entity;
  379. }
  380. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(apply) + "#cut#" + Newtonsoft.Json.JsonConvert.SerializeObject(order) + "#cut#" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "机具申请订单取消日志");
  381. db.MachineApply.Remove(apply);
  382. db.Orders.Remove(order);
  383. db.SaveChanges();
  384. }
  385. else
  386. {
  387. foreach (string sub in list)
  388. {
  389. string SourcePosSn = sub.Split(':')[0];
  390. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourcePosSn) ?? new MachineForSnNo();
  391. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  392. if (pos != null)
  393. {
  394. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(apply) + "#cut#" + Newtonsoft.Json.JsonConvert.SerializeObject(order) + "#cut#" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "机具申请订单取消日志");
  395. pos.IsPurchase = 0;
  396. }
  397. }
  398. db.MachineApply.Remove(apply);
  399. db.Orders.Remove(order);
  400. db.SaveChanges();
  401. }
  402. RedisDbconn.Instance.Clear("ConfirmApply2:" + key);
  403. }
  404. }
  405. }
  406. return "success";
  407. }
  408. #endregion
  409. #region 开启
  410. /// <summary>
  411. /// 开启
  412. /// </summary>
  413. /// <returns></returns>
  414. public string Open(string Id)
  415. {
  416. string[] idlist = Id.Split(new char[] { ',' });
  417. AddSysLog(Id, "MachineApply", "open");
  418. foreach (string subid in idlist)
  419. {
  420. int id = int.Parse(subid);
  421. Dictionary<string, object> Fields = new Dictionary<string, object>();
  422. Fields.Add("Status", 1);
  423. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, id);
  424. }
  425. db.SaveChanges();
  426. return "success";
  427. }
  428. #endregion
  429. #region 关闭
  430. /// <summary>
  431. /// 关闭
  432. /// </summary>
  433. /// <returns></returns>
  434. public string Close(string Id)
  435. {
  436. string[] idlist = Id.Split(new char[] { ',' });
  437. AddSysLog(Id, "MachineApply", "close");
  438. foreach (string subid in idlist)
  439. {
  440. int id = int.Parse(subid);
  441. Dictionary<string, object> Fields = new Dictionary<string, object>();
  442. Fields.Add("Status", 0);
  443. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, id);
  444. }
  445. db.SaveChanges();
  446. return "success";
  447. }
  448. #endregion
  449. #region 排序
  450. /// <summary>
  451. /// 排序
  452. /// </summary>
  453. /// <param name="Id"></param>
  454. public string Sort(int Id, int Sort)
  455. {
  456. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("MachineApply", Sort, Id);
  457. AddSysLog(Id.ToString(), "MachineApply", "sort");
  458. return "success";
  459. }
  460. #endregion
  461. #region 导入数据
  462. /// <summary>
  463. /// 导入数据
  464. /// </summary>
  465. /// <param name="ExcelData"></param>
  466. public string Import(string ExcelData)
  467. {
  468. ExcelData = HttpUtility.UrlDecode(ExcelData);
  469. JsonData list = JsonMapper.ToObject(ExcelData);
  470. for (int i = 1; i < list.Count; i++)
  471. {
  472. JsonData dr = list[i];
  473. db.MachineApply.Add(new MachineApply()
  474. {
  475. CreateDate = DateTime.Now,
  476. UpdateDate = DateTime.Now,
  477. });
  478. db.SaveChanges();
  479. }
  480. AddSysLog("0", "MachineApply", "Import");
  481. return "success";
  482. }
  483. #endregion
  484. #region 导出Excel
  485. /// <summary>
  486. /// 导出Excel
  487. /// </summary>
  488. /// <returns></returns>
  489. public JsonResult ExportExcel(MachineApply data, string MakerCode, string RealName, string StoreNo, string StoreName, string StoreMakerCode, string StatusSelect, string SendStatusSelect, string StoreTypeSelect)
  490. {
  491. Dictionary<string, string> Fields = new Dictionary<string, string>();
  492. Fields.Add("ApplyNo", "1"); //申请单号
  493. Fields.Add("BrandId", "1"); //品牌
  494. Fields.Add("ApplyTime", "3"); //申请时间
  495. Fields.Add("ExpressNo", "1"); //快递单号
  496. Fields.Add("DeliveryType", "0"); //提货类型
  497. Fields.Add("StoreManager", "1"); //仓库联系人
  498. Fields.Add("SendDate", "3"); //发货时间
  499. Fields.Add("TopUserId", "0"); //顶级创客
  500. Fields.Add("SwapSnExpand", "1"); //兑换SN
  501. Fields.Add("SendSn", "1"); //发货SN
  502. string condition = " and Status>-1";
  503. //创客编号
  504. if (!string.IsNullOrEmpty(MakerCode))
  505. {
  506. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  507. }
  508. //创客名称
  509. if (!string.IsNullOrEmpty(RealName))
  510. {
  511. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  512. }
  513. //仓库编号
  514. if (!string.IsNullOrEmpty(StoreNo))
  515. {
  516. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  517. }
  518. //仓库名称
  519. if (!string.IsNullOrEmpty(RealName))
  520. {
  521. condition += " and StoreId in (select StoreId from StoreForName where Name='" + RealName + "')";
  522. }
  523. //仓库归属创客编号
  524. if (!string.IsNullOrEmpty(StoreMakerCode))
  525. {
  526. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + StoreMakerCode + "')";
  527. }
  528. //订单状态
  529. if (!string.IsNullOrEmpty(StatusSelect))
  530. {
  531. condition += " and Status=" + StatusSelect;
  532. }
  533. //发货状态
  534. if (!string.IsNullOrEmpty(SendStatusSelect))
  535. {
  536. condition += " and SendStatus=" + SendStatusSelect;
  537. }
  538. //仓库类型
  539. if (!string.IsNullOrEmpty(StoreTypeSelect))
  540. {
  541. condition += " and StoreType=" + StoreTypeSelect;
  542. }
  543. 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);
  544. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  545. foreach (Dictionary<string, object> dic in diclist)
  546. {
  547. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  548. //发货仓库
  549. int StoreId = int.Parse(dic["StoreId"].ToString());
  550. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  551. dic["StoreNo"] = store.StoreNo;
  552. dic["StoreName"] = store.StoreName;
  553. //仓库归属信息
  554. int StoreUserId = int.Parse(dic["StoreUserId"].ToString());
  555. Users storeUser = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  556. dic["StoreMakerCode"] = storeUser.MakerCode;
  557. int StoreType = int.Parse(dic["StoreType"].ToString());
  558. if (StoreType == 0) dic["StoreType"] = "总仓";
  559. if (StoreType == 1) dic["StoreType"] = "分仓";
  560. //创客信息
  561. int UserId = int.Parse(dic["UserId"].ToString());
  562. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  563. dic["MakerCode"] = puser.MakerCode;
  564. dic["MakerName"] = puser.RealName;
  565. //顶级创客
  566. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  567. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  568. dic["TopMakerCode"] = tuser.MakerCode;
  569. dic["TopRealName"] = tuser.RealName;
  570. //订单状态
  571. int Status = int.Parse(dic["Status"].ToString());
  572. if (Status == 0) dic["Status"] = "待审核";
  573. if (Status == 1) dic["Status"] = "申请成功";
  574. if (Status == 2) dic["Status"] = "申请失败";
  575. //提货方式
  576. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  577. if (DeliveryType == 0) dic["DeliveryType"] = "";
  578. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  579. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  580. //发货状态
  581. int SendStatus = int.Parse(dic["SendStatus"].ToString());
  582. if (SendStatus == 0) dic["SendStatus"] = "未发货";
  583. if (SendStatus == 1) dic["SendStatus"] = "已发货";
  584. dic.Remove("UserId");
  585. dic.Remove("TopUserId");
  586. dic.Remove("StoreId");
  587. dic.Remove("StoreUserId");
  588. }
  589. Dictionary<string, object> result = new Dictionary<string, object>();
  590. result.Add("Status", "1");
  591. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  592. result.Add("Obj", diclist);
  593. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  594. ReturnFields.Add("ApplyNo", "申请单号");
  595. ReturnFields.Add("StoreNo", "发货仓库编号");
  596. ReturnFields.Add("StoreName", "发货仓库名称");
  597. ReturnFields.Add("StoreMakerCode", "仓库归属创客编号");
  598. ReturnFields.Add("StoreRealName", "仓库归属创客名称");
  599. ReturnFields.Add("MakerCode", "创客编号");
  600. ReturnFields.Add("MakerName", "创客名称");
  601. ReturnFields.Add("StoreType", "仓库类型");
  602. ReturnFields.Add("StoreManager", "仓库联系人");
  603. ReturnFields.Add("StoreManagerMobile", "仓库联系人手机号");
  604. ReturnFields.Add("BrandId", "产品类型");
  605. ReturnFields.Add("Areas", "收货所在地区");
  606. ReturnFields.Add("Address", "收货详细地址");
  607. ReturnFields.Add("RealName", "收件人姓名");
  608. ReturnFields.Add("Mobile", "收件人手机号");
  609. ReturnFields.Add("ApplyDeviceName", "申请机具名称");
  610. ReturnFields.Add("ApplyDeviceNum", "申请机具数量");
  611. ReturnFields.Add("Status", "订单状态");
  612. ReturnFields.Add("ApplyTime", "申请时间");
  613. ReturnFields.Add("SendStatus", "发货状态");
  614. ReturnFields.Add("SendDate", "发货时间");
  615. ReturnFields.Add("ExpressNo", "快递单号");
  616. ReturnFields.Add("ExpressName", "快递名称");
  617. ReturnFields.Add("DeliveryType", "提货类型");
  618. ReturnFields.Add("Remark", "订单备注");
  619. result.Add("Fields", ReturnFields);
  620. AddSysLog("0", "MachineApply", "ExportExcel");
  621. return Json(result);
  622. }
  623. #endregion
  624. #region 审核发货
  625. public IActionResult AuditSend(string right, int Id = 0)
  626. {
  627. ViewBag.RightInfo = RightInfo;
  628. ViewBag.right = right;
  629. MachineApply editData = db.MachineApply.FirstOrDefault(m => m.Id == Id) ?? new MachineApply();
  630. ViewBag.data = editData;
  631. return View();
  632. }
  633. #endregion
  634. #region 审核发货
  635. [HttpPost]
  636. public string AuditSend(MachineApply data)
  637. {
  638. Dictionary<string, object> Fields = new Dictionary<string, object>();
  639. Fields.Add("ExpressNo", data.ExpressNo);
  640. Fields.Add("ExpressName", data.ExpressName);
  641. Fields.Add("StoreId", data.StoreId);
  642. Fields.Add("AuditResult", data.AuditResult);
  643. Fields.Add("SendSn", data.SendSn);
  644. Fields.Add("SendStatus", 1);
  645. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("MachineApply", Fields, data.Id);
  646. AddSysLog(data.Id.ToString(), "MachineApply", "AuditSend");
  647. db.SaveChanges();
  648. return "success";
  649. }
  650. #endregion
  651. }
  652. }