OrdersController.cs 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134
  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. 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["SqlConnStr"].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 StatusSelect, 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("ErpCode", "1"); //运单号
  54. Fields.Add("TradeNo", "1"); //支付交易号
  55. Fields.Add("StoreContact", "1"); //仓库联系人
  56. Fields.Add("SnNos", "2"); //SN编号
  57. Fields.Add("TopUserId", "0");
  58. // string condition = " and Status>=-1 and Status<4";
  59. string condition = " and Status>=-1 and Sort=0";
  60. //平台订单号
  61. if (!string.IsNullOrEmpty(OrderNo))
  62. {
  63. condition += " and OrderNo like '" + OrderNo + "'";
  64. }
  65. //渠道订单号
  66. if (!string.IsNullOrEmpty(TradeNo))
  67. {
  68. condition += " and TradeNo='" + TradeNo + "'";
  69. }
  70. //收件人姓名
  71. if (!string.IsNullOrEmpty(RealName))
  72. {
  73. condition += " and RealName='" + RealName + "'";
  74. }
  75. //收件人电话
  76. if (!string.IsNullOrEmpty(Mobile))
  77. {
  78. condition += " and Mobile='" + Mobile + "'";
  79. }
  80. //创客编号
  81. if (!string.IsNullOrEmpty(UserIdMakerCode))
  82. {
  83. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  84. }
  85. //创客真实姓名
  86. if (!string.IsNullOrEmpty(UserIdRealName))
  87. {
  88. condition += " and UserId in (select Id from Users where RealName='" + UserIdRealName + "')";
  89. }
  90. //支付方式
  91. if (!string.IsNullOrEmpty(PayModeSelect))
  92. {
  93. condition += " and PayMode=" + PayModeSelect;
  94. }
  95. //仓库编号
  96. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  97. {
  98. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  99. }
  100. //仓库名称
  101. if (!string.IsNullOrEmpty(StoreIdStoreName))
  102. {
  103. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  104. }
  105. //仓库联系人
  106. if (!string.IsNullOrEmpty(UserIdMakerCode))
  107. {
  108. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  109. }
  110. //仓库归属创客编号
  111. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  112. {
  113. condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  114. }
  115. //仓库归属创客真实姓名
  116. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  117. {
  118. condition += " and StoreUserId in (select Id from Users where RealName='" + StoreUserIdRealName + "')";
  119. }
  120. //快递单号
  121. if (!string.IsNullOrEmpty(ErpCode))
  122. {
  123. condition += " and ErpCode='" + ErpCode + "'";
  124. }
  125. //SN
  126. if (!string.IsNullOrEmpty(SnNos))
  127. {
  128. condition += " and SnNos like '%" + SnNos + "%'";
  129. }
  130. //支付时间
  131. if (!string.IsNullOrEmpty(PayDateData))
  132. {
  133. string[] datelist = PayDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  134. string start = datelist[0];
  135. string end = datelist[1];
  136. condition += " and PayDate>='" + start + " 00:00:00' and PayDate<='" + end + " 23:59:59'";
  137. }
  138. //下单时间
  139. if (!string.IsNullOrEmpty(CreateDateData))
  140. {
  141. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  142. string start = datelist[0];
  143. string end = datelist[1];
  144. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  145. }
  146. //发货时间
  147. if (!string.IsNullOrEmpty(SendDateData))
  148. {
  149. string[] datelist = SendDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  150. string start = datelist[0];
  151. string end = datelist[1];
  152. condition += " and SendDate>='" + start + " 00:00:00' and SendDate<='" + end + " 23:59:59'";
  153. }
  154. //订单状态
  155. if (!string.IsNullOrEmpty(StatusSelect))
  156. {
  157. condition += " and Status=" + StatusSelect;
  158. }
  159. //退款状态
  160. if (!string.IsNullOrEmpty(RefundStatusSelect))
  161. {
  162. condition += " and RefundStatus=" + RefundStatusSelect;
  163. }
  164. //提货类型
  165. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  166. {
  167. condition += " and DeliveryType=" + DeliveryTypeSelect;
  168. }
  169. //发货状态
  170. if (!string.IsNullOrEmpty(SendStatusSelect))
  171. {
  172. condition += " and SendStatus=" + SendStatusSelect;
  173. }
  174. //商品类型名称
  175. if (!string.IsNullOrEmpty(ProductIdSelect))
  176. {
  177. condition += " and Id in (select OrderId from OrderProduct where ProductId=" + ProductIdSelect + ")";//表数据量过大时不适用
  178. }
  179. //仓库类型
  180. if (!string.IsNullOrEmpty(StoreTypeSelect))
  181. {
  182. condition += " and StoreType=" + StoreTypeSelect;
  183. }
  184. //支付状态
  185. if (!string.IsNullOrEmpty(PayStatusSelect))
  186. {
  187. condition += " and PayStatus=" + PayStatusSelect;
  188. }
  189. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Orders", Fields, "Id desc", "0", page, limit, condition);
  190. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  191. foreach (Dictionary<string, object> dic in diclist)
  192. {
  193. dic["OrderNo"] = dic["OrderNo"].ToString() + "<br />" + dic["TradeNo"].ToString();
  194. dic["StoreContact"] = dic["StoreContact"].ToString() + "<br />" + dic["StoreContactMobile"].ToString();
  195. dic["Address"] = dic["Areas"].ToString() + dic["Address"].ToString();
  196. dic["RecieveInfo"] = dic["RealName"].ToString() + "<br />" + dic["Mobile"].ToString();
  197. dic["ErpInfo"] = dic["ErpCode"].ToString() + "<br />" + dic["ErpName"].ToString();
  198. //创客
  199. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  200. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  201. dic["UserInfo"] = userid_Users.MakerCode + "<br />" + userid_Users.RealName + "<br />" + userid_Users.Id;
  202. //顶级创客信息
  203. if (!string.IsNullOrEmpty(userid_Users.ParentNav))
  204. {
  205. string[] ParentNavList = userid_Users.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  206. var topUserInfo = new Users();
  207. if (ParentNavList.Length > 1)
  208. {
  209. topUserInfo = PublicFunction.GetTopUserInfo(userid_Users.ParentNav, 1);
  210. }
  211. else
  212. {
  213. topUserInfo = PublicFunction.GetTopUserInfo(userid_Users.ParentNav, 0);
  214. }
  215. //顶级创客信息
  216. dic["TopUserInfo"] = topUserInfo.MakerCode + "<br />" + topUserInfo.RealName;
  217. //分离顶级创客信息
  218. dic["TopUserInfoMakerCode"] = topUserInfo.MakerCode;
  219. dic["TopUserInfoRealName"] = topUserInfo.RealName;
  220. }
  221. else
  222. {
  223. dic["TopUserInfo"] = "";
  224. }
  225. //订单状态
  226. int Status = int.Parse(dic["Status"].ToString());
  227. if (Status == -1) dic["StatusName"] = "已取消";
  228. if (Status == 1) dic["StatusName"] = "待发货";
  229. if (Status == 2) dic["StatusName"] = "已完成";
  230. if (Status == 3) dic["StatusName"] = "已发货";
  231. if (Status == 4) dic["StatusName"] = "已退款";
  232. //物流名称
  233. dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
  234. //支付方式
  235. int PayMode = int.Parse(dic["PayMode"].ToString());
  236. if (PayMode == 1) dic["PayMode"] = "支付宝";
  237. if (PayMode == 2) dic["PayMode"] = "微信";
  238. if (PayMode == 3) dic["PayMode"] = "账户余额";
  239. if (PayMode == 0) dic["PayMode"] = "";
  240. //仓库
  241. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  242. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  243. //仓库类型
  244. int StoreType = int.Parse(dic["StoreType"].ToString());
  245. if (StoreType == 0) dic["StoreType"] = "总仓";
  246. if (StoreType == 1) dic["StoreType"] = "分仓";
  247. dic["Store"] = storeid_StoreHouse.StoreNo + "<br />" + dic["StoreType"].ToString();
  248. dic.Remove("StoreId");
  249. // //退款状态
  250. // int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
  251. // if (RefundStatus == 0) dic["RefundStatusName"] = "未退款";
  252. // if (RefundStatus == 1) dic["RefundStatusName"] = "已退款";
  253. //提货类型
  254. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  255. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  256. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  257. if (DeliveryType == 0) dic["DeliveryType"] = "";
  258. // //发货状态
  259. // int SendStatus = int.Parse(dic["SendStatus"].ToString());
  260. // if (SendStatus == -1) dic["SendStatusName"] = "已驳回";
  261. // if (SendStatus == 0) dic["SendStatusName"] = "未发货";
  262. // if (SendStatus == 1) dic["SendStatusName"] = "已发货";
  263. // if (SendStatus == 2) dic["SendStatusName"] = "已退货";
  264. // if (SendStatus == 0)
  265. // {
  266. // dic["SendInfo"] = dic["SendStatusName"];
  267. // }
  268. // else
  269. // {
  270. // dic["SendInfo"] = dic["SendStatusName"].ToString() + "<br />" + dic["SendDate"].ToString();
  271. // }
  272. //商品名称
  273. dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
  274. //商品名称
  275. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  276. OrderProduct orderProducts = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id) ?? new OrderProduct();
  277. var product = db.Products.FirstOrDefault(m => m.Id == orderProducts.ProductId) ?? new Products();
  278. dic["ProductName"] = orderProducts.ProductName;
  279. if (product.ProductKind == 1) dic["ProductKind"] = "实物商品";
  280. if (product.ProductKind == 2) dic["ProductKind"] = "虚拟商品";
  281. //退款时间
  282. var orderRefund = db.OrderRefund.FirstOrDefault(m => m.OrderId == Id) ?? new OrderRefund();
  283. dic["RefundDate"] = "";
  284. if (orderRefund.Id > 0)
  285. {
  286. dic["RefundDate"] = orderRefund.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  287. }
  288. //仓库归属创客
  289. int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
  290. Users storeuserid_Users = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  291. dic["StoreFrom"] = storeuserid_Users.MakerCode + "<br />" + storeid_StoreHouse.StoreName;
  292. dic.Remove("StoreUserId");
  293. // //支付状态
  294. // int PayStatus = int.Parse(dic["PayStatus"].ToString());
  295. // if (PayStatus == 0) dic["PayStatusName"] = "未支付";
  296. // if (PayStatus == 1) dic["PayStatusName"] = "支付成功";
  297. // if (PayStatus == 2) dic["PayStatusName"] = "支付失败";
  298. // if (PayStatus == 3) dic["PayStatusName"] = "支付锁定中";
  299. // if (PayStatus == 4) dic["PayStatusName"] = "支付处理中";
  300. }
  301. Dictionary<string, object> other = new Dictionary<string, object>();
  302. string SuccessAmount = "0.00";//支付成功总金额
  303. string FailAmount = "0.00";//支付失败总金额
  304. DataTable dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1 and Status>-1" + condition);
  305. if (dt.Rows.Count > 0)
  306. {
  307. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  308. }
  309. dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=2 and Status>-1" + condition);
  310. if (dt.Rows.Count > 0)
  311. {
  312. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  313. }
  314. other.Add("SuccessAmount", SuccessAmount);
  315. other.Add("FailAmount", FailAmount);
  316. obj.Add("other", other);
  317. return Json(obj);
  318. }
  319. #endregion
  320. #region 创客退货订单列表
  321. /// <summary>
  322. /// 根据条件查询创客退货订单列表
  323. /// </summary>
  324. /// <returns></returns>
  325. public IActionResult IndexRefund(Orders data, string right)
  326. {
  327. ViewBag.RightInfo = RightInfo;
  328. ViewBag.right = right;
  329. return View();
  330. }
  331. #endregion
  332. #region 根据条件查询创客退货订单列表
  333. /// <summary>
  334. /// 创客退货订单列表
  335. /// </summary>
  336. /// <returns></returns>
  337. public JsonResult IndexRefundData(Orders data, string OrderNo, string CreateDateData, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string ProductIdSelect, int page = 1, int limit = 30)
  338. {
  339. Dictionary<string, string> Fields = new Dictionary<string, string>();
  340. string condition = " and Status in(4,5)";
  341. //平台订单号
  342. if (!string.IsNullOrEmpty(OrderNo))
  343. {
  344. condition += " and OrderNo like '" + OrderNo + "'";
  345. }
  346. //创客编号
  347. if (!string.IsNullOrEmpty(UserIdMakerCode))
  348. {
  349. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  350. }
  351. //支付方式
  352. if (!string.IsNullOrEmpty(PayModeSelect))
  353. {
  354. condition += " and PayMode=" + PayModeSelect;
  355. }
  356. //商品类型名称
  357. if (!string.IsNullOrEmpty(ProductIdSelect))
  358. {
  359. condition += " and Id in (select OrderId from OrderProduct where ProductId=" + ProductIdSelect + ")";//表数据量过大时不适用
  360. }
  361. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Orders", Fields, "Id desc", "0", page, limit, condition);
  362. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  363. foreach (Dictionary<string, object> dic in diclist)
  364. {
  365. dic["OrderNo"] = dic["OrderNo"].ToString() + "<br />" + dic["TradeNo"].ToString();
  366. //状态
  367. int Status = int.Parse(dic["Status"].ToString());
  368. if (Status == 4) dic["StatusName"] = "已退款";
  369. // if (Status == 5) dic["StatusName"] = "已退货";
  370. //创客
  371. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  372. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  373. dic["UserInfo"] = userid_Users.MakerCode + "<br />" + userid_Users.RealName;
  374. dic.Remove("UserId");
  375. //支付方式
  376. int PayMode = int.Parse(dic["PayMode"].ToString());
  377. if (PayMode == 1) dic["PayMode"] = "支付宝";
  378. if (PayMode == 2) dic["PayMode"] = "微信";
  379. if (PayMode == 3) dic["PayMode"] = "账户余额";
  380. if (PayMode == 0) dic["PayMode"] = "";
  381. //商品名称
  382. dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
  383. //商品名称
  384. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  385. OrderProduct orderProducts = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id) ?? new OrderProduct();
  386. dic["ProductName"] = orderProducts.ProductName;
  387. //退款时间
  388. var info = db.OrderRefund.FirstOrDefault(m => m.OrderId == Id) ?? new OrderRefund();
  389. dic["ReturnDate"] = info.CreateDate == null ? "" : info.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  390. }
  391. return Json(obj);
  392. }
  393. #endregion
  394. #region WIFI押金列表
  395. /// <summary>
  396. /// 根据条件查询WIFI押金列表
  397. /// </summary>
  398. /// <returns></returns>
  399. public IActionResult IndexWifiDeposit(Orders data, string right)
  400. {
  401. ViewBag.RightInfo = RightInfo;
  402. ViewBag.right = right;
  403. return View();
  404. }
  405. #endregion
  406. #region 根据条件查询WIFI押金列表
  407. /// <summary>
  408. /// WIFI押金列表
  409. /// </summary>
  410. /// <returns></returns>
  411. public JsonResult IndexWifiDepositData(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 StatusSelect, string RefundStatusSelect, string DeliveryTypeSelect, string SendStatusSelect, string ProductIdSelect, string StoreTypeSelect, string StoreUserIdMakerCode, string StoreUserIdRealName, string PayStatusSelect, int page = 1, int limit = 30)
  412. {
  413. Dictionary<string, string> Fields = new Dictionary<string, string>();
  414. Fields.Add("ErpCode", "1"); //运单号
  415. Fields.Add("TradeNo", "1"); //支付交易号
  416. Fields.Add("StoreContact", "1"); //仓库联系人
  417. Fields.Add("SnNos", "2"); //SN编号
  418. Fields.Add("TopUserId", "0");
  419. // string condition = " and Status>=-1 and Status<4";
  420. string condition = " and Status>=-1 and Sort=0";
  421. //平台订单号
  422. if (!string.IsNullOrEmpty(OrderNo))
  423. {
  424. condition += " and OrderNo like '" + OrderNo + "'";
  425. }
  426. //渠道订单号
  427. if (!string.IsNullOrEmpty(TradeNo))
  428. {
  429. condition += " and TradeNo='" + TradeNo + "'";
  430. }
  431. //收件人姓名
  432. if (!string.IsNullOrEmpty(RealName))
  433. {
  434. condition += " and RealName='" + RealName + "'";
  435. }
  436. //收件人电话
  437. if (!string.IsNullOrEmpty(Mobile))
  438. {
  439. condition += " and Mobile='" + Mobile + "'";
  440. }
  441. //创客编号
  442. if (!string.IsNullOrEmpty(UserIdMakerCode))
  443. {
  444. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  445. }
  446. //创客真实姓名
  447. if (!string.IsNullOrEmpty(UserIdRealName))
  448. {
  449. condition += " and UserId in (select Id from Users where RealName='" + UserIdRealName + "')";
  450. }
  451. //支付方式
  452. if (!string.IsNullOrEmpty(PayModeSelect))
  453. {
  454. condition += " and PayMode=" + PayModeSelect;
  455. }
  456. //仓库编号
  457. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  458. {
  459. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  460. }
  461. //仓库名称
  462. if (!string.IsNullOrEmpty(StoreIdStoreName))
  463. {
  464. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  465. }
  466. //仓库联系人
  467. if (!string.IsNullOrEmpty(UserIdMakerCode))
  468. {
  469. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  470. }
  471. //仓库归属创客编号
  472. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  473. {
  474. condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  475. }
  476. //仓库归属创客真实姓名
  477. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  478. {
  479. condition += " and StoreUserId in (select Id from Users where RealName='" + StoreUserIdRealName + "')";
  480. }
  481. //快递单号
  482. if (!string.IsNullOrEmpty(ErpCode))
  483. {
  484. condition += " and ErpCode='" + ErpCode + "'";
  485. }
  486. //SN
  487. if (!string.IsNullOrEmpty(SnNos))
  488. {
  489. condition += " and SnNos like '%" + SnNos + "%'";
  490. }
  491. //支付时间
  492. if (!string.IsNullOrEmpty(PayDateData))
  493. {
  494. string[] datelist = PayDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  495. string start = datelist[0];
  496. string end = datelist[1];
  497. condition += " and PayDate>='" + start + " 00:00:00' and PayDate<='" + end + " 23:59:59'";
  498. }
  499. //下单时间
  500. if (!string.IsNullOrEmpty(CreateDateData))
  501. {
  502. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  503. string start = datelist[0];
  504. string end = datelist[1];
  505. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  506. }
  507. //发货时间
  508. if (!string.IsNullOrEmpty(SendDateData))
  509. {
  510. string[] datelist = SendDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  511. string start = datelist[0];
  512. string end = datelist[1];
  513. condition += " and SendDate>='" + start + " 00:00:00' and SendDate<='" + end + " 23:59:59'";
  514. }
  515. //订单状态
  516. if (!string.IsNullOrEmpty(StatusSelect))
  517. {
  518. condition += " and Status=" + StatusSelect;
  519. }
  520. //退款状态
  521. if (!string.IsNullOrEmpty(RefundStatusSelect))
  522. {
  523. condition += " and RefundStatus=" + RefundStatusSelect;
  524. }
  525. //提货类型
  526. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  527. {
  528. condition += " and DeliveryType=" + DeliveryTypeSelect;
  529. }
  530. //发货状态
  531. if (!string.IsNullOrEmpty(SendStatusSelect))
  532. {
  533. condition += " and SendStatus=" + SendStatusSelect;
  534. }
  535. //商品类型名称
  536. if (!string.IsNullOrEmpty(ProductIdSelect))
  537. {
  538. condition += " and Id in (select OrderId from OrderProduct where ProductId=" + ProductIdSelect + ")";//表数据量过大时不适用
  539. }
  540. //仓库类型
  541. if (!string.IsNullOrEmpty(StoreTypeSelect))
  542. {
  543. condition += " and StoreType=" + StoreTypeSelect;
  544. }
  545. //支付状态
  546. if (!string.IsNullOrEmpty(PayStatusSelect))
  547. {
  548. condition += " and PayStatus=" + PayStatusSelect;
  549. }
  550. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Orders", Fields, "Id desc", "0", page, limit, condition);
  551. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  552. foreach (Dictionary<string, object> dic in diclist)
  553. {
  554. dic["OrderNo"] = dic["OrderNo"].ToString() + "<br />" + dic["TradeNo"].ToString();
  555. dic["StoreContact"] = dic["StoreContact"].ToString() + "<br />" + dic["StoreContactMobile"].ToString();
  556. dic["Address"] = dic["Areas"].ToString() + dic["Address"].ToString();
  557. dic["RecieveInfo"] = dic["RealName"].ToString() + "<br />" + dic["Mobile"].ToString();
  558. dic["ErpInfo"] = dic["ErpCode"].ToString() + "<br />" + dic["ErpName"].ToString();
  559. //创客
  560. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  561. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  562. dic["UserInfo"] = userid_Users.MakerCode + "<br />" + userid_Users.RealName + "<br />" + userid_Users.Id;
  563. //顶级创客信息
  564. if (!string.IsNullOrEmpty(userid_Users.ParentNav))
  565. {
  566. string[] ParentNavList = userid_Users.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  567. var topUserInfo = new Users();
  568. if (ParentNavList.Length > 1)
  569. {
  570. topUserInfo = PublicFunction.GetTopUserInfo(userid_Users.ParentNav, 1);
  571. }
  572. else
  573. {
  574. topUserInfo = PublicFunction.GetTopUserInfo(userid_Users.ParentNav, 0);
  575. }
  576. //顶级创客信息
  577. dic["TopUserInfo"] = topUserInfo.MakerCode + "<br />" + topUserInfo.RealName;
  578. //分离顶级创客信息
  579. dic["TopUserInfoMakerCode"] = topUserInfo.MakerCode;
  580. dic["TopUserInfoRealName"] = topUserInfo.RealName;
  581. }
  582. else
  583. {
  584. dic["TopUserInfo"] = "";
  585. }
  586. //订单状态
  587. int Status = int.Parse(dic["Status"].ToString());
  588. if (Status == -1) dic["StatusName"] = "已取消";
  589. if (Status == 1) dic["StatusName"] = "待发货";
  590. if (Status == 2) dic["StatusName"] = "已完成";
  591. if (Status == 3) dic["StatusName"] = "已发货";
  592. if (Status == 4) dic["StatusName"] = "已退款";
  593. //物流名称
  594. dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
  595. //支付方式
  596. int PayMode = int.Parse(dic["PayMode"].ToString());
  597. if (PayMode == 1) dic["PayMode"] = "支付宝";
  598. if (PayMode == 2) dic["PayMode"] = "微信";
  599. if (PayMode == 3) dic["PayMode"] = "账户余额";
  600. if (PayMode == 0) dic["PayMode"] = "";
  601. //仓库
  602. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  603. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  604. //仓库类型
  605. int StoreType = int.Parse(dic["StoreType"].ToString());
  606. if (StoreType == 0) dic["StoreType"] = "总仓";
  607. if (StoreType == 1) dic["StoreType"] = "分仓";
  608. dic["Store"] = storeid_StoreHouse.StoreNo + "<br />" + dic["StoreType"].ToString();
  609. dic.Remove("StoreId");
  610. // //退款状态
  611. // int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
  612. // if (RefundStatus == 0) dic["RefundStatusName"] = "未退款";
  613. // if (RefundStatus == 1) dic["RefundStatusName"] = "已退款";
  614. //提货类型
  615. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  616. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  617. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  618. if (DeliveryType == 0) dic["DeliveryType"] = "";
  619. // //发货状态
  620. // int SendStatus = int.Parse(dic["SendStatus"].ToString());
  621. // if (SendStatus == -1) dic["SendStatusName"] = "已驳回";
  622. // if (SendStatus == 0) dic["SendStatusName"] = "未发货";
  623. // if (SendStatus == 1) dic["SendStatusName"] = "已发货";
  624. // if (SendStatus == 2) dic["SendStatusName"] = "已退货";
  625. // if (SendStatus == 0)
  626. // {
  627. // dic["SendInfo"] = dic["SendStatusName"];
  628. // }
  629. // else
  630. // {
  631. // dic["SendInfo"] = dic["SendStatusName"].ToString() + "<br />" + dic["SendDate"].ToString();
  632. // }
  633. //商品名称
  634. dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
  635. //商品名称
  636. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  637. OrderProduct orderProducts = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id) ?? new OrderProduct();
  638. var product = db.Products.FirstOrDefault(m => m.Id == orderProducts.ProductId) ?? new Products();
  639. dic["ProductName"] = orderProducts.ProductName;
  640. if (product.ProductKind == 1) dic["ProductKind"] = "实物商品";
  641. if (product.ProductKind == 2) dic["ProductKind"] = "虚拟商品";
  642. //退款时间
  643. var orderRefund = db.OrderRefund.FirstOrDefault(m => m.OrderId == Id) ?? new OrderRefund();
  644. dic["RefundDate"] = "";
  645. if (orderRefund.Id > 0)
  646. {
  647. dic["RefundDate"] = orderRefund.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  648. }
  649. //仓库归属创客
  650. int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
  651. Users storeuserid_Users = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  652. dic["StoreFrom"] = storeuserid_Users.MakerCode + "<br />" + storeid_StoreHouse.StoreName;
  653. dic.Remove("StoreUserId");
  654. // //支付状态
  655. // int PayStatus = int.Parse(dic["PayStatus"].ToString());
  656. // if (PayStatus == 0) dic["PayStatusName"] = "未支付";
  657. // if (PayStatus == 1) dic["PayStatusName"] = "支付成功";
  658. // if (PayStatus == 2) dic["PayStatusName"] = "支付失败";
  659. // if (PayStatus == 3) dic["PayStatusName"] = "支付锁定中";
  660. // if (PayStatus == 4) dic["PayStatusName"] = "支付处理中";
  661. }
  662. Dictionary<string, object> other = new Dictionary<string, object>();
  663. string SuccessAmount = "0.00";//支付成功总金额
  664. string FailAmount = "0.00";//支付失败总金额
  665. DataTable dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1 and Status>-1" + condition);
  666. if (dt.Rows.Count > 0)
  667. {
  668. SuccessAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  669. }
  670. dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=2 and Status>-1" + condition);
  671. if (dt.Rows.Count > 0)
  672. {
  673. FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  674. }
  675. other.Add("SuccessAmount", SuccessAmount);
  676. other.Add("FailAmount", FailAmount);
  677. obj.Add("other", other);
  678. return Json(obj);
  679. }
  680. #endregion
  681. #region 增加创客订单
  682. /// <summary>
  683. /// 增加或修改创客订单信息
  684. /// </summary>
  685. /// <returns></returns>
  686. public IActionResult Add(string right)
  687. {
  688. ViewBag.RightInfo = RightInfo;
  689. ViewBag.right = right;
  690. return View();
  691. }
  692. #endregion
  693. #region 增加创客订单
  694. /// <summary>
  695. /// 增加或修改创客订单信息
  696. /// </summary>
  697. /// <returns></returns>
  698. [HttpPost]
  699. public string Add(Orders data)
  700. {
  701. Dictionary<string, object> Fields = new Dictionary<string, object>();
  702. Fields.Add("RealName", data.RealName); //姓名
  703. Fields.Add("ErpName", data.ErpName); //物流名称
  704. Fields.Add("ErpCode", data.ErpCode); //运单号
  705. Fields.Add("StoreId", data.StoreId); //仓库
  706. Fields.Add("SnNos", data.SnNos); //SN编号
  707. Fields.Add("SeoTitle", data.SeoTitle);
  708. Fields.Add("SeoKeyword", data.SeoKeyword);
  709. Fields.Add("SeoDescription", data.SeoDescription);
  710. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("Orders", Fields, 0);
  711. AddSysLog(data.Id.ToString(), "Orders", "add");
  712. db.SaveChanges();
  713. return "success";
  714. }
  715. #endregion
  716. #region 修改创客订单
  717. /// <summary>
  718. /// 增加或修改创客订单信息
  719. /// </summary>
  720. /// <returns></returns>
  721. public IActionResult Edit(string right, int Id = 0)
  722. {
  723. ViewBag.RightInfo = RightInfo;
  724. ViewBag.right = right;
  725. Orders editData = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  726. ViewBag.data = editData;
  727. return View();
  728. }
  729. #endregion
  730. #region 修改创客订单
  731. /// <summary>
  732. /// 增加或修改创客订单信息
  733. /// </summary>
  734. /// <returns></returns>
  735. [HttpPost]
  736. public string Edit(Orders data)
  737. {
  738. Dictionary<string, object> Fields = new Dictionary<string, object>();
  739. Fields.Add("RealName", data.RealName); //姓名
  740. Fields.Add("ErpName", data.ErpName); //物流名称
  741. Fields.Add("ErpCode", data.ErpCode); //运单号
  742. Fields.Add("StoreId", data.StoreId); //仓库
  743. Fields.Add("SnNos", data.SnNos); //SN编号
  744. Fields.Add("SeoTitle", data.SeoTitle);
  745. Fields.Add("SeoKeyword", data.SeoKeyword);
  746. Fields.Add("SeoDescription", data.SeoDescription);
  747. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Orders", Fields, data.Id);
  748. AddSysLog(data.Id.ToString(), "Orders", "update");
  749. db.SaveChanges();
  750. return "success";
  751. }
  752. #endregion
  753. #region 发货
  754. public IActionResult Send(string right, int Id = 0)
  755. {
  756. ViewBag.RightInfo = RightInfo;
  757. ViewBag.right = right;
  758. Orders editData = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  759. ViewBag.data = editData;
  760. Users user = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  761. ViewBag.MakerCode = user.MakerCode;
  762. ViewBag.RealName = user.RealName;
  763. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == editData.StoreId) ?? new StoreHouse();
  764. ViewBag.StoreName = store.StoreName;
  765. List<OrderProduct> products = db.OrderProduct.Where(m => m.OrderId == editData.Id).ToList();
  766. ViewBag.products = products;
  767. var orderProduct = db.OrderProduct.FirstOrDefault(m => m.OrderId == editData.Id);
  768. ViewBag.productId = orderProduct.ProductId;
  769. return View();
  770. }
  771. #endregion
  772. #region 发货
  773. [HttpPost]
  774. public string Send(Orders data, string IdList, string SnNosList)
  775. {
  776. Dictionary<string, object> Fields = new Dictionary<string, object>();
  777. Fields.Add("ErpName", data.ErpName); //物流名称
  778. Fields.Add("ErpCode", data.ErpCode); //运单号
  779. Fields.Add("SnNos", SnNosList); //SN编号
  780. Fields.Add("SendStatus", 1); //发货状态
  781. Fields.Add("Status", 3); //状态
  782. Fields.Add("SendDate", DateTime.Now); //发货时间
  783. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Orders", Fields, data.Id);
  784. AddSysLog(data.Id.ToString(), "Orders", "Send");
  785. db.SaveChanges();
  786. Orders order = db.Orders.FirstOrDefault(m => m.Id == data.Id) ?? new Orders();
  787. if(order.ProductId == 10 || order.ProductId == 11 || order.ProductId == 77 || order.ProductId == 78 || order.ProductId == 79 || order.ProductId == 92)
  788. {
  789. Utils.Instance.SendMqOrder(order);
  790. }
  791. return "success";
  792. }
  793. #endregion
  794. #region 退货
  795. public IActionResult Return(string right, int Id = 0)
  796. {
  797. ViewBag.RightInfo = RightInfo;
  798. ViewBag.right = right;
  799. Orders editData = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  800. ViewBag.data = editData;
  801. return View();
  802. }
  803. #endregion
  804. #region 退货
  805. [HttpPost]
  806. public string Return(Orders data)
  807. {
  808. AddSysLog(data.Id.ToString(), "Orders", "Return");
  809. Orders order = db.Orders.FirstOrDefault(m => m.Id == data.Id);
  810. if (order != null)
  811. {
  812. if (order.TotalPrice <= 0)
  813. {
  814. return "该订单不符合退货规则!";
  815. }
  816. else if (order.TotalPrice < decimal.Parse(data.RefundActAmount.ToString()) || decimal.Parse(data.RefundActAmount.ToString()) <= 0)
  817. {
  818. return "退款金额和订单金额不符!";
  819. }
  820. else
  821. {
  822. // order.UpdateDate = DateTime.Now;
  823. order.Status = 4;
  824. order.RefundStatus = 1;
  825. order.UpdateMan = SysUserName + "_" + SysRealName;
  826. order.RefundReason = data.RefundReason;
  827. order.RefundActAmount = data.RefundActAmount;
  828. db.SaveChanges();
  829. var Remark = "";
  830. var orderProduct = db.OrderProduct.FirstOrDefault(m => m.OrderId == order.Id) ?? new OrderProduct();
  831. Remark = orderProduct.ProductName + "退款至余额";
  832. // string SendData = "{\"OrderId\":\"" + data.Id + "\",\"Operator\":\"" + SysUserName + "_" + SysRealName + "\",\"Amount\":\"" + data.RefundActAmount + "\",\"Remark\":\"" + Remark + "\"}";
  833. // RedisDbconn.Instance.AddList("RefundQueue", SendData);
  834. bool op = true;
  835. decimal TotalPrice = order.TotalPrice;
  836. decimal Amount = data.RefundActAmount;
  837. if (order.PayMode == 1)
  838. {
  839. PublicAccountSet set = db.PublicAccountSet.FirstOrDefault() ?? new PublicAccountSet();
  840. string result = new Alipay.AlipayPublicClass(_accessor.HttpContext).Refund(set.AlipayAppId, set.AlipayPrivateKey, set.AlipayPublicKey, order.OrderNo, Amount);
  841. }
  842. else if (order.PayMode == 3)
  843. {
  844. UserAccount user = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId);
  845. if (user == null)
  846. {
  847. user = db.UserAccount.Add(new UserAccount()
  848. {
  849. Id = order.UserId,
  850. UserId = order.UserId,
  851. }).Entity;
  852. db.SaveChanges();
  853. }
  854. decimal BeforeTotalAmount = user.TotalAmount; //变更前总金额
  855. decimal BeforeFreezeAmount = user.FreezeAmount; //变更前冻结金额
  856. decimal BeforeBalanceAmount = user.BalanceAmount; //变更前余额
  857. user.BalanceAmount += Amount;
  858. decimal AfterTotalAmount = user.TotalAmount; //变更后总金额
  859. decimal AfterFreezeAmount = user.FreezeAmount; //变更后冻结金额
  860. decimal AfterBalanceAmount = user.BalanceAmount; //变更后余额
  861. db.UserAccountRecord.Add(new UserAccountRecord()
  862. {
  863. CreateDate = DateTime.Now,
  864. UpdateDate = DateTime.Now,
  865. UserId = order.UserId, //创客
  866. ChangeType = 21, //变动类型
  867. ChangeAmount = Amount, //变更金额
  868. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  869. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  870. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  871. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  872. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  873. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  874. QueryCount = order.Id,
  875. Remark = Remark,
  876. });
  877. }
  878. if (op)
  879. {
  880. order.RefundStatus = 1;
  881. order.RefundActAmount = Amount;
  882. db.OrderRefund.Add(new OrderRefund()
  883. {
  884. CreateDate = DateTime.Now,
  885. Mobile = order.Mobile,
  886. Amount = Amount,
  887. SeoDescription = Remark,
  888. ProductId = order.ProductId.ToString(),
  889. OrderId = order.Id,
  890. UserId = order.UserId,
  891. });
  892. }
  893. else
  894. {
  895. order.RefundStatus = 0;
  896. order.RefundReason = null;
  897. order.RefundActAmount = 0;
  898. }
  899. if(!string.IsNullOrEmpty(order.SnNos) && order.ProductId == 134)
  900. {
  901. int count = (int)order.TotalPrice / 750;
  902. List<string> list = order.SnNos.Split(',').ToList();
  903. IQueryable<PosMachinesTwo> poslist = db.PosMachinesTwo.Where(m => list.Contains(m.PosSn) && m.IsOpAct == 1).Take(count);
  904. foreach(PosMachinesTwo pos in poslist)
  905. {
  906. pos.IsOpAct = 2;
  907. }
  908. }
  909. db.SaveChanges();
  910. }
  911. }
  912. return "success";
  913. }
  914. #endregion
  915. #region wifi押金退款
  916. public IActionResult WifiReturn(string right, int Id = 0)
  917. {
  918. ViewBag.RightInfo = RightInfo;
  919. ViewBag.right = right;
  920. Orders editData = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  921. ViewBag.data = editData;
  922. decimal CurAmount = editData.TotalPrice - editData.RefundActAmount;
  923. ViewBag.CurAmount = CurAmount.ToString();
  924. return View();
  925. }
  926. #endregion
  927. #region wifi押金退款
  928. [HttpPost]
  929. public string WifiReturn(Orders data)
  930. {
  931. AddSysLog(data.Id.ToString(), "Orders", "Return");
  932. Orders order = db.Orders.FirstOrDefault(m => m.Id == data.Id);
  933. if (order != null)
  934. {
  935. if (order.TotalPrice <= 0)
  936. {
  937. return "该订单不符合退货规则!";
  938. }
  939. else if (order.TotalPrice < decimal.Parse(data.RefundActAmount.ToString()) || decimal.Parse(data.RefundActAmount.ToString()) <= 0)
  940. {
  941. return "退款金额和订单金额不符!";
  942. }
  943. else
  944. {
  945. order.UpdateMan = SysUserName + "_" + SysRealName;
  946. order.RefundActAmount += data.RefundActAmount;
  947. if(order.RefundActAmount >= order.TotalPrice)
  948. {
  949. order.Status = 4;
  950. order.RefundStatus = 1;
  951. order.RefundReason = data.RefundReason;
  952. }
  953. db.SaveChanges();
  954. var Remark = "";
  955. var orderProduct = db.OrderProduct.FirstOrDefault(m => m.OrderId == order.Id) ?? new OrderProduct();
  956. Remark = orderProduct.ProductName + "退款至余额";
  957. bool op = true;
  958. decimal TotalPrice = order.TotalPrice;
  959. decimal Amount = data.RefundActAmount;
  960. if (order.PayMode == 1)
  961. {
  962. PublicAccountSet set = db.PublicAccountSet.FirstOrDefault() ?? new PublicAccountSet();
  963. string result = new Alipay.AlipayPublicClass(_accessor.HttpContext).Refund(set.AlipayAppId, set.AlipayPrivateKey, set.AlipayPublicKey, order.OrderNo, Amount);
  964. }
  965. else if (order.PayMode == 3)
  966. {
  967. UserAccount user = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId);
  968. if (user == null)
  969. {
  970. user = db.UserAccount.Add(new UserAccount()
  971. {
  972. Id = order.UserId,
  973. UserId = order.UserId,
  974. }).Entity;
  975. db.SaveChanges();
  976. }
  977. decimal BeforeTotalAmount = user.TotalAmount; //变更前总金额
  978. decimal BeforeFreezeAmount = user.FreezeAmount; //变更前冻结金额
  979. decimal BeforeBalanceAmount = user.BalanceAmount; //变更前余额
  980. user.BalanceAmount += Amount;
  981. decimal AfterTotalAmount = user.TotalAmount; //变更后总金额
  982. decimal AfterFreezeAmount = user.FreezeAmount; //变更后冻结金额
  983. decimal AfterBalanceAmount = user.BalanceAmount; //变更后余额
  984. db.UserAccountRecord.Add(new UserAccountRecord()
  985. {
  986. CreateDate = DateTime.Now,
  987. UpdateDate = DateTime.Now,
  988. UserId = order.UserId, //创客
  989. ChangeType = 21, //变动类型
  990. ChangeAmount = Amount, //变更金额
  991. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  992. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  993. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  994. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  995. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  996. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  997. QueryCount = order.Id,
  998. Remark = Remark,
  999. });
  1000. }
  1001. if (op)
  1002. {
  1003. db.OrderRefund.Add(new OrderRefund()
  1004. {
  1005. CreateDate = DateTime.Now,
  1006. Mobile = order.Mobile,
  1007. Amount = Amount,
  1008. SeoDescription = Remark,
  1009. ProductId = order.ProductId.ToString(),
  1010. OrderId = order.Id,
  1011. UserId = order.UserId,
  1012. });
  1013. }
  1014. else
  1015. {
  1016. order.RefundStatus = 0;
  1017. order.RefundReason = null;
  1018. order.RefundActAmount = 0;
  1019. }
  1020. if(!string.IsNullOrEmpty(order.SnNos) && order.ProductId == 134)
  1021. {
  1022. int count = (int)order.TotalPrice / 750;
  1023. List<string> list = order.SnNos.Split(',').ToList();
  1024. IQueryable<PosMachinesTwo> poslist = db.PosMachinesTwo.Where(m => list.Contains(m.PosSn) && m.IsOpAct == 1).Take(count);
  1025. foreach(PosMachinesTwo pos in poslist)
  1026. {
  1027. pos.IsOpAct = 2;
  1028. }
  1029. }
  1030. db.SaveChanges();
  1031. }
  1032. }
  1033. return "success";
  1034. }
  1035. #endregion
  1036. #region 订单详情
  1037. public IActionResult Detail(string right, int Id = 0)
  1038. {
  1039. ViewBag.RightInfo = RightInfo;
  1040. ViewBag.right = right;
  1041. Orders editData = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  1042. ViewBag.data = editData;
  1043. Users user = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  1044. ViewBag.MakerCode = user.MakerCode;
  1045. ViewBag.RealName = user.RealName;
  1046. //支付状态
  1047. int PayStatus = editData.PayStatus;
  1048. if (PayStatus == 0) ViewBag.PayStatus = "未支付";
  1049. if (PayStatus == 1) ViewBag.PayStatus = "支付成功";
  1050. if (PayStatus == 2) ViewBag.PayStatus = "支付失败";
  1051. if (PayStatus == 3) ViewBag.PayStatus = "支付锁定中";
  1052. if (PayStatus == 4) ViewBag.PayStatus = "支付处理中";
  1053. //支付方式
  1054. int PayMode = editData.PayMode;
  1055. if (PayMode == 1)
  1056. {
  1057. ViewBag.PayMode = "支付宝支付";
  1058. ViewBag.PayModeCode = "Alipay";
  1059. }
  1060. if (PayMode == 2)
  1061. {
  1062. ViewBag.PayMode = "微信支付";
  1063. ViewBag.PayModeCode = "WeChat";
  1064. }
  1065. if (PayMode == 3)
  1066. {
  1067. ViewBag.PayMode = "账户余额支付";
  1068. ViewBag.PayModeCode = "AccBalancePay";
  1069. }
  1070. //发货状态
  1071. int SendStatus = editData.SendStatus;
  1072. if (SendStatus == 0) ViewBag.SendStatus = "未发货";
  1073. if (SendStatus == 1) ViewBag.SendStatus = "已发货";
  1074. if (SendStatus == 2) ViewBag.SendStatus = "已退货";
  1075. //提货类型
  1076. int DeliveryType = editData.DeliveryType;
  1077. if (DeliveryType == 1) ViewBag.DeliveryType = "邮寄到付";
  1078. if (DeliveryType == 2) ViewBag.DeliveryType = "上门自提";
  1079. List<OrderProduct> products = db.OrderProduct.Where(m => m.OrderId == editData.Id).ToList();
  1080. List<Dictionary<string, object>> ProductList = new List<Dictionary<string, object>>();
  1081. foreach (OrderProduct product in products)
  1082. {
  1083. Dictionary<string, object> item = new Dictionary<string, object>();
  1084. item.Add("ProductCode", product.ProductCode); //商品编号
  1085. item.Add("ProductName", product.ProductName); //商品名称
  1086. item.Add("ProductCount", product.ProductCount); //商品数量
  1087. item.Add("ProductPrice", product.ProductPrice); //商品单价
  1088. item.Add("SeoKeyword", product.SeoKeyword); //商品简介
  1089. item.Add("SeoDescription", product.SeoDescription); //备注
  1090. item.Add("ProductPhoto", SourceHost + product.ProductPhoto); //商品小图
  1091. item.Add("NormDetail", product.NormDetail); //商品规格
  1092. ProductList.Add(item);
  1093. }
  1094. ViewBag.ProductList = ProductList;
  1095. return View();
  1096. }
  1097. #endregion
  1098. #region 删除创客订单信息
  1099. /// <summary>
  1100. /// 删除创客订单信息
  1101. /// </summary>
  1102. /// <returns></returns>
  1103. public string Delete(string Id)
  1104. {
  1105. string[] idlist = Id.Split(new char[] { ',' });
  1106. AddSysLog(Id, "Orders", "del");
  1107. foreach (string subid in idlist)
  1108. {
  1109. int id = int.Parse(subid);
  1110. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1111. Fields.Add("Status", -1);
  1112. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Orders", Fields, id);
  1113. }
  1114. db.SaveChanges();
  1115. return "success";
  1116. }
  1117. #endregion
  1118. #region 开启
  1119. /// <summary>
  1120. /// 开启
  1121. /// </summary>
  1122. /// <returns></returns>
  1123. public string Open(string Id)
  1124. {
  1125. string[] idlist = Id.Split(new char[] { ',' });
  1126. AddSysLog(Id, "Orders", "open");
  1127. foreach (string subid in idlist)
  1128. {
  1129. int id = int.Parse(subid);
  1130. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1131. Fields.Add("Status", 1);
  1132. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Orders", Fields, id);
  1133. }
  1134. db.SaveChanges();
  1135. return "success";
  1136. }
  1137. #endregion
  1138. #region 关闭
  1139. /// <summary>
  1140. /// 关闭
  1141. /// </summary>
  1142. /// <returns></returns>
  1143. public string Close(string Id)
  1144. {
  1145. string[] idlist = Id.Split(new char[] { ',' });
  1146. AddSysLog(Id, "Orders", "close");
  1147. foreach (string subid in idlist)
  1148. {
  1149. int id = int.Parse(subid);
  1150. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1151. Fields.Add("Status", 0);
  1152. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("Orders", Fields, id);
  1153. }
  1154. db.SaveChanges();
  1155. return "success";
  1156. }
  1157. #endregion
  1158. #region 排序
  1159. /// <summary>
  1160. /// 排序
  1161. /// </summary>
  1162. /// <param name="Id"></param>
  1163. public string Sort(int Id, int Sort)
  1164. {
  1165. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("Orders", Sort, Id);
  1166. AddSysLog(Id.ToString(), "Orders", "sort");
  1167. return "success";
  1168. }
  1169. #endregion
  1170. #region 导入数据
  1171. /// <summary>
  1172. /// 导入数据
  1173. /// </summary>
  1174. /// <param name="ExcelData"></param>
  1175. public string Import(string ExcelData)
  1176. {
  1177. ExcelData = HttpUtility.UrlDecode(ExcelData);
  1178. JsonData list = JsonMapper.ToObject(ExcelData);
  1179. for (int i = 1; i < list.Count; i++)
  1180. {
  1181. JsonData dr = list[i];
  1182. db.Orders.Add(new Orders()
  1183. {
  1184. CreateDate = DateTime.Now,
  1185. UpdateDate = DateTime.Now,
  1186. });
  1187. db.SaveChanges();
  1188. }
  1189. AddSysLog("0", "Orders", "Import");
  1190. return "success";
  1191. }
  1192. #endregion
  1193. #region 导出Excel
  1194. /// <summary>
  1195. /// 导出Excel
  1196. /// </summary>
  1197. /// <returns></returns>
  1198. 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")
  1199. {
  1200. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1201. Fields.Add("CreateDate", "3"); //时间
  1202. Fields.Add("OrderNo", "1"); //订单号
  1203. Fields.Add("RealName", "1"); //姓名
  1204. Fields.Add("Mobile", "1"); //手机号
  1205. Fields.Add("ErpCode", "1"); //运单号
  1206. Fields.Add("SendDate", "3"); //发货时间
  1207. Fields.Add("TradeNo", "1"); //支付交易号
  1208. Fields.Add("StoreContact", "1"); //仓库联系人
  1209. Fields.Add("SnNos", "2"); //SN编号
  1210. Fields.Add("TopUserId", "0");
  1211. string condition = " and Status>-1";
  1212. //创客编号
  1213. if (!string.IsNullOrEmpty(UserIdMakerCode))
  1214. {
  1215. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  1216. }
  1217. //创客真实姓名
  1218. if (!string.IsNullOrEmpty(UserIdRealName))
  1219. {
  1220. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  1221. }
  1222. //支付方式
  1223. if (!string.IsNullOrEmpty(PayModeSelect))
  1224. {
  1225. condition += " and PayMode=" + PayModeSelect;
  1226. }
  1227. //仓库编号
  1228. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  1229. {
  1230. condition += " and StoreId in (select StoreId from StoreHouseForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
  1231. }
  1232. //仓库名称
  1233. if (!string.IsNullOrEmpty(StoreIdStoreName))
  1234. {
  1235. condition += " and StoreId in (select StoreId from StoreHouseForStoreName where StoreName='" + StoreIdStoreName + "')";
  1236. }
  1237. //退款状态
  1238. if (!string.IsNullOrEmpty(RefundStatusSelect))
  1239. {
  1240. condition += " and RefundStatus=" + RefundStatusSelect;
  1241. }
  1242. //提货类型
  1243. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  1244. {
  1245. condition += " and DeliveryType=" + DeliveryTypeSelect;
  1246. }
  1247. //发货状态
  1248. if (!string.IsNullOrEmpty(SendStatusSelect))
  1249. {
  1250. condition += " and SendStatus=" + SendStatusSelect;
  1251. }
  1252. //商品名称
  1253. if (!string.IsNullOrEmpty(ProductIdSelect))
  1254. {
  1255. condition += " and ProductId=" + ProductIdSelect;
  1256. }
  1257. //仓库类型
  1258. if (!string.IsNullOrEmpty(StoreTypeSelect))
  1259. {
  1260. condition += " and StoreType=" + StoreTypeSelect;
  1261. }
  1262. //仓库归属创客编号
  1263. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  1264. {
  1265. condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  1266. }
  1267. //仓库归属创客真实姓名
  1268. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  1269. {
  1270. condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
  1271. }
  1272. //支付状态
  1273. if (!string.IsNullOrEmpty(PayStatusSelect))
  1274. {
  1275. condition += " and PayStatus=" + PayStatusSelect;
  1276. }
  1277. //创建工作薄
  1278. var workbook = new XSSFWorkbook();
  1279. //创建表
  1280. var table = workbook.CreateSheet("Sheet1");
  1281. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).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);
  1282. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1283. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1284. ReturnFields.Add("UserIdMakerCode", "创客编号");
  1285. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  1286. ReturnFields.Add("OrderNo", "订单号");
  1287. ReturnFields.Add("RealName", "姓名");
  1288. ReturnFields.Add("Mobile", "手机号");
  1289. ReturnFields.Add("TotalPrice", "总价");
  1290. ReturnFields.Add("Areas", "所在地区");
  1291. ReturnFields.Add("Address", "详细地址");
  1292. ReturnFields.Add("ErpName", "物流名称");
  1293. ReturnFields.Add("ErpCode", "运单号");
  1294. ReturnFields.Add("SendDate", "发货时间");
  1295. ReturnFields.Add("PayMode", "支付方式");
  1296. ReturnFields.Add("TradeNo", "支付交易号");
  1297. ReturnFields.Add("StoreIdStoreNo", "仓库编号");
  1298. ReturnFields.Add("StoreIdStoreName", "仓库名称");
  1299. ReturnFields.Add("RefundStatus", "退款状态");
  1300. ReturnFields.Add("DeliveryType", "提货类型");
  1301. ReturnFields.Add("SendStatus", "发货状态");
  1302. ReturnFields.Add("ProductId", "商品名称");
  1303. ReturnFields.Add("StoreContact", "仓库联系人");
  1304. ReturnFields.Add("StoreType", "仓库类型");
  1305. ReturnFields.Add("StoreUserIdMakerCode", "仓库归属创客编号");
  1306. ReturnFields.Add("StoreUserIdRealName", "仓库归属创客姓名");
  1307. ReturnFields.Add("TopUserIdMakerCode", "顶级创客编号");
  1308. ReturnFields.Add("TopUserIdRealName", "顶级创客姓名");
  1309. ReturnFields.Add("PayStatus", "支付状态");
  1310. ReturnFields.Add("BuyCount", "下单数量");
  1311. ReturnFields.Add("Remark", "订单备注");
  1312. int i = 0;
  1313. foreach (Dictionary<string, object> dic in diclist)
  1314. {
  1315. i += 1;
  1316. //创客
  1317. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  1318. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  1319. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  1320. dic["UserIdRealName"] = userid_Users.RealName;
  1321. dic.Remove("UserId");
  1322. //物流名称
  1323. dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
  1324. //支付方式
  1325. int PayMode = int.Parse(dic["PayMode"].ToString());
  1326. if (PayMode == 1) dic["PayMode"] = "支付宝";
  1327. if (PayMode == 2) dic["PayMode"] = "微信";
  1328. if (PayMode == 3) dic["PayMode"] = "账户余额";
  1329. if (PayMode == 0) dic["PayMode"] = "";
  1330. //仓库
  1331. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  1332. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  1333. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  1334. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  1335. dic.Remove("StoreId");
  1336. //退款状态
  1337. int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
  1338. if (RefundStatus == 0) dic["RefundStatus"] = "未退款";
  1339. if (RefundStatus == 1) dic["RefundStatus"] = "已退款";
  1340. //提货类型
  1341. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  1342. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  1343. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  1344. if (DeliveryType == 0) dic["DeliveryType"] = "";
  1345. //发货状态
  1346. int SendStatus = int.Parse(dic["SendStatus"].ToString());
  1347. if (SendStatus == 0) dic["SendStatus"] = "未发货";
  1348. if (SendStatus == 1) dic["SendStatus"] = "已发货";
  1349. if (SendStatus == 2) dic["SendStatus"] = "已退货";
  1350. //商品名称
  1351. dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
  1352. //仓库类型
  1353. int StoreType = int.Parse(dic["StoreType"].ToString());
  1354. if (StoreType == 0) dic["StoreType"] = "总仓";
  1355. if (StoreType == 1) dic["StoreType"] = "分仓";
  1356. //仓库归属创客
  1357. int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
  1358. Users storeuserid_Users = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  1359. dic["StoreUserIdMakerCode"] = storeuserid_Users.MakerCode;
  1360. dic["StoreUserIdRealName"] = storeuserid_Users.RealName;
  1361. dic.Remove("StoreUserId");
  1362. //顶级创客
  1363. int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
  1364. Users topuserid_Users = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1365. dic["TopUserIdMakerCode"] = topuserid_Users.MakerCode;
  1366. dic["TopUserIdRealName"] = topuserid_Users.RealName;
  1367. dic.Remove("TopUserId");
  1368. //支付状态
  1369. int PayStatus = int.Parse(dic["PayStatus"].ToString());
  1370. if (PayStatus == 0) dic["PayStatus"] = "未支付";
  1371. if (PayStatus == 1) dic["PayStatus"] = "支付成功";
  1372. if (PayStatus == 2) dic["PayStatus"] = "支付失败";
  1373. if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
  1374. if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
  1375. int OrderId = int.Parse(dic["Id"].ToString());
  1376. List<OrderProduct> products = db.OrderProduct.Where(m => m.OrderId == OrderId).ToList();
  1377. foreach (OrderProduct product in products)
  1378. {
  1379. dic["ProductCode"] = product.ProductCode; //商品编号
  1380. dic["ProductName"] = product.ProductName; //商品名称
  1381. dic["ProductCount"] = product.ProductCount; //商品数量
  1382. dic["ProductPrice"] = product.ProductPrice; //商品单价
  1383. dic["NormDetail"] = product.NormDetail; //商品规格
  1384. if (i == 1)
  1385. {
  1386. ReturnFields.Add("ProductCode", "商品编号");
  1387. ReturnFields.Add("ProductName", "商品名称");
  1388. ReturnFields.Add("ProductCount", "商品数量");
  1389. ReturnFields.Add("ProductPrice", "商品单价");
  1390. ReturnFields.Add("NormDetail", "商品规格");
  1391. }
  1392. }
  1393. dic.Remove("Id");
  1394. var row = table.CreateRow(i);
  1395. int index = 0;
  1396. foreach (string key in ReturnFields.Keys)
  1397. {
  1398. var cell = row.CreateCell(index);
  1399. string val = dic[key] == null ? "" : dic[key].ToString();
  1400. ICellStyle style = workbook.CreateCellStyle();
  1401. style.BorderBottom = BorderStyle.Thin;
  1402. style.BorderTop = BorderStyle.Thin;
  1403. style.BorderLeft = BorderStyle.Thin;
  1404. style.BorderRight = BorderStyle.Thin;
  1405. style.BottomBorderColor = HSSFColor.Black.Index;
  1406. style.TopBorderColor = HSSFColor.Black.Index;
  1407. style.LeftBorderColor = HSSFColor.Black.Index;
  1408. style.RightBorderColor = HSSFColor.Black.Index;
  1409. cell.CellStyle = style;
  1410. cell.SetCellValue(val);
  1411. index += 1;
  1412. }
  1413. RedisDbconn.Instance.Set("CheckExport:" + RedisKey, i.ToString() + " / " + diclist.Count);
  1414. }
  1415. var title = table.CreateRow(0);
  1416. int j = 0;
  1417. foreach (string key in ReturnFields.Keys)
  1418. {
  1419. var cell = title.CreateCell(j);
  1420. ICellStyle style = workbook.CreateCellStyle();
  1421. style.BorderBottom = BorderStyle.Thin;
  1422. style.BorderTop = BorderStyle.Thin;
  1423. style.BorderLeft = BorderStyle.Thin;
  1424. style.BorderRight = BorderStyle.Thin;
  1425. style.BottomBorderColor = HSSFColor.Black.Index;
  1426. style.TopBorderColor = HSSFColor.Black.Index;
  1427. style.LeftBorderColor = HSSFColor.Black.Index;
  1428. style.RightBorderColor = HSSFColor.Black.Index;
  1429. cell.CellStyle = style;
  1430. cell.SetCellValue(ReturnFields[key].ToString());
  1431. j += 1;
  1432. }
  1433. //打开xls文件,如没有则创建,如存在则在创建是不要打开该文件
  1434. string FilePath = function.getPath("/static/export/");
  1435. if (!System.IO.Directory.Exists(FilePath))
  1436. {
  1437. System.IO.Directory.CreateDirectory(FilePath);
  1438. }
  1439. string FileName = "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx";
  1440. using (var fs = System.IO.File.OpenWrite(FilePath + FileName))
  1441. {
  1442. workbook.Write(fs); //向打开的这个xls文件中写入mySheet表并保存。
  1443. }
  1444. AddSysLog("0", "Orders", "ExportExcel");
  1445. RedisDbconn.Instance.Set("CheckExport:" + RedisKey, "finish");
  1446. return "success|/static/export/" + FileName;
  1447. }
  1448. public string CheckExport(string RedisKey = "ExportKey")
  1449. {
  1450. string result = RedisDbconn.Instance.Get<string>("CheckExport:" + RedisKey);
  1451. return result;
  1452. }
  1453. #endregion
  1454. #region 导出Excel
  1455. /// <summary>
  1456. /// 导出Excel
  1457. /// </summary>
  1458. /// <returns></returns>
  1459. public JsonResult ExportsExcel(Orders data, string UserIdMakerCode, string UserIdRealName, string PayModeSelect, string StoreIdStoreNo, string StoreIdStoreName, string StatusSelect, 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")
  1460. {
  1461. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1462. // Fields.Add("CreateDate", "3"); //时间
  1463. Fields.Add("OrderNo", "1"); //订单号
  1464. Fields.Add("RealName", "1"); //姓名
  1465. Fields.Add("Mobile", "1"); //手机号
  1466. Fields.Add("ErpCode", "1"); //运单号
  1467. Fields.Add("TradeNo", "1"); //支付交易号
  1468. Fields.Add("StoreContact", "1"); //仓库联系人
  1469. Fields.Add("SnNos", "2"); //SN编号
  1470. Fields.Add("TopUserId", "0");
  1471. string condition = " and Status>=-1 and Sort=0";
  1472. //创客编号
  1473. if (!string.IsNullOrEmpty(UserIdMakerCode))
  1474. {
  1475. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  1476. }
  1477. //创客真实姓名
  1478. if (!string.IsNullOrEmpty(UserIdRealName))
  1479. {
  1480. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  1481. }
  1482. //支付方式
  1483. if (!string.IsNullOrEmpty(PayModeSelect))
  1484. {
  1485. condition += " and PayMode=" + PayModeSelect;
  1486. }
  1487. //仓库编号
  1488. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  1489. {
  1490. condition += " and StoreId in (select StoreId from StoreHouseForStoreNo where StoreNo='" + StoreIdStoreNo + "')";
  1491. }
  1492. //仓库名称
  1493. if (!string.IsNullOrEmpty(StoreIdStoreName))
  1494. {
  1495. condition += " and StoreId in (select StoreId from StoreHouseForStoreName where StoreName='" + StoreIdStoreName + "')";
  1496. }
  1497. //订单状态
  1498. if (!string.IsNullOrEmpty(StatusSelect))
  1499. {
  1500. condition += " and Status=" + StatusSelect;
  1501. }
  1502. //退款状态
  1503. if (!string.IsNullOrEmpty(RefundStatusSelect))
  1504. {
  1505. condition += " and RefundStatus=" + RefundStatusSelect;
  1506. }
  1507. //提货类型
  1508. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  1509. {
  1510. condition += " and DeliveryType=" + DeliveryTypeSelect;
  1511. }
  1512. //发货状态
  1513. if (!string.IsNullOrEmpty(SendStatusSelect))
  1514. {
  1515. condition += " and SendStatus=" + SendStatusSelect;
  1516. }
  1517. //商品名称
  1518. if (!string.IsNullOrEmpty(ProductIdSelect))
  1519. {
  1520. condition += " and ProductId=" + ProductIdSelect;
  1521. }
  1522. //仓库类型
  1523. if (!string.IsNullOrEmpty(StoreTypeSelect))
  1524. {
  1525. condition += " and StoreType=" + StoreTypeSelect;
  1526. }
  1527. //仓库归属创客编号
  1528. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  1529. {
  1530. condition += " and StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  1531. }
  1532. //仓库归属创客真实姓名
  1533. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  1534. {
  1535. condition += " and StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
  1536. }
  1537. //支付状态
  1538. if (!string.IsNullOrEmpty(PayStatusSelect))
  1539. {
  1540. condition += " and PayStatus=" + PayStatusSelect;
  1541. }
  1542. //支付时间
  1543. if (!string.IsNullOrEmpty(PayDateData))
  1544. {
  1545. string[] datelist = PayDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1546. string start = datelist[0];
  1547. string end = datelist[1];
  1548. condition += " and PayDate>='" + start + " 00:00:00' and PayDate<='" + end + " 23:59:59'";
  1549. }
  1550. //下单时间
  1551. if (!string.IsNullOrEmpty(CreateDateData))
  1552. {
  1553. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1554. string start = datelist[0];
  1555. string end = datelist[1];
  1556. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  1557. }
  1558. //发货时间
  1559. if (!string.IsNullOrEmpty(SendDateData))
  1560. {
  1561. string[] datelist = SendDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1562. string start = datelist[0];
  1563. string end = datelist[1];
  1564. condition += " and SendDate>='" + start + " 00:00:00' and SendDate<='" + end + " 23:59:59'";
  1565. }
  1566. // Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).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);
  1567. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Orders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,OrderNo,RealName,Mobile,TotalPrice,Areas,Address,ErpName,ErpCode,SendDate,PayMode,PayDate,TradeNo,StoreId,DeliveryType,ProductId,StoreContact,StoreType,StoreUserId,TopUserId,Status,BuyCount,Remark,Id", false);
  1568. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  1569. foreach (Dictionary<string, object> dic in diclist)
  1570. {
  1571. //创客
  1572. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  1573. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  1574. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  1575. dic["UserIdRealName"] = userid_Users.RealName;
  1576. dic.Remove("UserId");
  1577. //物流名称
  1578. dic["ErpName"] = RelationClass.GetErpCompanysInfo(dic["ErpName"].ToString());
  1579. //支付方式
  1580. int PayMode = int.Parse(dic["PayMode"].ToString());
  1581. if (PayMode == 1) dic["PayMode"] = "支付宝";
  1582. if (PayMode == 2) dic["PayMode"] = "微信";
  1583. if (PayMode == 3) dic["PayMode"] = "账户余额";
  1584. if (PayMode == 0) dic["PayMode"] = "";
  1585. //仓库
  1586. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  1587. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  1588. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  1589. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  1590. dic.Remove("StoreId");
  1591. // //退款状态
  1592. // int RefundStatus = int.Parse(dic["RefundStatus"].ToString());
  1593. // if (RefundStatus == 0) dic["RefundStatus"] = "未退款";
  1594. // if (RefundStatus == 1) dic["RefundStatus"] = "已退款";
  1595. //提货类型
  1596. int DeliveryType = int.Parse(dic["DeliveryType"].ToString());
  1597. if (DeliveryType == 1) dic["DeliveryType"] = "邮寄到付";
  1598. if (DeliveryType == 2) dic["DeliveryType"] = "上门自提";
  1599. if (DeliveryType == 0) dic["DeliveryType"] = "";
  1600. // //发货状态
  1601. // int SendStatus = int.Parse(dic["SendStatus"].ToString());
  1602. // if (SendStatus == 0) dic["SendStatus"] = "未发货";
  1603. // if (SendStatus == 1) dic["SendStatus"] = "已发货";
  1604. // if (SendStatus == 2) dic["SendStatus"] = "已退货";
  1605. //商品名称
  1606. dic["ProductId"] = RelationClass.GetProductsInfo(int.Parse(dic["ProductId"].ToString()));
  1607. //仓库类型
  1608. int StoreType = int.Parse(dic["StoreType"].ToString());
  1609. if (StoreType == 0) dic["StoreType"] = "总仓";
  1610. if (StoreType == 1) dic["StoreType"] = "分仓";
  1611. //仓库归属创客
  1612. int StoreUserId = int.Parse(function.CheckInt(dic["StoreUserId"].ToString()));
  1613. Users storeuserid_Users = db.Users.FirstOrDefault(m => m.Id == StoreUserId) ?? new Users();
  1614. dic["StoreUserIdMakerCode"] = storeuserid_Users.MakerCode;
  1615. dic["StoreUserIdRealName"] = storeuserid_Users.RealName;
  1616. dic.Remove("StoreUserId");
  1617. //顶级创客
  1618. int TopUserId = int.Parse(function.CheckInt(dic["TopUserId"].ToString()));
  1619. Users topuserid_Users = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1620. dic["TopUserIdMakerCode"] = topuserid_Users.MakerCode;
  1621. dic["TopUserIdRealName"] = topuserid_Users.RealName;
  1622. dic.Remove("TopUserId");
  1623. // //支付状态
  1624. // int PayStatus = int.Parse(dic["PayStatus"].ToString());
  1625. // if (PayStatus == 0) dic["PayStatus"] = "未支付";
  1626. // if (PayStatus == 1) dic["PayStatus"] = "支付成功";
  1627. // if (PayStatus == 2) dic["PayStatus"] = "支付失败";
  1628. // if (PayStatus == 3) dic["PayStatus"] = "支付锁定中";
  1629. // if (PayStatus == 4) dic["PayStatus"] = "支付处理中";
  1630. int OrderId = int.Parse(dic["Id"].ToString());
  1631. List<OrderProduct> products = db.OrderProduct.Where(m => m.OrderId == OrderId).ToList();
  1632. foreach (OrderProduct product in products)
  1633. {
  1634. dic["ProductCode"] = product.ProductCode; //商品编号
  1635. dic["ProductName"] = product.ProductName; //商品名称
  1636. dic["ProductCount"] = product.ProductCount; //商品数量
  1637. dic["ProductPrice"] = product.ProductPrice; //商品单价
  1638. dic["NormDetail"] = product.NormDetail; //商品规格
  1639. }
  1640. dic.Remove("Id");
  1641. }
  1642. Dictionary<string, object> result = new Dictionary<string, object>();
  1643. result.Add("Status", "1");
  1644. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1645. result.Add("Obj", diclist);
  1646. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1647. ReturnFields.Add("UserIdMakerCode", "创客编号");
  1648. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  1649. ReturnFields.Add("OrderNo", "订单号");
  1650. ReturnFields.Add("RealName", "姓名");
  1651. ReturnFields.Add("Mobile", "手机号");
  1652. ReturnFields.Add("TotalPrice", "总价");
  1653. ReturnFields.Add("Areas", "所在地区");
  1654. ReturnFields.Add("Address", "详细地址");
  1655. ReturnFields.Add("ErpName", "物流名称");
  1656. ReturnFields.Add("ErpCode", "运单号");
  1657. ReturnFields.Add("SendDate", "发货时间");
  1658. ReturnFields.Add("PayMode", "支付方式");
  1659. ReturnFields.Add("PayDate", "支付时间");
  1660. ReturnFields.Add("TradeNo", "支付交易号");
  1661. ReturnFields.Add("StoreIdStoreNo", "仓库编号");
  1662. ReturnFields.Add("StoreIdStoreName", "仓库名称");
  1663. // ReturnFields.Add("RefundStatus", "退款状态");
  1664. ReturnFields.Add("DeliveryType", "提货类型");
  1665. // ReturnFields.Add("SendStatus", "发货状态");
  1666. ReturnFields.Add("ProductId", "商品名称");
  1667. ReturnFields.Add("StoreContact", "仓库联系人");
  1668. ReturnFields.Add("StoreType", "仓库类型");
  1669. ReturnFields.Add("StoreUserIdMakerCode", "仓库归属创客编号");
  1670. ReturnFields.Add("StoreUserIdRealName", "仓库归属创客姓名");
  1671. ReturnFields.Add("TopUserIdMakerCode", "顶级创客编号");
  1672. ReturnFields.Add("TopUserIdRealName", "顶级创客姓名");
  1673. // ReturnFields.Add("PayStatus", "支付状态");
  1674. ReturnFields.Add("BuyCount", "下单数量");
  1675. ReturnFields.Add("Remark", "订单备注");
  1676. ReturnFields.Add("ProductCode", "商品编号");
  1677. ReturnFields.Add("ProductName", "商品名称");
  1678. ReturnFields.Add("ProductCount", "商品数量");
  1679. ReturnFields.Add("ProductPrice", "商品单价");
  1680. ReturnFields.Add("NormDetail", "商品规格");
  1681. result.Add("Fields", ReturnFields);
  1682. AddSysLog("0", "Orders", "ExportExcel");
  1683. return Json(result);
  1684. }
  1685. #endregion
  1686. #region 快捷导出Excel
  1687. public IActionResult QuickExportExcel(string right)
  1688. {
  1689. ViewBag.RightInfo = RightInfo;
  1690. ViewBag.right = right;
  1691. return View();
  1692. }
  1693. [HttpPost]
  1694. public string QuickExportExcelDo(string OrderNo, 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)
  1695. {
  1696. string SqlString = " where 1=1 and a.Status>=-1 and a.Sort=0";
  1697. //订单号
  1698. if (!string.IsNullOrEmpty(OrderNo))
  1699. {
  1700. SqlString += " and a.OrderNo='" + OrderNo + "'";
  1701. }
  1702. if (!string.IsNullOrEmpty(UserIdMakerCode))
  1703. {
  1704. SqlString += " and a.UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  1705. }
  1706. //创客真实姓名
  1707. if (!string.IsNullOrEmpty(UserIdRealName))
  1708. {
  1709. SqlString += " and a.UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  1710. }
  1711. //支付方式
  1712. if (!string.IsNullOrEmpty(PayModeSelect))
  1713. {
  1714. SqlString += " and a.PayMode=" + PayModeSelect;
  1715. }
  1716. //仓库编号
  1717. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  1718. {
  1719. SqlString += " and a.StoreId in (select StoreId from StoreForCode where StoreNo='" + StoreIdStoreNo + "')";
  1720. }
  1721. //仓库名称
  1722. if (!string.IsNullOrEmpty(StoreIdStoreName))
  1723. {
  1724. SqlString += " and a.StoreId in (select Id from StoreHouse where StoreName='" + StoreIdStoreName + "')";
  1725. }
  1726. //退款状态
  1727. if (!string.IsNullOrEmpty(RefundStatusSelect))
  1728. {
  1729. SqlString += " and a.RefundStatus=" + RefundStatusSelect;
  1730. }
  1731. //提货类型
  1732. if (!string.IsNullOrEmpty(DeliveryTypeSelect))
  1733. {
  1734. SqlString += " and a.DeliveryType=" + DeliveryTypeSelect;
  1735. }
  1736. //发货状态
  1737. if (!string.IsNullOrEmpty(SendStatusSelect))
  1738. {
  1739. SqlString += " and a.SendStatus=" + SendStatusSelect;
  1740. }
  1741. //商品名称
  1742. if (!string.IsNullOrEmpty(ProductIdSelect))
  1743. {
  1744. // SqlString += " and a.ProductId=" + ProductIdSelect;
  1745. SqlString += " and a.Id in (select OrderId from OrderProduct where ProductId=" + ProductIdSelect + ")";
  1746. }
  1747. //仓库类型
  1748. if (!string.IsNullOrEmpty(StoreTypeSelect))
  1749. {
  1750. SqlString += " and a.StoreType=" + StoreTypeSelect;
  1751. }
  1752. //仓库归属创客编号
  1753. if (!string.IsNullOrEmpty(StoreUserIdMakerCode))
  1754. {
  1755. SqlString += " and a.StoreUserId in (select StoreUserId from UserForMakerCode where MakerCode='" + StoreUserIdMakerCode + "')";
  1756. }
  1757. //仓库归属创客真实姓名
  1758. if (!string.IsNullOrEmpty(StoreUserIdRealName))
  1759. {
  1760. SqlString += " and a.StoreUserId in (select StoreUserId from UserForRealName where RealName='" + StoreUserIdRealName + "')";
  1761. }
  1762. //支付状态
  1763. if (!string.IsNullOrEmpty(PayStatusSelect))
  1764. {
  1765. SqlString += " and a.PayStatus=" + PayStatusSelect;
  1766. }
  1767. //支付时间
  1768. if (!string.IsNullOrEmpty(PayDateData))
  1769. {
  1770. string[] datelist = PayDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1771. string start = datelist[0];
  1772. string end = datelist[1];
  1773. SqlString += " and a.PayDate>='" + start + " 00:00:00' and a.PayDate<='" + end + " 23:59:59'";
  1774. }
  1775. //下单时间
  1776. if (!string.IsNullOrEmpty(CreateDateData))
  1777. {
  1778. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1779. string start = datelist[0];
  1780. string end = datelist[1];
  1781. SqlString += " and a.CreateDate>='" + start + " 00:00:00' and a.CreateDate<='" + end + " 23:59:59'";
  1782. }
  1783. //发货时间
  1784. if (!string.IsNullOrEmpty(SendDateData))
  1785. {
  1786. string[] datelist = SendDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1787. string start = datelist[0];
  1788. string end = datelist[1];
  1789. SqlString += " and a.SendDate>='" + start + " 00:00:00' and a.SendDate<='" + end + " 23:59:59'";
  1790. }
  1791. var Sql = "SELECT aa.*,bb.MakerCode '顶级创客编号',bb.RealName '顶级创客姓名' FROM(SELECT b.Id '创客Id',b.MakerCode '创客编号',b.RealName '创客真实姓名',a.OrderNo '订单号',SUBSTRING_INDEX(SUBSTRING_INDEX(b.ParentNav,',',4),',',-1) TopId,a.Mobile '手机号',a.RealName '姓名',a.TotalPrice '总价',a.Areas '所在地区',a.Address '详细地址',a.ErpName '物流名称',a.ErpCode '运单号',DATE_FORMAT(a.SendDate,'%Y-%m-%d %H:%i:%s') '发货时间',(CASE WHEN a.PayMode=1 THEN '支付宝' WHEN a.PayMode=2 THEN '微信' WHEN a.PayMode=3 THEN '账户余额' ELSE '' end) '支付方式',DATE_FORMAT(a.PayDate,'%Y-%m-%d %H:%i:%s') '支付时间',a.TradeNo '支付交易号',c.StoreNo '仓库编号',c.StoreName '仓库名称',(CASE WHEN a.RefundStatus=0 THEN '未退款' WHEN a.RefundStatus=1 THEN '已退款' end) '退款状态',(CASE WHEN a.DeliveryType=1 THEN '邮寄到付' WHEN a.DeliveryType=2 THEN '上门自提' ELSE '' end) '提货类型',(CASE WHEN a.SendStatus=0 THEN '未发货' WHEN a.SendStatus=1 THEN '已发货' WHEN a.SendStatus=2 THEN '已退货' ELSE '' end) '发货状态',d.ProductName '商品名称',a.BuyCount '下单数量',d.TotalPrice '商品单价',d.NormDetail '商品规格',a.StoreContact '仓库联系人',(CASE WHEN a.StoreType=0 THEN '总仓' WHEN a.StoreType=1 THEN '分仓' ELSE '' end) '仓库类型',e.MakerCode '仓库归属创客编号',e.RealName '仓库归属创客姓名',(CASE WHEN a.PayStatus=0 THEN '未支付' WHEN a.PayStatus=1 THEN '支付成功' WHEN a.PayStatus=2 THEN '支付失败' WHEN a.PayStatus=3 THEN '支付锁定中' WHEN a.PayStatus=4 THEN '支付处理中' ELSE '' end) '支付状态',a.Remark '订单备注' FROM Orders a LEFT JOIN Users b ON a.UserId=b.Id LEFT JOIN StoreHouse c ON a.StoreId=c.Id LEFT JOIN OrderProduct d ON a.Id=d.OrderId LEFT JOIN Users e ON a.StoreUserId=e.Id" + SqlString + ")aa LEFT JOIN Users bb ON aa.TopId = bb.Id";
  1792. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  1793. var FileName = "商城订单记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1794. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  1795. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  1796. return "success";
  1797. }
  1798. #endregion
  1799. #region 查询直推奖励100
  1800. public Dictionary<string, string> Prize100(int Id)
  1801. {
  1802. Dictionary<string, string> dic = new Dictionary<string, string>();
  1803. string result = "";
  1804. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id) ?? new Orders();
  1805. if (order.PayStatus < 1)
  1806. {
  1807. result += "未付款\n";
  1808. dic.Add("code", "1");
  1809. dic.Add("result", result);
  1810. return dic;
  1811. }
  1812. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  1813. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1814. result += "订单号:" + order.OrderNo + "\n";
  1815. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  1816. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1817. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  1818. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1819. if (machineCount + ActiveCount >= 3)
  1820. {
  1821. string IsGet = "未发放";
  1822. int ToUserId = 0;
  1823. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == Id);
  1824. if (item == null)
  1825. {
  1826. DateTime start = order.PayDate.Value.AddMinutes(-2);
  1827. DateTime end = order.PayDate.Value.AddMinutes(2);
  1828. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  1829. }
  1830. if (item != null)
  1831. {
  1832. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1833. ToUserId = item.UserId;
  1834. dic.Add("code", "1");
  1835. }
  1836. else
  1837. {
  1838. dic.Add("code", "0");
  1839. }
  1840. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  1841. result += "是否发放:" + IsGet + "\n";
  1842. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1843. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  1844. }
  1845. else
  1846. {
  1847. result += "上级创客未满足条件\n兑换机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  1848. dic.Add("code", "1");
  1849. }
  1850. dic.Add("result", result);
  1851. return dic;
  1852. }
  1853. public string AddPrize100(int Id)
  1854. {
  1855. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  1856. if (order != null)
  1857. {
  1858. //机具券逻辑
  1859. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  1860. if (pro != null)
  1861. {
  1862. //推荐下单奖励
  1863. if (pro.ProductId == 10 || pro.ProductId == 11)
  1864. {
  1865. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1866. if (user != null)
  1867. {
  1868. int ParentUserId = user.ParentUserId;
  1869. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台兑换机
  1870. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1871. if (machineCount + ActiveCount >= 3)
  1872. {
  1873. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == ParentUserId);
  1874. if (account == null)
  1875. {
  1876. account = db.UserAccount.Add(new UserAccount()
  1877. {
  1878. Id = ParentUserId,
  1879. UserId = ParentUserId,
  1880. }).Entity;
  1881. db.SaveChanges();
  1882. }
  1883. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  1884. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  1885. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  1886. account.BalanceAmount += 100;
  1887. account.TotalAmount += 100;
  1888. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  1889. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  1890. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  1891. UserAccountRecord add = db.UserAccountRecord.Add(new UserAccountRecord()
  1892. {
  1893. CreateDate = DateTime.Now,
  1894. UpdateDate = DateTime.Now,
  1895. UserId = ParentUserId, //创客
  1896. ChangeType = 112, //变动类型
  1897. ChangeAmount = 100, //变更金额
  1898. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  1899. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  1900. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  1901. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  1902. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  1903. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  1904. QueryCount = order.Id,
  1905. }).Entity;
  1906. db.SaveChanges();
  1907. PublicFunction.SplitUserAccountRecord(add);
  1908. //推荐下单上级获得30天的机具循环天数
  1909. var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.UserId, m.BindingState, m.RecycEndDate }).Where(m => m.UserId == ParentUserId && m.BindingState == 0 && m.RecycEndDate != null).ToList();
  1910. foreach (var subPos in posList)
  1911. {
  1912. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == subPos.Id);
  1913. if (pos != null)
  1914. {
  1915. pos.RecycEndDate = pos.RecycEndDate.Value.AddDays(30);
  1916. }
  1917. }
  1918. db.SaveChanges();
  1919. return "success";
  1920. }
  1921. else
  1922. {
  1923. return "上级创客未满足条件:兑换机:" + machineCount + "台,激活机:" + ActiveCount + "台";
  1924. }
  1925. }
  1926. }
  1927. }
  1928. }
  1929. return "操作失败";
  1930. }
  1931. #endregion
  1932. }
  1933. }