OrdersController.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using MySystem.MainModels;
  10. using LitJson;
  11. using Library;
  12. namespace MySystem.Areas.Api.Controllers.v1
  13. {
  14. [Area("Api")]
  15. [Route("Api/v1/[controller]/[action]")]
  16. public class OrdersController : BaseController
  17. {
  18. public OrdersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  19. {
  20. }
  21. #region 创客-商城-确认支付
  22. [Authorize]
  23. public JsonResult Pay(string value)
  24. {
  25. value = DesDecrypt(value);
  26. JsonData data = JsonMapper.ToObject(value);
  27. AppResultJson result = PayDo(value);
  28. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  29. }
  30. public AppResultJson PayDo(string value)
  31. {
  32. JsonData data = JsonMapper.ToObject(value);
  33. int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式
  34. Dictionary<string, object> Obj = new Dictionary<string, object>();
  35. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
  36. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  37. Orders query = maindb.Orders.FirstOrDefault(m => m.Id == Id);
  38. if (query != null)
  39. {
  40. query.PayMode = PayMode; //支付方式
  41. maindb.SaveChanges();
  42. string PayData = "";
  43. // int proId = OrderProductDbconn.Instance.GetList(Id).FirstOrDefault();
  44. OrderProduct pro = maindb.OrderProduct.FirstOrDefault(m => m.OrderId == Id) ?? new OrderProduct();
  45. Products product = maindb.Products.FirstOrDefault(m => m.Id == pro.ProductId) ?? new Products();
  46. PublicAccountSet set = new AlipayFunction(_accessor.HttpContext).SetData(UserId); //RedisDbconn.Instance.Get<PublicAccountSet>("PublicAccountSet") ?? new PublicAccountSet();
  47. if (PayMode == 1)
  48. {
  49. string TotalPrice = query.TotalPrice.ToString();
  50. if (UserId == 1)
  51. {
  52. TotalPrice = "0.01";
  53. }
  54. function.WriteLog(query.OrderNo, "支付宝支付日志");
  55. function.WriteLog(TotalPrice.ToString(), "支付宝支付日志");
  56. function.WriteLog(product.ProductName, "支付宝支付日志");
  57. string ProductName = product.ProductName;
  58. if(string.IsNullOrEmpty(ProductName) && query.OrderNo.StartsWith("CBJ"))
  59. {
  60. ProductName = "储备金";
  61. }
  62. if (query.ParentOrderId > 0)
  63. {
  64. OrderProduct ppro = maindb.OrderProduct.FirstOrDefault(m => m.OrderId == query.ParentOrderId) ?? new OrderProduct();
  65. ProductName = ppro.ProductName;
  66. }
  67. PayData = new Alipay.AlipayPublicClass(_accessor.HttpContext).GetAlipayInfo(query.OrderNo, TotalPrice, ProductName, set.AlipayAppId, set.AlipayPrivateKey, SourceHost + "/Api/Alipay/NoticePay");
  68. function.WriteLog(PayData, "支付宝支付日志");
  69. }
  70. else if (PayMode == 2)
  71. {
  72. Dictionary<string, string> payinfo = new WeChat.WeChatPublicClass(_accessor.HttpContext).AppPay(set.WeChatOpenAppId, set.WeChatMchId, query.TotalPrice, query.OrderNo, product.ProductName, product.ProductName, set.ServerIp, set.WeChatPayKey, SourceHost + "/Api/WeChat/NoticePay");
  73. string AppId = payinfo["appId"];
  74. //string timeStamp = payinfo["timeStamp"];
  75. string timeStamp = function.ConvertDateTimeInt(DateTime.Now).ToString();
  76. string nonce_str = payinfo["nonce_str"];
  77. string package = payinfo["package"];
  78. string signStr = "appid=" + AppId;
  79. signStr += "&noncestr=" + nonce_str;
  80. signStr += "&package=Sign=WXPay";
  81. signStr += "&partnerid=" + set.WeChatMchId;
  82. signStr += "&prepayid=" + package.Replace("prepay_id=", "");
  83. signStr += "&timestamp=" + timeStamp;
  84. signStr += "&key=" + set.WeChatPayKey;
  85. string paySign = function.MD532(signStr).ToUpper();
  86. PayData = "{";
  87. PayData += "\"partnerId\":\"" + set.WeChatMchId + "\",";
  88. PayData += "\"prepayId\":\"" + package.Replace("prepay_id=", "") + "\",";
  89. PayData += "\"nonceStr\":\"" + nonce_str + "\",";
  90. PayData += "\"timeStamp\":\"" + timeStamp + "\",";
  91. PayData += "\"sign\":\"" + paySign + "\"";
  92. PayData += "}";
  93. }
  94. else if (PayMode == 3)//余额支付
  95. {
  96. string TotalPrice = query.TotalPrice.ToString();
  97. if (UserId == 1)
  98. {
  99. TotalPrice = "0.01";
  100. }
  101. else
  102. {
  103. if(decimal.Parse(TotalPrice) == 10000)
  104. {
  105. TotalPrice = "10800";
  106. }
  107. else if(decimal.Parse(TotalPrice) == 40000)
  108. {
  109. TotalPrice = "43200";
  110. }
  111. query.TotalPrice = decimal.Parse(TotalPrice);
  112. maindb.SaveChanges();
  113. }
  114. var PayTotal = Convert.ToDecimal(TotalPrice);
  115. UserAccount userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  116. if (userAccount.AccountStatus == 1)
  117. {
  118. return new AppResultJson() { Status = "-1", Info = "参数错误,请联系客服" };
  119. }
  120. else
  121. {
  122. if (userAccount.BalanceAmount >= PayTotal)
  123. {
  124. function.WriteLog(query.OrderNo, "余额支付日志");
  125. function.WriteLog(TotalPrice.ToString(), "余额支付日志");
  126. function.WriteLog(product.ProductName, "余额支付日志");
  127. RedisDbconn.Instance.AddList("BalancePayQueue", Id.ToString());
  128. }
  129. else
  130. {
  131. return new AppResultJson() { Status = "-1", Info = "您的余额不足!", Data = Obj };
  132. }
  133. }
  134. }
  135. else if (PayMode == 4)//盟主储蓄金支付
  136. {
  137. string TotalPrice = query.TotalPrice.ToString();
  138. if (UserId == 1)
  139. {
  140. TotalPrice = "0.01";
  141. }
  142. var PayTotal = Convert.ToDecimal(TotalPrice);
  143. UserAccount userAccount = maindb.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  144. if (userAccount.AccountStatus == 1)
  145. {
  146. return new AppResultJson() { Status = "-1", Info = "参数错误,请联系客服" };
  147. }
  148. else
  149. {
  150. if (userAccount.LeaderReserve >= PayTotal)
  151. {
  152. function.WriteLog(query.OrderNo, "盟主储蓄金支付日志");
  153. function.WriteLog(TotalPrice.ToString(), "盟主储蓄金支付日志");
  154. function.WriteLog(product.ProductName, "盟主储蓄金支付日志");
  155. RedisDbconn.Instance.AddList("ReservePayQueue", Id.ToString());
  156. }
  157. else
  158. {
  159. return new AppResultJson() { Status = "-1", Info = "您的盟主储蓄金不足!", Data = Obj };
  160. }
  161. }
  162. }
  163. Obj.Add("PayData", PayData); //支付宝微信SDK所需数据
  164. }
  165. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  166. }
  167. #endregion
  168. #region 创客-商城-确认订单
  169. [Authorize]
  170. public JsonResult ConfirmOrder(string value)
  171. {
  172. value = DesDecrypt(value);
  173. JsonData data = JsonMapper.ToObject(value);
  174. AppResultJson result = ConfirmOrderDo(value);
  175. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  176. }
  177. public AppResultJson ConfirmOrderDo(string value)
  178. {
  179. function.WriteLog(value, "创客-商城-确认订单");
  180. JsonData data = JsonMapper.ToObject(value);
  181. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  182. int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
  183. int DeliveryType = int.Parse(function.CheckInt(data["DeliveryType"].ToString())); //提货类型
  184. string Remark = data["Remark"].ToString(); //订单备注
  185. int AddressId = int.Parse(function.CheckInt(data["AddressId"].ToString())); //收货地址Id
  186. JsonData ProductJson = data["ProductJson"]; //商品信息
  187. Dictionary<string, object> Obj = new Dictionary<string, object>();
  188. string OrderNo = "BM" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  189. UserAddress address = UserAddressDbconn.Instance.Get(AddressId) ?? new UserAddress();
  190. StoreHouse store = StoreHouseDbconn.Instance.Get(StoreId) ?? new StoreHouse();
  191. Users storeUser = UsersDbconn.Instance.Get(store.ManageUserId) ?? new Users();
  192. Users user = UsersDbconn.Instance.Get(UserId) ?? new Users();
  193. int TopUserId = PublicFunction.GetTopUserId(user.ParentNav);
  194. decimal TotalPrice = 0; //订单总额
  195. int TotalBuyCount = 0;
  196. for (int a = 0; a < ProductJson.Count; a++)
  197. {
  198. JsonData jsonData = ProductJson[a];
  199. int Id = int.Parse(function.CheckInt(jsonData["ProductId"].ToString()));
  200. int Count = int.Parse(function.CheckInt(jsonData["BuyCount"].ToString()));
  201. Products products = maindb.Products.FirstOrDefault(m => m.Id == Id);
  202. if (products.Stock - Count >= 0)
  203. {
  204. Orders query = maindb.Orders.Add(new Orders()
  205. {
  206. OrderNo = OrderNo,
  207. RealName = address.RealName,
  208. Mobile = address.Mobile,
  209. Areas = address.Areas,
  210. Address = address.Address,
  211. StoreContact = storeUser.RealName,
  212. StoreContactMobile = store.ManageMobile,
  213. StoreUserId = store.UserId,
  214. StoreType = store.StoreType,
  215. CreateDate = DateTime.Now, //创建时间
  216. UserId = UserId, //创客
  217. StoreId = StoreId, //仓库
  218. TopUserId = TopUserId, //顶级创客
  219. DeliveryType = DeliveryType, //提货类型
  220. BuyCount = TotalBuyCount,
  221. TotalPrice = TotalPrice, //订单总额
  222. Remark = Remark, //订单备注
  223. }).Entity;
  224. maindb.SaveChanges();
  225. OrderForNo orderFor = maindb.OrderForNo.Add(new OrderForNo()
  226. {
  227. OrderNo = OrderNo,
  228. OrderIds = query.Id.ToString(),
  229. }).Entity;
  230. maindb.SaveChanges();
  231. for (int i = 0; i < ProductJson.Count; i++)
  232. {
  233. JsonData item = ProductJson[i];
  234. int ProductId = int.Parse(function.CheckInt(item["ProductId"].ToString()));
  235. int NormId = int.Parse(function.CheckInt(item["NormId"].ToString()));
  236. int BuyCount = int.Parse(function.CheckInt(item["BuyCount"].ToString()));
  237. Products product = ProductsDbconn.Instance.Get(ProductId) ?? new Products();
  238. ProductNorm norm = ProductNormDbconn.Instance.Get(NormId) ?? new ProductNorm();
  239. OrderProduct pro = maindb.OrderProduct.Add(new OrderProduct()
  240. {
  241. CreateDate = DateTime.Now, //创建时间
  242. OrderId = query.Id,
  243. ProductId = ProductId,
  244. ProductCount = BuyCount,
  245. ProductName = product.ProductName,
  246. ProductPhoto = product.ListPicPath,
  247. NormId = NormId.ToString(),
  248. NormDetail = norm.ColName,
  249. ProductPrice = NormId == 0 ? product.Price : norm.Price,
  250. TotalPrice = NormId == 0 ? product.Price * BuyCount : norm.Price * BuyCount,
  251. ProductCode = product.ProductCode,
  252. UserId = UserId,
  253. StoreId = StoreId,
  254. }).Entity;
  255. maindb.SaveChanges();
  256. if (NormId == 0)
  257. {
  258. TotalPrice += product.Price * BuyCount;
  259. }
  260. else
  261. {
  262. TotalPrice += norm.Price * BuyCount;
  263. }
  264. TotalBuyCount += BuyCount;
  265. }
  266. query.TotalPrice = TotalPrice;
  267. query.BuyCount = TotalBuyCount;
  268. maindb.SaveChanges();
  269. Obj.Add("Id", query.Id); //Id
  270. }
  271. else
  272. {
  273. return new AppResultJson() { Status = "-1", Info = "商品库存不足", Data = Obj };
  274. }
  275. }
  276. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  277. }
  278. #endregion
  279. #region 创客-商城-确认订单-机具券
  280. [Authorize]
  281. public JsonResult ConfirmOrder2(string value)
  282. {
  283. value = DesDecrypt(value);
  284. JsonData data = JsonMapper.ToObject(value);
  285. AppResultJson result = ConfirmOrder2Do(value);
  286. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  287. }
  288. public AppResultJson ConfirmOrder2Do(string value)
  289. {
  290. JsonData data = JsonMapper.ToObject(value);
  291. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  292. string Remark = data["Remark"].ToString(); //订单备注
  293. JsonData ProductJson = data["ProductJson"]; //商品信息
  294. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  295. for (int i = 0; i < ProductJson.Count; i++)
  296. {
  297. JsonData item = ProductJson[i];
  298. int ProductId = int.Parse(function.CheckInt(item["ProductId"].ToString()));
  299. if (ProductId == 15)
  300. {
  301. bool checkPro = maindb.OrderProduct.Any(m => m.CreateDate >= start && m.UserId == UserId && m.ProductId == ProductId && m.Status > -1);
  302. if (checkPro)
  303. {
  304. return new AppResultJson() { Status = "-1", Info = "请勿重复下单" };
  305. }
  306. }
  307. if (ProductId == 29)
  308. {
  309. bool checkPro = maindb.OrderProduct.Any(m => m.CreateDate >= start && m.UserId == UserId && m.ProductId == ProductId && m.Status > -1);
  310. if (checkPro)
  311. {
  312. return new AppResultJson() { Status = "-1", Info = "请勿重复下单" };
  313. }
  314. }
  315. }
  316. Dictionary<string, object> Obj = new Dictionary<string, object>();
  317. string OrderNo = "BM" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  318. Users user = UsersDbconn.Instance.Get(UserId) ?? new Users();
  319. int TopUserId = PublicFunction.GetTopUserId(user.ParentNav);
  320. decimal TotalPrice = 0; //订单总额
  321. int TotalBuyCount = 0;
  322. for (int a = 0; a < ProductJson.Count; a++)
  323. {
  324. JsonData jsonData = ProductJson[a];
  325. int Id = int.Parse(function.CheckInt(jsonData["ProductId"].ToString()));
  326. int Count = int.Parse(function.CheckInt(jsonData["BuyCount"].ToString()));
  327. Products products = maindb.Products.FirstOrDefault(m => m.Id == Id);
  328. if (products != null)
  329. {
  330. if (products.Stock - Count >= 0)
  331. {
  332. Orders query = maindb.Orders.Add(new Orders()
  333. {
  334. OrderNo = OrderNo,
  335. CreateDate = DateTime.Now, //创建时间
  336. UserId = UserId, //创客
  337. TopUserId = TopUserId, //顶级创客
  338. BuyCount = TotalBuyCount,
  339. TotalPrice = TotalPrice, //订单总额
  340. Remark = Remark, //订单备注
  341. }).Entity;
  342. maindb.SaveChanges();
  343. for (int i = 0; i < ProductJson.Count; i++)
  344. {
  345. JsonData item = ProductJson[i];
  346. int ProductId = int.Parse(function.CheckInt(item["ProductId"].ToString()));
  347. int NormId = int.Parse(function.CheckInt(item["NormId"].ToString()));
  348. int BuyCount = int.Parse(function.CheckInt(item["BuyCount"].ToString()));
  349. Products product = ProductsDbconn.Instance.Get(ProductId) ?? new Products();
  350. ProductNorm norm = ProductNormDbconn.Instance.Get(NormId) ?? new ProductNorm();
  351. OrderProduct pro = maindb.OrderProduct.Add(new OrderProduct()
  352. {
  353. CreateDate = DateTime.Now, //创建时间
  354. OrderId = query.Id,
  355. ProductId = ProductId,
  356. ProductCount = BuyCount,
  357. ProductName = product.ProductName,
  358. ProductPhoto = product.ListPicPath,
  359. NormId = NormId.ToString(),
  360. NormDetail = norm.ColName,
  361. ProductPrice = NormId == 0 ? product.Price : norm.Price,
  362. TotalPrice = NormId == 0 ? product.Price * BuyCount : norm.Price * BuyCount,
  363. ProductCode = product.ProductCode,
  364. UserId = UserId,
  365. }).Entity;
  366. maindb.SaveChanges();
  367. if (NormId == 0)
  368. {
  369. TotalPrice += product.Price * BuyCount;
  370. }
  371. else
  372. {
  373. TotalPrice += norm.Price * BuyCount;
  374. }
  375. TotalBuyCount += BuyCount;
  376. }
  377. query.TotalPrice = TotalPrice;
  378. query.BuyCount = TotalBuyCount;
  379. OrderForNo orderFor = maindb.OrderForNo.Add(new OrderForNo()
  380. {
  381. OrderNo = OrderNo,
  382. OrderIds = query.Id.ToString(),
  383. }).Entity;
  384. maindb.SaveChanges();
  385. Obj.Add("Id", query.Id); //Id
  386. }
  387. else
  388. {
  389. return new AppResultJson() { Status = "-1", Info = "商品库存不足", Data = Obj };
  390. }
  391. }
  392. else
  393. {
  394. return new AppResultJson() { Status = "-1", Info = "无该商品", Data = Obj };
  395. }
  396. }
  397. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  398. }
  399. #endregion
  400. #region 创客-首页-机具管理-我的订单
  401. [Authorize]
  402. public JsonResult List(string value)
  403. {
  404. value = DesDecrypt(value);
  405. JsonData data = JsonMapper.ToObject(value);
  406. List<Dictionary<string, object>> dataList = ListDo(value);
  407. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  408. }
  409. public List<Dictionary<string, object>> ListDo(string value)
  410. {
  411. JsonData data = JsonMapper.ToObject(value);
  412. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  413. string ProductType = data["ProductType"].ToString(); //产品类型
  414. int Status = int.Parse(function.CheckInt(data["Status"].ToString())); //状态
  415. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  416. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  417. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  418. IQueryable<Orders> query = maindb.Orders.Where(m => m.Status > -1 && m.UserId == UserId && m.ParentOrderId == 0 && m.QueryCount == 0 && m.TotalPrice > 0);
  419. if (Status > 0)
  420. {
  421. if (Status == 1) Status = 0;
  422. query = query.Where(m => m.Status == Status);
  423. }
  424. query = query.OrderByDescending(m => m.Id);
  425. if (PageNum == 1)
  426. {
  427. query = query.Take(PageSize);
  428. }
  429. else
  430. {
  431. int skipNum = PageSize * (PageNum - 1);
  432. query = query.Skip(skipNum).Take(PageSize);
  433. }
  434. foreach (var subdata in query.ToList())
  435. {
  436. Dictionary<string, object> curData = new Dictionary<string, object>();
  437. int finshPay = -1;
  438. var order = maindb.Orders.Any(m => m.Id == subdata.Id && m.Status == 0 && m.ProductId <= 13 && m.ProductId >= 12 && m.ErpMode >= 0 && m.ErpMode <= 1);
  439. if (order)
  440. {
  441. var totalOd = maindb.Orders.Where(m => m.ParentOrderId == subdata.Id).Count();
  442. var paiedOd = maindb.Orders.Where(m => m.ParentOrderId == subdata.Id && m.PayStatus == 1).Count();
  443. if (totalOd > paiedOd && paiedOd > 0)
  444. {
  445. finshPay = 0;
  446. curData.Add("FinshStatus", finshPay); //部分支付
  447. }
  448. }
  449. var orders = maindb.Orders.Any(m => m.Id == subdata.Id && m.Status == 0);
  450. if (orders)
  451. {
  452. var totalOd = maindb.Orders.Where(m => m.ParentOrderId == subdata.Id).Count();
  453. var paiedOd = maindb.Orders.Where(m => m.ParentOrderId == subdata.Id && m.PayStatus == 1).Count();
  454. if (totalOd > paiedOd && paiedOd > 0)
  455. {
  456. finshPay = 0;
  457. curData.Add("FinshStatus", finshPay); //部分支付
  458. }
  459. }
  460. curData.Add("TotalPrice", subdata.TotalPrice); //总价
  461. curData.Add("BuyCount", subdata.BuyCount); //下单数量
  462. curData.Add("Id", subdata.Id); //Id
  463. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  464. List<Dictionary<string, object>> prolist = new List<Dictionary<string, object>>();
  465. List<int> pros = OrderProductDbconn.Instance.GetList(subdata.Id);
  466. int ProductId = 0;
  467. foreach (int proId in pros)
  468. {
  469. ProductId = proId;
  470. OrderProduct pro = OrderProductDbconn.Instance.Get(proId) ?? new OrderProduct();
  471. Dictionary<string, object> row = new Dictionary<string, object>();
  472. row.Add("ProductName", pro.ProductName);
  473. row.Add("ProductPrice", pro.ProductPrice);
  474. row.Add("ProductCount", pro.ProductCount);
  475. row.Add("ProductPhoto", DefaultPic(pro.ProductPhoto));
  476. prolist.Add(row);
  477. }
  478. string StatusName = RelationClass.GetOrderStatusInfo(subdata.Status);
  479. if (StatusName == "待发货" && (ProductId == 15 || ProductId == 29))
  480. {
  481. StatusName = RelationClass.GetOrderStatusInfo(2);
  482. }
  483. curData.Add("Status", StatusName); //Status
  484. curData.Add("Products", prolist);
  485. dataList.Add(curData);
  486. }
  487. return dataList;
  488. }
  489. #endregion
  490. #region 创客-首页-机具管理-我的订单-详情
  491. [Authorize]
  492. public JsonResult Detail(string value)
  493. {
  494. value = DesDecrypt(value);
  495. JsonData data = JsonMapper.ToObject(value);
  496. Dictionary<string, object> Obj = DetailDo(value);
  497. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  498. }
  499. public Dictionary<string, object> DetailDo(string value)
  500. {
  501. JsonData data = JsonMapper.ToObject(value);
  502. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  503. Dictionary<string, object> Obj = new Dictionary<string, object>();
  504. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  505. Orders query = maindb.Orders.FirstOrDefault(m => m.Id == Id && m.UserId == UserId) ?? new Orders();
  506. Obj.Add("OrderNo", query.OrderNo); //订单号
  507. Obj.Add("RealName", query.RealName); //姓名
  508. Obj.Add("Mobile", query.Mobile); //手机号
  509. Obj.Add("TotalPrice", query.TotalPrice); //总价
  510. Obj.Add("Areas", function.CheckNull(query.Areas).Replace(",", "")); //所在地区
  511. Obj.Add("Address", query.Address); //详细地址
  512. Obj.Add("PayDate", query.PayDate == null ? "" : query.PayDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //付款时间
  513. Obj.Add("DeliveryType", query.DeliveryType); //提货类型
  514. Obj.Add("SendStatus", query.SendStatus); //发货状态
  515. Obj.Add("StoreContact", query.StoreContact); //仓库联系人
  516. Obj.Add("BuyCount", query.BuyCount); //下单数量
  517. Obj.Add("StoreContactMobile", query.StoreContactMobile); //仓库联系人电话
  518. StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.Id == query.StoreId) ?? new StoreHouse();
  519. Obj.Add("StoreName", store.StoreName); //提货仓库
  520. Obj.Add("Status", query.Status); //状态
  521. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //创建时间
  522. List<Dictionary<string, object>> prolist = new List<Dictionary<string, object>>();
  523. List<int> pros = OrderProductDbconn.Instance.GetList(Id);
  524. int ProductId = 0;
  525. foreach (int proId in pros)
  526. {
  527. ProductId = proId;
  528. OrderProduct pro = OrderProductDbconn.Instance.Get(proId) ?? new OrderProduct();
  529. Dictionary<string, object> row = new Dictionary<string, object>();
  530. row.Add("ProductName", pro.ProductName);
  531. row.Add("ProductPrice", pro.ProductPrice);
  532. row.Add("ProductCount", pro.ProductCount);
  533. row.Add("ProductPhoto", DefaultPic(pro.ProductPhoto));
  534. prolist.Add(row);
  535. }
  536. string StatusName = RelationClass.GetOrderStatusInfo(query.Status);
  537. if (StatusName == "待发货" && (ProductId == 15 || ProductId == 29))
  538. {
  539. StatusName = RelationClass.GetOrderStatusInfo(2);
  540. }
  541. Obj.Add("StatusName", StatusName);
  542. Obj.Add("Products", prolist);
  543. return Obj;
  544. }
  545. #endregion
  546. #region 创客-首页-机具管理-我的订单-详情-V2
  547. [Authorize]
  548. public JsonResult Detail2(string value)
  549. {
  550. value = DesDecrypt(value);
  551. JsonData data = JsonMapper.ToObject(value);
  552. Dictionary<string, object> Obj = Detail2Do(value);
  553. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  554. }
  555. public Dictionary<string, object> Detail2Do(string value)
  556. {
  557. JsonData data = JsonMapper.ToObject(value);
  558. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  559. Dictionary<string, object> Obj = new Dictionary<string, object>();
  560. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  561. Orders query = OrdersDbconn.Instance.Get(Id) ?? new Orders();
  562. Obj.Add("OrderNo", query.OrderNo); //订单号
  563. Obj.Add("RealName", query.RealName); //姓名
  564. Obj.Add("Mobile", query.Mobile); //手机号
  565. Obj.Add("TotalPrice", query.TotalPrice); //总价
  566. Obj.Add("PayMode", query.PayMode);
  567. Obj.Add("Areas", function.CheckNull(query.Areas).Replace(",", "")); //所在地区
  568. Obj.Add("Address", query.Address); //详细地址
  569. Obj.Add("PayDate", query.PayDate == null ? "" : query.PayDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //付款时间
  570. Obj.Add("DeliveryType", query.DeliveryType); //提货类型
  571. Obj.Add("SendStatus", query.SendStatus); //发货状态
  572. Obj.Add("StoreContact", query.StoreContact); //仓库联系人
  573. Obj.Add("BuyCount", query.BuyCount); //下单数量
  574. Obj.Add("StoreContactMobile", query.StoreContactMobile); //仓库联系人电话
  575. StoreHouse store = maindb.StoreHouse.FirstOrDefault(m => m.Id == query.StoreId) ?? new StoreHouse();
  576. Obj.Add("StoreName", store.StoreName); //提货仓库
  577. Obj.Add("StatusName", RelationClass.GetOrderStatusInfo(query.Status));
  578. Obj.Add("Status", query.Status); //状态
  579. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //创建时间
  580. List<Dictionary<string, object>> prolist = new List<Dictionary<string, object>>();
  581. List<int> pros = OrderProductDbconn.Instance.GetList(Id);
  582. foreach (int proId in pros)
  583. {
  584. OrderProduct pro = OrderProductDbconn.Instance.Get(proId) ?? new OrderProduct();
  585. Dictionary<string, object> row = new Dictionary<string, object>();
  586. row.Add("ProductName", pro.ProductName);
  587. row.Add("ProductPrice", pro.ProductPrice);
  588. row.Add("ProductCount", pro.ProductCount);
  589. row.Add("ProductPhoto", DefaultPic(pro.ProductPhoto));
  590. prolist.Add(row);
  591. }
  592. Obj.Add("Products", prolist);
  593. string Codes = query.SnNos;
  594. List<string> CodeList = new List<string>();
  595. if (!string.IsNullOrEmpty(Codes))
  596. {
  597. CodeList = Codes.Split(',').ToList();
  598. }
  599. Obj.Add("ExchangeCodeList", CodeList);
  600. return Obj;
  601. }
  602. #endregion
  603. #region 创客-首页-机具管理-我的订单-取消订单
  604. [Authorize]
  605. public JsonResult CancelOrder(string value)
  606. {
  607. value = DesDecrypt(value);
  608. JsonData data = JsonMapper.ToObject(value);
  609. Dictionary<string, object> Obj = CancelOrderDo(value);
  610. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  611. }
  612. public Dictionary<string, object> CancelOrderDo(string value)
  613. {
  614. JsonData data = JsonMapper.ToObject(value);
  615. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  616. Dictionary<string, object> Obj = new Dictionary<string, object>();
  617. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  618. Orders query = maindb.Orders.FirstOrDefault(m => m.Id == Id && m.UserId == UserId);
  619. if (query != null)
  620. {
  621. query.Status = -1;
  622. var orderpros = maindb.OrderProduct.Select(m => new { m.Id, m.OrderId }).Where(m => m.OrderId == Id).ToList();
  623. foreach (var orderpro in orderpros)
  624. {
  625. OrderProduct edit = maindb.OrderProduct.FirstOrDefault(m => m.Id == orderpro.Id);
  626. if (edit != null)
  627. {
  628. edit.Status = -1;
  629. }
  630. }
  631. maindb.SaveChanges();
  632. }
  633. return Obj;
  634. }
  635. #endregion
  636. #region 创客-首页-仓库管理-订单列表
  637. [Authorize]
  638. public JsonResult StoreOrderList(string value)
  639. {
  640. value = DesDecrypt(value);
  641. JsonData data = JsonMapper.ToObject(value);
  642. Dictionary<string, object> Other = new Dictionary<string, object>();
  643. List<Dictionary<string, object>> dataList = StoreOrderListDo(value, out Other);
  644. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  645. }
  646. public List<Dictionary<string, object>> StoreOrderListDo(string value, out Dictionary<string, object> Other)
  647. {
  648. JsonData data = JsonMapper.ToObject(value);
  649. string SearchKey = data["SearchKey"].ToString(); //手机号
  650. int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库
  651. int Status = int.Parse(function.CheckInt(data["Status"].ToString())); //订单状态
  652. string StartDate = data["StartDate"].ToString(); //下单开始时间
  653. string EndDate = data["EndDate"].ToString(); //下单结束时间
  654. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  655. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  656. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  657. WebCMSEntities db = new WebCMSEntities();
  658. IQueryable<Orders> query = db.Orders.Where(m => m.StoreId == StoreId && m.PayStatus == 1 && m.QueryCount < 2);
  659. if (!string.IsNullOrEmpty(SearchKey))
  660. {
  661. query = query.Where(m => m.RealName == SearchKey || m.Mobile == SearchKey);
  662. }
  663. if (!string.IsNullOrEmpty(StartDate))
  664. {
  665. DateTime time = DateTime.Parse(StartDate.Substring(0, 4) + "-" + StartDate.Substring(4, 2) + "-" + StartDate.Substring(6, 2) + " 00:00:00");
  666. query = query.Where(m => m.CreateDate >= time);
  667. }
  668. if (!string.IsNullOrEmpty(EndDate))
  669. {
  670. DateTime time = DateTime.Parse(EndDate.Substring(0, 4) + "-" + EndDate.Substring(4, 2) + "-" + EndDate.Substring(6, 2) + " 23:59:59");
  671. query = query.Where(m => m.CreateDate <= time);
  672. }
  673. if (Status > 0)
  674. {
  675. if (Status == 2) Status = 0;
  676. query = query.Where(m => m.SendStatus == Status);
  677. }
  678. query = query.OrderByDescending(m => m.Id);
  679. if (PageNum == 1)
  680. {
  681. query = query.Take(PageSize);
  682. }
  683. else
  684. {
  685. int skipNum = PageSize * (PageNum - 1);
  686. query = query.Skip(skipNum).Take(PageSize);
  687. }
  688. foreach (var item in query.ToList())
  689. {
  690. Orders subdata = OrdersDbconn.Instance.Get(item.Id) ?? new Orders();
  691. Dictionary<string, object> curData = new Dictionary<string, object>();
  692. curData.Add("OrderNo", subdata.OrderNo); //订单号
  693. curData.Add("RealName", subdata.RealName); //姓名
  694. curData.Add("Mobile", subdata.Mobile); //手机号
  695. curData.Add("Areas", subdata.Areas); //所在地区
  696. curData.Add("Address", subdata.Address); //详细地址
  697. curData.Add("DeliveryType", subdata.DeliveryType); //提货类型
  698. curData.Add("BuyCount", subdata.BuyCount); //下单数量
  699. curData.Add("SnNos", subdata.SnNos); //SN编号
  700. curData.Add("Id", subdata.Id); //Id
  701. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  702. List<int> pros = OrderProductDbconn.Instance.GetList(subdata.Id);
  703. int pid = pros.Count > 0 ? pros[0] : 0;
  704. OrderProduct orderProduct = OrderProductDbconn.Instance.Get(pid) ?? new OrderProduct();
  705. Products pro = ProductsDbconn.Instance.Get(orderProduct.ProductId) ?? new Products();
  706. curData.Add("ProductName", pro.ProductName); //商品名称
  707. Users user = UsersDbconn.Instance.Get(subdata.UserId) ?? new Users();
  708. curData.Add("OrderRealName", user.RealName); //下单人姓名
  709. curData.Add("OrderMakerCode", user.MakerCode); //下单人编号
  710. curData.Add("OrderKind", subdata.Sort > 0 ? "机具申请" : "商城购买"); //订单类型
  711. curData.Add("SendStatus", item.SendStatus);
  712. dataList.Add(curData);
  713. }
  714. Other = new Dictionary<string, object>();
  715. var count = query.Count();//数据条数
  716. Other.Add("count", count);
  717. return dataList;
  718. }
  719. #endregion
  720. #region 创客-首页-仓库管理-订单详情
  721. [Authorize]
  722. public JsonResult StoreOrderDetail(string value)
  723. {
  724. value = DesDecrypt(value);
  725. JsonData data = JsonMapper.ToObject(value);
  726. Dictionary<string, object> Obj = StoreOrderDetailDo(value);
  727. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  728. }
  729. public Dictionary<string, object> StoreOrderDetailDo(string value)
  730. {
  731. JsonData data = JsonMapper.ToObject(value);
  732. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  733. Dictionary<string, object> Obj = new Dictionary<string, object>();
  734. Orders query = OrdersDbconn.Instance.Get(Id) ?? new Orders();
  735. Obj.Add("UserId", query.UserId); //创客
  736. Obj.Add("RealName", query.RealName); //姓名
  737. Obj.Add("Mobile", query.Mobile); //手机号
  738. Obj.Add("Areas", function.CheckNull(query.Areas).Replace(",", "")); //所在地区
  739. Obj.Add("Address", query.Address); //详细地址
  740. int DeliveryType = query.DeliveryType;
  741. if (DeliveryType == 1)
  742. {
  743. Obj.Add("DeliveryType", "邮寄到付"); //提货类型
  744. }
  745. else if (DeliveryType == 2)
  746. {
  747. Obj.Add("DeliveryType", "上门自提"); //提货类型
  748. }
  749. Obj.Add("BuyCount", query.BuyCount); //下单数量
  750. Obj.Add("SnNos", query.SnNos); //SN编号
  751. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  752. List<int> OrderProducts = OrderProductDbconn.Instance.GetList(Id);
  753. if (OrderProducts.Count > 0)
  754. {
  755. OrderProduct pro = OrderProductDbconn.Instance.Get(OrderProducts[0]) ?? new OrderProduct();
  756. Obj.Add("ProductName", pro.ProductName); //商品名称
  757. }
  758. else
  759. {
  760. Obj.Add("ProductName", ""); //商品名称
  761. }
  762. return Obj;
  763. }
  764. #endregion
  765. #region 创客-我的-盟主中心-储备金购买/充值
  766. [Authorize]
  767. public JsonResult BuyReserve(string value)
  768. {
  769. value = DesDecrypt(value);
  770. JsonData data = JsonMapper.ToObject(value);
  771. AppResultJson result = BuyReserveDo(value);
  772. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  773. }
  774. public AppResultJson BuyReserveDo(string value)
  775. {
  776. JsonData data = JsonMapper.ToObject(value);
  777. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  778. int BuyType = int.Parse(function.CheckInt(data["BuyType"].ToString())); //购买类型(1 升级 2 购买)
  779. decimal TotalPrice = decimal.Parse(function.CheckNum(data["TotalPrice"].ToString())); //总价
  780. // int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式(1-支付宝,3-余额支付)
  781. Dictionary<string, object> Obj = new Dictionary<string, object>();
  782. Users Users = maindb.Users.FirstOrDefault(m => m.Id == UserId);
  783. var productId = 0;
  784. if(BuyType == 2 && TotalPrice == 10000)
  785. {
  786. productId = 40;
  787. }
  788. else if(BuyType == 2 && TotalPrice == 40000)
  789. {
  790. productId = 39;
  791. }
  792. else if (Users.LeaderLevel == 1)
  793. {
  794. productId = 27;
  795. }
  796. // else if (Users.LeaderLevel == 2)
  797. // {
  798. // productId = 27;
  799. // }
  800. Products product = maindb.Products.FirstOrDefault(m => m.Id == productId) ?? new Products();
  801. string OrderNo = "CBJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  802. Orders query = maindb.Orders.Add(new Orders()
  803. {
  804. CreateDate = DateTime.Now, //创建时间
  805. PayStatus = 0,//支付状态(0 未支付 1 已支付)
  806. ErpMode = BuyType,//购买类型
  807. ProductId = productId,//27 大盟主 28 小盟主
  808. UserId = UserId, //创客
  809. BuyCount = 1,//购买数量
  810. TotalPrice = TotalPrice, //总价
  811. OrderNo = OrderNo,//订单号
  812. // PayMode = PayMode, //支付方式
  813. }).Entity;
  814. maindb.SaveChanges();
  815. maindb.OrderForNo.Add(new OrderForNo()
  816. {
  817. OrderNo = OrderNo,
  818. OrderIds = query.Id.ToString()
  819. });
  820. maindb.OrderProduct.Add(new OrderProduct()
  821. {
  822. CreateDate = DateTime.Now, //创建时间
  823. OrderId = query.Id,
  824. ProductId = productId,
  825. ProductCount = 1,
  826. ProductName = product.ProductName,
  827. ProductPhoto = product.ListPicPath,
  828. ProductPrice = TotalPrice,
  829. TotalPrice = TotalPrice,
  830. ProductCode = product.ProductCode,
  831. UserId = UserId,
  832. });
  833. maindb.SaveChanges();
  834. RedisDbconn.Instance.AddList("ReservePayQueue", query.Id.ToString());
  835. Obj.Add("Id", query.Id); //APP支付需要的数据
  836. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  837. }
  838. #endregion
  839. #region 创客-我的-盟主中心-储备金购买/充值支付
  840. [Authorize]
  841. public JsonResult PayReserve(string value)
  842. {
  843. value = DesDecrypt(value);
  844. JsonData data = JsonMapper.ToObject(value);
  845. AppResultJson result = PayReserveDo(value);
  846. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  847. }
  848. public AppResultJson PayReserveDo(string value)
  849. {
  850. JsonData data = JsonMapper.ToObject(value);
  851. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  852. // int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式(1-支付宝,3-余额支付)
  853. string OpMode = data["OpMode"].ToString(); //操作方式(1-全款支付,2-拆单支付)
  854. int Times = int.Parse(function.CheckInt(data["Times"].ToString())); //分次数量
  855. int OrderId = int.Parse(function.CheckInt(data["OrderId"].ToString())); //订单Id
  856. string check = RedisDbconn.Instance.Get<string>(UserId + ":" + OrderId);
  857. if(check == "1")
  858. {
  859. return new AppResultJson() { Status = "1", Info = "" };
  860. }
  861. Dictionary<string, object> Obj = new Dictionary<string, object>();
  862. Orders query = maindb.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
  863. var LeavePrice = query.TotalPrice;//剩余支付金额
  864. var TotalPrice = query.TotalPrice / Times;
  865. var min = (int)TotalPrice - 1000;
  866. var max = (int)TotalPrice + 1000;
  867. if (OpMode == "2")
  868. {
  869. for (int i = 0; i < Times - 1; i++)
  870. {
  871. string OrderNo = "CBJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  872. TotalPrice = function.get_Random(min, max);
  873. LeavePrice -= TotalPrice;
  874. Orders order = maindb.Orders.Add(new Orders()
  875. {
  876. CreateDate = DateTime.Now, //创建时间
  877. PayStatus = 0,//支付状态(0 未支付 1 已支付)
  878. ErpMode = query.ErpMode,//购买类型
  879. UserId = UserId, //创客
  880. TotalPrice = TotalPrice, //总价
  881. OrderNo = OrderNo,//订单号
  882. ParentOrderId = OrderId,//主订单Id
  883. }).Entity;
  884. maindb.SaveChanges();
  885. maindb.OrderForNo.Add(new OrderForNo()
  886. {
  887. OrderNo = OrderNo,
  888. OrderIds = order.Id.ToString()
  889. });
  890. maindb.SaveChanges();
  891. }
  892. string LastOrderNo = "CBJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  893. Orders orders = maindb.Orders.Add(new Orders()
  894. {
  895. CreateDate = DateTime.Now, //创建时间
  896. PayStatus = 0,//支付状态(0 未支付 1 已支付)
  897. ErpMode = query.ErpMode,//购买类型
  898. UserId = UserId, //创客
  899. TotalPrice = LeavePrice, //总价
  900. OrderNo = LastOrderNo,//订单号
  901. ParentOrderId = OrderId,//主订单Id
  902. }).Entity;
  903. maindb.SaveChanges();
  904. maindb.OrderForNo.Add(new OrderForNo()
  905. {
  906. OrderNo = LastOrderNo,
  907. OrderIds = orders.Id.ToString()
  908. });
  909. maindb.SaveChanges();
  910. RedisDbconn.Instance.Set(UserId + ":" + OrderId, "1");
  911. RedisDbconn.Instance.SetExpire(UserId + ":" + OrderId, 3600);
  912. }
  913. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  914. }
  915. #endregion
  916. #region 创客-首页-我的订单-详情-V2
  917. [Authorize]
  918. public JsonResult Detailv2(string value)
  919. {
  920. value = DesDecrypt(value);
  921. JsonData data = JsonMapper.ToObject(value);
  922. Dictionary<string, object> Obj = Detailv2Do(value);
  923. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  924. }
  925. public Dictionary<string, object> Detailv2Do(string value)
  926. {
  927. JsonData data = JsonMapper.ToObject(value);
  928. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  929. Dictionary<string, object> Obj = new Dictionary<string, object>();
  930. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  931. Orders query = OrdersDbconn.Instance.Get(Id) ?? new Orders();
  932. Obj.Add("OrderNo", query.OrderNo); //订单号
  933. Obj.Add("RealName", query.RealName); //姓名
  934. Obj.Add("Mobile", query.Mobile); //手机号
  935. Obj.Add("TotalPrice", query.TotalPrice); //总价
  936. Obj.Add("PayDate", query.PayDate == null ? "" : query.PayDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //付款时间
  937. Obj.Add("SendStatus", query.SendStatus); //发货状态
  938. Obj.Add("BuyCount", query.BuyCount); //下单数量
  939. Obj.Add("StatusName", RelationClass.GetOrderStatusInfo(query.Status));
  940. Obj.Add("Status", query.Status); //状态
  941. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //创建时间
  942. var orders = maindb.Orders.Where(m => m.ParentOrderId == Id).ToList();
  943. List<Dictionary<string, object>> childOrder = new List<Dictionary<string, object>>();
  944. foreach (var item in orders)
  945. {
  946. Dictionary<string, object> row = new Dictionary<string, object>();
  947. row.Add("Id", item.Id);//订单Id
  948. row.Add("ProductPrice", item.TotalPrice);//价格
  949. row.Add("OrderNo", item.OrderNo);//订单号
  950. row.Add("PayStatus", item.PayStatus);//支付状态
  951. row.Add("CreateDate", item.CreateDate);//下单时间
  952. row.Add("PayDate", item.PayDate);//支付时间
  953. childOrder.Add(row);
  954. }
  955. Obj.Add("ChileOrders", childOrder);//子订单
  956. return Obj;
  957. }
  958. #endregion
  959. #region 创客-活动-推荐王-检查参与情况
  960. [Authorize]
  961. public JsonResult CheckJoinStatus(string value)
  962. {
  963. value = DesDecrypt(value);
  964. JsonData data = JsonMapper.ToObject(value);
  965. Dictionary<string, object> Obj = CheckJoinStatusDo(value);
  966. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  967. }
  968. public Dictionary<string, object> CheckJoinStatusDo(string value)
  969. {
  970. JsonData data = JsonMapper.ToObject(value);
  971. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  972. DateTime start = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date;
  973. DateTime end = DateTime.Now.AddDays(8 - DateTime.Now.Day).Date;
  974. Dictionary<string, object> Obj = new Dictionary<string, object>();
  975. OrderProduct query = maindb.OrderProduct.FirstOrDefault(m => m.UserId == UserId && m.ProductId == 29 && m.CreateDate >= start && m.CreateDate <= end) ?? new OrderProduct();
  976. bool order = maindb.Orders.Any(m => m.Id == query.OrderId && m.Status > 0);
  977. if (order)
  978. {
  979. Obj.Add("Status", 1);
  980. }
  981. else
  982. {
  983. Obj.Add("Status", 0);
  984. }
  985. return Obj;
  986. }
  987. #endregion
  988. #region 首页-客小爽产品-机具管理-机具申请-要兑换的码牌
  989. [Authorize]
  990. public JsonResult ExchangeMachines(string value)
  991. {
  992. value = DesDecrypt(value);
  993. JsonData data = JsonMapper.ToObject(value);
  994. Dictionary<string, object> Other = new Dictionary<string, object>();
  995. List<Dictionary<string, object>> dataList = ExchangeMachinesDo(value, out Other);
  996. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  997. }
  998. public List<Dictionary<string, object>> ExchangeMachinesDo(string value, out Dictionary<string, object> Other)
  999. {
  1000. JsonData data = JsonMapper.ToObject(value);
  1001. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  1002. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  1003. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  1004. DateTime now = DateTime.Now;
  1005. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  1006. List<KqProducts> KqProducts = maindb.KqProducts.ToList();
  1007. IQueryable<PosMachines> query = maindb.PosMachines.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.IsPurchase == 0);
  1008. int ExpiredCount = query.Count(m => m.RecycEndDate < now);
  1009. int ActCount = query.Count(m => m.ActivationState == 1);
  1010. query = query.Where(m => m.RecycEndDate >= now && (m.ActivationState == 1 || (!string.IsNullOrEmpty(m.SeoKeyword) && m.SeoKeyword != "0")));
  1011. if (PageNum == 1)
  1012. {
  1013. query = query.Take(PageSize);
  1014. }
  1015. else
  1016. {
  1017. int skipNum = PageSize * (PageNum - 1);
  1018. query = query.Skip(skipNum).Take(PageSize);
  1019. }
  1020. foreach (var subdata in query.ToList())
  1021. {
  1022. Dictionary<string, object> curData = new Dictionary<string, object>();
  1023. curData.Add("SnId", subdata.Id); //机具Id
  1024. curData.Add("SnNo", subdata.PosSn); //SN号
  1025. curData.Add("MachineType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
  1026. int day = 0;
  1027. if (subdata.RecycEndDate != null)
  1028. {
  1029. TimeSpan ts = subdata.RecycEndDate.Value - DateTime.Now;
  1030. day = ts.Days;
  1031. }
  1032. curData.Add("RecycDays", day); //循环剩余天数
  1033. curData.Add("EndDate", subdata.RecycEndDate == null ? "" : subdata.RecycEndDate.Value.ToString("yyyy-MM-dd")); //截止日期
  1034. dataList.Add(curData);
  1035. }
  1036. Other = new Dictionary<string, object>();
  1037. Other.Add("ActCount", ActCount); //激活数
  1038. Other.Add("ExpiredCount", ExpiredCount); //过期数
  1039. Other.Add("MinCount", 1); //最少领取数
  1040. return dataList;
  1041. }
  1042. #endregion
  1043. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  1044. /// <summary>
  1045. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  1046. /// </summary>
  1047. /// <param name="value">请求的参数(json字符串)</param>
  1048. /// <param name="signField">要签名的字段</param>
  1049. /// <returns></returns>
  1050. private string CheckSign(string value, string[] signField)
  1051. {
  1052. JsonData json = JsonMapper.ToObject(value);
  1053. Dictionary<string, string> dic = new Dictionary<string, string>();
  1054. for (int i = 0; i < signField.Length; i++)
  1055. {
  1056. dic.Add(signField[i], json[signField[i]].ToString());
  1057. }
  1058. string sign = json["sign"].ToString(); //客户端签名字符串
  1059. return new Sign().sign(dic, sign);
  1060. }
  1061. #endregion
  1062. }
  1063. }