SysToolsController.cs 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855
  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. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  139. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  140. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  141. bool check = spdb.TradeRecord.Any(m => m.Id > StartId && m.TradeSnNo == pos.PosSn);
  142. if (check)
  143. {
  144. if (pos.BrandId == 1)
  145. {
  146. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  147. }
  148. else if (pos.BrandId == 2)
  149. {
  150. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  151. }
  152. else if (pos.BrandId == 3)
  153. {
  154. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  155. }
  156. else if (pos.BrandId == 4 || pos.BrandId == 5)
  157. {
  158. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  159. }
  160. else if (pos.BrandId == 6)
  161. {
  162. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  163. }
  164. else if (pos.BrandId == 7)
  165. {
  166. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  167. }
  168. else if (pos.BrandId == 8)
  169. {
  170. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  171. }
  172. else if (pos.BrandId == 9)
  173. {
  174. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  175. }
  176. pos.CreditTrade = CreditTrade;
  177. db.SaveChanges();
  178. StatTradeAmount(pos.PosSn, StartId);
  179. }
  180. if (AddActPrize == 1)
  181. {
  182. if (pos.BuyUserId == 0)
  183. {
  184. return "机具未划拨,无法补录激活奖励";
  185. }
  186. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  187. {
  188. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  189. if (has)
  190. {
  191. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  192. pos.SeoKeyword = chkAct.SeoTitle;
  193. db.SaveChanges();
  194. }
  195. }
  196. if (pos.BindingTime != null && pos.ActivationTime != null)
  197. {
  198. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  199. if (ts.TotalDays <= 30 || SysUserName == "admin")
  200. {
  201. AddAct(pos.Id);
  202. }
  203. }
  204. }
  205. decimal CheckMoney = 1000;
  206. if (pos.BrandId == 6)
  207. {
  208. CheckMoney = 5000;
  209. }
  210. if (pos.BuyUserId > 0)
  211. {
  212. if (pos.CreditTrade < CheckMoney)
  213. {
  214. return "该机具贷记卡累计交易不足" + CheckMoney;
  215. }
  216. if (pos.BindingTime != null && pos.ActivationTime != null)
  217. {
  218. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  219. if (ts.TotalDays > 30 && SysUserName != "admin")
  220. {
  221. return "机具划拨后已超过30天";
  222. }
  223. }
  224. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  225. {
  226. pos.ActivationState = 1;
  227. pos.ActivationTime = DateTime.Now;
  228. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  229. if (pos.ActivationState == 1 && mer != null)
  230. {
  231. mer.ActiveStatus = 1;
  232. mer.MerStandardDate = DateTime.Now;
  233. }
  234. }
  235. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  236. {
  237. if (AddActPrize == 1)
  238. {
  239. if (IsSend == 1)
  240. {
  241. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  242. {
  243. UserId = pos.BuyUserId, //接收创客
  244. MsgType = 2,
  245. Title = "补录成功通知", //标题
  246. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  247. CreateDate = DateTime.Now,
  248. }));
  249. }
  250. return "激活奖励已补录";
  251. }
  252. else
  253. {
  254. return "数据正常,无需补录";
  255. }
  256. }
  257. db.SaveChanges();
  258. return "success";
  259. }
  260. pos.UserId = user.Id;
  261. pos.BuyUserId = user.Id;
  262. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
  263. {
  264. // pos.IsPurchase = 0;
  265. pos.ActivationState = 1;
  266. pos.ActivationTime = DateTime.Now;
  267. }
  268. PosMerchantInfo merchant = new PosMerchantInfo();
  269. if (!string.IsNullOrEmpty(MerNo))
  270. {
  271. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  272. if (merchant == null)
  273. {
  274. int TopUserId = 0;
  275. if (!string.IsNullOrEmpty(user.ParentNav))
  276. {
  277. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  278. }
  279. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  280. if (bind == null)
  281. {
  282. return "该机具尚未绑定";
  283. }
  284. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  285. if (Mer == null)
  286. {
  287. return "该机具尚未绑定";
  288. }
  289. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  290. {
  291. CreateDate = Mer.CreateTime,
  292. UpdateDate = Mer.UpdateTime,
  293. TopUserId = TopUserId,
  294. MerUserType = user.MerchantType,
  295. BrandId = int.Parse(Mer.ProductType),
  296. SnStoreId = pos.StoreId,
  297. SnType = pos.PosSnType,
  298. UserId = user.Id,
  299. MgrName = Mer.AgentName,
  300. MerStatus = 1,
  301. KqSnNo = Mer.SnNo,
  302. KqMerNo = Mer.MerNo,
  303. MerIdcardNo = Mer.MerIdcardNo,
  304. MerRealName = Mer.MerRealName,
  305. MerchantMobile = Mer.MerMobile,
  306. MerchantName = Mer.MerName,
  307. MerchantNo = Mer.MerNo,
  308. }).Entity;
  309. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  310. if (forMerNo == null)
  311. {
  312. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  313. {
  314. MerNo = Mer.MerNo,
  315. SnId = pos.Id,
  316. }).Entity;
  317. }
  318. else
  319. {
  320. forMerNo.SnId = pos.Id;
  321. }
  322. }
  323. }
  324. else
  325. {
  326. if (pos.BindMerchantId > 0)
  327. {
  328. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  329. }
  330. else
  331. {
  332. return "找不到机具所属商户";
  333. }
  334. }
  335. merchant.UserId = user.Id;
  336. if (pos.ActivationState == 1)
  337. {
  338. merchant.ActiveStatus = 1;
  339. merchant.MerStandardDate = DateTime.Now;
  340. }
  341. if (pos.BindMerchantId == 0)
  342. {
  343. pos.BindMerchantId = merchant.Id;
  344. }
  345. db.SaveChanges();
  346. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize + ", IsPre:" + IsPre, "机具补录日志");
  347. return "success";
  348. }
  349. public IActionResult CheckMachine2(string right)
  350. {
  351. ViewBag.RightInfo = RightInfo;
  352. ViewBag.right = right;
  353. return View();
  354. }
  355. [HttpPost]
  356. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  357. {
  358. if (string.IsNullOrEmpty(MakerCode))
  359. {
  360. return "请输入创客编号";
  361. }
  362. if (string.IsNullOrEmpty(PosSn))
  363. {
  364. return "请输入机具SN";
  365. }
  366. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  367. if (pos == null)
  368. {
  369. return "机具SN不存在";
  370. }
  371. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  372. if (user == null)
  373. {
  374. return "创客编号不存在";
  375. }
  376. if (pos.BindingState == 0)
  377. {
  378. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  379. if (bind != null)
  380. {
  381. pos.BindingState = 1;
  382. pos.BindingTime = bind.CreateTime;
  383. db.SaveChanges();
  384. MerNo = bind.MerNo;
  385. }
  386. }
  387. decimal CreditTrade = 0;
  388. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  389. if (check)
  390. {
  391. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  392. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  393. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  394. if (pos.BrandId == 1)
  395. {
  396. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId &&m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M700")).Sum(m => m.TradeAmount) / 100;
  397. }
  398. else if (pos.BrandId == 2)
  399. {
  400. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId &&m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  401. }
  402. else if (pos.BrandId == 3)
  403. {
  404. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId &&m.TradeSnNo == pos.PosSn && m.ProductType == "1" && m.SerEntryMode != "N" && m.MerNo.StartsWith("M900")).Sum(m => m.TradeAmount) / 100;
  405. }
  406. else if (pos.BrandId == 4 || pos.BrandId == 5)
  407. {
  408. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId &&m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  409. }
  410. else if (pos.BrandId == 6)
  411. {
  412. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId &&m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  413. }
  414. else if (pos.BrandId == 8)
  415. {
  416. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId &&m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  417. }
  418. else if (pos.BrandId == 9)
  419. {
  420. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId &&m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  421. }
  422. pos.CreditTrade = CreditTrade;
  423. db.SaveChanges();
  424. StatTradeAmount(pos.PosSn);
  425. }
  426. if (AddActPrize == 1)
  427. {
  428. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  429. {
  430. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  431. if (has)
  432. {
  433. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  434. pos.SeoKeyword = chkAct.SeoTitle;
  435. db.SaveChanges();
  436. }
  437. }
  438. AddAct(pos.Id);
  439. }
  440. if (pos.BuyUserId > 0)
  441. {
  442. if (pos.CreditTrade < 1000)
  443. {
  444. // pos.IsPurchase = 99;
  445. db.SaveChanges();
  446. return "该机具贷记卡累计交易不足1000";
  447. }
  448. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  449. {
  450. // pos.IsPurchase = 0;
  451. pos.ActivationState = 1;
  452. pos.ActivationTime = DateTime.Now;
  453. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  454. if (pos.ActivationState == 1 && mer != null)
  455. {
  456. mer.ActiveStatus = 1;
  457. mer.MerStandardDate = DateTime.Now;
  458. RedisDbconn.Instance.Clear("PosMerchantInfo:" + mer.Id);
  459. }
  460. }
  461. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  462. {
  463. if (AddActPrize == 1)
  464. {
  465. return "激活奖励已补录";
  466. }
  467. else
  468. {
  469. return "数据正常,无需补录";
  470. }
  471. }
  472. db.SaveChanges();
  473. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  474. return "success";
  475. }
  476. pos.UserId = user.Id;
  477. pos.BuyUserId = user.Id;
  478. // if (pos.CreditTrade < 1000)
  479. // {
  480. // pos.IsPurchase = 99;
  481. // }
  482. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  483. {
  484. // pos.IsPurchase = 0;
  485. pos.ActivationState = 1;
  486. pos.ActivationTime = DateTime.Now;
  487. }
  488. PosMerchantInfo merchant = new PosMerchantInfo();
  489. if (!string.IsNullOrEmpty(MerNo))
  490. {
  491. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  492. if (merchant == null)
  493. {
  494. int TopUserId = 0;
  495. if (!string.IsNullOrEmpty(user.ParentNav))
  496. {
  497. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  498. }
  499. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  500. if (bind == null)
  501. {
  502. return "该机具尚未绑定";
  503. }
  504. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  505. if (Mer == null)
  506. {
  507. return "该机具尚未绑定";
  508. }
  509. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  510. {
  511. CreateDate = Mer.CreateTime,
  512. UpdateDate = Mer.UpdateTime,
  513. TopUserId = TopUserId,
  514. MerUserType = user.MerchantType,
  515. BrandId = int.Parse(Mer.ProductType),
  516. SnStoreId = pos.StoreId,
  517. SnType = pos.PosSnType,
  518. UserId = user.Id,
  519. MgrName = Mer.AgentName,
  520. MerStatus = 1,
  521. KqSnNo = Mer.SnNo,
  522. KqMerNo = Mer.MerNo,
  523. MerIdcardNo = Mer.MerIdcardNo,
  524. MerRealName = Mer.MerRealName,
  525. MerchantMobile = Mer.MerMobile,
  526. MerchantName = Mer.MerName,
  527. MerchantNo = Mer.MerNo,
  528. }).Entity;
  529. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  530. if (forMerNo == null)
  531. {
  532. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  533. {
  534. MerNo = Mer.MerNo,
  535. SnId = pos.Id,
  536. }).Entity;
  537. }
  538. else
  539. {
  540. forMerNo.SnId = pos.Id;
  541. }
  542. }
  543. }
  544. else
  545. {
  546. if (pos.BindMerchantId > 0)
  547. {
  548. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  549. }
  550. else
  551. {
  552. return "找不到机具所属商户";
  553. }
  554. }
  555. merchant.UserId = user.Id;
  556. if (pos.ActivationState == 1)
  557. {
  558. merchant.ActiveStatus = 1;
  559. merchant.MerStandardDate = DateTime.Now;
  560. }
  561. if (pos.BindMerchantId == 0)
  562. {
  563. pos.BindMerchantId = merchant.Id;
  564. }
  565. db.SaveChanges();
  566. RedisDbconn.Instance.Clear("PosMerchantInfo:" + merchant.Id);
  567. RedisDbconn.Instance.Clear("PosMachinesTwo:" + pos.Id);
  568. return "success";
  569. }
  570. public void AddAct(int posid = 0)
  571. {
  572. WebCMSEntities db = new WebCMSEntities();
  573. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
  574. if (pos != null)
  575. {
  576. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
  577. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  578. if (merchant != null)
  579. {
  580. // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
  581. // if (otherInfo != null)
  582. // {
  583. // otherInfo.PrizeFlag1 = 1;
  584. // db.SaveChanges();
  585. string ParentNav = "";
  586. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  587. if (user != null)
  588. {
  589. int GetUserId = user.Id;
  590. ParentNav = user.ParentNav;
  591. int TopUserId = 1;
  592. if (!string.IsNullOrEmpty(ParentNav))
  593. {
  594. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  595. if (ParentNavList.Length > 1)
  596. {
  597. TopUserId = int.Parse(ParentNavList[1]);
  598. }
  599. else if (ParentNavList.Length == 1)
  600. {
  601. TopUserId = int.Parse(ParentNavList[0]);
  602. }
  603. }
  604. List<decimal> prizes = new List<decimal>();
  605. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  606. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
  607. {
  608. ActPrize = ActPrize / 100;
  609. }
  610. if (ActPrize > 0)
  611. {
  612. if (ActPrize == 99)
  613. {
  614. ActPrize = 100;
  615. }
  616. else if (ActPrize == 199)
  617. {
  618. ActPrize = 200;
  619. }
  620. else if (ActPrize == 299)
  621. {
  622. ActPrize = 300;
  623. }
  624. else if (ActPrize == 249)
  625. {
  626. ActPrize = 260;
  627. }
  628. prizes.Add(ActPrize);
  629. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  630. {
  631. prizes.Add(40);
  632. }
  633. }
  634. else if (pos.BrandId == 6 && ActPrize == 0)
  635. {
  636. prizes.Add(50);
  637. }
  638. foreach (decimal prize in prizes)
  639. {
  640. int ChangeType = prize == 40 ? 12 : 0;
  641. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  642. if (!check)
  643. {
  644. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  645. db.ActiveReward.Add(new ActiveReward()
  646. {
  647. CreateDate = DateTime.Now,
  648. UpdateDate = DateTime.Now,
  649. UserId = GetUserId, //创客
  650. MerchantId = pos.BindMerchantId, //商户
  651. StandardDate = pos.ActivationTime, //达标日期
  652. RewardAmount = prize, //奖励金额
  653. BrandId = pos.BrandId, //品牌
  654. UserNav = ParentNav, //创客父级
  655. DirectBuddyNo = merchant.UserId, //商户直属创客
  656. KqMerNo = merchant.KqMerNo, //渠道商户编号
  657. KqSnNo = pos.PosSn, //渠道SN号
  658. SnType = pos.PosSnType, //机具类型
  659. SnApplyUserId = pos.BuyUserId, //机具申请创客
  660. ActType = 0, //激活类型
  661. SnStoreId = pos.StoreId, //SN仓库
  662. RewardTips = "激活奖励", //奖励描述
  663. Remark = "激活奖励", //备注
  664. ActDate = pos.ActivationTime, //激活时间
  665. TopUserId = TopUserId, //顶级创客
  666. SeoTitle = machineUser.RealName,
  667. });
  668. db.SaveChanges();
  669. string IdBrand = GetUserId + "_" + pos.BrandId;
  670. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  671. if (userData == null)
  672. {
  673. userData = db.UserMachineData.Add(new UserMachineData()
  674. {
  675. IdBrand = IdBrand,
  676. }).Entity;
  677. db.SaveChanges();
  678. }
  679. userData.ActProfit += prize;
  680. db.SaveChanges();
  681. RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
  682. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  683. if (account == null)
  684. {
  685. account = db.UserAccount.Add(new UserAccount()
  686. {
  687. Id = GetUserId,
  688. UserId = GetUserId,
  689. }).Entity;
  690. db.SaveChanges();
  691. }
  692. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  693. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  694. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  695. account.BalanceAmount += prize;
  696. account.TotalAmount += prize;
  697. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  698. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  699. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  700. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  701. {
  702. CreateDate = DateTime.Now,
  703. UpdateDate = DateTime.Now,
  704. UserId = GetUserId, //创客
  705. ChangeType = ChangeType, //变动类型
  706. ProductType = pos.BrandId, //产品类型
  707. ChangeAmount = prize, //变更金额
  708. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  709. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  710. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  711. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  712. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  713. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  714. }).Entity;
  715. db.SaveChanges();
  716. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  717. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  718. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  719. // 激活奖励列表
  720. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  721. if (!dates.Contains(dateString))
  722. {
  723. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  724. }
  725. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  726. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  727. if (!months.Contains(monthString))
  728. {
  729. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  730. }
  731. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  732. // 激活奖励详情
  733. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  734. if (!actPrizeList.Contains(pos.BindMerchantId))
  735. {
  736. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  737. }
  738. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  739. //收支明细
  740. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  741. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  742. }
  743. }
  744. }
  745. // }
  746. }
  747. }
  748. db.Dispose();
  749. }
  750. //重置交易额
  751. public void StatTradeAmount(string PosSn, int StartId = 0)
  752. {
  753. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  754. if (DateTime.Now.Day == 1)
  755. {
  756. start = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
  757. }
  758. DateTime end = DateTime.Now;
  759. SycnSpTradeService.Instance.Start(PosSn, start, end, StartId);
  760. RedisDbconn.Instance.AddList("ResetTradeAmountList", PosSn);
  761. }
  762. #endregion
  763. #region 设置商户代理
  764. public IActionResult SetMerAgent(string right)
  765. {
  766. ViewBag.RightInfo = RightInfo;
  767. ViewBag.right = right;
  768. return View();
  769. }
  770. [HttpPost]
  771. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
  772. {
  773. if (string.IsNullOrEmpty(MakerCode))
  774. {
  775. return "请输入创客编号";
  776. }
  777. if (string.IsNullOrEmpty(PosSn))
  778. {
  779. return "请输入机具SN";
  780. }
  781. if (string.IsNullOrEmpty(MerNo))
  782. {
  783. return "请输入商户编号";
  784. }
  785. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  786. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  787. if (pos == null)
  788. {
  789. return "机具SN不存在";
  790. }
  791. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  792. if (user == null)
  793. {
  794. return "创客编号不存在";
  795. }
  796. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  797. if (merchant == null)
  798. {
  799. return "商户编号不存在";
  800. }
  801. pos.SeoTitle = user.Id.ToString();
  802. pos.UserId = user.Id;
  803. if (pos.BindMerchantId == 0)
  804. {
  805. pos.BindMerchantId = merchant.Id;
  806. if (IsSend == 1)
  807. {
  808. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  809. {
  810. UserId = pos.BuyUserId, //接收创客
  811. MsgType = 2,
  812. Title = "商户型代理设置成功", //标题
  813. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
  814. CreateDate = DateTime.Now,
  815. }));
  816. }
  817. }
  818. user.MerchantType = 1;
  819. merchant.UserId = user.Id;
  820. merchant.MerUserType = 1;
  821. db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
  822. {
  823. CreateDate = DateTime.Now,
  824. IsRecyc = (ulong)pos.IsPurchase,
  825. CreditAmount = pos.CreditTrade,
  826. PosSnType = pos.PosSnType,
  827. ActDate = pos.ActivationTime,
  828. BindDate = pos.BindingTime,
  829. ActStatus = (ulong)pos.ActivationState,
  830. BindStatus = (ulong)pos.BindingState,
  831. MerNo = MerNo,
  832. PosSn = pos.PosSn,
  833. Note = "后台设置商户型创客",
  834. ToUserId = user.Id,
  835. FromUserId = pos.BuyUserId,
  836. });
  837. db.SaveChanges();
  838. return "success";
  839. }
  840. #endregion
  841. #region 取消商户代理
  842. public IActionResult CancelMerAgent(string right)
  843. {
  844. ViewBag.RightInfo = RightInfo;
  845. ViewBag.right = right;
  846. return View();
  847. }
  848. [HttpPost]
  849. public string CancelMerAgentDo(string MakerCode, string PosSn, int IsSend = 0)
  850. {
  851. if (string.IsNullOrEmpty(MakerCode))
  852. {
  853. return "请输入创客编号";
  854. }
  855. if (string.IsNullOrEmpty(PosSn))
  856. {
  857. return "请输入机具SN";
  858. }
  859. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  860. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  861. if (pos == null)
  862. {
  863. return "机具SN不存在";
  864. }
  865. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  866. if (user == null)
  867. {
  868. return "创客编号不存在";
  869. }
  870. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == PosSn);
  871. pos.UserId = pos.BuyUserId;
  872. merchant.UserId = pos.BuyUserId;
  873. merchant.MerUserType = 0;
  874. user.MerchantType = 0;
  875. db.SaveChanges();
  876. if (pos.BindMerchantId == 0)
  877. {
  878. pos.BindMerchantId = merchant.Id;
  879. if (IsSend == 1)
  880. {
  881. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  882. {
  883. UserId = pos.BuyUserId, //接收创客
  884. MsgType = 2,
  885. Title = "商户型代理取消成功", //标题
  886. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已给下级代理" + user.RealName + "" + MakerCode + "取消成功",
  887. CreateDate = DateTime.Now,
  888. }));
  889. }
  890. }
  891. string text = string.Format("取消商户代理,创客编号: " + user.MakerCode + ",机具SN:" + pos.PosSn + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
  892. function.WriteLog(text, "CancelMerAgent");//取消商户型代理日志
  893. return "success";
  894. }
  895. #endregion
  896. #region 查看SP原始数据日志
  897. public IActionResult SeeSpLog(string right)
  898. {
  899. ViewBag.RightInfo = RightInfo;
  900. ViewBag.right = right;
  901. return View();
  902. }
  903. #endregion
  904. #region 查询机具信息
  905. public IActionResult SeeSnDetail(string right)
  906. {
  907. ViewBag.RightInfo = RightInfo;
  908. ViewBag.right = right;
  909. return View();
  910. }
  911. [HttpPost]
  912. public string SeeSnDetailDo(string PosSn)
  913. {
  914. if (string.IsNullOrEmpty(PosSn))
  915. {
  916. return "请输入机具SN";
  917. }
  918. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  919. if (pos == null)
  920. {
  921. return "机具SN不存在";
  922. }
  923. if (pos.Status == -1)
  924. {
  925. Users posUsers = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  926. decimal Deposits = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  927. if (pos.BrandId != 2 && pos.BrandId != 7)
  928. {
  929. Deposits = Deposits / 100;
  930. }
  931. string DepositGets = "未领取";
  932. string DepositUsers = "";
  933. ActiveReward rewards = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  934. if (rewards.Id > 0)
  935. {
  936. Users user = db.Users.FirstOrDefault(m => m.Id == rewards.UserId) ?? new Users();
  937. DepositGets = "已领取";
  938. DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  939. }
  940. string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  941. string results = "该机具为故障机" + "\n";
  942. results += "押金返现实际返现对象:" + DepositUsers + "\n";
  943. results += "押金:" + Deposits + "\n";
  944. results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
  945. return results;
  946. }
  947. string merInfo = "";
  948. string merName = "";
  949. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  950. if (mer != null)
  951. {
  952. merInfo = mer.KqMerNo;
  953. merName = mer.MerchantName;
  954. }
  955. else
  956. {
  957. merInfo = "未找到商户";
  958. }
  959. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  960. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  961. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  962. int TopUserId = 0;
  963. if (!string.IsNullOrEmpty(posUser.ParentNav))
  964. {
  965. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  966. if (ParentNavs.Length > 1)
  967. {
  968. TopUserId = int.Parse(ParentNavs[1]);
  969. }
  970. if (ParentNavs.Length == 1)
  971. {
  972. TopUserId = int.Parse(ParentNavs[0]);
  973. }
  974. }
  975. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  976. string bindResult = "", bindTime = "";
  977. if (pos.BindingState == 0)
  978. {
  979. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  980. if (bind != null)
  981. {
  982. if (bind.Status != 1)
  983. {
  984. bindResult = "执行中";
  985. }
  986. }
  987. else
  988. {
  989. bindResult = "未绑定";
  990. }
  991. }
  992. else
  993. {
  994. bindResult = "已绑定";
  995. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  996. }
  997. string activeResult = "", activeTime = "";
  998. if (pos.ActivationState == 0)
  999. {
  1000. if (pos.CreditTrade < 1000)
  1001. {
  1002. activeResult = "未刷满1000";
  1003. }
  1004. else if (pos.TransferTime == null)
  1005. {
  1006. activeResult = "未激活, 需补录";
  1007. }
  1008. }
  1009. else
  1010. {
  1011. activeResult = "已激活";
  1012. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1013. }
  1014. string tradeAmount = pos.CreditTrade.ToString();
  1015. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1016. if (pos.BrandId != 2 && pos.BrandId != 7)
  1017. {
  1018. Deposit = Deposit / 100;
  1019. }
  1020. string DepositGet = "未领取";
  1021. string DepositUser = "";
  1022. string DepositToUser = "";
  1023. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1024. if (reward.Id > 0)
  1025. {
  1026. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1027. DepositGet = "已领取";
  1028. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1029. }
  1030. string DepositGet6 = "未领取";
  1031. string DepositUser6 = "";
  1032. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  1033. if (lisreward.Id > 0)
  1034. {
  1035. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  1036. DepositGet6 = "已领取";
  1037. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1038. }
  1039. string FluxGet6 = "未领取";
  1040. string FluxUser6 = "";
  1041. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1042. if (flux.Id > 0)
  1043. {
  1044. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1045. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1046. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1047. }
  1048. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1049. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  1050. string OpenUser10 = "未领取";
  1051. string OpenUser20 = "未领取";
  1052. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1053. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1054. if (openreward.Id > 0)
  1055. {
  1056. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1057. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1058. }
  1059. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1060. if (openreward.Id > 0)
  1061. {
  1062. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1063. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1064. }
  1065. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1066. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1067. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1068. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1069. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1070. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1071. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1072. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1073. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1074. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1075. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1076. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1077. string result = "";
  1078. result += "机具SN:" + pos.PosSn + "\n";
  1079. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1080. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  1081. if (change.Id > 0)
  1082. {
  1083. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1084. }
  1085. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  1086. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  1087. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1088. if (pos.PreUserId > 0)
  1089. {
  1090. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1091. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1092. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1093. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",手机号:" + smallStoreUser.Mobile + ",预发时间:" + preSendDate + "\n";
  1094. }
  1095. else
  1096. {
  1097. result += "机具所属小分仓:暂无小分仓\n";
  1098. }
  1099. result += "入库时间:" + CreateDate + "\n";
  1100. result += "循环到期时间:" + RecycEndDate + "\n";
  1101. result += "划拨时间:" + TransferTime + "\n";
  1102. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1103. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1104. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1105. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1106. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1107. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1108. result += "押金:" + Deposit + "\n";
  1109. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1110. result += "押金返现应返现对象:" + DepositToUser + "\n";
  1111. result += "押金返现实际返现对象:" + DepositUser + "\n";
  1112. if (pos.BrandId == 6)
  1113. {
  1114. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1115. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1116. }
  1117. result += "流量费:" + FluxGet6 + "\n";
  1118. result += "流量费发放对象:" + FluxUser6 + "\n";
  1119. result += "开机奖20:" + OpenUser20 + "\n";
  1120. result += "开机奖10:" + OpenUser10 + "\n";
  1121. return result;
  1122. }
  1123. //解析金控日志
  1124. // public decimal CheckLog(DateTime startDate, string PosSn)
  1125. // {
  1126. // bool op = true;
  1127. // decimal result = 0;
  1128. // DateTime today = DateTime.Now;
  1129. // int i = 0;
  1130. // while (op)
  1131. // {
  1132. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  1133. // if (check <= today)
  1134. // {
  1135. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  1136. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  1137. // foreach (Match sub in mc)
  1138. // {
  1139. // string content = sub.Value;
  1140. // JsonData jsonObj = JsonMapper.ToObject(content);
  1141. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  1142. // string posSnCheck = jsonObj["posSn"].ToString();
  1143. // if (posSnCheck == PosSn && serviceAmount > 0)
  1144. // {
  1145. // result = serviceAmount / 100;
  1146. // op = false;
  1147. // }
  1148. // }
  1149. // }
  1150. // else
  1151. // {
  1152. // op = false;
  1153. // }
  1154. // i += 1;
  1155. // }
  1156. // return result;
  1157. // }
  1158. #endregion
  1159. #region 生成机具兑换码
  1160. public IActionResult MakeCoupons(string right)
  1161. {
  1162. ViewBag.RightInfo = RightInfo;
  1163. ViewBag.right = right;
  1164. return View();
  1165. }
  1166. [HttpPost]
  1167. public string MakeCouponsDo(int Kind, int Number)
  1168. {
  1169. DateTime checkTime = DateTime.Parse("1900-01-01");
  1170. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1171. if (!string.IsNullOrEmpty(checkTimeString))
  1172. {
  1173. checkTime = DateTime.Parse(checkTimeString);
  1174. }
  1175. if (checkTime.AddHours(1) < DateTime.Now)
  1176. {
  1177. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1178. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1179. return "生成程序已执行";
  1180. }
  1181. return "请稍后再试";
  1182. }
  1183. #endregion
  1184. #region 导出没有刷满1000的机具
  1185. public IActionResult ExportPos(string right)
  1186. {
  1187. ViewBag.RightInfo = RightInfo;
  1188. ViewBag.right = right;
  1189. return View();
  1190. }
  1191. [HttpPost]
  1192. public JsonResult ExportPosDo()
  1193. {
  1194. WebCMSEntities db = new WebCMSEntities();
  1195. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1196. int total = poses.Count;
  1197. int index = 0;
  1198. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1199. foreach (PosMachinesTwo pos in poses)
  1200. {
  1201. index += 1;
  1202. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1203. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1204. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1205. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1206. Dictionary<string, object> item = new Dictionary<string, object>();
  1207. string TopRealName = "";
  1208. string TopMakerCode = "";
  1209. string TopMobile = "";
  1210. string ParentNav = user.ParentNav;
  1211. if (!string.IsNullOrEmpty(ParentNav))
  1212. {
  1213. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1214. if (navlist.Length > 1)
  1215. {
  1216. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1217. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1218. TopRealName = tuser.RealName;
  1219. TopMakerCode = tuser.MakerCode;
  1220. TopMobile = tuser.Mobile;
  1221. }
  1222. }
  1223. item.Add("TopRealName", TopRealName); //顶级姓名
  1224. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1225. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1226. item.Add("UpRealName", puser.RealName); //上级姓名
  1227. item.Add("RealName", user.RealName); //代理姓名
  1228. item.Add("MakerCode", user.MakerCode); //代理编号
  1229. item.Add("Mobile", user.Mobile); //代理手机号
  1230. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1231. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1232. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1233. item.Add("Sn", pos.PosSn); //SN
  1234. list.Add(item);
  1235. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1236. }
  1237. db.Dispose();
  1238. Dictionary<string, object> result = new Dictionary<string, object>();
  1239. result.Add("Status", "1");
  1240. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1241. result.Add("Obj", list);
  1242. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1243. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1244. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1245. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1246. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1247. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1248. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1249. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1250. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1251. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1252. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1253. ReturnFields.Add("Sn", "SN"); //SN
  1254. result.Add("Fields", ReturnFields);
  1255. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1256. return Json(result);
  1257. }
  1258. public string ExportPosCheck()
  1259. {
  1260. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1261. if (content == "finish")
  1262. {
  1263. RedisDbconn.Instance.Clear("ExportPosCheck");
  1264. }
  1265. return content;
  1266. }
  1267. #endregion
  1268. #region 更换机具
  1269. public IActionResult ChangePos(string right)
  1270. {
  1271. ViewBag.RightInfo = RightInfo;
  1272. ViewBag.right = right;
  1273. return View();
  1274. }
  1275. [HttpPost]
  1276. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1277. {
  1278. if (string.IsNullOrEmpty(OldSn))
  1279. {
  1280. return "请输入原机具SN";
  1281. }
  1282. if (string.IsNullOrEmpty(NewSn))
  1283. {
  1284. return "请输入新机具SN";
  1285. }
  1286. string[] OldSnList = OldSn.Split('\n');
  1287. string[] NewSnList = NewSn.Split('\n');
  1288. if (OldSnList.Length != NewSnList.Length)
  1289. {
  1290. return "原机具SN数量和新机具SN数量不一致";
  1291. }
  1292. WebCMSEntities db = new WebCMSEntities();
  1293. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1294. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1295. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1296. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1297. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1298. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1299. KqProducts oldPosBrand = new KqProducts();
  1300. KqProducts newPosBrand = new KqProducts();
  1301. MachineChange add = db.MachineChange.Add(new MachineChange()
  1302. {
  1303. CreateDate = DateTime.Now,
  1304. UpdateDate = DateTime.Now,
  1305. CreateMan = SysUserName + "-" + SysRealName,
  1306. ChangeNo = ChangeNo, //转换单号
  1307. UserId = 0, //创客
  1308. ChangeTime = DateTime.Now, //转换时间
  1309. BackStoreId = BackStore.Id, //退回仓库
  1310. BackStoreName = BackStore.StoreName, //退回仓库名称
  1311. Remark = "机具更换", //订单备注
  1312. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1313. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1314. OutProductName = OutStore.ProductName, //出库产品名称
  1315. OutStoreId = OutStore.Id, //出库仓库
  1316. OutStoreName = OutStore.StoreName, //出库仓库名称
  1317. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1318. OutStoreAddress = OutStore.Address, //出库仓库地址
  1319. OutStoreManager = "", //出库仓库联系人
  1320. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1321. }).Entity;
  1322. db.SaveChanges();
  1323. int BackProductType = 0;
  1324. string BackProductName = "";
  1325. string ChangeDeviceName = "";
  1326. string ChangeSnExpand = "";
  1327. for (int i = 0; i < OldSnList.Length; i++)
  1328. {
  1329. string OldSnNum = OldSnList[i];
  1330. string NewSnNum = NewSnList[i];
  1331. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1332. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1333. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1334. if (oldpos == null)
  1335. {
  1336. return "原机具SN不正确";
  1337. }
  1338. // if (oldpos.BindingState != 1)
  1339. // {
  1340. // return "原机具未绑定";
  1341. // }
  1342. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1343. if (newpos == null)
  1344. {
  1345. return "新机具SN不正确";
  1346. }
  1347. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1348. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1349. PosMerchantInfo merchant = new PosMerchantInfo();
  1350. if (!string.IsNullOrEmpty(MerNo))
  1351. {
  1352. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1353. }
  1354. else
  1355. {
  1356. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
  1357. }
  1358. newpos.BindMerchantId = merchant.Id;
  1359. newpos.BuyUserId = oldpos.BuyUserId;
  1360. newpos.UserId = oldpos.UserId;
  1361. newpos.RecycEndDate = oldpos.RecycEndDate;
  1362. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1363. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1364. newpos.CreditTrade = oldpos.CreditTrade;
  1365. newpos.PosSnType = oldpos.PosSnType;
  1366. newpos.TransferTime = oldpos.TransferTime;
  1367. newpos.IsPurchase = oldpos.IsPurchase;
  1368. newpos.BindingState = oldpos.BindingState;
  1369. newpos.ActivationState = oldpos.ActivationState;
  1370. newpos.BindingTime = oldpos.BindingTime;
  1371. newpos.ActivationTime = oldpos.ActivationTime;
  1372. newpos.IsFirst = oldpos.IsFirst;
  1373. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1374. // if (!checkActReward)
  1375. // {
  1376. newpos.SeoKeyword = oldpos.SeoKeyword;
  1377. newpos.PrizeParams = oldpos.PrizeParams;
  1378. newpos.LeaderUserId = oldpos.LeaderUserId;
  1379. newpos.IsFirst = oldpos.IsFirst;
  1380. // }
  1381. // oldpos.BuyUserId = 0;
  1382. // oldpos.UserId = 0;
  1383. oldpos.Status = -1;
  1384. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1385. if (forMerNo != null)
  1386. {
  1387. forMerNo.SnId = newpos.Id;
  1388. }
  1389. merchant.KqSnNo = NewSn;
  1390. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1391. {
  1392. CreateDate = DateTime.Now,
  1393. UpdateDate = DateTime.Now,
  1394. CreateMan = SysUserName + "-" + SysRealName,
  1395. ChangeNo = ChangeNo, //订单号
  1396. ChangeId = add.Id, //订单Id
  1397. BackProductType = oldpos.BrandId, //退回产品类型
  1398. BackProductName = oldPosBrand.Name, //退回产品名称
  1399. UserId = 0, //创客
  1400. BackSnNo = oldpos.PosSn, //设备SN编号
  1401. OutProductType = newpos.BrandId, //出库产品类型
  1402. OutProductName = newPosBrand.Name, //出库产品名称
  1403. OutSnNo = newpos.PosSn, //出库设备SN编号
  1404. OutSnType = newpos.PosSnType, //出库SN机具类型
  1405. Remark = "机具更换", //备注
  1406. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1407. });
  1408. db.SaveChanges();
  1409. BackProductType = oldpos.BrandId;
  1410. BackProductName = newPosBrand.Name;
  1411. ChangeDeviceName = oldpos.DeviceName;
  1412. ChangeSnExpand += oldpos.PosSn + "\n";
  1413. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1414. }
  1415. add.BackProductType = BackProductType; //退回产品类型
  1416. add.BackProductName = BackProductName; //退回产品名称
  1417. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1418. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1419. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1420. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1421. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1422. db.SaveChanges();
  1423. db.Dispose();
  1424. if (IsSend == 1)
  1425. {
  1426. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1427. {
  1428. UserId = pos.BuyUserId, //接收创客
  1429. MsgType = 2,
  1430. Title = "换绑成功通知", //标题
  1431. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1432. CreateDate = DateTime.Now,
  1433. }));
  1434. }
  1435. return "success";
  1436. }
  1437. #endregion
  1438. #region 坏机换新
  1439. public IActionResult ChangeBadPos(string right)
  1440. {
  1441. ViewBag.RightInfo = RightInfo;
  1442. ViewBag.right = right;
  1443. return View();
  1444. }
  1445. [HttpPost]
  1446. public string ChangeBadPosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MakerCode = "", int IsSend = 0)
  1447. {
  1448. if (string.IsNullOrEmpty(OldSn))
  1449. {
  1450. return "请输入原机具SN";
  1451. }
  1452. if (string.IsNullOrEmpty(NewSn))
  1453. {
  1454. return "请输入新机具SN";
  1455. }
  1456. string[] OldSnList = OldSn.Split('\n');
  1457. string[] NewSnList = NewSn.Split('\n');
  1458. if (OldSnList.Length != NewSnList.Length)
  1459. {
  1460. return "原机具SN数量和新机具SN数量不一致";
  1461. }
  1462. WebCMSEntities db = new WebCMSEntities();
  1463. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1464. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1465. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1466. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1467. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1468. string ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1469. KqProducts oldPosBrand = new KqProducts();
  1470. KqProducts newPosBrand = new KqProducts();
  1471. MachineChange add = db.MachineChange.Add(new MachineChange()
  1472. {
  1473. CreateDate = DateTime.Now,
  1474. UpdateDate = DateTime.Now,
  1475. CreateMan = SysUserName + "-" + SysRealName,
  1476. ChangeNo = ChangeNo, //转换单号
  1477. UserId = 0, //创客
  1478. ChangeTime = DateTime.Now, //转换时间
  1479. BackStoreId = BackStore.Id, //退回仓库
  1480. BackStoreName = BackStore.StoreName, //退回仓库名称
  1481. Remark = "坏机换新", //订单备注
  1482. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1483. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1484. OutProductName = OutStore.ProductName, //出库产品名称
  1485. OutStoreId = OutStore.Id, //出库仓库
  1486. OutStoreName = OutStore.StoreName, //出库仓库名称
  1487. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1488. OutStoreAddress = OutStore.Address, //出库仓库地址
  1489. OutStoreManager = "", //出库仓库联系人
  1490. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1491. }).Entity;
  1492. db.SaveChanges();
  1493. int BackProductType = 0;
  1494. string BackProductName = "";
  1495. string ChangeDeviceName = "";
  1496. string ChangeSnExpand = "";
  1497. for (int i = 0; i < OldSnList.Length; i++)
  1498. {
  1499. string OldSnNum = OldSnList[i];
  1500. string NewSnNum = NewSnList[i];
  1501. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1502. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1503. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1504. if (oldpos == null)
  1505. {
  1506. return "原机具SN不正确";
  1507. }
  1508. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1509. if (newpos == null)
  1510. {
  1511. return "新机具SN不正确";
  1512. }
  1513. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1514. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1515. Users user = new Users();
  1516. if (!string.IsNullOrEmpty(MakerCode))
  1517. {
  1518. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1519. user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  1520. }
  1521. else
  1522. {
  1523. user = db.Users.FirstOrDefault(m => m.Id == oldpos.UserId) ?? new Users();
  1524. }
  1525. newpos.BuyUserId = oldpos.BuyUserId;
  1526. newpos.UserId = oldpos.UserId;
  1527. newpos.RecycEndDate = oldpos.RecycEndDate;
  1528. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1529. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1530. newpos.CreditTrade = oldpos.CreditTrade;
  1531. newpos.PosSnType = oldpos.PosSnType;
  1532. newpos.TransferTime = oldpos.TransferTime;
  1533. newpos.IsPurchase = oldpos.IsPurchase;
  1534. newpos.BindingState = oldpos.BindingState;
  1535. newpos.ActivationState = oldpos.ActivationState;
  1536. newpos.BindingTime = oldpos.BindingTime;
  1537. newpos.ActivationTime = oldpos.ActivationTime;
  1538. newpos.IsFirst = oldpos.IsFirst;
  1539. newpos.SeoKeyword = oldpos.SeoKeyword;
  1540. newpos.PrizeParams = oldpos.PrizeParams;
  1541. newpos.LeaderUserId = oldpos.LeaderUserId;
  1542. newpos.IsFirst = oldpos.IsFirst;
  1543. oldpos.Status = -1;
  1544. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1545. {
  1546. CreateDate = DateTime.Now,
  1547. CreateMan = SysUserName + "-" + SysRealName,
  1548. ChangeNo = ChangeNo, //订单号
  1549. ChangeId = add.Id, //订单Id
  1550. BackProductType = oldpos.BrandId, //退回产品类型
  1551. BackProductName = oldPosBrand.Name, //退回产品名称
  1552. UserId = 0, //创客
  1553. BackSnNo = oldpos.PosSn, //设备SN编号
  1554. OutProductType = newpos.BrandId, //出库产品类型
  1555. OutProductName = newPosBrand.Name, //出库产品名称
  1556. OutSnNo = newpos.PosSn, //出库设备SN编号
  1557. OutSnType = newpos.PosSnType, //出库SN机具类型
  1558. Remark = "坏机换新", //备注
  1559. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1560. });
  1561. db.SaveChanges();
  1562. BackProductType = oldpos.BrandId;
  1563. BackProductName = newPosBrand.Name;
  1564. ChangeDeviceName = oldpos.DeviceName;
  1565. ChangeSnExpand += oldpos.PosSn + "\n";
  1566. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1567. }
  1568. add.BackProductType = BackProductType; //退回产品类型
  1569. add.BackProductName = BackProductName; //退回产品名称
  1570. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1571. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1572. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1573. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1574. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1575. db.SaveChanges();
  1576. db.Dispose();
  1577. if (IsSend == 1)
  1578. {
  1579. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1580. {
  1581. UserId = pos.BuyUserId, //接收创客
  1582. MsgType = 2,
  1583. Title = "坏机换新成功通知", //标题
  1584. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为您换为" + newPosBrand.Name + "SN:" + NewSn + "。",
  1585. CreateDate = DateTime.Now,
  1586. }));
  1587. }
  1588. return "success";
  1589. }
  1590. #endregion
  1591. #region 机具解绑
  1592. public IActionResult Unbind(string right)
  1593. {
  1594. ViewBag.RightInfo = RightInfo;
  1595. ViewBag.right = right;
  1596. return View();
  1597. }
  1598. [HttpPost]
  1599. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  1600. {
  1601. if (string.IsNullOrEmpty(PosSn))
  1602. {
  1603. return "请输入机具SN";
  1604. }
  1605. if (string.IsNullOrEmpty(MakerCode))
  1606. {
  1607. return "请输入创客编号";
  1608. }
  1609. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1610. if (forSnNo == null)
  1611. {
  1612. return "机具SN不存在";
  1613. }
  1614. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  1615. if (pos == null)
  1616. {
  1617. return "机具SN不存在";
  1618. }
  1619. if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  1620. {
  1621. return "请输入商户编号";
  1622. }
  1623. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1624. if (forMakerCode == null)
  1625. {
  1626. return "创客不存在";
  1627. }
  1628. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1629. if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  1630. {
  1631. return "商户编号不存在";
  1632. }
  1633. if (pos.BuyUserId != forMakerCode.UserId)
  1634. {
  1635. return "机具SN和创客不匹配";
  1636. }
  1637. if (pos.ActivationState == 1)
  1638. {
  1639. return "机具已激活,不能解绑";
  1640. }
  1641. if (pos.BuyUserId == 0)
  1642. {
  1643. return "机具是仓库机,不支持解绑";
  1644. }
  1645. if (pos.BindingState == 0)
  1646. {
  1647. return "机具未绑定,不支持解绑";
  1648. }
  1649. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  1650. {
  1651. return "机具绑定已超过30天,不支持解绑";
  1652. }
  1653. if (forMerNo != null)
  1654. {
  1655. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  1656. if(merchant != null)
  1657. {
  1658. db.PosMerchantInfo.Remove(merchant);
  1659. }
  1660. db.MachineForMerNo.Remove(forMerNo);
  1661. db.SaveChanges();
  1662. }
  1663. db.MachineUnBind.Add(new MachineUnBind()
  1664. {
  1665. CreateDate = DateTime.Now,
  1666. SeoTitle = SysUserName + "-" + SysRealName,
  1667. MerchantId = pos.BindMerchantId,
  1668. AuditDate = DateTime.Now,
  1669. AuditDesc = "平台操作解绑",
  1670. AuditStatus = 1,
  1671. SnNo = pos.PosSn,
  1672. BrandId = pos.BrandId,
  1673. UserId = pos.BuyUserId,
  1674. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  1675. });
  1676. pos.BindMerchantId = 0;
  1677. pos.BindingState = 0;
  1678. pos.BindingTime = DateTime.Parse("1900-01-01");
  1679. pos.UserId = pos.BuyUserId;
  1680. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  1681. db.SaveChanges();
  1682. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  1683. if (IsSend == 1)
  1684. {
  1685. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1686. {
  1687. UserId = pos.BuyUserId, //接收创客
  1688. MsgType = 2,
  1689. Title = "解绑成功通知", //标题
  1690. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  1691. CreateDate = DateTime.Now,
  1692. }));
  1693. }
  1694. return "success";
  1695. }
  1696. #endregion
  1697. #region 通过券码修改盟主标记
  1698. public IActionResult ChangeSignQuan(string right)
  1699. {
  1700. ViewBag.RightInfo = RightInfo;
  1701. ViewBag.right = right;
  1702. return View();
  1703. }
  1704. [HttpPost]
  1705. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  1706. {
  1707. if (string.IsNullOrEmpty(Coupons))
  1708. {
  1709. return "请输入机具券码,多个券码用回车分隔";
  1710. }
  1711. if (string.IsNullOrEmpty(MakerCode))
  1712. {
  1713. return "请输入创客编号";
  1714. }
  1715. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1716. if (forMakerCode == null)
  1717. {
  1718. return "创客不存在";
  1719. }
  1720. string[] SnList = Coupons.Split('\n');
  1721. foreach (var item in SnList)
  1722. {
  1723. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  1724. if (coupos == null)
  1725. {
  1726. return "机具券不存在";
  1727. }
  1728. else
  1729. {
  1730. coupos.LeaderUserId = forMakerCode.UserId;
  1731. }
  1732. }
  1733. db.SaveChanges();
  1734. return "success";
  1735. }
  1736. #endregion
  1737. #region 通过机具SN修改盟主标记
  1738. public IActionResult ChangeSignSn(string right)
  1739. {
  1740. ViewBag.RightInfo = RightInfo;
  1741. ViewBag.right = right;
  1742. return View();
  1743. }
  1744. [HttpPost]
  1745. public string ChangeSignSnDo(string PosSn, string MakerCode)
  1746. {
  1747. if (string.IsNullOrEmpty(PosSn))
  1748. {
  1749. return "请输入机具SN,多个SN用回车分隔";
  1750. }
  1751. if (string.IsNullOrEmpty(MakerCode))
  1752. {
  1753. return "请输入创客编号";
  1754. }
  1755. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1756. if (forMakerCode == null)
  1757. {
  1758. return "创客不存在";
  1759. }
  1760. string[] SnList = PosSn.Split('\n');
  1761. foreach (var item in SnList)
  1762. {
  1763. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  1764. if (pos == null)
  1765. {
  1766. return "该机具不存在";
  1767. }
  1768. else
  1769. {
  1770. pos.LeaderUserId = forMakerCode.UserId;
  1771. }
  1772. }
  1773. db.SaveChanges();
  1774. return "success";
  1775. }
  1776. #endregion
  1777. #region 机具循环列表
  1778. /// <summary>
  1779. /// 根据条件查询机具循环列表
  1780. /// </summary>
  1781. /// <returns></returns>
  1782. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  1783. {
  1784. ViewBag.RightInfo = RightInfo;
  1785. ViewBag.right = right;
  1786. ViewBag.SwapSnExpand = SwapSnExpand;
  1787. ViewBag.SnNos = SnNos;
  1788. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  1789. var machineApplie = db.MachineApply.Where(m => m.Status > -1).ToList();
  1790. if (!string.IsNullOrEmpty(SwapSnExpand))
  1791. {
  1792. machineApplie = db.MachineApply.Where(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)).ToList();
  1793. foreach (var item in machineApplie)
  1794. {
  1795. var orders = db.Orders.FirstOrDefault(m => m.Sort == item.Id && m.Id == item.QueryCount);
  1796. Dictionary<string, object> data = new Dictionary<string, object>();
  1797. data["ApplyNo"] = item.ApplyNo.ToString();
  1798. data["OrderNo"] = orders.OrderNo.ToString();
  1799. data["MakerCode"] = item.ApplyNo.ToString();
  1800. data["RealName"] = item.ApplyNo.ToString();
  1801. data["ComeSn"] = item.ApplyNo.ToString();
  1802. data["SendSn"] = item.ApplyNo.ToString();
  1803. data["CreateDate"] = item.ApplyNo.ToString();
  1804. data["Status"] = item.ApplyNo.ToString();
  1805. dataList.Add(data);
  1806. }
  1807. }
  1808. if (!string.IsNullOrEmpty(SnNos))
  1809. {
  1810. machineApplie = db.MachineApply.Where(m => m.Status > -1 && m.SwapSnExpand.Contains(SnNos)).ToList();
  1811. foreach (var item in machineApplie)
  1812. {
  1813. var orders = db.Orders.FirstOrDefault(m => m.Sort == item.Id && m.Id == item.QueryCount);
  1814. Dictionary<string, object> data = new Dictionary<string, object>();
  1815. data["ApplyNo"] = item.ApplyNo.ToString();
  1816. data["OrderNo"] = orders.OrderNo.ToString();
  1817. data["MakerCode"] = item.ApplyNo.ToString();
  1818. data["RealName"] = item.ApplyNo.ToString();
  1819. data["ComeSn"] = item.ApplyNo.ToString();
  1820. data["SendSn"] = item.ApplyNo.ToString();
  1821. data["CreateDate"] = item.ApplyNo.ToString();
  1822. data["Status"] = item.ApplyNo.ToString();
  1823. dataList.Add(data);
  1824. }
  1825. }
  1826. return View(dataList);
  1827. }
  1828. #endregion
  1829. #region 根据条件查询机具循环列表
  1830. /// <summary>
  1831. /// 机具循环列表
  1832. /// </summary>
  1833. /// <returns></returns>
  1834. [HttpPost]
  1835. public JsonResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  1836. {
  1837. Dictionary<string, string> Fields = new Dictionary<string, string>();
  1838. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  1839. Fields.Add("SnNos", "1"); //发货机具SN
  1840. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  1841. var machineApplie = db.MachineApply.Where(m => m.Status > -1).ToList();
  1842. if (!string.IsNullOrEmpty(SwapSnExpand))
  1843. {
  1844. machineApplie = db.MachineApply.Where(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)).ToList();
  1845. foreach (var item in machineApplie)
  1846. {
  1847. var orders = db.Orders.FirstOrDefault(m => m.Sort == item.Id && m.Id == item.QueryCount);
  1848. Dictionary<string, object> data = new Dictionary<string, object>();
  1849. data["ApplyNo"] = item.ApplyNo.ToString();
  1850. data["OrderNo"] = orders.OrderNo.ToString();
  1851. data["MakerCode"] = item.ApplyNo.ToString();
  1852. data["RealName"] = item.ApplyNo.ToString();
  1853. data["ComeSn"] = item.ApplyNo.ToString();
  1854. data["SendSn"] = item.ApplyNo.ToString();
  1855. data["CreateDate"] = item.ApplyNo.ToString();
  1856. data["Status"] = item.ApplyNo.ToString();
  1857. dataList.Add(data);
  1858. }
  1859. }
  1860. else if (!string.IsNullOrEmpty(SnNos))
  1861. {
  1862. machineApplie = db.MachineApply.Where(m => m.Status > -1 && m.SwapSnExpand.Contains(SnNos)).ToList();
  1863. foreach (var item in machineApplie)
  1864. {
  1865. var orders = db.Orders.FirstOrDefault(m => m.Sort == item.Id && m.Id == item.QueryCount);
  1866. Dictionary<string, object> data = new Dictionary<string, object>();
  1867. data["ApplyNo"] = item.ApplyNo.ToString();
  1868. data["OrderNo"] = orders.OrderNo.ToString();
  1869. data["MakerCode"] = item.ApplyNo.ToString();
  1870. data["RealName"] = item.ApplyNo.ToString();
  1871. data["ComeSn"] = item.ApplyNo.ToString();
  1872. data["SendSn"] = item.ApplyNo.ToString();
  1873. data["CreateDate"] = item.ApplyNo.ToString();
  1874. data["Status"] = item.ApplyNo.ToString();
  1875. dataList.Add(data);
  1876. }
  1877. }
  1878. else
  1879. {
  1880. machineApplie = db.MachineApply.Where(m => m.Status > -1).ToList();
  1881. foreach (var item in machineApplie)
  1882. {
  1883. var orders = db.Orders.FirstOrDefault(m => m.Sort == item.Id && m.Id == item.QueryCount);
  1884. Dictionary<string, object> data = new Dictionary<string, object>();
  1885. data["ApplyNo"] = item.ApplyNo.ToString();
  1886. data["OrderNo"] = orders.OrderNo.ToString();
  1887. data["MakerCode"] = item.ApplyNo.ToString();
  1888. data["RealName"] = item.ApplyNo.ToString();
  1889. data["ComeSn"] = item.ApplyNo.ToString();
  1890. data["SendSn"] = item.ApplyNo.ToString();
  1891. data["CreateDate"] = item.ApplyNo.ToString();
  1892. data["Status"] = item.ApplyNo.ToString();
  1893. dataList.Add(data);
  1894. }
  1895. }
  1896. return Json(dataList);
  1897. }
  1898. #endregion
  1899. #region 查询创客直推奖
  1900. public IActionResult Prize100(string right)
  1901. {
  1902. ViewBag.RightInfo = RightInfo;
  1903. ViewBag.right = right;
  1904. return View();
  1905. }
  1906. [HttpPost]
  1907. public Dictionary<string, string> Prize100Do(string MakerCode)
  1908. {
  1909. Dictionary<string, string> dic = new Dictionary<string, string>();
  1910. string result = "";
  1911. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1912. if (forMakerCode == null)
  1913. {
  1914. result += "创客编号不存在\n";
  1915. dic.Add("code", "1");
  1916. dic.Add("result", result);
  1917. return dic;
  1918. }
  1919. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  1920. if (OrderCount == 0)
  1921. {
  1922. result += "该创客未下单\n";
  1923. dic.Add("code", "1");
  1924. dic.Add("result", result);
  1925. return dic;
  1926. }
  1927. if (OrderCount > 1)
  1928. {
  1929. result += "该创客已不是首笔下单\n";
  1930. dic.Add("code", "1");
  1931. dic.Add("result", result);
  1932. return dic;
  1933. }
  1934. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  1935. if (order.PayStatus < 1)
  1936. {
  1937. result += "未付款\n";
  1938. dic.Add("code", "1");
  1939. dic.Add("result", result);
  1940. return dic;
  1941. }
  1942. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  1943. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1944. result += "订单号:" + order.OrderNo + "\n";
  1945. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  1946. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1947. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  1948. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  1949. if (machineCount + ActiveCount >= 3)
  1950. {
  1951. string IsGet = "未发放";
  1952. int ToUserId = 0;
  1953. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  1954. if (item == null)
  1955. {
  1956. DateTime start = order.PayDate.Value.AddMinutes(-2);
  1957. DateTime end = order.PayDate.Value.AddMinutes(2);
  1958. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  1959. }
  1960. if (item != null)
  1961. {
  1962. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1963. ToUserId = item.UserId;
  1964. dic.Add("code", "1");
  1965. }
  1966. else
  1967. {
  1968. dic.Add("id", order.Id.ToString());
  1969. dic.Add("code", "0");
  1970. }
  1971. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  1972. result += "是否发放:" + IsGet + "\n";
  1973. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  1974. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  1975. }
  1976. else
  1977. {
  1978. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  1979. dic.Add("code", "1");
  1980. }
  1981. dic.Add("result", result);
  1982. return dic;
  1983. }
  1984. public string AddPrize100(int Id)
  1985. {
  1986. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  1987. if (order != null)
  1988. {
  1989. //机具券逻辑
  1990. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  1991. if (pro != null)
  1992. {
  1993. //推荐下单奖励
  1994. if (pro.ProductId == 10 || pro.ProductId == 11)
  1995. {
  1996. int OrderId = order.Id;
  1997. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  1998. if (!checkPrize)
  1999. {
  2000. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2001. if (user != null)
  2002. {
  2003. bool directPrize = false; //直推奖标记
  2004. int ParentUserId = user.ParentUserId;
  2005. // List<int> proids = new List<int>();
  2006. // proids.Add(10);
  2007. // proids.Add(11);
  2008. while (ParentUserId > 0)
  2009. {
  2010. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2011. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  2012. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2013. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2014. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2015. {
  2016. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2017. directPrize = true;
  2018. db.SaveChanges();
  2019. return "发放成功";
  2020. }
  2021. ParentUserId = puser.ParentUserId;
  2022. }
  2023. }
  2024. }
  2025. return "已发放,请勿重复发放";
  2026. }
  2027. }
  2028. }
  2029. return "操作失败";
  2030. }
  2031. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2032. {
  2033. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2034. if (account == null)
  2035. {
  2036. account = db.UserAccount.Add(new UserAccount()
  2037. {
  2038. Id = UserId,
  2039. UserId = UserId,
  2040. }).Entity;
  2041. db.SaveChanges();
  2042. }
  2043. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2044. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2045. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2046. account.BalanceAmount += 100 * Count;
  2047. account.TotalAmount += 100 * Count;
  2048. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2049. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2050. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2051. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2052. {
  2053. CreateDate = DateTime.Now,
  2054. UpdateDate = DateTime.Now,
  2055. UserId = UserId, //创客
  2056. ChangeType = 112, //变动类型
  2057. ChangeAmount = 100 * Count, //变更金额
  2058. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2059. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2060. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2061. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2062. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2063. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2064. QueryCount = OrderId,
  2065. }).Entity;
  2066. db.SaveChanges();
  2067. }
  2068. #endregion
  2069. #region 查询机具开机奖
  2070. public IActionResult OpenPrize(string right)
  2071. {
  2072. ViewBag.RightInfo = RightInfo;
  2073. ViewBag.right = right;
  2074. return View();
  2075. }
  2076. [HttpPost]
  2077. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2078. {
  2079. Dictionary<string, string> dic = new Dictionary<string, string>();
  2080. string result = "";
  2081. PosMachinesTwo pos = db.PosMachinesTwo .FirstOrDefault(m => m.PosSn == PosSn);
  2082. if (pos == null)
  2083. {
  2084. result += "机具SN号不存在\n";
  2085. dic.Add("code", "1");
  2086. dic.Add("result", result);
  2087. return dic;
  2088. }
  2089. if(pos.BindingState == 0)
  2090. {
  2091. result += "机具未绑定\n";
  2092. dic.Add("code", "1");
  2093. dic.Add("result", result);
  2094. return dic;
  2095. }
  2096. if(pos.ActivationState == 0)
  2097. {
  2098. result += "机具未激活\n";
  2099. dic.Add("code", "1");
  2100. dic.Add("result", result);
  2101. return dic;
  2102. }
  2103. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2104. if (merchant == null)
  2105. {
  2106. result += "商户不存在\n";
  2107. dic.Add("code", "1");
  2108. dic.Add("result", result);
  2109. return dic;
  2110. }
  2111. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2112. result += "机具号:" + PosSn + "\n";
  2113. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2114. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2115. string OpenUser10 = "未领取";
  2116. string OpenUser20 = "未领取";
  2117. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2118. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2119. if (openreward.Id > 0)
  2120. {
  2121. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2122. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2123. }
  2124. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2125. if (openreward.Id > 0)
  2126. {
  2127. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2128. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2129. }
  2130. result += "开机奖20:" + OpenUser20 + "\n";
  2131. result += "开机奖10:" + OpenUser10 + "\n";
  2132. dic.Add("id", pos.Id.ToString());
  2133. dic.Add("code", "0");
  2134. dic.Add("result", result);
  2135. return dic;
  2136. }
  2137. public string AddOpenPrize(int Id)
  2138. {
  2139. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2140. if (pos == null)
  2141. {
  2142. return "机具未激活";
  2143. }
  2144. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2145. {
  2146. return "绑定已超过30天";
  2147. }
  2148. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2149. if (ActPrize == 0)
  2150. {
  2151. return "机具无押金";
  2152. }
  2153. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2154. if (merchant == null)
  2155. {
  2156. return "商户不存在";
  2157. }
  2158. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2159. if(check)
  2160. {
  2161. return "开机奖励已发放,请勿重复操作";
  2162. }
  2163. // 从机具所属人上级开始分开机奖励
  2164. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2165. if (user != null)
  2166. {
  2167. if (!string.IsNullOrEmpty(user.ParentNav))
  2168. {
  2169. decimal Prize = 20;
  2170. List<string> PrizeFlag = new List<string>();
  2171. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2172. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2173. {
  2174. int UserId = int.Parse(ParentNavs[i]);
  2175. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2176. if (puser != null && Prize > 0)
  2177. {
  2178. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2179. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2180. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2181. if (machineCount + ActiveCount + couponCount >= 3)
  2182. {
  2183. int pTopUserId = 0;
  2184. if (!string.IsNullOrEmpty(puser.ParentNav))
  2185. {
  2186. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2187. }
  2188. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2189. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2190. {
  2191. CreateDate = DateTime.Now,
  2192. UpdateDate = DateTime.Now,
  2193. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2194. TradeDate = pos.ActivationTime, //达标日期
  2195. UserId = puser.Id, //创客
  2196. BrandId = pos.BrandId, //品牌
  2197. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2198. MerchantId = pos.BindMerchantId, //商户
  2199. DirectUserId = merchant.UserId, //商户直属人
  2200. SnNo = pos.PosSn, //SN号
  2201. MerNo = merchant.KqMerNo, //渠道商户号
  2202. SnType = pos.PosSnType, //机具类型
  2203. StandardDate = pos.ActivationTime, //商户的激活日期
  2204. SnStoreId = pos.StoreId, //SN仓库
  2205. MerBuddyType = puser.MerchantType, //商户创客类型
  2206. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2207. RewardTips = "开机奖励", //奖励描述
  2208. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2209. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2210. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2211. RewardDesc = "开机奖励", //奖励描述
  2212. TopUserId = pTopUserId, //顶级创客
  2213. SeoTitle = machineUser.RealName,
  2214. }).Entity;
  2215. db.OpenReward.Add(new OpenReward()
  2216. {
  2217. CreateDate = DateTime.Now,
  2218. UpdateDate = DateTime.Now,
  2219. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2220. TradeDate = DateTime.Now, //达标日期
  2221. UserId = puser.Id, //创客
  2222. BrandId = pos.BrandId, //品牌
  2223. RewardType = 2, //奖励类型
  2224. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2225. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2226. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2227. RewardDesc = "开机奖励", //奖励描述
  2228. TopUserId = pTopUserId, //顶级创客
  2229. });
  2230. string IdBrand = puser.Id + "_" + pos.BrandId;
  2231. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2232. if (userData == null)
  2233. {
  2234. userData = db.UserMachineData.Add(new UserMachineData()
  2235. {
  2236. IdBrand = IdBrand,
  2237. }).Entity;
  2238. db.SaveChanges();
  2239. }
  2240. userData.OpenProfit += Prize;
  2241. db.SaveChanges();
  2242. RedisDbconn.Instance.Set("UserMachineData:" + IdBrand, userData);
  2243. //账户入库
  2244. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2245. if (account == null)
  2246. {
  2247. account = db.UserAccount.Add(new UserAccount()
  2248. {
  2249. Id = puser.Id,
  2250. UserId = puser.Id,
  2251. }).Entity;
  2252. db.SaveChanges();
  2253. }
  2254. //收支明细入库
  2255. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2256. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2257. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2258. account.BalanceAmount += Prize;
  2259. account.TotalAmount += Prize;
  2260. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2261. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2262. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2263. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2264. {
  2265. CreateDate = DateTime.Now,
  2266. UpdateDate = DateTime.Now,
  2267. UserId = puser.Id, //创客
  2268. ChangeType = 50, //变动类型
  2269. ProductType = pos.BrandId, //产品类型
  2270. ChangeAmount = Prize, //变更金额
  2271. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2272. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2273. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2274. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2275. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2276. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2277. }).Entity;
  2278. db.SaveChanges();
  2279. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  2280. string dateString = DateTime.Now.ToString("yyyyMMdd");
  2281. string monthString = DateTime.Now.ToString("yyyyMM");
  2282. // 开机奖励列表
  2283. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  2284. if (!dates.Contains(dateString))
  2285. {
  2286. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  2287. }
  2288. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  2289. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  2290. if (!months.Contains(monthString))
  2291. {
  2292. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  2293. }
  2294. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  2295. // 开机奖励详情
  2296. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  2297. //收支明细
  2298. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  2299. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  2300. Prize -= 10;
  2301. PrizeFlag.Add(Prize.ToString("f0"));
  2302. }
  2303. }
  2304. }
  2305. string result = "";
  2306. if(!PrizeFlag.Contains("20"))
  2307. {
  2308. result += "20元奖励未发,请检查上级是否满足条件\n";
  2309. }
  2310. if(!PrizeFlag.Contains("10"))
  2311. {
  2312. result += "10元奖励未发,请检查上级是否满足条件\n";
  2313. }
  2314. if(string.IsNullOrEmpty(result))
  2315. {
  2316. return "发放成功";
  2317. }
  2318. return result;
  2319. }
  2320. }
  2321. db.Dispose();
  2322. return "操作失败";
  2323. }
  2324. #endregion
  2325. #region 查询机具流量费分佣
  2326. public IActionResult FluxPrize(string right)
  2327. {
  2328. ViewBag.RightInfo = RightInfo;
  2329. ViewBag.right = right;
  2330. return View();
  2331. }
  2332. [HttpPost]
  2333. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  2334. {
  2335. Dictionary<string, string> dic = new Dictionary<string, string>();
  2336. string result = "";
  2337. PosMachinesTwo pos = db.PosMachinesTwo .FirstOrDefault(m => m.PosSn == PosSn);
  2338. if (pos == null)
  2339. {
  2340. result += "机具SN号不存在\n";
  2341. dic.Add("code", "1");
  2342. dic.Add("result", result);
  2343. return dic;
  2344. }
  2345. if(pos.BindingState == 0)
  2346. {
  2347. result += "机具未绑定\n";
  2348. dic.Add("code", "1");
  2349. dic.Add("result", result);
  2350. return dic;
  2351. }
  2352. if(pos.ActivationState == 0)
  2353. {
  2354. result += "机具未激活\n";
  2355. dic.Add("code", "1");
  2356. dic.Add("result", result);
  2357. return dic;
  2358. }
  2359. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2360. if (merchant == null)
  2361. {
  2362. result += "商户不存在\n";
  2363. dic.Add("code", "1");
  2364. dic.Add("result", result);
  2365. return dic;
  2366. }
  2367. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2368. result += "机具号:" + PosSn + "\n";
  2369. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2370. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2371. string FluxGet6 = "未领取";
  2372. string FluxUser6 = "";
  2373. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  2374. if (flux.Id > 0)
  2375. {
  2376. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  2377. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2378. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2379. }
  2380. result += "流量费:" + FluxGet6 + "\n";
  2381. result += "流量费发放对象:" + FluxUser6 + "\n";
  2382. dic.Add("id", pos.Id.ToString());
  2383. dic.Add("code", "0");
  2384. dic.Add("result", result);
  2385. return dic;
  2386. }
  2387. public string AddFluxPrize(int Id)
  2388. {
  2389. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2390. if (pos == null)
  2391. {
  2392. return "机具未激活";
  2393. }
  2394. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2395. {
  2396. return "绑定已超过30天";
  2397. }
  2398. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2399. if (ActPrize == 0)
  2400. {
  2401. return "机具无押金";
  2402. }
  2403. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2404. if (merchant == null)
  2405. {
  2406. return "商户不存在";
  2407. }
  2408. if(pos.BrandId == 6)
  2409. {
  2410. return "立刷不支持流量费分佣";
  2411. }
  2412. if(decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  2413. {
  2414. return "无押金机,不支持流量费分佣";
  2415. }
  2416. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  2417. if(check)
  2418. {
  2419. return "开机奖励已发放,请勿重复操作";
  2420. }
  2421. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  2422. if(trade != null)
  2423. {
  2424. try
  2425. {
  2426. string OrderNo = trade.TradeSerialNo; //单号
  2427. DateTime TradeDate = trade.CreateDate.Value;
  2428. string TradeMonth = TradeDate.ToString("yyyyMM");
  2429. decimal FeeAmount = trade.FeeAmount; //流量费
  2430. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  2431. {
  2432. FeeAmount = FeeAmount / 100;
  2433. }
  2434. string TradeSnNo = trade.TradeSnNo; //机具SN
  2435. decimal FluxProfit = 0;
  2436. if (trade.ProductType == "1" && FeeAmount == 60)
  2437. {
  2438. FluxProfit = 24;
  2439. }
  2440. else if (trade.ProductType == "7" && FeeAmount == 46)
  2441. {
  2442. FluxProfit = 10;
  2443. }
  2444. else if (trade.ProductType != "1" && FeeAmount == 48)
  2445. {
  2446. FluxProfit = 12;
  2447. }
  2448. if (FluxProfit > 0)
  2449. {
  2450. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2451. int GetUserId = user.Id;
  2452. int TopUserId = 0;
  2453. string ParentNav = user.ParentNav;
  2454. if (!string.IsNullOrEmpty(ParentNav))
  2455. {
  2456. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2457. if (ParentNavList.Length > 1)
  2458. {
  2459. TopUserId = int.Parse(ParentNavList[1]);
  2460. }
  2461. else if (ParentNavList.Length == 1)
  2462. {
  2463. TopUserId = int.Parse(ParentNavList[0]);
  2464. }
  2465. }
  2466. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  2467. if (fluxProfit == null)
  2468. {
  2469. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  2470. {
  2471. CreateDate = DateTime.Now,
  2472. UpdateDate = DateTime.Now,
  2473. UserId = GetUserId, //创客
  2474. BrandId = pos.BrandId,
  2475. TopUserId = TopUserId, //顶级创客
  2476. TradeMonth = TradeMonth, //交易月
  2477. MerUserType = user.MerchantType, //商户创客类型
  2478. Remark = "流量卡分佣", //备注
  2479. }).Entity;
  2480. db.SaveChanges();
  2481. }
  2482. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  2483. db.FluxProfitDetail.Add(new FluxProfitDetail()
  2484. {
  2485. CreateDate = DateTime.Now,
  2486. UpdateDate = DateTime.Now,
  2487. RecordNo = OrderNo, //单号
  2488. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  2489. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  2490. TradeMonth = TradeMonth, //交易月
  2491. UserId = GetUserId, //创客
  2492. MerchantId = pos.BindMerchantId, //商户
  2493. MerchantUserId = pos.UserId, //商户直属人
  2494. MerNo = merchant.KqMerNo, //渠道商户编号
  2495. SnNo = pos.PosSn, //渠道SN号
  2496. FluxOrderNo = OrderNo, //流量扣费单号
  2497. TradeOrderNo = OrderNo, //交易流水号
  2498. TradeAmt = trade.TradeAmount, //商户交易额
  2499. FluxFeeAmt = FeeAmount, //流量费
  2500. FluxProfitAmt = FluxProfit, //流量分润总金额
  2501. PosType = pos.PosSnType.ToString(), //POS类型
  2502. Remark = "流量卡分佣", //备注
  2503. BrandId = pos.BrandId, //品牌
  2504. TopUserId = TopUserId, //顶级创客
  2505. MerUserType = user.MerchantType, //商户创客类型
  2506. });
  2507. string IdBrand = user.Id + "_" + pos.BrandId;
  2508. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2509. if (userData == null)
  2510. {
  2511. userData = db.UserMachineData.Add(new UserMachineData()
  2512. {
  2513. IdBrand = IdBrand,
  2514. }).Entity;
  2515. db.SaveChanges();
  2516. }
  2517. userData.FluxProfit += FluxProfit;
  2518. db.SaveChanges();
  2519. RedisDbconn.Instance.Clear("UserMachineData:" + IdBrand);
  2520. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  2521. if (account == null)
  2522. {
  2523. account = db.UserAccount.Add(new UserAccount()
  2524. {
  2525. Id = GetUserId,
  2526. UserId = GetUserId,
  2527. }).Entity;
  2528. db.SaveChanges();
  2529. }
  2530. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2531. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2532. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2533. account.BalanceAmount += FluxProfit;
  2534. account.TotalAmount += FluxProfit;
  2535. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2536. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2537. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2538. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2539. {
  2540. CreateDate = DateTime.Now,
  2541. UpdateDate = DateTime.Now,
  2542. UserId = GetUserId, //创客
  2543. ChangeType = 60, //变动类型
  2544. ProductType = pos.BrandId, //产品类型
  2545. ChangeAmount = FluxProfit, //变更金额
  2546. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2547. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2548. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2549. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2550. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2551. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2552. }).Entity;
  2553. db.SaveChanges();
  2554. spdb.Dispose();
  2555. db.Dispose();
  2556. return "发放成功";
  2557. }
  2558. }
  2559. catch (Exception ex)
  2560. {
  2561. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  2562. }
  2563. }
  2564. spdb.Dispose();
  2565. db.Dispose();
  2566. return "操作失败";
  2567. }
  2568. #endregion
  2569. #region 设置立刷费率
  2570. public IActionResult LisFee(string right)
  2571. {
  2572. ViewBag.RightInfo = RightInfo;
  2573. ViewBag.right = right;
  2574. return View();
  2575. }
  2576. [HttpPost]
  2577. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  2578. {
  2579. if (string.IsNullOrEmpty(PosSns))
  2580. {
  2581. return "请输入机具号";
  2582. }
  2583. string result = SysUserName + "设置\n";
  2584. string[] PosSnList = PosSns.Split('\n');
  2585. int total = PosSnList.Length;
  2586. int index = 0;
  2587. foreach (string SubPosSn in PosSnList)
  2588. {
  2589. index += 1;
  2590. string PosSn = SubPosSn.Replace("\r", "");
  2591. result += PosSn + ":" + Fee + "\n";
  2592. if (Kind == "M5")
  2593. {
  2594. result += SetLiSFee(PosSn, Fee) + "\n";
  2595. }
  2596. else if (Kind == "N1")
  2597. {
  2598. result += SetLiSDeposit(PosSn, (int)Fee);
  2599. }
  2600. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  2601. }
  2602. result += "\n\n";
  2603. function.WriteLog(result, "设置立刷费率");
  2604. return result;
  2605. }
  2606. public string LisFeeProcess()
  2607. {
  2608. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  2609. }
  2610. #region 立刷
  2611. string LiSAgentId = "50814834";
  2612. string LiSPrivateKey = "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDTdeLXqQmfVJM/ATVnq+TdhgpKKPp3hXcuY2s9qrN1Uws7I7jqnq/gfoBHBWBu/PnQp/z65okBoz4PEpWzJYZDF4csgh3E45He46ialNzUlOPWv6yLzgQPHuneq2pXOb7dbN4kZx+g3nEbBjH+/P9xp+lU3HCwjNxIFSr3EyBAQf2HgvNqh70u9T13fGVx3Jtd2xbIKYhvGNPH9ZCGiZNiCy+m+F+TKywgKK/xify1KQgR6otVUOVIGYvPYlXAgLJM2/V54166KX1UUFMsKRj4Kt2j4GqoHzDfRk9ibYJ/8iSDGX4+WH5+8mq/raqA77VcAD+bMrt3Bm59XmaWtjZwDY1zh5sP5jEaxu4lde2xZD80kQ6p1ZydpqnjmWm6NKXSz8j85gRkTQqNALKNANnJb6f1Yy30WirnrhMkqU2dqBzzXxtk3k/2zv9BENjYs1igrRYpwX3QRx87aTOrIk/PO6cxMaWl249LPigah0OqVyIg5yOvtnUCdU12OqaVELIw5GnZ7rTRn3tAsJ+u1om+3XktbN3GUEpw5RWAT3UAsAU7Vxt9xPCss+JXF+ogXYgo9QpEjanXOfLo5KPv2CkBuzy87d85OId71gXpYcbp0zbKz5eXKZanVP9pwn43jqiPkqtam8N1TLCCmZ4t2cd+gpW2CX/+W7bmc25HJtRPuwIDAQABAoICAE7B9GfwTGYsYN8xewuOySH8n255jrffXMFJRBLmtgo3kNJI/sFbsxPA6dQJ253a2MxvFNj57gNPInkIqfrcOgJZC/52w9GmFJlYX16bnRgMEEPWhdRYOcjL8bz+SRANsNnVh3M1eWE4GBZBm3NmFVnmeRAjPlFzVUP/pk35sKReL6g+DJ0by0lnC6qqCTp8ON2fEQAh/++o5o/uFRMWwG7ezbO5hBdTGA8uOEGU7CspChlqKtTu2UaeRSVLcbbN+BqKPgZUud5KP6Scei3TbLpZdM1pczAE1fYCwORe9yDiNdkiMJPV798mOL4FV6DIJtsKOKZ8Ibg2DAbjlwABA4rQsgBUAA4Nj+skqLE7gGnJViHzKw87zve+v3CV9NEldHV7g2a78yKye489vlmmxcLj+Ln5O/Y3OQnDwsO8mVua5Ddyp26N88oB1wW62VLUn68ePclDd3Bdub/ayiBqFOqA0cTlqI5Dvz0rqrK9dkq4Ij295EK3OfYHCjuoHN+mJP0K0+o+5ItPXu7KWRz/Bf+KPneAAgvTRaDMww+HpfbcM6sxfiZqVE0yGux39i6wjEOCcIbfO8O7wgCEk4GE/98Z6/+lp1NEaQLHcu24FlUeCgThTVaJsmcY9aHB+jFn11yBiJ6+N+RYONWto0xLDyt71qM5KXEEngYambCK8D0JAoIBAQD5tYwpTNfcessxPcYAXkdJWNAP3/8kwz97rFi9gZYsxhZJ/JCU8TUCYlpJDf91mCe0i7uayGb3FbtzoWEwHxKL4DdlL47ZaaGA2dIVNMkxksXDehEE6/bVRAcFH1fT9mZr7uB2uX1YjesFRKEEd3UXpfKSPwtm3QUQz7P7WxzL0CWpfC11vAK2biCG72inE3MelCw/z1Y7M7oo2fyflObMPKkqyuy5NGtZ5t9xpMvLaZrOzJkYbwPaIqxIvISg9rxilZhjMhIFHOW8xM0lVHMEkk2NrwwsMihxFmDaUohZf0GiyYzNEEVBmVEhAZSOV5d1JlWYQStyvDas195/IHjNAoIBAQDYyakyJbbEhgcLSrmXKtJY584y6SYFE1mOZKKkON2EfDpAlwFmJYV26dWiPb77mUsf1HUU/aIT6sfZsrh6axvs0rqqp5ltIr6AzXnJce590EMJnASWLTAdhYXK6e5Y1W8AhylP4LzZk/dy4LOaF09pMi3ugogFFJAWV8j/cv2niUsCXg/I6cQz/Co6cwVhBzOnAMIjdvZbJ2ONJ1Jy/4yS17DBFRyHxMbGVPckXEVodjZ73TAfUQIM83Z8YILxyym2d2f7lvuCyT+ZjmpEJQztdxPO8qT9MaROs4c/qVjJZndoTZ3z4i2eke9Bf3Qcd6Bfy6jPq/r73hl0w0kBo4qnAoIBAQCC8fgZJEnCPcZWAR3WzZm2VdNtr7n9TkH5GazDW7QjsJC5pa8v27k/kdHko2mGAg84N1pe1Z5hDc1p2oO7l1/DaAXEkwbm7eSaTB9FrZOf4mbAlj9chFzBA1ZnEkOdTIXzLaYZvDWF/Y30CkQhsn79srEcjeDtxRNF+JVaRzI3kuRdF1hDeB84CVIXUG5hxupEa9E0eQawLvT9PSqjiJLrIRhY72bpzBpLX61my9NuzOc4cMQLsxOjDTGpRuqJ+jlZvTbXNceLVNcIgW9OlxVlnU778IKCnp7khqatdkA4JmqF8gla86BNwRdxJoH/juFGtp6GJA6jsR0+0EjGA4I1AoIBAGl2ITNeGX2dXgvmPEcH8/CARFWMCozpjuWwm1acu1baQFRvoaSZmEXzF5SnySMIvf0sFBE0GgbqbnK/ePNE6/7XvSuMAR2Qi3CJhTe0jzrxd8tS9QBB12hlLmM6TlM08Z0mI7jSMcz/KJ/gJD9QG7enS6T+J0GhcT8NUaDDxhYcujram384CdToVXq9vd4n7L7PpaIvG0XY8ZsXiAqduzssZrZnmMuLtM+DQf+US8e3ymWTgveZJxA52GhFYy5RkWdMy28fUheb467GE3g3NgTHqwFAFXd/ENmgiKk1rxW7HVfGepLMczjy8ZvBbzDyGTjBEMyGc8DXmTauUfPUJX0CggEBAKEWyNHhEBcEfW6ppPYsaKTlIquA2Chr15KsZcSFOMIcsF/6D7TDZg2NPDYFmlALF/cdqDjRIAP/v5IMRiu3UtHyfDbRyEHx0prvucFMY0HyX9VOJnticwTb39awHi/uFJLs7txERw89eJFcLaxRRRRSpPq3PCalGFpC2i8HXsPnv3gyt+bfE92h6E2YTyP41NYmcuuXkyWM83s11YSC9ZgeilbJuvdajePHrtIAxy8cny+yTBcbnJnWw1yHtzWCA5FAw5OWSaeotbWaFEAHaOW1VG9e1I54pgmVTc5n+WixsgH1fpiz04ojlWRWRyP7hqS+GbAyGgg00KyErRrPcwc=";
  2613. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  2614. public string LiSSign(string data)
  2615. {
  2616. var rsa = RSA.Create();
  2617. var key = Convert.FromBase64String(LiSPrivateKey);
  2618. var content = Encoding.UTF8.GetBytes(data);
  2619. rsa.ImportPkcs8PrivateKey(key, out _);
  2620. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  2621. return Convert.ToBase64String(result);
  2622. }
  2623. // 设置费率
  2624. public string SetLiSFee(string sn, decimal serviceFee)
  2625. {
  2626. Dictionary<string, object> dic = new Dictionary<string, object>();
  2627. dic.Add("agentId", LiSAgentId);
  2628. dic.Add("deviceSn", sn);
  2629. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2630. Dictionary<string, object> item = new Dictionary<string, object>();
  2631. item.Add("feeCalcType", "M5");
  2632. item.Add("fixed", "0");
  2633. item.Add("rate", serviceFee);
  2634. feeList.Add(item);
  2635. dic.Add("feeList", feeList);
  2636. dic.Add("signMethod", "02");
  2637. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  2638. string signstr = LiSSign(content);
  2639. dic.Add("signData", signstr);
  2640. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2641. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2642. return result;
  2643. }
  2644. // 设置押金
  2645. public string SetLiSDeposit(string sn, int serviceFee)
  2646. {
  2647. serviceFee = serviceFee * 100;
  2648. Dictionary<string, object> dic = new Dictionary<string, object>();
  2649. dic.Add("agentId", LiSAgentId);
  2650. dic.Add("deviceSn", sn);
  2651. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2652. Dictionary<string, object> item = new Dictionary<string, object>();
  2653. item.Add("feeCalcType", "N1");
  2654. item.Add("fixed", "1");
  2655. item.Add("rate", serviceFee);
  2656. feeList.Add(item);
  2657. dic.Add("feeList", feeList);
  2658. dic.Add("signMethod", "02");
  2659. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  2660. string signstr = LiSSign(content);
  2661. dic.Add("signData", signstr);
  2662. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2663. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2664. return result;
  2665. }
  2666. #endregion
  2667. #endregion
  2668. #region 查询商户型创客设置信息
  2669. public IActionResult SeeMerchantType(string right)
  2670. {
  2671. ViewBag.RightInfo = RightInfo;
  2672. ViewBag.right = right;
  2673. return View();
  2674. }
  2675. [HttpPost]
  2676. public string SeeMerchantTypeDo(string PosSn)
  2677. {
  2678. if (string.IsNullOrEmpty(PosSn))
  2679. {
  2680. return "请输入机具SN或者创客编号";
  2681. }
  2682. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  2683. if (PosSn.StartsWith("K"))
  2684. {
  2685. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  2686. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  2687. if (check)
  2688. {
  2689. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  2690. }
  2691. }
  2692. else
  2693. {
  2694. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  2695. if (check)
  2696. {
  2697. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  2698. }
  2699. }
  2700. if (pos.Id == 0)
  2701. {
  2702. return "查无信息";
  2703. }
  2704. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  2705. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  2706. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2707. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2708. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2709. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  2710. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  2711. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  2712. string result = "";
  2713. result += "机具SN:" + pos.PosSn + "\n";
  2714. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  2715. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  2716. result += "商户编号:" + pos.MerNo + "\n";
  2717. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  2718. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  2719. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  2720. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  2721. result += "是否循环:" + RecycFlag + "\n";
  2722. return result;
  2723. }
  2724. #endregion
  2725. }
  2726. }