OrdersController.cs 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  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.KxsMainModels;
  16. using Library;
  17. using LitJson;
  18. using MySystemLib;
  19. using NPOI.HSSF.UserModel;
  20. using NPOI.XSSF.UserModel;
  21. using NPOI.SS.UserModel;
  22. using NPOI.HSSF.Util;
  23. namespace MySystem.Areas.Admin.Controllers
  24. {
  25. [Area("Admin")]
  26. [Route("Admin/[controller]/[action]")]
  27. public class OrdersController : BaseController
  28. {
  29. public OrdersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  30. {
  31. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["KxsSqlConnStr"].ToString();
  32. }
  33. #region 创客订单列表
  34. /// <summary>
  35. /// 根据条件查询创客订单列表
  36. /// </summary>
  37. /// <returns></returns>
  38. public IActionResult Index(Orders data, string right)
  39. {
  40. ViewBag.RightInfo = RightInfo;
  41. ViewBag.right = right;
  42. return View();
  43. }
  44. #endregion
  45. #region 根据条件查询创客订单列表
  46. /// <summary>
  47. /// 创客订单列表
  48. /// </summary>
  49. /// <returns></returns>
  50. public JsonResult IndexData(Orders data, string OrderNo, string TradeNo, string RealName, string Mobile, string StoreContact, string ErpCode, string SnNos, string PayDateData, string CreateDateData, string SendDateData, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, int page = 1, int limit = 30)
  51. {
  52. Dictionary<string, string> Fields = new Dictionary<string, string>();
  53. Fields.Add("OrderNo", "1"); //订单号
  54. Fields.Add("RealName", "1"); //姓名
  55. Fields.Add("Mobile", "1"); //手机号
  56. Fields.Add("ErpCode", "1"); //运单号
  57. Fields.Add("TradeNo", "1"); //支付交易号
  58. Fields.Add("StoreContact", "1"); //仓库联系人
  59. Fields.Add("SnNos", "2"); //SN编号
  60. Fields.Add("TopUserId", "0");
  61. string condition = " and Status>-1 and ProductId=52";
  62. //平台订单号
  63. if (!string.IsNullOrEmpty(OrderNo))
  64. {
  65. condition += " and OrderNo like '" + OrderNo + "'";
  66. }
  67. //渠道订单号
  68. if (!string.IsNullOrEmpty(TradeNo))
  69. {
  70. condition += " and TradeNo=" + TradeNo;
  71. }
  72. //收件人姓名
  73. if (!string.IsNullOrEmpty(RealName))
  74. {
  75. condition += " and RealName=" + RealName;
  76. }
  77. //收件人电话
  78. if (!string.IsNullOrEmpty(Mobile))
  79. {
  80. condition += " and Mobile=" + Mobile;
  81. }
  82. //创客编号
  83. if (!string.IsNullOrEmpty(UserIdMakerCode))
  84. {
  85. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  86. }
  87. //创客真实姓名
  88. if (!string.IsNullOrEmpty(UserIdRealName))
  89. {
  90. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  91. }
  92. //支付方式
  93. if (!string.IsNullOrEmpty(PayModeSelect))
  94. {
  95. condition += " and PayMode=" + PayModeSelect;
  96. }
  97. //仓库编号
  98. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  99. {
  100. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  101. }
  102. //仓库名称
  103. if (!string.IsNullOrEmpty(StoreIdStoreName))
  104. {
  105. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  106. }
  107. //仓库联系人
  108. if (!string.IsNullOrEmpty(UserIdMakerCode))
  109. {
  110. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  111. }
  112. //仓库归属创客编号
  113. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  114. {
  115. condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  116. }
  117. //仓库归属创客真实姓名
  118. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  119. {
  120. condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
  121. }
  122. //快递单号
  123. if (!string.IsNullOrEmpty(ErpCode))
  124. {
  125. condition += " and ErpCode=" + ErpCode;
  126. }
  127. //SN
  128. if (!string.IsNullOrEmpty(SnNos))
  129. {
  130. condition += " and SnNos=" + SnNos;
  131. }
  132. //支付时间
  133. if (!string.IsNullOrEmpty(PayDateData))
  134. {
  135. string[] datelist = PayDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  136. string start = datelist[0];
  137. string end = datelist[1];
  138. condition += " and PayDate>='" + start + " 00:00:00' and PayDate<='" + end + " 23:59:59'";
  139. }
  140. //下单时间
  141. if (!string.IsNullOrEmpty(CreateDateData))
  142. {
  143. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  144. string start = datelist[0];
  145. string end = datelist[1];
  146. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  147. }
  148. //发货时间
  149. if (!string.IsNullOrEmpty(SendDateData))
  150. {
  151. string[] datelist = SendDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  152. string start = datelist[0];
  153. string end = datelist[1];
  154. condition += " and SendDate>='" + start + " 00:00:00' and SendDate<='" + end + " 23:59:59'";
  155. }
  156. //退款状态
  157. if (!string.IsNullOrEmpty(RefundStatusSelect))
  158. {
  159. condition += " and RefundStatus=" + RefundStatusSelect;
  160. }
  161. //提货类型
  162. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  163. {
  164. condition += " and DeliveryType=" + DeliveryTypeSelect;
  165. }
  166. //发货状态
  167. if (!string.IsNullOrEmpty(SendStatusSelect))
  168. {
  169. condition += " and SendStatus=" + SendStatusSelect;
  170. }
  171. //商品类型名称
  172. if (!string.IsNullOrEmpty(ProductIdSelect))
  173. {
  174. condition += " and Id in (select OrderId from OrderProduct where ProductId=" + ProductIdSelect + ")";//表数据量过大时不适用
  175. }
  176. //仓库类型
  177. if (!string.IsNullOrEmpty(StoreTypeSelect))
  178. {
  179. condition += " and StoreType=" + StoreTypeSelect;
  180. }
  181. //支付状态
  182. if (!string.IsNullOrEmpty(PayStatusSelect))
  183. {
  184. condition += " and PayStatus=" + PayStatusSelect;
  185. }
  186. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).IndexData("Orders", Fields, "Id desc", "0", page, limit, condition);
  187. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  188. foreach (Dictionary<string, object> dic in diclist)
  189. {
  190. dic["OrderNo"] = dic["OrderNo"].ToString() + "<br />" + dic["TradeNo"].ToString();
  191. dic["StoreContact"] = dic["StoreContact"].ToString() + "<br />" + dic["StoreContactMobile"].ToString();
  192. dic["Address"] = dic["Areas"].ToString() + dic["Address"].ToString();
  193. dic["RecieveInfo"] = dic["RealName"].ToString() + "<br />" + dic["Mobile"].ToString();
  194. dic["ErpInfo"] = dic["ErpCode"].ToString() + "<br />" + dic["ErpName"].ToString();
  195. //创客
  196. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  197. Users userid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  198. dic["UserInfo"] = userid_Users.MakerCode + "<br />" + userid_Users.RealName;
  199. dic.Remove("UserId");
  200. //物流名称
  201. dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
  202. //支付方式
  203. int PayMode = int.Parse(dic["PayMode"].ToString());
  204. if (PayMode == 1) dic["PayMode"] = "支付宝";
  205. if (PayMode == 2) dic["PayMode"] = "微信";
  206. if (PayMode == 3) dic["PayMode"] = "账户余额";
  207. if (PayMode == 0) dic["PayMode"] = "";
  208. //仓库
  209. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  210. StoreHouse storeid_StoreHouse = kxsdb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  211. //仓库类型
  212. int StoreType = int.Parse(dic["StoreType"].ToString());
  213. if (StoreType == 0) dic["StoreType"] = "总仓";
  214. if (StoreType == 1) dic["StoreType"] = "分仓";
  215. dic["Store"] = storeid_StoreHouse.StoreNo + "<br />" + dic["StoreType"].ToString();
  216. dic.Remove("StoreId");
  217. //退款状态
  218. int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
  219. if (RefundStatus == 0) dic["RefundStatusName"] = "未退款";
  220. if (RefundStatus == 1) dic["RefundStatusName"] = "已退款";
  221. //提货类型
  222. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  223. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  224. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  225. if (DeliveryType == 0) dic["DeliveryType"] = "";
  226. //发货状态
  227. int SendStatus = int.Parse(dic["SendStatus"].ToString());
  228. if (SendStatus == 0) dic["SendStatusName"] = "未发货";
  229. if (SendStatus == 1) dic["SendStatusName"] = "已发货";
  230. if (SendStatus == 2) dic["SendStatusName"] = "已退货";
  231. if (SendStatus == 0)
  232. {
  233. dic["SendInfo"] = dic["SendStatus"].ToString();
  234. }
  235. else
  236. {
  237. dic["SendInfo"] = dic["SendStatusName"].ToString() + "<br />" + dic["SendDate"].ToString();
  238. }
  239. //商品名称
  240. dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
  241. //商品名称
  242. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  243. OrderProduct orderProducts = kxsdb.OrderProduct.FirstOrDefault(m => m.OrderId == Id) ?? new OrderProduct();
  244. dic["ProductName"] = orderProducts.ProductName;
  245. //仓库归属创客
  246. int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
  247. Users storeuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  248. dic["StoreFrom"] = storeuserid_Users.MakerCode + "<br />" + storeid_StoreHouse.StoreName;
  249. dic.Remove("StoreUserId");
  250. //顶级创客
  251. int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
  252. Users topuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  253. dic["TopUserInfo"] = topuserid_Users.MakerCode + "<br />" + topuserid_Users.RealName;
  254. dic.Remove("TopUserId");
  255. //支付状态
  256. int PayStatus = int.Parse(dic["PayStatus"].ToString());
  257. if (PayStatus == 0) dic["PayStatus"] = "未支付";
  258. if (PayStatus == 1) dic["PayStatus"] = "支付成功";
  259. if (PayStatus == 2) dic["PayStatus"] = "支付失败";
  260. if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
  261. if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
  262. }
  263. Dictionary<string, object> other = new Dictionary<string, object>();
  264. string SuccessAmount = "0.00";//支付成功总金额
  265. string FailAmount = "0.00";//支付失败总金额
  266. DataTable dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  267. if (dt.Rows.Count > 0)
  268. {
  269. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  270. }
  271. dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=2" + condition);
  272. if (dt.Rows.Count > 0)
  273. {
  274. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  275. }
  276. other.Add("SuccessAmount", SuccessAmount);
  277. other.Add("FailAmount", FailAmount);
  278. obj.Add("other", other);
  279. return Json(obj);
  280. }
  281. public JsonResult IndexDatas(string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, int page = 1, int limit = 30)
  282. {
  283. string condition = " and Status>-1";
  284. //创客编号
  285. if (!string.IsNullOrEmpty(UserIdMakerCode))
  286. {
  287. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  288. }
  289. //创客真实姓名
  290. if (!string.IsNullOrEmpty(UserIdRealName))
  291. {
  292. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  293. }
  294. //支付方式
  295. if (!string.IsNullOrEmpty(PayModeSelect))
  296. {
  297. condition += " and PayMode=" + PayModeSelect;
  298. }
  299. //仓库编号
  300. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  301. {
  302. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  303. }
  304. //仓库名称
  305. if (!string.IsNullOrEmpty(StoreIdStoreName))
  306. {
  307. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  308. }
  309. //退款状态
  310. if (!string.IsNullOrEmpty(RefundStatusSelect))
  311. {
  312. condition += " and RefundStatus=" + RefundStatusSelect;
  313. }
  314. //提货类型
  315. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  316. {
  317. condition += " and DeliveryType=" + DeliveryTypeSelect;
  318. }
  319. //发货状态
  320. if (!string.IsNullOrEmpty(SendStatusSelect))
  321. {
  322. condition += " and SendStatus=" + SendStatusSelect;
  323. }
  324. //商品名称
  325. if (!string.IsNullOrEmpty(ProductIdSelect))
  326. {
  327. condition += " and ProductId=" + ProductIdSelect;
  328. }
  329. //仓库类型
  330. if (!string.IsNullOrEmpty(StoreTypeSelect))
  331. {
  332. condition += " and StoreType=" + StoreTypeSelect;
  333. }
  334. //仓库归属创客编号
  335. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  336. {
  337. condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  338. }
  339. //仓库归属创客真实姓名
  340. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  341. {
  342. condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
  343. }
  344. //支付状态
  345. if (!string.IsNullOrEmpty(PayStatusSelect))
  346. {
  347. condition += " and PayStatus=" + PayStatusSelect;
  348. }
  349. List<Dictionary<string, object>> other = new List<Dictionary<string, object>>();
  350. Dictionary<string, object> obj = new Dictionary<string, object>();
  351. DataTable dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=0" + condition);
  352. return null;
  353. }
  354. #endregion
  355. #region 增加创客订单
  356. /// <summary>
  357. /// 增加或修改创客订单信息
  358. /// </summary>
  359. /// <returns></returns>
  360. public IActionResult Add(string right)
  361. {
  362. ViewBag.RightInfo = RightInfo;
  363. ViewBag.right = right;
  364. return View();
  365. }
  366. #endregion
  367. #region 增加创客订单
  368. /// <summary>
  369. /// 增加或修改创客订单信息
  370. /// </summary>
  371. /// <returns></returns>
  372. [HttpPost]
  373. public string Add(Orders data)
  374. {
  375. Dictionary<string, object> Fields = new Dictionary<string, object>();
  376. Fields.Add("RealName", data.RealName); //姓名
  377. Fields.Add("ErpName", data.ErpName); //物流名称
  378. Fields.Add("ErpCode", data.ErpCode); //运单号
  379. Fields.Add("StoreId", data.StoreId); //仓库
  380. Fields.Add("SnNos", data.SnNos); //SN编号
  381. Fields.Add("SeoTitle", data.SeoTitle);
  382. Fields.Add("SeoKeyword", data.SeoKeyword);
  383. Fields.Add("SeoDescription", data.SeoDescription);
  384. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Add("Orders", Fields, 0);
  385. AddSysLog(data.Id.ToString(), "Orders", "add");
  386. kxsdb.SaveChanges();
  387. return "success";
  388. }
  389. #endregion
  390. #region 修改创客订单
  391. /// <summary>
  392. /// 增加或修改创客订单信息
  393. /// </summary>
  394. /// <returns></returns>
  395. public IActionResult Edit(string right, int Id = 0)
  396. {
  397. ViewBag.RightInfo = RightInfo;
  398. ViewBag.right = right;
  399. Orders editData = kxsdb.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  400. ViewBag.data = editData;
  401. return View();
  402. }
  403. #endregion
  404. #region 修改创客订单
  405. /// <summary>
  406. /// 增加或修改创客订单信息
  407. /// </summary>
  408. /// <returns></returns>
  409. [HttpPost]
  410. public string Edit(Orders data)
  411. {
  412. Dictionary<string, object> Fields = new Dictionary<string, object>();
  413. Fields.Add("RealName", data.RealName); //姓名
  414. Fields.Add("ErpName", data.ErpName); //物流名称
  415. Fields.Add("ErpCode", data.ErpCode); //运单号
  416. Fields.Add("StoreId", data.StoreId); //仓库
  417. Fields.Add("SnNos", data.SnNos); //SN编号
  418. Fields.Add("SeoTitle", data.SeoTitle);
  419. Fields.Add("SeoKeyword", data.SeoKeyword);
  420. Fields.Add("SeoDescription", data.SeoDescription);
  421. new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, data.Id);
  422. AddSysLog(data.Id.ToString(), "Orders", "update");
  423. kxsdb.SaveChanges();
  424. return "success";
  425. }
  426. #endregion
  427. #region 发货
  428. public IActionResult Send(string right, int Id = 0)
  429. {
  430. ViewBag.RightInfo = RightInfo;
  431. ViewBag.right = right;
  432. Orders editData = kxsdb.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  433. ViewBag.data = editData;
  434. Users user = kxsdb.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  435. ViewBag.MakerCode = user.MakerCode;
  436. ViewBag.RealName = user.RealName;
  437. StoreHouse store = kxsdb.StoreHouse.FirstOrDefault(m => m.Id == editData.StoreId) ?? new StoreHouse();
  438. ViewBag.StoreName = store.StoreName;
  439. List<OrderProduct> products = kxsdb.OrderProduct.Where(m => m.OrderId == editData.Id).ToList();
  440. ViewBag.products = products;
  441. return View();
  442. }
  443. #endregion
  444. #region 发货
  445. [HttpPost]
  446. public string Send(Orders data, string IdList, string StoreIdList, string SnNosList)
  447. {
  448. Dictionary<string, object> Fields = new Dictionary<string, object>();
  449. Fields.Add("ErpName", data.ErpName); //物流名称
  450. Fields.Add("ErpCode", data.ErpCode); //运单号
  451. Fields.Add("SnNos", SnNosList); //SN编号
  452. Fields.Add("SendStatus", 1); //发货状态
  453. Fields.Add("SendDate", DateTime.Now); //发货时间
  454. string[] Ids = IdList.TrimEnd('#').Split('#');
  455. string[] StoreIds = StoreIdList.TrimEnd('#').Split('#');
  456. string[] SnNoss = SnNosList.TrimEnd('\n').Split('\n');
  457. string err = "";
  458. for (int i = 0; i < Ids.Length; i++)
  459. {
  460. string SnNos = SnNoss[i];
  461. bool check = db.PosMachinesTwo.Any(m => m.PosSn == SnNos);
  462. if(!check)
  463. {
  464. err += SnNos + "不存在\n";
  465. }
  466. }
  467. if(!string.IsNullOrEmpty(err))
  468. {
  469. return err;
  470. }
  471. int StoreId = 1;
  472. if(StoreIds.Length > 0) StoreId = int.Parse(StoreIds[0]);
  473. Fields.Add("StoreId", StoreId);
  474. new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, data.Id);
  475. PublicFunction.StatUserMachineData(data.UserId, 0, SnNoss.Length);
  476. PublicFunction.SendRecord(db, 0, data.UserId, StoreId, SnNoss);
  477. AddSysLog(data.Id.ToString(), "Orders", "Send");
  478. kxsdb.SaveChanges();
  479. db.SaveChanges();
  480. return "success";
  481. }
  482. #endregion
  483. #region 退货
  484. public IActionResult Return(string right, int Id = 0)
  485. {
  486. ViewBag.RightInfo = RightInfo;
  487. ViewBag.right = right;
  488. Orders editData = kxsdb.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  489. ViewBag.data = editData;
  490. return View();
  491. }
  492. #endregion
  493. #region 退货
  494. [HttpPost]
  495. public string Return(Orders data)
  496. {
  497. AddSysLog(data.Id.ToString(), "Orders", "Return");
  498. Orders order = kxsdb.Orders.FirstOrDefault(m => m.Id == data.Id);
  499. if (order != null)
  500. {
  501. // TODO: 调用支付接口退款,需要测试
  502. // PublicAccountSet set = new AlipayFunction(_accessor.HttpContext).SetData();
  503. // string result = new Alipay.AlipayPublicClass(_accessor.HttpContext).Refund(set.AlipayAppId, set.AlipayPrivateKey, set.AlipayPublicKey, order.OrderNo, order.TotalPrice);
  504. // if (result.StartsWith("success"))
  505. // {
  506. if (order.PayStatus > 0)
  507. {
  508. return "已支付订单不可退货";
  509. }
  510. else
  511. {
  512. order.RefundActAmount = data.RefundActAmount;
  513. order.RefundReason = data.RefundReason;
  514. order.RefundStatus = 1;
  515. kxsdb.SaveChanges();
  516. return "success";
  517. }
  518. // }
  519. // else
  520. // {
  521. // return result.Split('|')[1];
  522. // }
  523. }
  524. return "退货失败";
  525. }
  526. #endregion
  527. #region 订单详情
  528. public IActionResult Detail(string right, int Id = 0)
  529. {
  530. ViewBag.RightInfo = RightInfo;
  531. ViewBag.right = right;
  532. Orders editData = kxsdb.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  533. ViewBag.data = editData;
  534. Users user = kxsdb.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  535. ViewBag.MakerCode = user.MakerCode;
  536. ViewBag.RealName = user.RealName;
  537. //支付状态
  538. int PayStatus = editData.PayStatus;
  539. if (PayStatus == 0) ViewBag.PayStatus = "未支付";
  540. if (PayStatus == 1) ViewBag.PayStatus = "支付成功";
  541. if (PayStatus == 2) ViewBag.PayStatus = "支付失败";
  542. if (PayStatus == 3) ViewBag.PayStatus = "支付锁定中";
  543. if (PayStatus == 4) ViewBag.PayStatus = "支付处理中";
  544. //支付方式
  545. int PayMode = editData.PayMode;
  546. if (PayMode == 1)
  547. {
  548. ViewBag.PayMode = "支付宝支付";
  549. ViewBag.PayModeCode = "Alipay";
  550. }
  551. if (PayMode == 2)
  552. {
  553. ViewBag.PayMode = "微信支付";
  554. ViewBag.PayModeCode = "WeChat";
  555. }
  556. if (PayMode == 3)
  557. {
  558. ViewBag.PayMode = "账户余额支付";
  559. ViewBag.PayModeCode = "AccBalancePay";
  560. }
  561. //发货状态
  562. int SendStatus = editData.SendStatus;
  563. if (SendStatus == 0) ViewBag.SendStatus = "未发货";
  564. if (SendStatus == 1) ViewBag.SendStatus = "已发货";
  565. if (SendStatus == 2) ViewBag.SendStatus = "已退货";
  566. //提货类型
  567. int DeliveryType = editData.DeliveryType;
  568. if (DeliveryType == 1) ViewBag.DeliveryType = "邮寄到付";
  569. if (DeliveryType == 2) ViewBag.DeliveryType = "上门自提";
  570. List<OrderProduct> products = kxsdb.OrderProduct.Where(m => m.OrderId == editData.Id).ToList();
  571. List<Dictionary<string, object>> ProductList = new List<Dictionary<string, object>>();
  572. foreach (OrderProduct product in products)
  573. {
  574. Dictionary<string, object> item = new Dictionary<string, object>();
  575. item.Add("ProductCode", product.ProductCode); //商品编号
  576. item.Add("ProductName", product.ProductName); //商品名称
  577. item.Add("ProductCount", product.ProductCount); //商品数量
  578. item.Add("ProductPrice", product.ProductPrice); //商品单价
  579. item.Add("SeoKeyword", product.SeoKeyword); //商品简介
  580. item.Add("SeoDescription", product.SeoDescription); //备注
  581. item.Add("ProductPhoto", SourceHost + product.ProductPhoto); //商品小图
  582. item.Add("NormDetail", product.NormDetail); //商品规格
  583. ProductList.Add(item);
  584. }
  585. ViewBag.ProductList = ProductList;
  586. return View();
  587. }
  588. #endregion
  589. #region 删除创客订单信息
  590. /// <summary>
  591. /// 删除创客订单信息
  592. /// </summary>
  593. /// <returns></returns>
  594. public string Delete(string Id)
  595. {
  596. string[] idlist = Id.Split(new char[] { ',' });
  597. AddSysLog(Id, "Orders", "del");
  598. foreach (string subid in idlist)
  599. {
  600. int id = int.Parse(subid);
  601. Dictionary<string, object> Fields = new Dictionary<string, object>();
  602. Fields.Add("Status", -1);
  603. new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, id);
  604. }
  605. kxsdb.SaveChanges();
  606. return "success";
  607. }
  608. #endregion
  609. #region 开启
  610. /// <summary>
  611. /// 开启
  612. /// </summary>
  613. /// <returns></returns>
  614. public string Open(string Id)
  615. {
  616. string[] idlist = Id.Split(new char[] { ',' });
  617. AddSysLog(Id, "Orders", "open");
  618. foreach (string subid in idlist)
  619. {
  620. int id = int.Parse(subid);
  621. Dictionary<string, object> Fields = new Dictionary<string, object>();
  622. Fields.Add("Status", 1);
  623. new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, id);
  624. }
  625. kxsdb.SaveChanges();
  626. return "success";
  627. }
  628. #endregion
  629. #region 关闭
  630. /// <summary>
  631. /// 关闭
  632. /// </summary>
  633. /// <returns></returns>
  634. public string Close(string Id)
  635. {
  636. string[] idlist = Id.Split(new char[] { ',' });
  637. AddSysLog(Id, "Orders", "close");
  638. foreach (string subid in idlist)
  639. {
  640. int id = int.Parse(subid);
  641. Dictionary<string, object> Fields = new Dictionary<string, object>();
  642. Fields.Add("Status", 0);
  643. new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Edit("Orders", Fields, id);
  644. }
  645. kxsdb.SaveChanges();
  646. return "success";
  647. }
  648. #endregion
  649. #region 排序
  650. /// <summary>
  651. /// 排序
  652. /// </summary>
  653. /// <param name="Id"></param>
  654. public string Sort(int Id, int Sort)
  655. {
  656. new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).Sort("Orders", Sort, Id);
  657. AddSysLog(Id.ToString(), "Orders", "sort");
  658. return "success";
  659. }
  660. #endregion
  661. #region 导入数据
  662. /// <summary>
  663. /// 导入数据
  664. /// </summary>
  665. /// <param name="ExcelData"></param>
  666. public string Import(string ExcelData)
  667. {
  668. ExcelData = HttpUtility.UrlDecode(ExcelData);
  669. JsonData list = JsonMapper.ToObject(ExcelData);
  670. for (int i = 1; i < list.Count; i++)
  671. {
  672. JsonData dr = list[i];
  673. kxsdb.Orders.Add(new Orders()
  674. {
  675. CreateDate = DateTime.Now,
  676. UpdateDate = DateTime.Now,
  677. });
  678. kxsdb.SaveChanges();
  679. }
  680. AddSysLog("0", "Orders", "Import");
  681. return "success";
  682. }
  683. #endregion
  684. #region 导出Excel
  685. /// <summary>
  686. /// 导出Excel
  687. /// </summary>
  688. /// <returns></returns>
  689. public string ExportExcel(Orders data, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, string RedisKey = "ExportKey")
  690. {
  691. Dictionary<string, string> Fields = new Dictionary<string, string>();
  692. Fields.Add("CreateDate", "3"); //时间
  693. Fields.Add("OrderNo", "1"); //订单号
  694. Fields.Add("RealName", "1"); //姓名
  695. Fields.Add("Mobile", "1"); //手机号
  696. Fields.Add("ErpCode", "1"); //运单号
  697. Fields.Add("SendDate", "3"); //发货时间
  698. Fields.Add("TradeNo", "1"); //支付交易号
  699. Fields.Add("StoreContact", "1"); //仓库联系人
  700. Fields.Add("SnNos", "2"); //SN编号
  701. Fields.Add("TopUserId", "0");
  702. string condition = " and Status>-1 and ProductId=52";
  703. //创客编号
  704. if (!string.IsNullOrEmpty(UserIdMakerCode))
  705. {
  706. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  707. }
  708. //创客真实姓名
  709. if (!string.IsNullOrEmpty(UserIdRealName))
  710. {
  711. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  712. }
  713. //支付方式
  714. if (!string.IsNullOrEmpty(PayModeSelect))
  715. {
  716. condition += " and PayMode=" + PayModeSelect;
  717. }
  718. //仓库编号
  719. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  720. {
  721. condition += " and StoreId in (select StoreId from StoreHouseForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
  722. }
  723. //仓库名称
  724. if (!string.IsNullOrEmpty(StoreIdStoreName))
  725. {
  726. condition += " and StoreId in (select StoreId from StoreHouseForStoreName where StoreName='" + StoreIdStoreName + "')";
  727. }
  728. //退款状态
  729. if (!string.IsNullOrEmpty(RefundStatusSelect))
  730. {
  731. condition += " and RefundStatus=" + RefundStatusSelect;
  732. }
  733. //提货类型
  734. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  735. {
  736. condition += " and DeliveryType=" + DeliveryTypeSelect;
  737. }
  738. //发货状态
  739. if (!string.IsNullOrEmpty(SendStatusSelect))
  740. {
  741. condition += " and SendStatus=" + SendStatusSelect;
  742. }
  743. //商品名称
  744. if (!string.IsNullOrEmpty(ProductIdSelect))
  745. {
  746. condition += " and ProductId=" + ProductIdSelect;
  747. }
  748. //仓库类型
  749. if (!string.IsNullOrEmpty(StoreTypeSelect))
  750. {
  751. condition += " and StoreType=" + StoreTypeSelect;
  752. }
  753. //仓库归属创客编号
  754. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  755. {
  756. condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  757. }
  758. //仓库归属创客真实姓名
  759. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  760. {
  761. condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
  762. }
  763. //支付状态
  764. if (!string.IsNullOrEmpty(PayStatusSelect))
  765. {
  766. condition += " and PayStatus=" + PayStatusSelect;
  767. }
  768. //创建工作薄
  769. var workbook = new XSSFWorkbook();
  770. //创建表
  771. var table = workbook.CreateSheet("Sheet1");
  772. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).IndexData("Orders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,OrderNo,RealName,Mobile,TotalPrice,Areas,Address,ErpName,ErpCode,SendDate,PayMode,TradeNo,StoreId,RefundStatus,DeliveryType,SendStatus,ProductId,StoreContact,StoreType,StoreUserId,TopUserId,PayStatus,BuyCount,Remark,Id", false);
  773. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  774. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  775. ReturnFields.Add("UserIdMakerCode", "创客编号");
  776. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  777. ReturnFields.Add("OrderNo", "订单号");
  778. ReturnFields.Add("RealName", "姓名");
  779. ReturnFields.Add("Mobile", "手机号");
  780. ReturnFields.Add("TotalPrice", "总价");
  781. ReturnFields.Add("Areas", "所在地区");
  782. ReturnFields.Add("Address", "详细地址");
  783. ReturnFields.Add("ErpName", "物流名称");
  784. ReturnFields.Add("ErpCode", "运单号");
  785. ReturnFields.Add("SendDate", "发货时间");
  786. ReturnFields.Add("PayMode", "支付方式");
  787. ReturnFields.Add("TradeNo", "支付交易号");
  788. ReturnFields.Add("StoreIdStoreNo", "仓库编号");
  789. ReturnFields.Add("StoreIdStoreName", "仓库名称");
  790. ReturnFields.Add("RefundStatus", "退款状态");
  791. ReturnFields.Add("DeliveryType", "提货类型");
  792. ReturnFields.Add("SendStatus", "发货状态");
  793. ReturnFields.Add("ProductId", "商品名称");
  794. ReturnFields.Add("StoreContact", "仓库联系人");
  795. ReturnFields.Add("StoreType", "仓库类型");
  796. ReturnFields.Add("StoreUserIdMakerCode", "仓库归属创客编号");
  797. ReturnFields.Add("StoreUserIdRealName", "仓库归属创客姓名");
  798. ReturnFields.Add("TopUserIdMakerCode", "顶级创客编号");
  799. ReturnFields.Add("TopUserIdRealName", "顶级创客姓名");
  800. ReturnFields.Add("PayStatus", "支付状态");
  801. ReturnFields.Add("BuyCount", "下单数量");
  802. ReturnFields.Add("Remark", "订单备注");
  803. int i = 0;
  804. foreach (Dictionary<string, object> dic in diclist)
  805. {
  806. i += 1;
  807. //创客
  808. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  809. Users userid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  810. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  811. dic["UserIdRealName"] = userid_Users.RealName;
  812. dic.Remove("UserId");
  813. //物流名称
  814. dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
  815. //支付方式
  816. int PayMode = int.Parse(dic["PayMode"].ToString());
  817. if (PayMode == 1) dic["PayMode"] = "支付宝";
  818. if (PayMode == 2) dic["PayMode"] = "微信";
  819. if (PayMode == 3) dic["PayMode"] = "账户余额";
  820. if (PayMode == 0) dic["PayMode"] = "";
  821. //仓库
  822. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  823. StoreHouse storeid_StoreHouse = kxsdb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  824. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  825. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  826. dic.Remove("StoreId");
  827. //退款状态
  828. int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
  829. if (RefundStatus == 0) dic["RefundStatus"] = "未退款";
  830. if (RefundStatus == 1) dic["RefundStatus"] = "已退款";
  831. //提货类型
  832. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  833. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  834. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  835. if (DeliveryType == 0) dic["DeliveryType"] = "";
  836. //发货状态
  837. int SendStatus = int.Parse(dic["SendStatus"].ToString());
  838. if (SendStatus == 0) dic["SendStatus"] = "未发货";
  839. if (SendStatus == 1) dic["SendStatus"] = "已发货";
  840. if (SendStatus == 2) dic["SendStatus"] = "已退货";
  841. //商品名称
  842. dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
  843. //仓库类型
  844. int StoreType = int.Parse(dic["StoreType"].ToString());
  845. if (StoreType == 0) dic["StoreType"] = "总仓";
  846. if (StoreType == 1) dic["StoreType"] = "分仓";
  847. //仓库归属创客
  848. int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
  849. Users storeuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  850. dic["StoreUserIdMakerCode"] = storeuserid_Users.MakerCode;
  851. dic["StoreUserIdRealName"] = storeuserid_Users.RealName;
  852. dic.Remove("StoreUserId");
  853. //顶级创客
  854. int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
  855. Users topuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  856. dic["TopUserIdMakerCode"] = topuserid_Users.MakerCode;
  857. dic["TopUserIdRealName"] = topuserid_Users.RealName;
  858. dic.Remove("TopUserId");
  859. //支付状态
  860. int PayStatus = int.Parse(dic["PayStatus"].ToString());
  861. if (PayStatus == 0) dic["PayStatus"] = "未支付";
  862. if (PayStatus == 1) dic["PayStatus"] = "支付成功";
  863. if (PayStatus == 2) dic["PayStatus"] = "支付失败";
  864. if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
  865. if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
  866. int OrderId = int.Parse(dic["Id"].ToString());
  867. List<OrderProduct> products = kxsdb.OrderProduct.Where(m => m.OrderId == OrderId).ToList();
  868. foreach (OrderProduct product in products)
  869. {
  870. dic["ProductCode"] = product.ProductCode; //商品编号
  871. dic["ProductName"] = product.ProductName; //商品名称
  872. dic["ProductCount"] = product.ProductCount; //商品数量
  873. dic["ProductPrice"] = product.ProductPrice; //商品单价
  874. dic["NormDetail"] = product.NormDetail; //商品规格
  875. if (i == 1)
  876. {
  877. ReturnFields.Add("ProductCode", "商品编号");
  878. ReturnFields.Add("ProductName", "商品名称");
  879. ReturnFields.Add("ProductCount", "商品数量");
  880. ReturnFields.Add("ProductPrice", "商品单价");
  881. ReturnFields.Add("NormDetail", "商品规格");
  882. }
  883. }
  884. dic.Remove("Id");
  885. var row = table.CreateRow(i);
  886. int index = 0;
  887. foreach (string key in ReturnFields.Keys)
  888. {
  889. var cell = row.CreateCell(index);
  890. string val = dic[key] == null ? "" : dic[key].ToString();
  891. ICellStyle style = workbook.CreateCellStyle();
  892. style.BorderBottom = BorderStyle.Thin;
  893. style.BorderTop = BorderStyle.Thin;
  894. style.BorderLeft = BorderStyle.Thin;
  895. style.BorderRight = BorderStyle.Thin;
  896. style.BottomBorderColor = HSSFColor.Black.Index;
  897. style.TopBorderColor = HSSFColor.Black.Index;
  898. style.LeftBorderColor = HSSFColor.Black.Index;
  899. style.RightBorderColor = HSSFColor.Black.Index;
  900. cell.CellStyle = style;
  901. cell.SetCellValue(val);
  902. index += 1;
  903. }
  904. RedisDbconn.Instance.Set("CheckExport:" + RedisKey, i.ToString() + " / " + diclist.Count);
  905. }
  906. // Dictionary<string, object> result = new Dictionary<string, object>();
  907. // result.Add("Status", "1");
  908. // result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  909. // result.Add("Obj", diclist);
  910. var title = table.CreateRow(0);
  911. int j = 0;
  912. foreach (string key in ReturnFields.Keys)
  913. {
  914. var cell = title.CreateCell(j);
  915. ICellStyle style = workbook.CreateCellStyle();
  916. style.BorderBottom = BorderStyle.Thin;
  917. style.BorderTop = BorderStyle.Thin;
  918. style.BorderLeft = BorderStyle.Thin;
  919. style.BorderRight = BorderStyle.Thin;
  920. style.BottomBorderColor = HSSFColor.Black.Index;
  921. style.TopBorderColor = HSSFColor.Black.Index;
  922. style.LeftBorderColor = HSSFColor.Black.Index;
  923. style.RightBorderColor = HSSFColor.Black.Index;
  924. cell.CellStyle = style;
  925. cell.SetCellValue(ReturnFields[key].ToString());
  926. j += 1;
  927. }
  928. //打开xls文件,如没有则创建,如存在则在创建是不要打开该文件
  929. string FilePath = function.getPath("/static/export/");
  930. if (!System.IO.Directory.Exists(FilePath))
  931. {
  932. System.IO.Directory.CreateDirectory(FilePath);
  933. }
  934. string FileName = "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx";
  935. using (var fs = System.IO.File.OpenWrite(FilePath + FileName))
  936. {
  937. workbook.Write(fs); //向打开的这个xls文件中写入mySheet表并保存。
  938. }
  939. // result.Add("Fields", ReturnFields);
  940. AddSysLog("0", "Orders", "ExportExcel");
  941. RedisDbconn.Instance.Set("CheckExport:" + RedisKey, "finish");
  942. return "success|/static/export/" + FileName;
  943. }
  944. public string CheckExport(string RedisKey = "ExportKey")
  945. {
  946. string result = RedisDbconn.Instance.Get<string>("CheckExport:" + RedisKey);
  947. return result;
  948. }
  949. #endregion
  950. #region 导出Excel
  951. /// <summary>
  952. /// 导出Excel
  953. /// </summary>
  954. /// <returns></returns>
  955. public JsonResult ExportsExcel(Orders data, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, string CreateDateData, string SendDateData, string PayDateData, string RedisKey = "ExportKey")
  956. {
  957. Dictionary<string, string> Fields = new Dictionary<string, string>();
  958. // Fields.Add("CreateDate", "3"); //时间
  959. Fields.Add("OrderNo", "1"); //订单号
  960. Fields.Add("RealName", "1"); //姓名
  961. Fields.Add("Mobile", "1"); //手机号
  962. Fields.Add("ErpCode", "1"); //运单号
  963. // Fields.Add("SendDate", "3"); //发货时间
  964. Fields.Add("TradeNo", "1"); //支付交易号
  965. Fields.Add("StoreContact", "1"); //仓库联系人
  966. Fields.Add("SnNos", "2"); //SN编号
  967. Fields.Add("TopUserId", "0");
  968. string condition = " and Status>-1 and ProductId=49";
  969. //创客编号
  970. if (!string.IsNullOrEmpty(UserIdMakerCode))
  971. {
  972. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  973. }
  974. //创客真实姓名
  975. if (!string.IsNullOrEmpty(UserIdRealName))
  976. {
  977. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  978. }
  979. //支付方式
  980. if (!string.IsNullOrEmpty(PayModeSelect))
  981. {
  982. condition += " and PayMode=" + PayModeSelect;
  983. }
  984. //仓库编号
  985. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  986. {
  987. condition += " and StoreId in (select StoreId from StoreHouseForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
  988. }
  989. //仓库名称
  990. if (!string.IsNullOrEmpty(StoreIdStoreName))
  991. {
  992. condition += " and StoreId in (select StoreId from StoreHouseForStoreName where StoreName='" + StoreIdStoreName + "')";
  993. }
  994. //退款状态
  995. if (!string.IsNullOrEmpty(RefundStatusSelect))
  996. {
  997. condition += " and RefundStatus=" + RefundStatusSelect;
  998. }
  999. //提货类型
  1000. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  1001. {
  1002. condition += " and DeliveryType=" + DeliveryTypeSelect;
  1003. }
  1004. //发货状态
  1005. if (!string.IsNullOrEmpty(SendStatusSelect))
  1006. {
  1007. condition += " and SendStatus=" + SendStatusSelect;
  1008. }
  1009. //商品名称
  1010. if (!string.IsNullOrEmpty(ProductIdSelect))
  1011. {
  1012. condition += " and ProductId=" + ProductIdSelect;
  1013. }
  1014. //仓库类型
  1015. if (!string.IsNullOrEmpty(StoreTypeSelect))
  1016. {
  1017. condition += " and StoreType=" + StoreTypeSelect;
  1018. }
  1019. //仓库归属创客编号
  1020. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  1021. {
  1022. condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  1023. }
  1024. //仓库归属创客真实姓名
  1025. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  1026. {
  1027. condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
  1028. }
  1029. //支付状态
  1030. if (!string.IsNullOrEmpty(PayStatusSelect))
  1031. {
  1032. condition += " and PayStatus=" + PayStatusSelect;
  1033. }
  1034. //支付时间
  1035. if (!string.IsNullOrEmpty(PayDateData))
  1036. {
  1037. string[] datelist = PayDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1038. string start = datelist[0];
  1039. string end = datelist[1];
  1040. condition += " and PayDate>='" + start + " 00:00:00' and PayDate<='" + end + " 23:59:59'";
  1041. }
  1042. //下单时间
  1043. if (!string.IsNullOrEmpty(CreateDateData))
  1044. {
  1045. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1046. string start = datelist[0];
  1047. string end = datelist[1];
  1048. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  1049. }
  1050. //发货时间
  1051. if (!string.IsNullOrEmpty(SendDateData))
  1052. {
  1053. string[] datelist = SendDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1054. string start = datelist[0];
  1055. string end = datelist[1];
  1056. condition += " and SendDate>='" + start + " 00:00:00' and SendDate<='" + end + " 23:59:59'";
  1057. }
  1058. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.KxsMainTables).IndexData("Orders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,OrderNo,RealName,Mobile,TotalPrice,Areas,Address,ErpName,ErpCode,SendDate,PayMode,PayDate,TradeNo,StoreId,RefundStatus,DeliveryType,SendStatus,ProductId,StoreContact,StoreType,StoreUserId,TopUserId,PayStatus,BuyCount,Remark,Id", false);
  1059. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1060. foreach (Dictionary<string, object> dic in diclist)
  1061. {
  1062. //创客
  1063. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  1064. Users userid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  1065. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  1066. dic["UserIdRealName"] = userid_Users.RealName;
  1067. dic.Remove("UserId");
  1068. //物流名称
  1069. dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
  1070. //支付方式
  1071. int PayMode = int.Parse(dic["PayMode"].ToString());
  1072. if (PayMode == 1) dic["PayMode"] = "支付宝";
  1073. if (PayMode == 2) dic["PayMode"] = "微信";
  1074. if (PayMode == 3) dic["PayMode"] = "账户余额";
  1075. if (PayMode == 0) dic["PayMode"] = "";
  1076. //仓库
  1077. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  1078. StoreHouse storeid_StoreHouse = kxsdb.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  1079. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  1080. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  1081. dic.Remove("StoreId");
  1082. //退款状态
  1083. int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
  1084. if (RefundStatus == 0) dic["RefundStatus"] = "未退款";
  1085. if (RefundStatus == 1) dic["RefundStatus"] = "已退款";
  1086. //提货类型
  1087. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  1088. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  1089. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  1090. if (DeliveryType == 0) dic["DeliveryType"] = "";
  1091. //发货状态
  1092. int SendStatus = int.Parse(dic["SendStatus"].ToString());
  1093. if (SendStatus == 0) dic["SendStatus"] = "未发货";
  1094. if (SendStatus == 1) dic["SendStatus"] = "已发货";
  1095. if (SendStatus == 2) dic["SendStatus"] = "已退货";
  1096. //商品名称
  1097. dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
  1098. //仓库类型
  1099. int StoreType = int.Parse(dic["StoreType"].ToString());
  1100. if (StoreType == 0) dic["StoreType"] = "总仓";
  1101. if (StoreType == 1) dic["StoreType"] = "分仓";
  1102. //仓库归属创客
  1103. int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
  1104. Users storeuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  1105. dic["StoreUserIdMakerCode"] = storeuserid_Users.MakerCode;
  1106. dic["StoreUserIdRealName"] = storeuserid_Users.RealName;
  1107. dic.Remove("StoreUserId");
  1108. //顶级创客
  1109. int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
  1110. Users topuserid_Users = kxsdb.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1111. dic["TopUserIdMakerCode"] = topuserid_Users.MakerCode;
  1112. dic["TopUserIdRealName"] = topuserid_Users.RealName;
  1113. dic.Remove("TopUserId");
  1114. //支付状态
  1115. int PayStatus = int.Parse(dic["PayStatus"].ToString());
  1116. if (PayStatus == 0) dic["PayStatus"] = "未支付";
  1117. if (PayStatus == 1) dic["PayStatus"] = "支付成功";
  1118. if (PayStatus == 2) dic["PayStatus"] = "支付失败";
  1119. if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
  1120. if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
  1121. int OrderId = int.Parse(dic["Id"].ToString());
  1122. List<OrderProduct> products = kxsdb.OrderProduct.Where(m => m.OrderId == OrderId).ToList();
  1123. foreach (OrderProduct product in products)
  1124. {
  1125. dic["ProductCode"] = product.ProductCode; //商品编号
  1126. dic["ProductName"] = product.ProductName; //商品名称
  1127. dic["ProductCount"] = product.ProductCount; //商品数量
  1128. dic["ProductPrice"] = product.ProductPrice; //商品单价
  1129. dic["NormDetail"] = product.NormDetail; //商品规格
  1130. }
  1131. dic.Remove("Id");
  1132. }
  1133. Dictionary<string, object> result = new Dictionary<string, object>();
  1134. result.Add("Status", "1");
  1135. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1136. result.Add("Obj", diclist);
  1137. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1138. ReturnFields.Add("UserIdMakerCode", "创客编号");
  1139. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  1140. ReturnFields.Add("OrderNo", "订单号");
  1141. ReturnFields.Add("RealName", "姓名");
  1142. ReturnFields.Add("Mobile", "手机号");
  1143. ReturnFields.Add("TotalPrice", "总价");
  1144. ReturnFields.Add("Areas", "所在地区");
  1145. ReturnFields.Add("Address", "详细地址");
  1146. ReturnFields.Add("ErpName", "物流名称");
  1147. ReturnFields.Add("ErpCode", "运单号");
  1148. ReturnFields.Add("SendDate", "发货时间");
  1149. ReturnFields.Add("PayMode", "支付方式");
  1150. ReturnFields.Add("PayDate", "支付时间");
  1151. ReturnFields.Add("TradeNo", "支付交易号");
  1152. ReturnFields.Add("StoreIdStoreNo", "仓库编号");
  1153. ReturnFields.Add("StoreIdStoreName", "仓库名称");
  1154. ReturnFields.Add("RefundStatus", "退款状态");
  1155. ReturnFields.Add("DeliveryType", "提货类型");
  1156. ReturnFields.Add("SendStatus", "发货状态");
  1157. ReturnFields.Add("ProductId", "商品名称");
  1158. ReturnFields.Add("StoreContact", "仓库联系人");
  1159. ReturnFields.Add("StoreType", "仓库类型");
  1160. ReturnFields.Add("StoreUserIdMakerCode", "仓库归属创客编号");
  1161. ReturnFields.Add("StoreUserIdRealName", "仓库归属创客姓名");
  1162. ReturnFields.Add("TopUserIdMakerCode", "顶级创客编号");
  1163. ReturnFields.Add("TopUserIdRealName", "顶级创客姓名");
  1164. ReturnFields.Add("PayStatus", "支付状态");
  1165. ReturnFields.Add("BuyCount", "下单数量");
  1166. ReturnFields.Add("Remark", "订单备注");
  1167. ReturnFields.Add("ProductCode", "商品编号");
  1168. ReturnFields.Add("ProductName", "商品名称");
  1169. ReturnFields.Add("ProductCount", "商品数量");
  1170. ReturnFields.Add("ProductPrice", "商品单价");
  1171. ReturnFields.Add("NormDetail", "商品规格");
  1172. result.Add("Fields", ReturnFields);
  1173. AddSysLog("0", "Orders", "ExportExcel");
  1174. return Json(result);
  1175. }
  1176. #endregion
  1177. }
  1178. }