SysToolsController.cs 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  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.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. using System.Text.RegularExpressions;
  19. using System.Security.Cryptography;
  20. using System.Text;
  21. namespace MySystem.Areas.Admin.Controllers
  22. {
  23. [Area("Admin")]
  24. [Route("Admin/[controller]/[action]")]
  25. public class SysToolsController : BaseController
  26. {
  27. public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  28. {
  29. }
  30. #region 关联上下级
  31. public IActionResult RelationForUser(string right)
  32. {
  33. ViewBag.RightInfo = RightInfo;
  34. ViewBag.right = right;
  35. return View();
  36. }
  37. [HttpPost]
  38. public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
  39. {
  40. if (string.IsNullOrEmpty(MakerCode))
  41. {
  42. return "请输入创客编号";
  43. }
  44. if (string.IsNullOrEmpty(ParentMakerCode))
  45. {
  46. return "请输入上级创客编号";
  47. }
  48. MakerCode = MakerCode.ToUpper();
  49. ParentMakerCode = ParentMakerCode.ToUpper();
  50. Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  51. if (puser != null)
  52. {
  53. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  54. if (user != null)
  55. {
  56. if (IsTeam == 1)
  57. {
  58. RelationForUserSub(user.Id, user);
  59. }
  60. user.ParentUserId = puser.Id;
  61. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  62. db.SaveChanges();
  63. function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
  64. return "success";
  65. }
  66. return "创客编号不存在";
  67. }
  68. return "上级创客编号不存在";
  69. }
  70. private void RelationForUserSub(int ParentUserId, Users puser)
  71. {
  72. var subusers = db.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
  73. foreach (var subuser in subusers)
  74. {
  75. Users user = db.Users.FirstOrDefault(m => m.Id == subuser.Id);
  76. if (user != null)
  77. {
  78. user.ParentUserId = puser.Id;
  79. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  80. db.SaveChanges();
  81. RelationForUserSub(user.Id, user);
  82. }
  83. }
  84. }
  85. #endregion
  86. #region 机具补录
  87. public IActionResult CheckMachine(string right)
  88. {
  89. ViewBag.RightInfo = RightInfo;
  90. ViewBag.right = right;
  91. return View();
  92. }
  93. [HttpPost]
  94. public string CheckMachineDo(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0, int IsPre = 0, int IsSend = 0)
  95. {
  96. if (string.IsNullOrEmpty(MakerCode))
  97. {
  98. return "请输入创客编号";
  99. }
  100. if (string.IsNullOrEmpty(PosSn))
  101. {
  102. return "请输入机具SN";
  103. }
  104. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  105. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  106. if (pos == null)
  107. {
  108. return "机具SN不存在";
  109. }
  110. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  111. if (user == null)
  112. {
  113. return "创客编号不存在";
  114. }
  115. if (IsPre == 1)
  116. {
  117. if (pos.BuyUserId == 0)
  118. {
  119. pos.BuyUserId = user.Id;
  120. }
  121. if (pos.UserId == 0)
  122. {
  123. pos.UserId = user.Id;
  124. }
  125. }
  126. if (pos.BindingState == 0)
  127. {
  128. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  129. if (bind != null)
  130. {
  131. pos.BindingState = 1;
  132. pos.BindingTime = bind.CreateTime;
  133. db.SaveChanges();
  134. MerNo = bind.MerNo;
  135. }
  136. }
  137. decimal CreditTrade = 0;
  138. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  139. if (check)
  140. {
  141. if (pos.BrandId == 1)
  142. {
  143. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  144. }
  145. else if (pos.BrandId == 2)
  146. {
  147. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  148. }
  149. else if (pos.BrandId == 3)
  150. {
  151. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  152. }
  153. else if (pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 8 || pos.BrandId == 9)
  154. {
  155. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  156. }
  157. else if (pos.BrandId == 6)
  158. {
  159. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  160. }
  161. else if (pos.BrandId == 7)
  162. {
  163. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  164. }
  165. pos.CreditTrade = CreditTrade;
  166. db.SaveChanges();
  167. StatTradeAmount(pos.PosSn);
  168. }
  169. if (AddActPrize == 1)
  170. {
  171. if (pos.BuyUserId == 0)
  172. {
  173. return "机具未划拨,无法补录激活奖励";
  174. }
  175. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  176. {
  177. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  178. if (has)
  179. {
  180. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  181. pos.SeoKeyword = chkAct.SeoTitle;
  182. db.SaveChanges();
  183. }
  184. }
  185. if (pos.BindingTime != null && pos.ActivationTime != null)
  186. {
  187. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  188. if (ts.TotalDays <= 30)
  189. {
  190. AddAct(pos.Id);
  191. }
  192. }
  193. }
  194. decimal CheckMoney = 1000;
  195. if (pos.BrandId == 6)
  196. {
  197. CheckMoney = 5000;
  198. }
  199. if (pos.BuyUserId > 0)
  200. {
  201. if (pos.CreditTrade < CheckMoney)
  202. {
  203. return "该机具贷记卡累计交易不足" + CheckMoney;
  204. }
  205. if (pos.BindingTime != null && pos.ActivationTime != null)
  206. {
  207. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  208. if (ts.TotalDays > 30)
  209. {
  210. return "机具划拨后已超过30天";
  211. }
  212. }
  213. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  214. {
  215. // pos.IsPurchase = 0;
  216. pos.ActivationState = 1;
  217. pos.ActivationTime = DateTime.Now;
  218. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  219. if (pos.ActivationState == 1 && mer != null)
  220. {
  221. mer.ActiveStatus = 1;
  222. mer.MerStandardDate = DateTime.Now;
  223. }
  224. }
  225. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  226. {
  227. if (AddActPrize == 1)
  228. {
  229. if (IsSend == 1)
  230. {
  231. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  232. {
  233. UserId = user.Id, //接收创客
  234. MsgType = 2,
  235. Title = "补录成功通知", //标题
  236. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  237. CreateDate = DateTime.Now,
  238. }));
  239. }
  240. return "激活奖励已补录";
  241. }
  242. else
  243. {
  244. return "数据正常,无需补录";
  245. }
  246. }
  247. db.SaveChanges();
  248. return "success";
  249. }
  250. pos.UserId = user.Id;
  251. pos.BuyUserId = user.Id;
  252. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && pos.BindingTime > DateTime.Now.AddDays(-30))
  253. {
  254. // pos.IsPurchase = 0;
  255. pos.ActivationState = 1;
  256. pos.ActivationTime = DateTime.Now;
  257. }
  258. PosMerchantInfo merchant = new PosMerchantInfo();
  259. if (!string.IsNullOrEmpty(MerNo))
  260. {
  261. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  262. if (merchant == null)
  263. {
  264. int TopUserId = 0;
  265. if (!string.IsNullOrEmpty(user.ParentNav))
  266. {
  267. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  268. }
  269. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  270. if (bind == null)
  271. {
  272. return "该机具尚未绑定";
  273. }
  274. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  275. if (Mer == null)
  276. {
  277. return "该机具尚未绑定";
  278. }
  279. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  280. {
  281. CreateDate = Mer.CreateTime,
  282. UpdateDate = Mer.UpdateTime,
  283. TopUserId = TopUserId,
  284. MerUserType = user.MerchantType,
  285. BrandId = int.Parse(Mer.ProductType),
  286. SnStoreId = pos.StoreId,
  287. SnType = pos.PosSnType,
  288. UserId = user.Id,
  289. MgrName = Mer.AgentName,
  290. MerStatus = 1,
  291. KqSnNo = Mer.SnNo,
  292. KqMerNo = Mer.MerNo,
  293. MerIdcardNo = Mer.MerIdcardNo,
  294. MerRealName = Mer.MerRealName,
  295. MerchantMobile = Mer.MerMobile,
  296. MerchantName = Mer.MerName,
  297. MerchantNo = Mer.MerNo,
  298. }).Entity;
  299. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  300. if (forMerNo == null)
  301. {
  302. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  303. {
  304. MerNo = Mer.MerNo,
  305. SnId = pos.Id,
  306. }).Entity;
  307. }
  308. else
  309. {
  310. forMerNo.SnId = pos.Id;
  311. }
  312. }
  313. }
  314. else
  315. {
  316. if (pos.BindMerchantId > 0)
  317. {
  318. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  319. }
  320. else
  321. {
  322. return "找不到机具所属商户";
  323. }
  324. }
  325. merchant.UserId = user.Id;
  326. if (pos.ActivationState == 1)
  327. {
  328. merchant.ActiveStatus = 1;
  329. merchant.MerStandardDate = DateTime.Now;
  330. }
  331. if (pos.BindMerchantId == 0)
  332. {
  333. pos.BindMerchantId = merchant.Id;
  334. }
  335. db.SaveChanges();
  336. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize + ", IsPre:" + IsPre, "机具补录日志");
  337. return "success";
  338. }
  339. public IActionResult CheckMachine2(string right)
  340. {
  341. ViewBag.RightInfo = RightInfo;
  342. ViewBag.right = right;
  343. return View();
  344. }
  345. [HttpPost]
  346. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  347. {
  348. if (string.IsNullOrEmpty(MakerCode))
  349. {
  350. return "请输入创客编号";
  351. }
  352. if (string.IsNullOrEmpty(PosSn))
  353. {
  354. return "请输入机具SN";
  355. }
  356. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  357. if (pos == null)
  358. {
  359. return "机具SN不存在";
  360. }
  361. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  362. if (user == null)
  363. {
  364. return "创客编号不存在";
  365. }
  366. if (pos.BindingState == 0)
  367. {
  368. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  369. if (bind != null)
  370. {
  371. pos.BindingState = 1;
  372. pos.BindingTime = bind.CreateTime;
  373. db.SaveChanges();
  374. MerNo = bind.MerNo;
  375. }
  376. }
  377. decimal CreditTrade = 0;
  378. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  379. if (check)
  380. {
  381. if (pos.BrandId == 1)
  382. {
  383. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  384. }
  385. else if (pos.BrandId == 2)
  386. {
  387. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  388. }
  389. else if (pos.BrandId == 3)
  390. {
  391. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  392. }
  393. else if (pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 8 || pos.BrandId == 9)
  394. {
  395. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  396. }
  397. else if (pos.BrandId == 6)
  398. {
  399. CreditTrade = spdb.TradeRecord.Where(m => m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  400. }
  401. pos.CreditTrade = CreditTrade;
  402. db.SaveChanges();
  403. StatTradeAmount(pos.PosSn);
  404. }
  405. if (AddActPrize == 1)
  406. {
  407. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  408. {
  409. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  410. if (has)
  411. {
  412. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  413. pos.SeoKeyword = chkAct.SeoTitle;
  414. db.SaveChanges();
  415. }
  416. }
  417. AddAct(pos.Id);
  418. }
  419. if (pos.BuyUserId > 0)
  420. {
  421. if (pos.CreditTrade < 1000)
  422. {
  423. // pos.IsPurchase = 99;
  424. db.SaveChanges();
  425. return "该机具贷记卡累计交易不足1000";
  426. }
  427. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  428. {
  429. // pos.IsPurchase = 0;
  430. pos.ActivationState = 1;
  431. pos.ActivationTime = DateTime.Now;
  432. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  433. if (pos.ActivationState == 1 && mer != null)
  434. {
  435. mer.ActiveStatus = 1;
  436. mer.MerStandardDate = DateTime.Now;
  437. RedisDbconn.Instance.Clear("PosMerchantInfo:" + mer.Id);
  438. }
  439. }
  440. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  441. {
  442. if (AddActPrize == 1)
  443. {
  444. return "激活奖励已补录";
  445. }
  446. else
  447. {
  448. return "数据正常,无需补录";
  449. }
  450. }
  451. db.SaveChanges();
  452. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  453. return "success";
  454. }
  455. pos.UserId = user.Id;
  456. pos.BuyUserId = user.Id;
  457. // if (pos.CreditTrade < 1000)
  458. // {
  459. // pos.IsPurchase = 99;
  460. // }
  461. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  462. {
  463. // pos.IsPurchase = 0;
  464. pos.ActivationState = 1;
  465. pos.ActivationTime = DateTime.Now;
  466. }
  467. PosMerchantInfo merchant = new PosMerchantInfo();
  468. if (!string.IsNullOrEmpty(MerNo))
  469. {
  470. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  471. if (merchant == null)
  472. {
  473. int TopUserId = 0;
  474. if (!string.IsNullOrEmpty(user.ParentNav))
  475. {
  476. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  477. }
  478. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  479. if (bind == null)
  480. {
  481. return "该机具尚未绑定";
  482. }
  483. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  484. if (Mer == null)
  485. {
  486. return "该机具尚未绑定";
  487. }
  488. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  489. {
  490. CreateDate = Mer.CreateTime,
  491. UpdateDate = Mer.UpdateTime,
  492. TopUserId = TopUserId,
  493. MerUserType = user.MerchantType,
  494. BrandId = int.Parse(Mer.ProductType),
  495. SnStoreId = pos.StoreId,
  496. SnType = pos.PosSnType,
  497. UserId = user.Id,
  498. MgrName = Mer.AgentName,
  499. MerStatus = 1,
  500. KqSnNo = Mer.SnNo,
  501. KqMerNo = Mer.MerNo,
  502. MerIdcardNo = Mer.MerIdcardNo,
  503. MerRealName = Mer.MerRealName,
  504. MerchantMobile = Mer.MerMobile,
  505. MerchantName = Mer.MerName,
  506. MerchantNo = Mer.MerNo,
  507. }).Entity;
  508. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  509. if (forMerNo == null)
  510. {
  511. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  512. {
  513. MerNo = Mer.MerNo,
  514. SnId = pos.Id,
  515. }).Entity;
  516. }
  517. else
  518. {
  519. forMerNo.SnId = pos.Id;
  520. }
  521. }
  522. }
  523. else
  524. {
  525. if (pos.BindMerchantId > 0)
  526. {
  527. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  528. }
  529. else
  530. {
  531. return "找不到机具所属商户";
  532. }
  533. }
  534. merchant.UserId = user.Id;
  535. if (pos.ActivationState == 1)
  536. {
  537. merchant.ActiveStatus = 1;
  538. merchant.MerStandardDate = DateTime.Now;
  539. }
  540. if (pos.BindMerchantId == 0)
  541. {
  542. pos.BindMerchantId = merchant.Id;
  543. }
  544. db.SaveChanges();
  545. RedisDbconn.Instance.Clear("PosMerchantInfo:" + merchant.Id);
  546. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  547. return "success";
  548. }
  549. public void AddAct(int posid = 0)
  550. {
  551. WebCMSEntities db = new WebCMSEntities();
  552. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
  553. if (pos != null)
  554. {
  555. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
  556. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  557. if (merchant != null)
  558. {
  559. // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
  560. // if (otherInfo != null)
  561. // {
  562. // otherInfo.PrizeFlag1 = 1;
  563. // db.SaveChanges();
  564. string ParentNav = "";
  565. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  566. if (user != null)
  567. {
  568. int GetUserId = user.Id;
  569. ParentNav = user.ParentNav;
  570. int TopUserId = 1;
  571. if (!string.IsNullOrEmpty(ParentNav))
  572. {
  573. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  574. if (ParentNavList.Length > 1)
  575. {
  576. TopUserId = int.Parse(ParentNavList[1]);
  577. }
  578. else if (ParentNavList.Length == 1)
  579. {
  580. TopUserId = int.Parse(ParentNavList[0]);
  581. }
  582. }
  583. List<decimal> prizes = new List<decimal>();
  584. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  585. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
  586. {
  587. ActPrize = ActPrize / 100;
  588. }
  589. if (ActPrize > 0)
  590. {
  591. if (ActPrize == 99)
  592. {
  593. ActPrize = 100;
  594. }
  595. else if (ActPrize == 199)
  596. {
  597. ActPrize = 200;
  598. }
  599. else if (ActPrize == 299)
  600. {
  601. ActPrize = 300;
  602. }
  603. else if (ActPrize == 249)
  604. {
  605. ActPrize = 260;
  606. }
  607. prizes.Add(ActPrize);
  608. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  609. {
  610. prizes.Add(40);
  611. }
  612. }
  613. else if (pos.BrandId == 6 && ActPrize == 0)
  614. {
  615. prizes.Add(50);
  616. }
  617. foreach (decimal prize in prizes)
  618. {
  619. int ChangeType = prize == 40 ? 12 : 0;
  620. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  621. if (!check)
  622. {
  623. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  624. db.ActiveReward.Add(new ActiveReward()
  625. {
  626. CreateDate = DateTime.Now,
  627. UpdateDate = DateTime.Now,
  628. UserId = GetUserId, //创客
  629. MerchantId = pos.BindMerchantId, //商户
  630. StandardDate = pos.ActivationTime, //达标日期
  631. RewardAmount = prize, //奖励金额
  632. BrandId = pos.BrandId, //品牌
  633. UserNav = ParentNav, //创客父级
  634. DirectBuddyNo = merchant.UserId, //商户直属创客
  635. KqMerNo = merchant.KqMerNo, //渠道商户编号
  636. KqSnNo = pos.PosSn, //渠道SN号
  637. SnType = pos.PosSnType, //机具类型
  638. SnApplyUserId = pos.BuyUserId, //机具申请创客
  639. ActType = 0, //激活类型
  640. SnStoreId = pos.StoreId, //SN仓库
  641. RewardTips = "激活奖励", //奖励描述
  642. Remark = "激活奖励", //备注
  643. ActDate = pos.ActivationTime, //激活时间
  644. TopUserId = TopUserId, //顶级创客
  645. SeoTitle = machineUser.RealName,
  646. });
  647. db.SaveChanges();
  648. string IdBrand = GetUserId + "_" + pos.BrandId;
  649. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  650. if (userData == null)
  651. {
  652. userData = db.UserMachineData.Add(new UserMachineData()
  653. {
  654. IdBrand = IdBrand,
  655. }).Entity;
  656. db.SaveChanges();
  657. }
  658. userData.ActProfit += prize;
  659. db.SaveChanges();
  660. RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
  661. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  662. if (account == null)
  663. {
  664. account = db.UserAccount.Add(new UserAccount()
  665. {
  666. Id = GetUserId,
  667. UserId = GetUserId,
  668. }).Entity;
  669. db.SaveChanges();
  670. }
  671. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  672. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  673. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  674. account.BalanceAmount += prize;
  675. account.TotalAmount += prize;
  676. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  677. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  678. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  679. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  680. {
  681. CreateDate = DateTime.Now,
  682. UpdateDate = DateTime.Now,
  683. UserId = GetUserId, //创客
  684. ChangeType = ChangeType, //变动类型
  685. ProductType = pos.BrandId, //产品类型
  686. ChangeAmount = prize, //变更金额
  687. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  688. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  689. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  690. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  691. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  692. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  693. }).Entity;
  694. db.SaveChanges();
  695. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  696. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  697. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  698. // 激活奖励列表
  699. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  700. if (!dates.Contains(dateString))
  701. {
  702. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  703. }
  704. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  705. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  706. if (!months.Contains(monthString))
  707. {
  708. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  709. }
  710. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  711. // 激活奖励详情
  712. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  713. if (!actPrizeList.Contains(pos.BindMerchantId))
  714. {
  715. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  716. }
  717. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  718. //收支明细
  719. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  720. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  721. }
  722. }
  723. }
  724. // }
  725. }
  726. }
  727. db.Dispose();
  728. }
  729. //重置交易额
  730. public void StatTradeAmount(string PosSn)
  731. {
  732. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  733. if (DateTime.Now.Day == 1)
  734. {
  735. start = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
  736. }
  737. DateTime end = DateTime.Now;
  738. SycnSpTradeService.Instance.Start(PosSn, start, end);
  739. RedisDbconn.Instance.AddList("ResetTradeAmountList", PosSn);
  740. }
  741. #endregion
  742. #region 设置商户代理
  743. public IActionResult SetMerAgent(string right)
  744. {
  745. ViewBag.RightInfo = RightInfo;
  746. ViewBag.right = right;
  747. return View();
  748. }
  749. [HttpPost]
  750. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
  751. {
  752. if (string.IsNullOrEmpty(MakerCode))
  753. {
  754. return "请输入创客编号";
  755. }
  756. if (string.IsNullOrEmpty(PosSn))
  757. {
  758. return "请输入机具SN";
  759. }
  760. if (string.IsNullOrEmpty(MerNo))
  761. {
  762. return "请输入商户编号";
  763. }
  764. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  765. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  766. if (pos == null)
  767. {
  768. return "机具SN不存在";
  769. }
  770. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  771. if (user == null)
  772. {
  773. return "创客编号不存在";
  774. }
  775. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  776. if (merchant == null)
  777. {
  778. return "商户编号不存在";
  779. }
  780. pos.SeoTitle = user.Id.ToString();
  781. pos.UserId = user.Id;
  782. if (pos.BindMerchantId == 0)
  783. {
  784. pos.BindMerchantId = merchant.Id;
  785. if (IsSend == 1)
  786. {
  787. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  788. {
  789. UserId = pos.UserId, //接收创客
  790. MsgType = 2,
  791. Title = "商户型代理设置成功", //标题
  792. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
  793. CreateDate = DateTime.Now,
  794. }));
  795. }
  796. }
  797. user.MerchantType = 1;
  798. merchant.UserId = user.Id;
  799. merchant.MerUserType = 1;
  800. db.SaveChanges();
  801. return "success";
  802. }
  803. #endregion
  804. #region 查看SP原始数据日志
  805. public IActionResult SeeSpLog(string right)
  806. {
  807. ViewBag.RightInfo = RightInfo;
  808. ViewBag.right = right;
  809. return View();
  810. }
  811. #endregion
  812. #region 查询机具信息
  813. public IActionResult SeeSnDetail(string right)
  814. {
  815. ViewBag.RightInfo = RightInfo;
  816. ViewBag.right = right;
  817. return View();
  818. }
  819. [HttpPost]
  820. public string SeeSnDetailDo(string PosSn)
  821. {
  822. if (string.IsNullOrEmpty(PosSn))
  823. {
  824. return "请输入机具SN";
  825. }
  826. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  827. if (pos == null)
  828. {
  829. return "机具SN不存在";
  830. }
  831. if (pos.Status == -1)
  832. {
  833. return "该机具为故障机";
  834. }
  835. string merInfo = "";
  836. string merName = "";
  837. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  838. if (mer != null)
  839. {
  840. merInfo = mer.KqMerNo;
  841. merName = mer.MerchantName;
  842. }
  843. else
  844. {
  845. merInfo = "未找到商户";
  846. }
  847. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  848. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  849. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  850. int TopUserId = 0;
  851. if (!string.IsNullOrEmpty(posUser.ParentNav))
  852. {
  853. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  854. if (ParentNavs.Length > 1)
  855. {
  856. TopUserId = int.Parse(ParentNavs[1]);
  857. }
  858. if (ParentNavs.Length == 1)
  859. {
  860. TopUserId = int.Parse(ParentNavs[0]);
  861. }
  862. }
  863. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  864. string bindResult = "", bindTime = "";
  865. if (pos.BindingState == 0)
  866. {
  867. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  868. if (bind != null)
  869. {
  870. if (bind.Status != 1)
  871. {
  872. bindResult = "执行中";
  873. }
  874. }
  875. else
  876. {
  877. bindResult = "未绑定";
  878. }
  879. }
  880. else
  881. {
  882. bindResult = "已绑定";
  883. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  884. }
  885. string activeResult = "", activeTime = "";
  886. if (pos.ActivationState == 0)
  887. {
  888. if (pos.CreditTrade < 1000)
  889. {
  890. activeResult = "未刷满1000";
  891. }
  892. else if (pos.TransferTime == null)
  893. {
  894. activeResult = "未激活, 需补录";
  895. }
  896. }
  897. else
  898. {
  899. activeResult = "已激活";
  900. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  901. }
  902. string tradeAmount = pos.CreditTrade.ToString();
  903. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  904. if (pos.BrandId != 2 && pos.BrandId != 7)
  905. {
  906. Deposit = Deposit / 100;
  907. }
  908. string DepositGet = "未领取";
  909. string DepositUser = "";
  910. string DepositToUser = "";
  911. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  912. if (reward.Id > 0)
  913. {
  914. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  915. DepositGet = "已领取";
  916. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  917. }
  918. string DepositGet6 = "未领取";
  919. string DepositUser6 = "";
  920. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  921. if (lisreward.Id > 0)
  922. {
  923. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  924. DepositGet6 = "已领取";
  925. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  926. }
  927. string FluxGet6 = "未领取";
  928. string FluxUser6 = "";
  929. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  930. if (flux.Id > 0)
  931. {
  932. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  933. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  934. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  935. }
  936. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  937. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  938. string OpenUser10 = "未领取";
  939. string OpenUser20 = "未领取";
  940. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  941. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  942. if (openreward.Id > 0)
  943. {
  944. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  945. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  946. }
  947. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  948. if (openreward.Id > 0)
  949. {
  950. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  951. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  952. }
  953. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  954. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  955. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  956. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  957. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  958. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  959. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  960. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  961. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  962. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  963. string result = "";
  964. result += "机具SN:" + pos.PosSn + "\n";
  965. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  966. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  967. if (change.Id > 0)
  968. {
  969. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  970. }
  971. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  972. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  973. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  974. if (pos.PreUserId > 0)
  975. {
  976. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  977. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  978. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  979. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",手机号:" + smallStoreUser.Mobile + ",预发时间:" + preSendDate + "\n";
  980. }
  981. else
  982. {
  983. result += "机具所属小分仓:暂无小分仓\n";
  984. }
  985. result += "划拨时间:" + TransferTime + "\n";
  986. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  987. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  988. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  989. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  990. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  991. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  992. result += "押金:" + Deposit + "\n";
  993. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  994. result += "押金返现应返现对象:" + DepositToUser + "\n";
  995. result += "押金返现实际返现对象:" + DepositUser + "\n";
  996. if (pos.BrandId == 6)
  997. {
  998. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  999. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1000. }
  1001. result += "流量费:" + FluxGet6 + "\n";
  1002. result += "流量费发放对象:" + FluxUser6 + "\n";
  1003. result += "开机奖20:" + OpenUser20 + "\n";
  1004. result += "开机奖10:" + OpenUser10 + "\n";
  1005. return result;
  1006. }
  1007. //解析金控日志
  1008. // public decimal CheckLog(DateTime startDate, string PosSn)
  1009. // {
  1010. // bool op = true;
  1011. // decimal result = 0;
  1012. // DateTime today = DateTime.Now;
  1013. // int i = 0;
  1014. // while (op)
  1015. // {
  1016. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  1017. // if (check <= today)
  1018. // {
  1019. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  1020. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  1021. // foreach (Match sub in mc)
  1022. // {
  1023. // string content = sub.Value;
  1024. // JsonData jsonObj = JsonMapper.ToObject(content);
  1025. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  1026. // string posSnCheck = jsonObj["posSn"].ToString();
  1027. // if (posSnCheck == PosSn && serviceAmount > 0)
  1028. // {
  1029. // result = serviceAmount / 100;
  1030. // op = false;
  1031. // }
  1032. // }
  1033. // }
  1034. // else
  1035. // {
  1036. // op = false;
  1037. // }
  1038. // i += 1;
  1039. // }
  1040. // return result;
  1041. // }
  1042. #endregion
  1043. #region 生成机具兑换码
  1044. public IActionResult MakeCoupons(string right)
  1045. {
  1046. ViewBag.RightInfo = RightInfo;
  1047. ViewBag.right = right;
  1048. return View();
  1049. }
  1050. [HttpPost]
  1051. public string MakeCouponsDo(int Kind, int Number)
  1052. {
  1053. DateTime checkTime = DateTime.Parse("1900-01-01");
  1054. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1055. if (!string.IsNullOrEmpty(checkTimeString))
  1056. {
  1057. checkTime = DateTime.Parse(checkTimeString);
  1058. }
  1059. if (checkTime.AddHours(1) < DateTime.Now)
  1060. {
  1061. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1062. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1063. return "生成程序已执行";
  1064. }
  1065. return "请稍后再试";
  1066. }
  1067. #endregion
  1068. #region 导出没有刷满1000的机具
  1069. public IActionResult ExportPos(string right)
  1070. {
  1071. ViewBag.RightInfo = RightInfo;
  1072. ViewBag.right = right;
  1073. return View();
  1074. }
  1075. [HttpPost]
  1076. public JsonResult ExportPosDo()
  1077. {
  1078. WebCMSEntities db = new WebCMSEntities();
  1079. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1080. int total = poses.Count;
  1081. int index = 0;
  1082. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1083. foreach (PosMachinesTwo pos in poses)
  1084. {
  1085. index += 1;
  1086. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1087. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1088. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1089. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1090. Dictionary<string, object> item = new Dictionary<string, object>();
  1091. string TopRealName = "";
  1092. string TopMakerCode = "";
  1093. string TopMobile = "";
  1094. string ParentNav = user.ParentNav;
  1095. if (!string.IsNullOrEmpty(ParentNav))
  1096. {
  1097. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1098. if (navlist.Length > 1)
  1099. {
  1100. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1101. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1102. TopRealName = tuser.RealName;
  1103. TopMakerCode = tuser.MakerCode;
  1104. TopMobile = tuser.Mobile;
  1105. }
  1106. }
  1107. item.Add("TopRealName", TopRealName); //顶级姓名
  1108. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1109. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1110. item.Add("UpRealName", puser.RealName); //上级姓名
  1111. item.Add("RealName", user.RealName); //代理姓名
  1112. item.Add("MakerCode", user.MakerCode); //代理编号
  1113. item.Add("Mobile", user.Mobile); //代理手机号
  1114. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1115. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1116. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1117. item.Add("Sn", pos.PosSn); //SN
  1118. list.Add(item);
  1119. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1120. }
  1121. db.Dispose();
  1122. Dictionary<string, object> result = new Dictionary<string, object>();
  1123. result.Add("Status", "1");
  1124. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1125. result.Add("Obj", list);
  1126. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1127. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1128. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1129. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1130. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1131. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1132. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1133. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1134. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1135. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1136. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1137. ReturnFields.Add("Sn", "SN"); //SN
  1138. result.Add("Fields", ReturnFields);
  1139. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1140. return Json(result);
  1141. }
  1142. public string ExportPosCheck()
  1143. {
  1144. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1145. if (content == "finish")
  1146. {
  1147. RedisDbconn.Instance.Clear("ExportPosCheck");
  1148. }
  1149. return content;
  1150. }
  1151. #endregion
  1152. #region 更换机具
  1153. public IActionResult ChangePos(string right)
  1154. {
  1155. ViewBag.RightInfo = RightInfo;
  1156. ViewBag.right = right;
  1157. return View();
  1158. }
  1159. [HttpPost]
  1160. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1161. {
  1162. if (string.IsNullOrEmpty(OldSn))
  1163. {
  1164. return "请输入原机具SN";
  1165. }
  1166. if (string.IsNullOrEmpty(NewSn))
  1167. {
  1168. return "请输入新机具SN";
  1169. }
  1170. string[] OldSnList = OldSn.Split('\n');
  1171. string[] NewSnList = NewSn.Split('\n');
  1172. if (OldSnList.Length != NewSnList.Length)
  1173. {
  1174. return "原机具SN数量和新机具SN数量不一致";
  1175. }
  1176. WebCMSEntities db = new WebCMSEntities();
  1177. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1178. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1179. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1180. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1181. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1182. KqProducts oldPosBrand = new KqProducts();
  1183. KqProducts newPosBrand = new KqProducts();
  1184. MachineChange add = db.MachineChange.Add(new MachineChange()
  1185. {
  1186. CreateDate = DateTime.Now,
  1187. UpdateDate = DateTime.Now,
  1188. CreateMan = SysUserName + "-" + SysRealName,
  1189. ChangeNo = ChangeNo, //转换单号
  1190. UserId = 0, //创客
  1191. ChangeTime = DateTime.Now, //转换时间
  1192. BackStoreId = BackStore.Id, //退回仓库
  1193. BackStoreName = BackStore.StoreName, //退回仓库名称
  1194. Remark = "机具更换", //订单备注
  1195. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1196. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1197. OutProductName = OutStore.ProductName, //出库产品名称
  1198. OutStoreId = OutStore.Id, //出库仓库
  1199. OutStoreName = OutStore.StoreName, //出库仓库名称
  1200. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1201. OutStoreAddress = OutStore.Address, //出库仓库地址
  1202. OutStoreManager = "", //出库仓库联系人
  1203. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1204. }).Entity;
  1205. db.SaveChanges();
  1206. int BackProductType = 0;
  1207. string BackProductName = "";
  1208. string ChangeDeviceName = "";
  1209. string ChangeSnExpand = "";
  1210. for (int i = 0; i < OldSnList.Length; i++)
  1211. {
  1212. string OldSnNum = OldSnList[i];
  1213. string NewSnNum = NewSnList[i];
  1214. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1215. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1216. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1217. if (oldpos == null)
  1218. {
  1219. return "原机具SN不正确";
  1220. }
  1221. // if (oldpos.BindingState != 1)
  1222. // {
  1223. // return "原机具未绑定";
  1224. // }
  1225. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1226. if (newpos == null)
  1227. {
  1228. return "新机具SN不正确";
  1229. }
  1230. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1231. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1232. PosMerchantInfo merchant = new PosMerchantInfo();
  1233. if (!string.IsNullOrEmpty(MerNo))
  1234. {
  1235. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1236. }
  1237. else
  1238. {
  1239. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
  1240. }
  1241. newpos.BindMerchantId = merchant.Id;
  1242. newpos.BuyUserId = oldpos.BuyUserId;
  1243. newpos.UserId = oldpos.UserId;
  1244. newpos.RecycEndDate = oldpos.RecycEndDate;
  1245. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1246. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1247. newpos.CreditTrade = oldpos.CreditTrade;
  1248. newpos.PosSnType = oldpos.PosSnType;
  1249. newpos.TransferTime = oldpos.TransferTime;
  1250. newpos.IsPurchase = oldpos.IsPurchase;
  1251. newpos.BindingState = oldpos.BindingState;
  1252. newpos.ActivationState = oldpos.ActivationState;
  1253. newpos.BindingTime = oldpos.BindingTime;
  1254. newpos.ActivationTime = oldpos.ActivationTime;
  1255. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1256. // if (!checkActReward)
  1257. // {
  1258. newpos.SeoKeyword = oldpos.SeoKeyword;
  1259. newpos.PrizeParams = oldpos.PrizeParams;
  1260. newpos.LeaderUserId = oldpos.LeaderUserId;
  1261. // }
  1262. // oldpos.BuyUserId = 0;
  1263. // oldpos.UserId = 0;
  1264. oldpos.Status = -1;
  1265. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1266. if (forMerNo != null)
  1267. {
  1268. forMerNo.SnId = newpos.Id;
  1269. }
  1270. merchant.KqSnNo = NewSn;
  1271. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1272. {
  1273. CreateDate = DateTime.Now,
  1274. UpdateDate = DateTime.Now,
  1275. CreateMan = SysUserName + "-" + SysRealName,
  1276. ChangeNo = ChangeNo, //订单号
  1277. ChangeId = add.Id, //订单Id
  1278. BackProductType = oldpos.BrandId, //退回产品类型
  1279. BackProductName = oldPosBrand.Name, //退回产品名称
  1280. UserId = 0, //创客
  1281. BackSnNo = oldpos.PosSn, //设备SN编号
  1282. OutProductType = newpos.BrandId, //出库产品类型
  1283. OutProductName = newPosBrand.Name, //出库产品名称
  1284. OutSnNo = newpos.PosSn, //出库设备SN编号
  1285. OutSnType = newpos.PosSnType, //出库SN机具类型
  1286. Remark = "机具更换", //备注
  1287. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1288. });
  1289. db.SaveChanges();
  1290. BackProductType = oldpos.BrandId;
  1291. BackProductName = newPosBrand.Name;
  1292. ChangeDeviceName = oldpos.DeviceName;
  1293. ChangeSnExpand += oldpos.PosSn + "\n";
  1294. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1295. }
  1296. add.BackProductType = BackProductType; //退回产品类型
  1297. add.BackProductName = BackProductName; //退回产品名称
  1298. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1299. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1300. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1301. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1302. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1303. db.SaveChanges();
  1304. db.Dispose();
  1305. if (IsSend == 1)
  1306. {
  1307. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1308. {
  1309. UserId = OutStore.UserId, //接收创客
  1310. MsgType = 2,
  1311. Title = "换绑成功通知", //标题
  1312. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1313. CreateDate = DateTime.Now,
  1314. }));
  1315. }
  1316. return "success";
  1317. }
  1318. #endregion
  1319. #region 机具解绑
  1320. public IActionResult Unbind(string right)
  1321. {
  1322. ViewBag.RightInfo = RightInfo;
  1323. ViewBag.right = right;
  1324. return View();
  1325. }
  1326. [HttpPost]
  1327. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  1328. {
  1329. if (string.IsNullOrEmpty(PosSn))
  1330. {
  1331. return "请输入机具SN";
  1332. }
  1333. if (string.IsNullOrEmpty(MakerCode))
  1334. {
  1335. return "请输入创客编号";
  1336. }
  1337. if (string.IsNullOrEmpty(MerNo))
  1338. {
  1339. return "请输入商户编号";
  1340. }
  1341. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1342. if (forSnNo == null)
  1343. {
  1344. return "机具SN不存在";
  1345. }
  1346. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1347. if (forMakerCode == null)
  1348. {
  1349. return "创客不存在";
  1350. }
  1351. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1352. if (forMerNo == null)
  1353. {
  1354. return "商户编号不存在";
  1355. }
  1356. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId && m.Id == forMerNo.SnId);
  1357. if (pos == null)
  1358. {
  1359. return "机具SN不存在";
  1360. }
  1361. if (pos.BuyUserId != forMakerCode.UserId)
  1362. {
  1363. return "机具SN和创客不匹配";
  1364. }
  1365. if (pos.ActivationState == 1)
  1366. {
  1367. return "机具已激活,不能解绑";
  1368. }
  1369. if (pos.BuyUserId == 0)
  1370. {
  1371. return "机具是仓库机,不支持解绑";
  1372. }
  1373. if (pos.BindingState == 0)
  1374. {
  1375. return "机具未绑定,不支持解绑";
  1376. }
  1377. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  1378. {
  1379. return "机具绑定已超过30天,不支持解绑";
  1380. }
  1381. if (forMerNo != null)
  1382. {
  1383. db.MachineForMerNo.Remove(forMerNo);
  1384. db.SaveChanges();
  1385. }
  1386. db.MachineUnBind.Add(new MachineUnBind()
  1387. {
  1388. CreateDate = DateTime.Now,
  1389. SeoTitle = SysUserName + "-" + SysRealName,
  1390. MerchantId = pos.BindMerchantId,
  1391. AuditDate = DateTime.Now,
  1392. AuditDesc = "平台操作解绑",
  1393. AuditStatus = 1,
  1394. SnNo = pos.PosSn,
  1395. BrandId = pos.BrandId,
  1396. UserId = pos.BuyUserId,
  1397. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  1398. });
  1399. pos.BindMerchantId = 0;
  1400. pos.BindingState = 0;
  1401. pos.BindingTime = DateTime.Parse("1900-01-01");
  1402. pos.UserId = pos.BuyUserId;
  1403. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  1404. db.SaveChanges();
  1405. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  1406. if (IsSend == 1)
  1407. {
  1408. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1409. {
  1410. UserId = forMakerCode.UserId, //接收创客
  1411. MsgType = 2,
  1412. Title = "解绑成功通知", //标题
  1413. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  1414. CreateDate = DateTime.Now,
  1415. }));
  1416. }
  1417. return "success";
  1418. }
  1419. #endregion
  1420. #region 查询创客直推奖
  1421. public IActionResult Prize100(string right)
  1422. {
  1423. ViewBag.RightInfo = RightInfo;
  1424. ViewBag.right = right;
  1425. return View();
  1426. }
  1427. [HttpPost]
  1428. public Dictionary<string, string> Prize100Do(string MakerCode)
  1429. {
  1430. Dictionary<string, string> dic = new Dictionary<string, string>();
  1431. string result = "";
  1432. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1433. if (forMakerCode == null)
  1434. {
  1435. result += "创客编号不存在\n";
  1436. dic.Add("code", "1");
  1437. dic.Add("result", result);
  1438. return dic;
  1439. }
  1440. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  1441. if (OrderCount == 0)
  1442. {
  1443. result += "该创客未下单\n";
  1444. dic.Add("code", "1");
  1445. dic.Add("result", result);
  1446. return dic;
  1447. }
  1448. if (OrderCount > 1)
  1449. {
  1450. result += "该创客已不是首笔下单\n";
  1451. dic.Add("code", "1");
  1452. dic.Add("result", result);
  1453. return dic;
  1454. }
  1455. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  1456. if (order.PayStatus < 1)
  1457. {
  1458. result += "未付款\n";
  1459. dic.Add("code", "1");
  1460. dic.Add("result", result);
  1461. return dic;
  1462. }
  1463. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  1464. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1465. result += "订单号:" + order.OrderNo + "\n";
  1466. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  1467. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1468. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  1469. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1470. if (machineCount + ActiveCount >= 3)
  1471. {
  1472. string IsGet = "未发放";
  1473. int ToUserId = 0;
  1474. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  1475. if (item == null)
  1476. {
  1477. DateTime start = order.PayDate.Value.AddMinutes(-2);
  1478. DateTime end = order.PayDate.Value.AddMinutes(2);
  1479. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  1480. }
  1481. if (item != null)
  1482. {
  1483. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1484. ToUserId = item.UserId;
  1485. dic.Add("code", "1");
  1486. }
  1487. else
  1488. {
  1489. dic.Add("id", order.Id.ToString());
  1490. dic.Add("code", "0");
  1491. }
  1492. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  1493. result += "是否发放:" + IsGet + "\n";
  1494. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1495. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  1496. }
  1497. else
  1498. {
  1499. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  1500. dic.Add("code", "1");
  1501. }
  1502. dic.Add("result", result);
  1503. return dic;
  1504. }
  1505. public string AddPrize100(int Id)
  1506. {
  1507. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  1508. if (order != null)
  1509. {
  1510. //机具券逻辑
  1511. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  1512. if (pro != null)
  1513. {
  1514. //推荐下单奖励
  1515. if (pro.ProductId == 10 || pro.ProductId == 11)
  1516. {
  1517. int OrderId = order.Id;
  1518. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  1519. if (!checkPrize)
  1520. {
  1521. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  1522. if (user != null)
  1523. {
  1524. bool directPrize = false; //直推奖标记
  1525. int ParentUserId = user.ParentUserId;
  1526. // List<int> proids = new List<int>();
  1527. // proids.Add(10);
  1528. // proids.Add(11);
  1529. while(ParentUserId > 0)
  1530. {
  1531. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  1532. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  1533. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1534. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  1535. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  1536. {
  1537. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  1538. directPrize = true;
  1539. db.SaveChanges();
  1540. return "发放成功";
  1541. }
  1542. ParentUserId = puser.ParentUserId;
  1543. }
  1544. }
  1545. }
  1546. return "已发放,请勿重复发放";
  1547. }
  1548. }
  1549. }
  1550. return "操作失败";
  1551. }
  1552. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  1553. {
  1554. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  1555. if (account == null)
  1556. {
  1557. account = db.UserAccount.Add(new UserAccount()
  1558. {
  1559. Id = UserId,
  1560. UserId = UserId,
  1561. }).Entity;
  1562. db.SaveChanges();
  1563. }
  1564. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  1565. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  1566. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  1567. account.BalanceAmount += 100 * Count;
  1568. account.TotalAmount += 100 * Count;
  1569. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  1570. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  1571. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  1572. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  1573. {
  1574. CreateDate = DateTime.Now,
  1575. UpdateDate = DateTime.Now,
  1576. UserId = UserId, //创客
  1577. ChangeType = 112, //变动类型
  1578. ChangeAmount = 100 * Count, //变更金额
  1579. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  1580. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  1581. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  1582. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  1583. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  1584. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  1585. QueryCount = OrderId,
  1586. }).Entity;
  1587. db.SaveChanges();
  1588. }
  1589. #endregion
  1590. #region 设置立刷费率
  1591. public IActionResult LisFee(string right)
  1592. {
  1593. ViewBag.RightInfo = RightInfo;
  1594. ViewBag.right = right;
  1595. return View();
  1596. }
  1597. [HttpPost]
  1598. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  1599. {
  1600. if (string.IsNullOrEmpty(PosSns))
  1601. {
  1602. return "请输入机具号";
  1603. }
  1604. string result = SysUserName + "设置\n";
  1605. string[] PosSnList = PosSns.Split('\n');
  1606. int total = PosSnList.Length;
  1607. int index = 0;
  1608. foreach (string SubPosSn in PosSnList)
  1609. {
  1610. index += 1;
  1611. string PosSn = SubPosSn.Replace("\r", "");
  1612. result += PosSn + ":" + Fee + "\n";
  1613. if (Kind == "M5")
  1614. {
  1615. result += SetLiSFee(PosSn, Fee) + "\n";
  1616. }
  1617. else if (Kind == "N1")
  1618. {
  1619. result += SetLiSDeposit(PosSn, (int)Fee);
  1620. }
  1621. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  1622. }
  1623. result += "\n\n";
  1624. function.WriteLog(result, "设置立刷费率");
  1625. return result;
  1626. }
  1627. public string LisFeeProcess()
  1628. {
  1629. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  1630. }
  1631. #region 立刷
  1632. string LiSAgentId = "50814834";
  1633. string LiSPrivateKey = "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";
  1634. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  1635. public string LiSSign(string data)
  1636. {
  1637. var rsa = RSA.Create();
  1638. var key = Convert.FromBase64String(LiSPrivateKey);
  1639. var content = Encoding.UTF8.GetBytes(data);
  1640. rsa.ImportPkcs8PrivateKey(key, out _);
  1641. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  1642. return Convert.ToBase64String(result);
  1643. }
  1644. // 设置费率
  1645. public string SetLiSFee(string sn, decimal serviceFee)
  1646. {
  1647. Dictionary<string, object> dic = new Dictionary<string, object>();
  1648. dic.Add("agentId", LiSAgentId);
  1649. dic.Add("deviceSn", sn);
  1650. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  1651. Dictionary<string, object> item = new Dictionary<string, object>();
  1652. item.Add("feeCalcType", "M5");
  1653. item.Add("fixed", "0");
  1654. item.Add("rate", serviceFee);
  1655. feeList.Add(item);
  1656. dic.Add("feeList", feeList);
  1657. dic.Add("signMethod", "02");
  1658. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  1659. string signstr = LiSSign(content);
  1660. dic.Add("signData", signstr);
  1661. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  1662. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  1663. return result;
  1664. }
  1665. // 设置押金
  1666. public string SetLiSDeposit(string sn, int serviceFee)
  1667. {
  1668. serviceFee = serviceFee * 100;
  1669. Dictionary<string, object> dic = new Dictionary<string, object>();
  1670. dic.Add("agentId", LiSAgentId);
  1671. dic.Add("deviceSn", sn);
  1672. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  1673. Dictionary<string, object> item = new Dictionary<string, object>();
  1674. item.Add("feeCalcType", "N1");
  1675. item.Add("fixed", "1");
  1676. item.Add("rate", serviceFee);
  1677. feeList.Add(item);
  1678. dic.Add("feeList", feeList);
  1679. dic.Add("signMethod", "02");
  1680. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  1681. string signstr = LiSSign(content);
  1682. dic.Add("signData", signstr);
  1683. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  1684. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  1685. return result;
  1686. }
  1687. #endregion
  1688. #endregion
  1689. #region 查询商户型创客设置信息
  1690. public IActionResult SeeMerchantType(string right)
  1691. {
  1692. ViewBag.RightInfo = RightInfo;
  1693. ViewBag.right = right;
  1694. return View();
  1695. }
  1696. [HttpPost]
  1697. public string SeeMerchantTypeDo(string PosSn)
  1698. {
  1699. if (string.IsNullOrEmpty(PosSn))
  1700. {
  1701. return "请输入机具SN或者创客编号";
  1702. }
  1703. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  1704. if (PosSn.StartsWith("K"))
  1705. {
  1706. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  1707. pos = db.SetMerchantTypeRecord.FirstOrDefault(m => m.ToUserId == userfor.UserId) ?? new SetMerchantTypeRecord();
  1708. }
  1709. else
  1710. {
  1711. pos = db.SetMerchantTypeRecord.FirstOrDefault(m => m.PosSn == PosSn) ?? new SetMerchantTypeRecord();
  1712. }
  1713. if (pos.Id == 0)
  1714. {
  1715. return "查无信息";
  1716. }
  1717. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  1718. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  1719. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1720. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1721. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1722. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  1723. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  1724. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  1725. string result = "";
  1726. result += "机具SN:" + pos.PosSn + "\n";
  1727. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  1728. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  1729. result += "商户编号:" + pos.MerNo + "\n";
  1730. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  1731. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1732. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1733. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  1734. result += "是否循环:" + RecycFlag + "\n";
  1735. return result;
  1736. }
  1737. #endregion
  1738. }
  1739. }