SysToolsController.cs 226 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751
  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.Security.Cryptography.X509Certificates;
  21. using System.Text;
  22. using System.Net;
  23. using System.Net.Security;
  24. using System.IO;
  25. namespace MySystem.Areas.Admin.Controllers
  26. {
  27. [Area("Admin")]
  28. [Route("Admin/[controller]/[action]")]
  29. public class SysToolsController : BaseController
  30. {
  31. public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  32. {
  33. }
  34. #region 关联上下级
  35. public IActionResult RelationForUser(string right)
  36. {
  37. ViewBag.RightInfo = RightInfo;
  38. ViewBag.right = right;
  39. return View();
  40. }
  41. [HttpPost]
  42. public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
  43. {
  44. if (string.IsNullOrEmpty(MakerCode))
  45. {
  46. return "请输入创客编号";
  47. }
  48. if (string.IsNullOrEmpty(ParentMakerCode))
  49. {
  50. return "请输入上级创客编号";
  51. }
  52. MakerCode = MakerCode.ToUpper();
  53. ParentMakerCode = ParentMakerCode.ToUpper();
  54. Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  55. if (puser != null)
  56. {
  57. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  58. if (user != null)
  59. {
  60. user.ParentUserId = puser.Id;
  61. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  62. if (IsTeam == 1)
  63. {
  64. RelationForUserSub(db, user.Id, user);
  65. }
  66. db.SaveChanges();
  67. function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
  68. return "success";
  69. }
  70. return "创客编号不存在";
  71. }
  72. return "上级创客编号不存在";
  73. }
  74. private void RelationForUserSub(WebCMSEntities dbnew, int ParentUserId, Users puser)
  75. {
  76. var subusers = dbnew.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
  77. foreach (var subuser in subusers)
  78. {
  79. Users user = dbnew.Users.FirstOrDefault(m => m.Id == subuser.Id);
  80. if (user != null)
  81. {
  82. user.ParentUserId = puser.Id;
  83. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  84. RelationForUserSub(dbnew, user.Id, user);
  85. }
  86. }
  87. }
  88. #endregion
  89. #region 机具补录
  90. public IActionResult CheckMachine(string right)
  91. {
  92. ViewBag.RightInfo = RightInfo;
  93. ViewBag.right = right;
  94. return View();
  95. }
  96. [HttpPost]
  97. public string CheckMachineDo(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0, int IsPre = 0, int IsSend = 0)
  98. {
  99. if (string.IsNullOrEmpty(MakerCode))
  100. {
  101. return "请输入创客编号";
  102. }
  103. if (string.IsNullOrEmpty(PosSn))
  104. {
  105. return "请输入机具SN";
  106. }
  107. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  108. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  109. if (pos == null)
  110. {
  111. return "机具SN不存在";
  112. }
  113. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  114. if (user == null)
  115. {
  116. return "创客编号不存在";
  117. }
  118. if (IsPre == 1)
  119. {
  120. if (pos.BuyUserId == 0)
  121. {
  122. pos.BuyUserId = user.Id;
  123. }
  124. if (pos.UserId == 0)
  125. {
  126. pos.UserId = user.Id;
  127. }
  128. }
  129. if (pos.BindingState == 0)
  130. {
  131. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  132. if (bind != null)
  133. {
  134. pos.BindingState = 1;
  135. pos.BindingTime = bind.CreateTime;
  136. db.SaveChanges();
  137. MerNo = bind.MerNo;
  138. }
  139. }
  140. decimal CreditTrade = 0;
  141. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  142. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  143. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  144. bool check = spdb.TradeRecord.Any(m => m.Id > StartId && m.TradeSnNo == pos.PosSn);
  145. if (check)
  146. {
  147. if (pos.BrandId == 1)
  148. {
  149. 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;
  150. }
  151. else if (pos.BrandId == 2)
  152. {
  153. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  154. }
  155. else if (pos.BrandId == 3)
  156. {
  157. 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;
  158. }
  159. else if (pos.BrandId == 4 || pos.BrandId == 5)
  160. {
  161. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  162. }
  163. else if (pos.BrandId == 6)
  164. {
  165. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  166. }
  167. else if (pos.BrandId == 7)
  168. {
  169. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  170. }
  171. else if (pos.BrandId == 8)
  172. {
  173. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  174. }
  175. else if (pos.BrandId == 9)
  176. {
  177. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  178. }
  179. else if (pos.BrandId == 10 || pos.BrandId == 11)
  180. {
  181. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  182. }
  183. pos.CreditTrade = CreditTrade;
  184. db.SaveChanges();
  185. }
  186. if (AddActPrize == 1)
  187. {
  188. if (pos.BuyUserId == 0)
  189. {
  190. return "机具未划拨,无法补录激活奖励";
  191. }
  192. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  193. {
  194. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  195. if (has)
  196. {
  197. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  198. pos.SeoKeyword = chkAct.SeoTitle;
  199. db.SaveChanges();
  200. }
  201. }
  202. if (pos.BindingTime != null && pos.ActivationTime != null)
  203. {
  204. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  205. if (ts.TotalDays <= 30 || SysUserName == "admin")
  206. {
  207. AddAct(pos.Id);
  208. }
  209. }
  210. }
  211. decimal CheckMoney = 1000;
  212. if (pos.BrandId == 6)
  213. {
  214. CheckMoney = 5000;
  215. }
  216. if (pos.BuyUserId > 0)
  217. {
  218. if (pos.CreditTrade < CheckMoney)
  219. {
  220. return "该机具贷记卡累计交易不足" + CheckMoney;
  221. }
  222. if (pos.BindingTime != null && pos.ActivationTime != null)
  223. {
  224. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  225. if (ts.TotalDays > 30 && SysUserName != "admin")
  226. {
  227. return "机具划拨后已超过30天";
  228. }
  229. }
  230. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  231. {
  232. pos.ActivationState = 1;
  233. pos.ActivationTime = DateTime.Now;
  234. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  235. if (pos.ActivationState == 1 && mer != null)
  236. {
  237. mer.ActiveStatus = 1;
  238. mer.MerStandardDate = DateTime.Now;
  239. }
  240. }
  241. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  242. {
  243. if (AddActPrize == 1)
  244. {
  245. if (IsSend == 1)
  246. {
  247. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  248. {
  249. UserId = pos.BuyUserId, //接收创客
  250. MsgType = 2,
  251. Title = "补录成功通知", //标题
  252. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  253. CreateDate = DateTime.Now,
  254. }));
  255. }
  256. return "激活奖励已补录";
  257. }
  258. else
  259. {
  260. return "数据正常,无需补录";
  261. }
  262. }
  263. db.SaveChanges();
  264. return "success";
  265. }
  266. pos.UserId = user.Id;
  267. pos.BuyUserId = user.Id;
  268. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
  269. {
  270. // pos.IsPurchase = 0;
  271. pos.ActivationState = 1;
  272. pos.ActivationTime = DateTime.Now;
  273. }
  274. PosMerchantInfo merchant = new PosMerchantInfo();
  275. if (!string.IsNullOrEmpty(MerNo))
  276. {
  277. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  278. if (merchant == null)
  279. {
  280. int TopUserId = 0;
  281. if (!string.IsNullOrEmpty(user.ParentNav))
  282. {
  283. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  284. }
  285. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  286. if (bind == null)
  287. {
  288. return "该机具尚未绑定";
  289. }
  290. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  291. if (Mer == null)
  292. {
  293. return "该机具尚未绑定";
  294. }
  295. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  296. {
  297. CreateDate = Mer.CreateTime,
  298. UpdateDate = Mer.UpdateTime,
  299. TopUserId = TopUserId,
  300. MerUserType = user.MerchantType,
  301. BrandId = int.Parse(Mer.ProductType),
  302. SnStoreId = pos.StoreId,
  303. SnType = pos.PosSnType,
  304. UserId = user.Id,
  305. MgrName = Mer.AgentName,
  306. MerStatus = 1,
  307. KqSnNo = Mer.SnNo,
  308. KqMerNo = Mer.MerNo,
  309. MerIdcardNo = Mer.MerIdcardNo,
  310. MerRealName = Mer.MerRealName,
  311. MerchantMobile = Mer.MerMobile,
  312. MerchantName = Mer.MerName,
  313. MerchantNo = Mer.MerNo,
  314. }).Entity;
  315. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  316. if (forMerNo == null)
  317. {
  318. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  319. {
  320. MerNo = Mer.MerNo,
  321. SnId = pos.Id,
  322. }).Entity;
  323. }
  324. else
  325. {
  326. forMerNo.SnId = pos.Id;
  327. }
  328. }
  329. }
  330. else
  331. {
  332. if (pos.BindMerchantId > 0)
  333. {
  334. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  335. }
  336. else
  337. {
  338. return "找不到机具所属商户";
  339. }
  340. }
  341. merchant.UserId = user.Id;
  342. if (pos.ActivationState == 1)
  343. {
  344. merchant.ActiveStatus = 1;
  345. merchant.MerStandardDate = DateTime.Now;
  346. }
  347. if (pos.BindMerchantId == 0)
  348. {
  349. pos.BindMerchantId = merchant.Id;
  350. }
  351. // var makerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  352. // var prePos = db.PreSendStockDetail.FirstOrDefault(m => m.ToUserId == makerCode.UserId && m.SnId == pos.Id && m.CreateDate < DateTime.Now.AddDays(-30) && m.AuthFlag == 1 && m.ApplyFlag == 0) ?? new PreSendStockDetail();
  353. // if (makerCode.UserId > 0 && prePos.Id > 0)
  354. // {
  355. // if (prePos.CreateDate <= DateTime.Now.AddDays(-30))
  356. // {
  357. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == prePos.BrandId);
  358. // var amount = 0;
  359. // if (brandInfo.Name.Contains("电签"))
  360. // {
  361. // amount = 200;
  362. // }
  363. // if (brandInfo.Name.Contains("大POS"))
  364. // {
  365. // amount = 300;
  366. // }
  367. // var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == makerCode.UserId) ?? new UserAccount();
  368. // if (userAccount.Id > 0)
  369. // {
  370. // userAccount.SmallStoreDeposit -= amount;
  371. // var add = db.UserAccountRecord.Add(new UserAccountRecord()
  372. // {
  373. // CreateDate = DateTime.Now,
  374. // Remark = "小分仓押金退还",
  375. // ChangeType = 65,
  376. // BeforeBalanceAmount = userAccount.SmallStoreDeposit + amount, //变更前小分仓押金
  377. // AfterBalanceAmount = userAccount.SmallStoreDeposit, //变更后小分仓押金
  378. // ChangeAmount = amount,//变动金额
  379. // UserId = userAccount.Id,
  380. // }).Entity;
  381. // db.SaveChanges();
  382. // }
  383. // }
  384. // }
  385. db.SaveChanges();
  386. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize + ", IsPre:" + IsPre, "机具补录日志");
  387. return "success";
  388. }
  389. public IActionResult CheckMachine2(string right)
  390. {
  391. ViewBag.RightInfo = RightInfo;
  392. ViewBag.right = right;
  393. return View();
  394. }
  395. [HttpPost]
  396. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  397. {
  398. if (string.IsNullOrEmpty(MakerCode))
  399. {
  400. return "请输入创客编号";
  401. }
  402. if (string.IsNullOrEmpty(PosSn))
  403. {
  404. return "请输入机具SN";
  405. }
  406. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  407. if (pos == null)
  408. {
  409. return "机具SN不存在";
  410. }
  411. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  412. if (user == null)
  413. {
  414. return "创客编号不存在";
  415. }
  416. if (pos.BindingState == 0)
  417. {
  418. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  419. if (bind != null)
  420. {
  421. pos.BindingState = 1;
  422. pos.BindingTime = bind.CreateTime;
  423. db.SaveChanges();
  424. MerNo = bind.MerNo;
  425. }
  426. }
  427. decimal CreditTrade = 0;
  428. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  429. if (check)
  430. {
  431. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  432. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  433. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  434. if (pos.BrandId == 1)
  435. {
  436. 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;
  437. }
  438. else if (pos.BrandId == 2)
  439. {
  440. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  441. }
  442. else if (pos.BrandId == 3)
  443. {
  444. 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;
  445. }
  446. else if (pos.BrandId == 4 || pos.BrandId == 5)
  447. {
  448. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  449. }
  450. else if (pos.BrandId == 6)
  451. {
  452. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  453. }
  454. else if (pos.BrandId == 8)
  455. {
  456. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  457. }
  458. else if (pos.BrandId == 9)
  459. {
  460. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  461. }
  462. else if (pos.BrandId == 10 || pos.BrandId == 11)
  463. {
  464. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
  465. }
  466. pos.CreditTrade = CreditTrade;
  467. db.SaveChanges();
  468. }
  469. if (AddActPrize == 1)
  470. {
  471. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  472. {
  473. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  474. if (has)
  475. {
  476. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  477. pos.SeoKeyword = chkAct.SeoTitle;
  478. db.SaveChanges();
  479. }
  480. }
  481. AddAct(pos.Id);
  482. }
  483. if (pos.BuyUserId > 0)
  484. {
  485. if (pos.CreditTrade < 1000)
  486. {
  487. // pos.IsPurchase = 99;
  488. db.SaveChanges();
  489. return "该机具贷记卡累计交易不足1000";
  490. }
  491. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  492. {
  493. // pos.IsPurchase = 0;
  494. pos.ActivationState = 1;
  495. pos.ActivationTime = DateTime.Now;
  496. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  497. if (pos.ActivationState == 1 && mer != null)
  498. {
  499. mer.ActiveStatus = 1;
  500. mer.MerStandardDate = DateTime.Now;
  501. }
  502. }
  503. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  504. {
  505. if (AddActPrize == 1)
  506. {
  507. return "激活奖励已补录";
  508. }
  509. else
  510. {
  511. return "数据正常,无需补录";
  512. }
  513. }
  514. db.SaveChanges();
  515. return "success";
  516. }
  517. pos.UserId = user.Id;
  518. pos.BuyUserId = user.Id;
  519. // if (pos.CreditTrade < 1000)
  520. // {
  521. // pos.IsPurchase = 99;
  522. // }
  523. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  524. {
  525. // pos.IsPurchase = 0;
  526. pos.ActivationState = 1;
  527. pos.ActivationTime = DateTime.Now;
  528. }
  529. PosMerchantInfo merchant = new PosMerchantInfo();
  530. if (!string.IsNullOrEmpty(MerNo))
  531. {
  532. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  533. if (merchant == null)
  534. {
  535. int TopUserId = 0;
  536. if (!string.IsNullOrEmpty(user.ParentNav))
  537. {
  538. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  539. }
  540. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  541. if (bind == null)
  542. {
  543. return "该机具尚未绑定";
  544. }
  545. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  546. if (Mer == null)
  547. {
  548. return "该机具尚未绑定";
  549. }
  550. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  551. {
  552. CreateDate = Mer.CreateTime,
  553. UpdateDate = Mer.UpdateTime,
  554. TopUserId = TopUserId,
  555. MerUserType = user.MerchantType,
  556. BrandId = int.Parse(Mer.ProductType),
  557. SnStoreId = pos.StoreId,
  558. SnType = pos.PosSnType,
  559. UserId = user.Id,
  560. MgrName = Mer.AgentName,
  561. MerStatus = 1,
  562. KqSnNo = Mer.SnNo,
  563. KqMerNo = Mer.MerNo,
  564. MerIdcardNo = Mer.MerIdcardNo,
  565. MerRealName = Mer.MerRealName,
  566. MerchantMobile = Mer.MerMobile,
  567. MerchantName = Mer.MerName,
  568. MerchantNo = Mer.MerNo,
  569. }).Entity;
  570. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  571. if (forMerNo == null)
  572. {
  573. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  574. {
  575. MerNo = Mer.MerNo,
  576. SnId = pos.Id,
  577. }).Entity;
  578. }
  579. else
  580. {
  581. forMerNo.SnId = pos.Id;
  582. }
  583. }
  584. }
  585. else
  586. {
  587. if (pos.BindMerchantId > 0)
  588. {
  589. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  590. }
  591. else
  592. {
  593. return "找不到机具所属商户";
  594. }
  595. }
  596. merchant.UserId = user.Id;
  597. if (pos.ActivationState == 1)
  598. {
  599. merchant.ActiveStatus = 1;
  600. merchant.MerStandardDate = DateTime.Now;
  601. }
  602. if (pos.BindMerchantId == 0)
  603. {
  604. pos.BindMerchantId = merchant.Id;
  605. }
  606. db.SaveChanges();
  607. return "success";
  608. }
  609. public void AddAct(int posid = 0)
  610. {
  611. WebCMSEntities db = new WebCMSEntities();
  612. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
  613. if (pos != null)
  614. {
  615. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
  616. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  617. if (merchant != null)
  618. {
  619. // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
  620. // if (otherInfo != null)
  621. // {
  622. // otherInfo.PrizeFlag1 = 1;
  623. // db.SaveChanges();
  624. string ParentNav = "";
  625. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  626. if (user != null)
  627. {
  628. int GetUserId = user.Id;
  629. ParentNav = user.ParentNav;
  630. int TopUserId = 1;
  631. if (!string.IsNullOrEmpty(ParentNav))
  632. {
  633. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  634. if (ParentNavList.Length > 1)
  635. {
  636. TopUserId = int.Parse(ParentNavList[1]);
  637. }
  638. else if (ParentNavList.Length == 1)
  639. {
  640. TopUserId = int.Parse(ParentNavList[0]);
  641. }
  642. }
  643. List<decimal> prizes = new List<decimal>();
  644. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  645. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
  646. {
  647. ActPrize = ActPrize / 100;
  648. }
  649. if (ActPrize > 0)
  650. {
  651. if (ActPrize == 99)
  652. {
  653. ActPrize = 100;
  654. }
  655. else if (ActPrize == 199)
  656. {
  657. ActPrize = 200;
  658. }
  659. else if (ActPrize == 299)
  660. {
  661. ActPrize = 300;
  662. }
  663. else if (ActPrize == 249)
  664. {
  665. ActPrize = 260;
  666. }
  667. prizes.Add(ActPrize);
  668. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  669. {
  670. prizes.Add(40);
  671. }
  672. }
  673. else if (pos.BrandId == 6 && ActPrize == 0) //立刷首台无押金机返50
  674. {
  675. prizes.Add(50);
  676. }
  677. else if((pos.BrandId == 10 || pos.BrandId == 11) && pos.IsFirst == 1 && ActPrize == 0) //联动首台无押金机返50
  678. {
  679. prizes.Add(50);
  680. }
  681. foreach (decimal prize in prizes)
  682. {
  683. int ChangeType = prize == 40 ? 12 : 0;
  684. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  685. if (!check)
  686. {
  687. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  688. db.ActiveReward.Add(new ActiveReward()
  689. {
  690. CreateDate = DateTime.Now,
  691. UpdateDate = DateTime.Now,
  692. UserId = GetUserId, //创客
  693. MerchantId = pos.BindMerchantId, //商户
  694. StandardDate = pos.ActivationTime, //达标日期
  695. RewardAmount = prize, //奖励金额
  696. BrandId = pos.BrandId, //品牌
  697. UserNav = ParentNav, //创客父级
  698. DirectBuddyNo = merchant.UserId, //商户直属创客
  699. KqMerNo = merchant.KqMerNo, //渠道商户编号
  700. KqSnNo = pos.PosSn, //渠道SN号
  701. SnType = pos.PosSnType, //机具类型
  702. SnApplyUserId = pos.BuyUserId, //机具申请创客
  703. ActType = 0, //激活类型
  704. SnStoreId = pos.StoreId, //SN仓库
  705. RewardTips = "激活奖励", //奖励描述
  706. Remark = "激活奖励", //备注
  707. ActDate = pos.ActivationTime, //激活时间
  708. TopUserId = TopUserId, //顶级创客
  709. SeoTitle = machineUser.RealName,
  710. });
  711. db.SaveChanges();
  712. string IdBrand = GetUserId + "_" + pos.BrandId;
  713. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  714. if (userData == null)
  715. {
  716. userData = db.UserMachineData.Add(new UserMachineData()
  717. {
  718. IdBrand = IdBrand,
  719. }).Entity;
  720. db.SaveChanges();
  721. }
  722. userData.ActProfit += prize;
  723. db.SaveChanges();
  724. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  725. if (account == null)
  726. {
  727. account = db.UserAccount.Add(new UserAccount()
  728. {
  729. Id = GetUserId,
  730. UserId = GetUserId,
  731. }).Entity;
  732. db.SaveChanges();
  733. }
  734. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  735. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  736. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  737. account.BalanceAmount += prize;
  738. account.TotalAmount += prize;
  739. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  740. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  741. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  742. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  743. {
  744. CreateDate = DateTime.Now,
  745. UpdateDate = DateTime.Now,
  746. UserId = GetUserId, //创客
  747. ChangeType = ChangeType, //变动类型
  748. ProductType = pos.BrandId, //产品类型
  749. ChangeAmount = prize, //变更金额
  750. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  751. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  752. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  753. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  754. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  755. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  756. }).Entity;
  757. db.SaveChanges();
  758. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  759. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  760. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  761. // 激活奖励列表
  762. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  763. if (!dates.Contains(dateString))
  764. {
  765. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  766. }
  767. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  768. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  769. if (!months.Contains(monthString))
  770. {
  771. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  772. }
  773. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  774. // 激活奖励详情
  775. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  776. if (!actPrizeList.Contains(pos.BindMerchantId))
  777. {
  778. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  779. }
  780. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  781. //收支明细
  782. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  783. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  784. }
  785. }
  786. }
  787. // }
  788. }
  789. }
  790. db.Dispose();
  791. }
  792. #endregion
  793. #region 设置商户代理
  794. public IActionResult SetMerAgent(string right)
  795. {
  796. ViewBag.RightInfo = RightInfo;
  797. ViewBag.right = right;
  798. return View();
  799. }
  800. [HttpPost]
  801. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
  802. {
  803. if (string.IsNullOrEmpty(MakerCode))
  804. {
  805. return "请输入创客编号";
  806. }
  807. if (string.IsNullOrEmpty(PosSn))
  808. {
  809. return "请输入机具SN";
  810. }
  811. if (string.IsNullOrEmpty(MerNo))
  812. {
  813. return "请输入商户编号";
  814. }
  815. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  816. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  817. if (pos == null)
  818. {
  819. return "机具SN不存在";
  820. }
  821. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  822. if (user == null)
  823. {
  824. return "创客编号不存在";
  825. }
  826. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  827. if (merchant == null)
  828. {
  829. return "商户编号不存在";
  830. }
  831. pos.SeoTitle = user.Id.ToString();
  832. pos.UserId = user.Id;
  833. if (pos.BindMerchantId == 0)
  834. {
  835. pos.BindMerchantId = merchant.Id;
  836. if (IsSend == 1)
  837. {
  838. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  839. {
  840. UserId = pos.BuyUserId, //接收创客
  841. MsgType = 2,
  842. Title = "商户型代理设置成功", //标题
  843. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
  844. CreateDate = DateTime.Now,
  845. }));
  846. }
  847. }
  848. user.MerchantType = 1;
  849. merchant.UserId = user.Id;
  850. merchant.MerUserType = 1;
  851. db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
  852. {
  853. CreateDate = DateTime.Now,
  854. IsRecyc = (ulong)pos.IsPurchase,
  855. CreditAmount = pos.CreditTrade,
  856. PosSnType = pos.PosSnType,
  857. ActDate = pos.ActivationTime,
  858. BindDate = pos.BindingTime,
  859. ActStatus = (ulong)pos.ActivationState,
  860. BindStatus = (ulong)pos.BindingState,
  861. MerNo = MerNo,
  862. PosSn = pos.PosSn,
  863. Note = "后台设置商户型创客",
  864. ToUserId = user.Id,
  865. FromUserId = pos.BuyUserId,
  866. });
  867. db.SaveChanges();
  868. return "success";
  869. }
  870. #endregion
  871. #region 取消商户代理
  872. public IActionResult CancelMerAgent(string right)
  873. {
  874. ViewBag.RightInfo = RightInfo;
  875. ViewBag.right = right;
  876. return View();
  877. }
  878. [HttpPost]
  879. public string CancelMerAgentDo(string MakerCode, string PosSn, int IsSend = 0)
  880. {
  881. if (string.IsNullOrEmpty(MakerCode))
  882. {
  883. return "请输入创客编号";
  884. }
  885. if (string.IsNullOrEmpty(PosSn))
  886. {
  887. return "请输入机具SN";
  888. }
  889. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  890. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  891. if (pos == null)
  892. {
  893. return "机具SN不存在";
  894. }
  895. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  896. if (user == null)
  897. {
  898. return "创客编号不存在";
  899. }
  900. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == PosSn);
  901. pos.UserId = pos.BuyUserId;
  902. merchant.UserId = pos.BuyUserId;
  903. merchant.MerUserType = 0;
  904. user.MerchantType = 0;
  905. db.SaveChanges();
  906. if (pos.BindMerchantId == 0)
  907. {
  908. pos.BindMerchantId = merchant.Id;
  909. if (IsSend == 1)
  910. {
  911. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  912. {
  913. UserId = pos.BuyUserId, //接收创客
  914. MsgType = 2,
  915. Title = "商户型代理取消成功", //标题
  916. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已给下级代理" + user.RealName + "" + MakerCode + "取消成功",
  917. CreateDate = DateTime.Now,
  918. }));
  919. }
  920. }
  921. string text = string.Format("取消商户代理,创客编号: " + user.MakerCode + ",机具SN:" + pos.PosSn + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
  922. function.WriteLog(text, "CancelMerAgent");//取消商户型代理日志
  923. return "success";
  924. }
  925. #endregion
  926. #region 查看SP原始数据日志
  927. public IActionResult SeeSpLog(string right)
  928. {
  929. ViewBag.RightInfo = RightInfo;
  930. ViewBag.right = right;
  931. return View();
  932. }
  933. #endregion
  934. #region 查询机具信息
  935. public IActionResult SeeSnDetail(string right)
  936. {
  937. ViewBag.RightInfo = RightInfo;
  938. ViewBag.right = right;
  939. return View();
  940. }
  941. [HttpPost]
  942. public string SeeSnDetailDo(string PosSn)
  943. {
  944. if (string.IsNullOrEmpty(PosSn))
  945. {
  946. return "请输入机具SN";
  947. }
  948. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  949. if (pos == null)
  950. {
  951. return "机具SN不存在";
  952. }
  953. if (pos.Status == -1)
  954. {
  955. Users posUsers = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  956. decimal Deposits = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  957. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11)
  958. {
  959. Deposits = Deposits / 100;
  960. }
  961. string DepositGets = "未领取";
  962. string DepositUsers = "";
  963. ActiveReward rewards = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  964. if (rewards.Id > 0)
  965. {
  966. Users user = db.Users.FirstOrDefault(m => m.Id == rewards.UserId) ?? new Users();
  967. DepositGets = "已领取";
  968. DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  969. // DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  970. }
  971. string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  972. var storeInfo = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  973. string results = "该机具为故障机" + "\n";
  974. results += "所在仓库:" + storeInfo.StoreNo + "\n";
  975. results += "仓库名称:" + storeInfo.StoreName + "\n";
  976. results += "押金返现实际返现对象:" + DepositUsers + "\n";
  977. results += "押金:" + Deposits + "\n";
  978. results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
  979. return results;
  980. }
  981. string merInfo = "";
  982. string merName = "";
  983. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  984. if (mer != null)
  985. {
  986. merInfo = mer.KqMerNo;
  987. merName = mer.MerchantName;
  988. }
  989. else
  990. {
  991. merInfo = "未找到商户";
  992. }
  993. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  994. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  995. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  996. int TopUserId = 0;
  997. if (!string.IsNullOrEmpty(posUser.ParentNav))
  998. {
  999. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1000. if (ParentNavs.Length > 1)
  1001. {
  1002. TopUserId = int.Parse(ParentNavs[1]);
  1003. }
  1004. if (ParentNavs.Length == 1)
  1005. {
  1006. TopUserId = int.Parse(ParentNavs[0]);
  1007. }
  1008. }
  1009. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1010. string bindResult = "", bindTime = "";
  1011. if (pos.BindingState == 0)
  1012. {
  1013. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  1014. if (bind != null)
  1015. {
  1016. if (bind.Status != 1)
  1017. {
  1018. bindResult = "执行中";
  1019. }
  1020. }
  1021. else
  1022. {
  1023. bindResult = "未绑定";
  1024. }
  1025. }
  1026. else
  1027. {
  1028. bindResult = "已绑定";
  1029. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1030. }
  1031. string activeResult = "", activeTime = "";
  1032. if (pos.ActivationState == 0)
  1033. {
  1034. if (pos.CreditTrade < 1000)
  1035. {
  1036. activeResult = "未刷满1000";
  1037. }
  1038. else if (pos.TransferTime == null)
  1039. {
  1040. activeResult = "未激活, 需补录";
  1041. }
  1042. }
  1043. else
  1044. {
  1045. activeResult = "已激活";
  1046. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1047. }
  1048. string tradeAmount = pos.CreditTrade.ToString();
  1049. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1050. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11)
  1051. {
  1052. Deposit = Deposit / 100;
  1053. }
  1054. string DepositGet = "未领取";
  1055. string DepositUser = "";
  1056. string DepositToUser = "";
  1057. decimal headAmount = 0;
  1058. decimal footAmount = 0;
  1059. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1060. if (reward.Id > 0)
  1061. {
  1062. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1063. DepositGet = "已领取";
  1064. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1065. // DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1066. var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
  1067. if (fAmount != null)
  1068. {
  1069. headAmount = fAmount.RewardAmount;
  1070. }
  1071. var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
  1072. if (lAmount != null)
  1073. {
  1074. footAmount = lAmount.RewardAmount;
  1075. }
  1076. }
  1077. string DepositGet6 = "未领取";
  1078. string DepositUser6 = "";
  1079. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  1080. if (lisreward.Id > 0)
  1081. {
  1082. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  1083. DepositGet6 = "已领取";
  1084. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1085. // DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1086. }
  1087. string FluxGet6 = "未领取";
  1088. string FluxUser6 = "";
  1089. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1090. if (flux.Id > 0)
  1091. {
  1092. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1093. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1094. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1095. // FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1096. }
  1097. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1098. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName;
  1099. // DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  1100. string OpenUser10 = "未领取";
  1101. string OpenUser20 = "未领取";
  1102. string Leader10 = "未领取";
  1103. string YYZX5 = "未领取";
  1104. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1105. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1106. if (openreward.Id > 0)
  1107. {
  1108. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1109. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1110. // OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1111. }
  1112. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1113. if (openreward.Id > 0)
  1114. {
  1115. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1116. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1117. // OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1118. }
  1119. var leader10 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 116) ?? new UserAccountRecord();
  1120. if (leader10.Id > 0)
  1121. {
  1122. Users user = db.Users.FirstOrDefault(m => m.Id == leader10.UserId) ?? new Users();
  1123. Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + leader10.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1124. // Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1125. }
  1126. var yyzx5 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 121) ?? new UserAccountRecord();
  1127. if (yyzx5.Id > 0)
  1128. {
  1129. Users user = db.Users.FirstOrDefault(m => m.Id == yyzx5.UserId) ?? new Users();
  1130. YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + yyzx5.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1131. // YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1132. }
  1133. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1134. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1135. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1136. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1137. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1138. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1139. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1140. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1141. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1142. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1143. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1144. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1145. string result = "";
  1146. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + "\n";
  1147. result += "\n";
  1148. result += "机具SN:" + pos.PosSn + "\n";
  1149. string PosSnType = pos.PosSnType == 0 ? "兑换机" : "循环机";
  1150. result += "机具类型:" + PosSnType + "\n";
  1151. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1152. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + "\n";
  1153. // result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  1154. if (change.Id > 0)
  1155. {
  1156. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1157. }
  1158. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + "\n";
  1159. // result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  1160. // result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  1161. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1162. if (pos.PreUserId > 0)
  1163. {
  1164. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1165. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1166. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1167. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",预发时间:" + preSendDate + "\n";
  1168. // result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",手机号:" + smallStoreUser.Mobile + ",预发时间:" + preSendDate + "\n";
  1169. }
  1170. else
  1171. {
  1172. result += "机具所属小分仓:暂无小分仓\n";
  1173. }
  1174. result += "入库时间:" + CreateDate + "\n";
  1175. result += "循环到期时间:" + RecycEndDate + "\n";
  1176. result += "划拨时间:" + TransferTime + "\n";
  1177. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1178. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1179. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1180. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1181. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1182. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1183. result += "押金:" + Deposit + "\n";
  1184. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1185. result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";
  1186. result += "押金返现应返现对象:" + DepositToUser + "\n";
  1187. result += "押金返现实际返现对象:" + DepositUser + "\n";
  1188. if (pos.BrandId == 6)
  1189. {
  1190. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1191. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1192. }
  1193. result += "流量费:" + FluxGet6 + "\n";
  1194. result += "流量费发放对象:" + FluxUser6 + "\n";
  1195. result += "开机奖20:" + OpenUser20 + "\n";
  1196. // result += "开机奖10:" + OpenUser10 + "\n";
  1197. result += "盟主奖:" + Leader10 + "\n";
  1198. result += "运营中心奖:" + YYZX5 + "\n";
  1199. return result;
  1200. }
  1201. //解析金控日志
  1202. // public decimal CheckLog(DateTime startDate, string PosSn)
  1203. // {
  1204. // bool op = true;
  1205. // decimal result = 0;
  1206. // DateTime today = DateTime.Now;
  1207. // int i = 0;
  1208. // while (op)
  1209. // {
  1210. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  1211. // if (check <= today)
  1212. // {
  1213. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  1214. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  1215. // foreach (Match sub in mc)
  1216. // {
  1217. // string content = sub.Value;
  1218. // JsonData jsonObj = JsonMapper.ToObject(content);
  1219. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  1220. // string posSnCheck = jsonObj["posSn"].ToString();
  1221. // if (posSnCheck == PosSn && serviceAmount > 0)
  1222. // {
  1223. // result = serviceAmount / 100;
  1224. // op = false;
  1225. // }
  1226. // }
  1227. // }
  1228. // else
  1229. // {
  1230. // op = false;
  1231. // }
  1232. // i += 1;
  1233. // }
  1234. // return result;
  1235. // }
  1236. #endregion
  1237. #region 生成机具兑换码
  1238. public IActionResult MakeCoupons(string right)
  1239. {
  1240. ViewBag.RightInfo = RightInfo;
  1241. ViewBag.right = right;
  1242. return View();
  1243. }
  1244. [HttpPost]
  1245. public string MakeCouponsDo(int Kind, int Number)
  1246. {
  1247. DateTime checkTime = DateTime.Parse("1900-01-01");
  1248. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1249. if (!string.IsNullOrEmpty(checkTimeString))
  1250. {
  1251. checkTime = DateTime.Parse(checkTimeString);
  1252. }
  1253. if (checkTime.AddHours(1) < DateTime.Now)
  1254. {
  1255. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1256. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1257. return "生成程序已执行";
  1258. }
  1259. return "请稍后再试";
  1260. }
  1261. #endregion
  1262. #region 导出没有刷满1000的机具
  1263. public IActionResult ExportPos(string right)
  1264. {
  1265. ViewBag.RightInfo = RightInfo;
  1266. ViewBag.right = right;
  1267. return View();
  1268. }
  1269. [HttpPost]
  1270. public JsonResult ExportPosDo()
  1271. {
  1272. WebCMSEntities db = new WebCMSEntities();
  1273. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1274. int total = poses.Count;
  1275. int index = 0;
  1276. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1277. foreach (PosMachinesTwo pos in poses)
  1278. {
  1279. index += 1;
  1280. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1281. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1282. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1283. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1284. Dictionary<string, object> item = new Dictionary<string, object>();
  1285. string TopRealName = "";
  1286. string TopMakerCode = "";
  1287. string TopMobile = "";
  1288. string ParentNav = user.ParentNav;
  1289. if (!string.IsNullOrEmpty(ParentNav))
  1290. {
  1291. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1292. if (navlist.Length > 1)
  1293. {
  1294. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1295. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1296. TopRealName = tuser.RealName;
  1297. TopMakerCode = tuser.MakerCode;
  1298. TopMobile = tuser.Mobile;
  1299. }
  1300. }
  1301. item.Add("TopRealName", TopRealName); //顶级姓名
  1302. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1303. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1304. item.Add("UpRealName", puser.RealName); //上级姓名
  1305. item.Add("RealName", user.RealName); //代理姓名
  1306. item.Add("MakerCode", user.MakerCode); //代理编号
  1307. item.Add("Mobile", user.Mobile); //代理手机号
  1308. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1309. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1310. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1311. item.Add("Sn", pos.PosSn); //SN
  1312. list.Add(item);
  1313. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1314. }
  1315. db.Dispose();
  1316. Dictionary<string, object> result = new Dictionary<string, object>();
  1317. result.Add("Status", "1");
  1318. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1319. result.Add("Obj", list);
  1320. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1321. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1322. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1323. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1324. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1325. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1326. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1327. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1328. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1329. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1330. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1331. ReturnFields.Add("Sn", "SN"); //SN
  1332. result.Add("Fields", ReturnFields);
  1333. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1334. return Json(result);
  1335. }
  1336. public string ExportPosCheck()
  1337. {
  1338. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1339. if (content == "finish")
  1340. {
  1341. RedisDbconn.Instance.Clear("ExportPosCheck");
  1342. }
  1343. return content;
  1344. }
  1345. #endregion
  1346. #region 更换机具
  1347. public IActionResult ChangePos(string right)
  1348. {
  1349. ViewBag.RightInfo = RightInfo;
  1350. ViewBag.right = right;
  1351. return View();
  1352. }
  1353. [HttpPost]
  1354. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1355. {
  1356. if (string.IsNullOrEmpty(OldSn))
  1357. {
  1358. return "请输入原机具SN";
  1359. }
  1360. if (string.IsNullOrEmpty(NewSn))
  1361. {
  1362. return "请输入新机具SN";
  1363. }
  1364. if (string.IsNullOrEmpty(MerNo))
  1365. {
  1366. return "请输入商户编号";
  1367. }
  1368. string[] OldSnList = OldSn.Split('\n');
  1369. string[] NewSnList = NewSn.Split('\n');
  1370. if (OldSnList.Length != NewSnList.Length)
  1371. {
  1372. return "原机具SN数量和新机具SN数量不一致";
  1373. }
  1374. WebCMSEntities db = new WebCMSEntities();
  1375. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1376. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1377. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1378. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1379. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1380. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1381. KqProducts oldPosBrand = new KqProducts();
  1382. KqProducts newPosBrand = new KqProducts();
  1383. MachineChange add = db.MachineChange.Add(new MachineChange()
  1384. {
  1385. CreateDate = DateTime.Now,
  1386. UpdateDate = DateTime.Now,
  1387. CreateMan = SysUserName + "-" + SysRealName,
  1388. ChangeNo = ChangeNo, //转换单号
  1389. UserId = 0, //创客
  1390. ChangeTime = DateTime.Now, //转换时间
  1391. BackStoreId = BackStore.Id, //退回仓库
  1392. BackStoreName = BackStore.StoreName, //退回仓库名称
  1393. Remark = "机具更换", //订单备注
  1394. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1395. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1396. OutProductName = OutStore.ProductName, //出库产品名称
  1397. OutStoreId = OutStore.Id, //出库仓库
  1398. OutStoreName = OutStore.StoreName, //出库仓库名称
  1399. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1400. OutStoreAddress = OutStore.Address, //出库仓库地址
  1401. OutStoreManager = "", //出库仓库联系人
  1402. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1403. }).Entity;
  1404. db.SaveChanges();
  1405. int BackProductType = 0;
  1406. string BackProductName = "";
  1407. string ChangeDeviceName = "";
  1408. string ChangeSnExpand = "";
  1409. for (int i = 0; i < OldSnList.Length; i++)
  1410. {
  1411. string OldSnNum = OldSnList[i];
  1412. string NewSnNum = NewSnList[i];
  1413. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1414. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1415. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1416. if (oldpos == null)
  1417. {
  1418. return "原机具SN不正确";
  1419. }
  1420. // if (oldpos.BindingState != 1)
  1421. // {
  1422. // return "原机具未绑定";
  1423. // }
  1424. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.PreUserId == 0);//添加新机是否为预发机判断
  1425. if (newpos == null)
  1426. {
  1427. return "新机具SN不正确或不满足条件";
  1428. }
  1429. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1430. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1431. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  1432. if (merchant == null)
  1433. {
  1434. CustomerSqlConn.op("insert into PosMerchantInfo select * from PosMerchantInfoBak where KqMerNo='" + MerNo + "'", MysqlConn.connstr);
  1435. }
  1436. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1437. newpos.BindMerchantId = merchant.Id;
  1438. newpos.BuyUserId = oldpos.BuyUserId;
  1439. newpos.UserId = oldpos.UserId;
  1440. newpos.RecycEndDate = oldpos.RecycEndDate;
  1441. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1442. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1443. newpos.CreditTrade = oldpos.CreditTrade;
  1444. newpos.PosSnType = oldpos.PosSnType;
  1445. newpos.TransferTime = oldpos.TransferTime;
  1446. newpos.IsPurchase = oldpos.IsPurchase;
  1447. newpos.BindingState = oldpos.BindingState;
  1448. newpos.ActivationState = oldpos.ActivationState;
  1449. newpos.BindingTime = oldpos.BindingTime;
  1450. newpos.ActivationTime = oldpos.ActivationTime;
  1451. newpos.IsFirst = oldpos.IsFirst;
  1452. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1453. // if (!checkActReward)
  1454. // {
  1455. newpos.SeoKeyword = oldpos.SeoKeyword;
  1456. newpos.PrizeParams = oldpos.PrizeParams;
  1457. newpos.LeaderUserId = oldpos.LeaderUserId;
  1458. // }
  1459. // oldpos.BuyUserId = 0;
  1460. // oldpos.UserId = 0;
  1461. oldpos.Status = -1;
  1462. //对应调整客小爽企业版数据
  1463. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
  1464. if (posInfo != null)
  1465. {
  1466. posInfo.PosSn = newpos.PosSn;
  1467. posInfo.PosId = newpos.Id;
  1468. db.SaveChanges();
  1469. }
  1470. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1471. if (forMerNo != null)
  1472. {
  1473. forMerNo.SnId = newpos.Id;
  1474. }
  1475. merchant.KqSnNo = NewSn;
  1476. merchant.ActiveStatus = newpos.ActivationState;
  1477. merchant.MerStandardDate = newpos.ActivationTime;
  1478. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1479. {
  1480. CreateDate = DateTime.Now,
  1481. UpdateDate = DateTime.Now,
  1482. CreateMan = SysUserName + "-" + SysRealName,
  1483. ChangeNo = ChangeNo, //订单号
  1484. ChangeId = add.Id, //订单Id
  1485. BackProductType = oldpos.BrandId, //退回产品类型
  1486. BackProductName = oldPosBrand.Name, //退回产品名称
  1487. UserId = 0, //创客
  1488. BackSnNo = oldpos.PosSn, //设备SN编号
  1489. OutProductType = newpos.BrandId, //出库产品类型
  1490. OutProductName = newPosBrand.Name, //出库产品名称
  1491. OutSnNo = newpos.PosSn, //出库设备SN编号
  1492. OutSnType = newpos.PosSnType, //出库SN机具类型
  1493. Remark = "机具更换", //备注
  1494. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1495. });
  1496. db.SaveChanges();
  1497. BackProductType = oldpos.BrandId;
  1498. BackProductName = newPosBrand.Name;
  1499. ChangeDeviceName = oldpos.DeviceName;
  1500. ChangeSnExpand += oldpos.PosSn + "\n";
  1501. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1502. }
  1503. add.BackProductType = BackProductType; //退回产品类型
  1504. add.BackProductName = BackProductName; //退回产品名称
  1505. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1506. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1507. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1508. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1509. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1510. db.SaveChanges();
  1511. db.Dispose();
  1512. if (IsSend == 1)
  1513. {
  1514. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1515. {
  1516. UserId = pos.BuyUserId, //接收创客
  1517. MsgType = 2,
  1518. Title = "换绑成功通知", //标题
  1519. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1520. CreateDate = DateTime.Now,
  1521. }));
  1522. }
  1523. return "success";
  1524. }
  1525. #endregion
  1526. #region 坏机换新
  1527. public IActionResult ChangeBadPos(string right)
  1528. {
  1529. ViewBag.RightInfo = RightInfo;
  1530. ViewBag.right = right;
  1531. return View();
  1532. }
  1533. [HttpPost]
  1534. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1535. {
  1536. string[] OldSnList;
  1537. string[] NewSnList;
  1538. decimal amount = 0;
  1539. List<string> opData = new List<string>();
  1540. //创客坏机换新
  1541. if (ChangeType == "0")
  1542. {
  1543. if (string.IsNullOrEmpty(MakerCode))
  1544. {
  1545. return "请输入创客编号";
  1546. }
  1547. if (string.IsNullOrEmpty(OldSn))
  1548. {
  1549. return "请输入坏机SN";
  1550. }
  1551. if (string.IsNullOrEmpty(NewSn))
  1552. {
  1553. return "请输入新机SN";
  1554. }
  1555. if (string.IsNullOrEmpty(FromStoreNo))
  1556. {
  1557. return "请输入新机发货仓库编号";
  1558. }
  1559. if (string.IsNullOrEmpty(BackStoreNo))
  1560. {
  1561. return "请输入坏机退回仓库编号";
  1562. }
  1563. OldSnList = OldSn.Split('\n');
  1564. NewSnList = NewSn.Split('\n');
  1565. if (OldSnList.Length != NewSnList.Length)
  1566. {
  1567. return "原机具SN数量和新机具SN数量不一致";
  1568. }
  1569. for (int i = 0; i < OldSnList.Length; i++)
  1570. {
  1571. string OldSnNum = OldSnList[i];
  1572. string NewSnNum = NewSnList[i];
  1573. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1574. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1575. if (storeForCodeFrom.StoreId == 0)
  1576. {
  1577. return "您输入的新机发货仓库编号不存在";
  1578. }
  1579. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1580. if (storeForCodeBack.StoreId == 0)
  1581. {
  1582. return "您输入的坏机退回仓库编号不存在";
  1583. }
  1584. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1585. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1586. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1587. if (oldpos.Id == 0)
  1588. {
  1589. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1590. }
  1591. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  1592. if (newpos.Id == 0)
  1593. {
  1594. return "您输入的新机SN不存在或不满足条件";
  1595. }
  1596. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1597. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  1598. {
  1599. return "您输入的新机发货仓库不符新机机具对应品牌";
  1600. }
  1601. if (newpos.StoreId != storeFrom.Id)
  1602. {
  1603. return "您输入的新机SN不在新机发货仓库";
  1604. }
  1605. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1606. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1607. {
  1608. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1609. }
  1610. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
  1611. {
  1612. return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
  1613. }
  1614. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1615. if (brandInfo.Name.Contains("大POS"))
  1616. {
  1617. amount = 300;
  1618. }
  1619. if (brandInfo.Name.Contains("电签"))
  1620. {
  1621. amount = 200;
  1622. }
  1623. // var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1624. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1625. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1626. // storeUserAcount.ValidAmount += amount;
  1627. storeFromUserAcount.ValidAmount += amount;
  1628. storeBackUserAcount.ValidAmount -= amount;
  1629. newpos.BuyUserId = oldpos.BuyUserId;
  1630. newpos.UserId = oldpos.UserId;
  1631. newpos.RecycEndDate = oldpos.RecycEndDate;
  1632. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1633. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1634. newpos.CreditTrade = oldpos.CreditTrade;
  1635. newpos.PosSnType = oldpos.PosSnType;
  1636. newpos.TransferTime = oldpos.TransferTime;
  1637. newpos.IsPurchase = oldpos.IsPurchase;
  1638. newpos.BindingState = oldpos.BindingState;
  1639. newpos.ActivationState = oldpos.ActivationState;
  1640. newpos.BindingTime = oldpos.BindingTime;
  1641. newpos.ActivationTime = oldpos.ActivationTime;
  1642. newpos.IsFirst = oldpos.IsFirst;
  1643. newpos.SeoKeyword = oldpos.SeoKeyword;
  1644. newpos.PrizeParams = oldpos.PrizeParams;
  1645. newpos.LeaderUserId = oldpos.LeaderUserId;
  1646. newpos.BindMerchantId = oldpos.BindMerchantId;
  1647. newpos.StoreId = oldpos.StoreId;
  1648. newpos.UserId = oldpos.UserId;
  1649. newpos.PreUserId = oldpos.PreUserId;
  1650. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  1651. {
  1652. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  1653. }
  1654. oldpos.StoreId = storeBack.Id;
  1655. oldpos.QueryCount = 0;
  1656. oldpos.UpdateDate = null;
  1657. oldpos.ActivityList = null;
  1658. oldpos.SeoKeyword = null;
  1659. oldpos.SeoDescription = null;
  1660. oldpos.OrderId = 0;
  1661. oldpos.RecycEndDate = null;
  1662. oldpos.RecycBackCount = 0;
  1663. oldpos.PrizeParams = null;
  1664. oldpos.ScanQrTrade = 0;
  1665. oldpos.BindMerchantId = 0;
  1666. oldpos.CreditTrade = 0;
  1667. oldpos.DebitCardTrade = 0;
  1668. oldpos.IsVip = 0;
  1669. oldpos.UserNav = null;
  1670. oldpos.TransferTime = null;
  1671. oldpos.IsPurchase = 0;
  1672. oldpos.Detail = null;
  1673. oldpos.BindingTime = null;
  1674. oldpos.BindingState = 0;
  1675. oldpos.ActivationTime = null;
  1676. oldpos.ActivationState = 0;
  1677. oldpos.LeaderUserId = 0;
  1678. oldpos.PreUserId = 0;
  1679. oldpos.IsFirst = 0;
  1680. oldpos.DownFeeMan = null;
  1681. oldpos.DownFeeFlag = 0;
  1682. oldpos.DownFeeDate = null;
  1683. oldpos.UpFeeMan = null;
  1684. oldpos.UpFeeFlag = 0;
  1685. oldpos.UpFeeDate = null;
  1686. oldpos.OpReserve1 = 0;
  1687. oldpos.OpReserve2 = 0;
  1688. oldpos.OpReserve3 = 0;
  1689. oldpos.OpId = 0;
  1690. oldpos.RecycStartDate = null;
  1691. oldpos.SourcePosSn = null;
  1692. oldpos.BuyUserId = 0;
  1693. oldpos.UserId = 0;
  1694. oldpos.Status = -1;
  1695. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  1696. db.SaveChanges();
  1697. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  1698. if (merchant != null)
  1699. {
  1700. merchant.KqSnNo = newpos.PosSn;
  1701. merchant.ActiveStatus = newpos.ActivationState;
  1702. }
  1703. db.SaveChanges();
  1704. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1705. {
  1706. CreateDate = DateTime.Now,
  1707. CreateMan = SysUserName + "-" + SysRealName,
  1708. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1709. OutStoreId = storeFrom.Id,
  1710. BackStoreId = storeBack.Id,
  1711. OutProductType = newpos.BrandId,
  1712. BackProductType = oldpos.BrandId,
  1713. UserId = userForMakerCode.UserId, //创客
  1714. }).Entity;
  1715. db.SaveChanges();
  1716. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1717. {
  1718. CreateDate = DateTime.Now,
  1719. CreateMan = SysUserName + "-" + SysRealName,
  1720. OutSnNo = OldSnNum,
  1721. BackSnNo = NewSnNum,
  1722. ChangeNo = add.ChangeNo, //转换单号
  1723. ChangeId = add.Id, //转换记录Id
  1724. UserId = add.UserId, //创客
  1725. }).Entity;
  1726. db.SaveChanges();
  1727. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1728. if (IsSend == 1)
  1729. {
  1730. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1731. {
  1732. UserId = userForMakerCode.UserId, //接收创客
  1733. MsgType = 2,
  1734. Title = "坏机换新成功通知", //标题
  1735. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1736. CreateDate = DateTime.Now,
  1737. }));
  1738. }
  1739. }
  1740. }
  1741. //仓库坏机换新
  1742. else
  1743. {
  1744. if (string.IsNullOrEmpty(StoreCode))
  1745. {
  1746. return "请输入仓库编号";
  1747. }
  1748. if (string.IsNullOrEmpty(OldSn))
  1749. {
  1750. return "请输入坏机SN";
  1751. }
  1752. if (string.IsNullOrEmpty(NewSn))
  1753. {
  1754. return "请输入新机SN";
  1755. }
  1756. if (string.IsNullOrEmpty(FromStoreNo))
  1757. {
  1758. return "请输入新机发货仓库编号";
  1759. }
  1760. if (string.IsNullOrEmpty(BackStoreNo))
  1761. {
  1762. return "请输入坏机退回仓库编号";
  1763. }
  1764. OldSnList = OldSn.Split('\n');
  1765. NewSnList = NewSn.Split('\n');
  1766. if (OldSnList.Length != NewSnList.Length)
  1767. {
  1768. return "原机具SN数量和新机具SN数量不一致";
  1769. }
  1770. for (int i = 0; i < OldSnList.Length; i++)
  1771. {
  1772. string OldSnNum = OldSnList[i];
  1773. string NewSnNum = NewSnList[i];
  1774. StoreHouse store = new StoreHouse();
  1775. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  1776. if (storeForBadCode.StoreId > 0)
  1777. {
  1778. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  1779. }
  1780. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1781. if (storeForCodeFrom.StoreId == 0)
  1782. {
  1783. return "您输入的新机发货仓库编号不存在";
  1784. }
  1785. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1786. if (storeForCodeBack.StoreId == 0)
  1787. {
  1788. return "您输入的坏机退回仓库编号不存在";
  1789. }
  1790. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1791. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1792. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  1793. if (oldpos.Id == 0)
  1794. {
  1795. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  1796. }
  1797. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  1798. if (newpos.Id == 0)
  1799. {
  1800. return "您输入的新机SN不存在或不满足条件";
  1801. }
  1802. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1803. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1804. {
  1805. return "您输入的新机发货仓库不符新机机具对应品牌";
  1806. }
  1807. if (newpos.StoreId != storeFrom.Id)
  1808. {
  1809. return "您输入的新机SN不在新机发货仓库";
  1810. }
  1811. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1812. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1813. {
  1814. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1815. }
  1816. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1817. if (brandInfo.Name.Contains("大POS"))
  1818. {
  1819. amount = 300;
  1820. }
  1821. if (brandInfo.Name.Contains("电签"))
  1822. {
  1823. amount = 200;
  1824. }
  1825. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1826. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1827. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1828. // storeUserAcount.ValidAmount += amount;
  1829. storeFromUserAcount.ValidAmount += amount;
  1830. storeBackUserAcount.ValidAmount -= amount;
  1831. newpos.StoreId = oldpos.StoreId;
  1832. newpos.BuyUserId = oldpos.BuyUserId;
  1833. newpos.UserId = oldpos.UserId;
  1834. newpos.LeaderUserId = oldpos.LeaderUserId;
  1835. newpos.PreUserId = oldpos.PreUserId;
  1836. newpos.IsFirst = oldpos.IsFirst;
  1837. newpos.TransferTime = oldpos.TransferTime;
  1838. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  1839. {
  1840. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  1841. }
  1842. oldpos.StoreId = storeBack.Id;
  1843. oldpos.QueryCount = 0;
  1844. oldpos.UpdateDate = null;
  1845. oldpos.ActivityList = null;
  1846. oldpos.SeoKeyword = null;
  1847. oldpos.SeoDescription = null;
  1848. oldpos.OrderId = 0;
  1849. oldpos.RecycEndDate = null;
  1850. oldpos.RecycBackCount = 0;
  1851. oldpos.PrizeParams = null;
  1852. oldpos.ScanQrTrade = 0;
  1853. oldpos.BindMerchantId = 0;
  1854. oldpos.CreditTrade = 0;
  1855. oldpos.DebitCardTrade = 0;
  1856. oldpos.IsVip = 0;
  1857. oldpos.UserNav = null;
  1858. oldpos.TransferTime = null;
  1859. oldpos.IsPurchase = 0;
  1860. oldpos.Detail = null;
  1861. oldpos.BindingTime = null;
  1862. oldpos.BindingState = 0;
  1863. oldpos.ActivationTime = null;
  1864. oldpos.ActivationState = 0;
  1865. oldpos.LeaderUserId = 0;
  1866. oldpos.PreUserId = 0;
  1867. oldpos.IsFirst = 0;
  1868. oldpos.DownFeeMan = null;
  1869. oldpos.DownFeeFlag = 0;
  1870. oldpos.DownFeeDate = null;
  1871. oldpos.UpFeeMan = null;
  1872. oldpos.UpFeeFlag = 0;
  1873. oldpos.UpFeeDate = null;
  1874. oldpos.OpReserve1 = 0;
  1875. oldpos.OpReserve2 = 0;
  1876. oldpos.OpReserve3 = 0;
  1877. oldpos.OpId = 0;
  1878. oldpos.RecycStartDate = null;
  1879. oldpos.SourcePosSn = null;
  1880. oldpos.BuyUserId = 0;
  1881. oldpos.UserId = 0;
  1882. oldpos.Status = -1;
  1883. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  1884. db.SaveChanges();
  1885. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1886. {
  1887. CreateDate = DateTime.Now,
  1888. CreateMan = SysUserName + "-" + SysRealName,
  1889. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1890. OutStoreId = storeFrom.Id,
  1891. BackStoreId = storeBack.Id,
  1892. OutProductType = newpos.BrandId,
  1893. BackProductType = oldpos.BrandId,
  1894. UserId = store.UserId, //创客
  1895. }).Entity;
  1896. db.SaveChanges();
  1897. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1898. {
  1899. CreateDate = DateTime.Now,
  1900. CreateMan = SysUserName + "-" + SysRealName,
  1901. OutSnNo = OldSnNum,
  1902. BackSnNo = NewSnNum,
  1903. ChangeNo = add.ChangeNo, //转换单号
  1904. ChangeId = add.Id, //转换记录Id
  1905. UserId = add.UserId, //创客
  1906. }).Entity;
  1907. db.SaveChanges();
  1908. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1909. if (IsSend == 1)
  1910. {
  1911. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1912. {
  1913. UserId = store.UserId, //接收创客
  1914. MsgType = 2,
  1915. Title = "坏机换新成功通知", //标题
  1916. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1917. CreateDate = DateTime.Now,
  1918. }));
  1919. }
  1920. }
  1921. }
  1922. // for (int i = 0; i < OldSnList.Length; i++)
  1923. // {
  1924. // string OldSnNum = OldSnList[i];
  1925. // string NewSnNum = NewSnList[i];
  1926. // StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1927. // MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1928. // MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1929. // StoreHouse oldStore = new StoreHouse();
  1930. // PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0);
  1931. // if (storeForCode.StoreId > 0)
  1932. // {
  1933. // StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId);
  1934. // if (Convert.ToInt32(store.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1935. // {
  1936. // return "您输入的仓库不符机具对应品牌";
  1937. // }
  1938. // oldStore = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId);
  1939. // oldpos.Status = -1;
  1940. // oldpos.StoreId = store.Id;
  1941. // }
  1942. // if (oldpos == null)
  1943. // {
  1944. // return "原机具SN不正确或者不符合换机条件";
  1945. // }
  1946. // PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BuyUserId == 0 && m.UserId == 0 && m.BindingState == 0);
  1947. // if (newpos == null)
  1948. // {
  1949. // return "新机具SN不正确或者不为仓库机";
  1950. // }
  1951. // if (oldpos.BrandId != newpos.BrandId)
  1952. // {
  1953. // return "新机具和旧机具品牌不相同";
  1954. // }
  1955. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1956. // if (brandInfo.Name.Contains("大POS"))
  1957. // {
  1958. // amount = 300;
  1959. // }
  1960. // if (brandInfo.Name.Contains("电签"))
  1961. // {
  1962. // amount = 200;
  1963. // }
  1964. // var storehouse = db.StoreHouse.FirstOrDefault(m => m.Id == newpos.StoreId) ?? new StoreHouse();
  1965. // storehouse.LaveNum -= 1;
  1966. // var userAcount = db.UserAccount.FirstOrDefault(m => m.Id == storehouse.UserId) ?? new UserAccount();
  1967. // if (oldpos.StoreId != newpos.StoreId)
  1968. // {
  1969. // userAcount.ValidAmount += amount;
  1970. // newpos.StoreId = oldpos.StoreId;
  1971. // newpos.BuyUserId = oldpos.BuyUserId;
  1972. // newpos.UserId = oldpos.UserId;
  1973. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1974. // newpos.PreUserId = oldpos.PreUserId;
  1975. // newpos.IsFirst = oldpos.IsFirst;
  1976. // newpos.TransferTime = oldpos.TransferTime;
  1977. // }
  1978. // else
  1979. // {
  1980. // newpos.BuyUserId = oldpos.BuyUserId;
  1981. // newpos.UserId = oldpos.UserId;
  1982. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1983. // newpos.PreUserId = oldpos.PreUserId;
  1984. // newpos.IsFirst = oldpos.IsFirst;
  1985. // newpos.TransferTime = oldpos.TransferTime;
  1986. // }
  1987. // db.SaveChanges();
  1988. // var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1989. // var newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1990. // var UserId = 0;
  1991. // if (oldpos.BuyUserId == 0)
  1992. // {
  1993. // UserId = oldStore.UserId;
  1994. // }
  1995. // else
  1996. // {
  1997. // UserId = oldpos.BuyUserId;
  1998. // }
  1999. // BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  2000. // {
  2001. // CreateDate = DateTime.Now,
  2002. // CreateMan = SysUserName + "-" + SysRealName,
  2003. // ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  2004. // UserId = UserId, //创客
  2005. // }).Entity;
  2006. // db.SaveChanges();
  2007. // BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  2008. // {
  2009. // CreateDate = DateTime.Now,
  2010. // CreateMan = SysUserName + "-" + SysRealName,
  2011. // OutSnNo = OldSnNum,
  2012. // BackSnNo = NewSnNum,
  2013. // ChangeNo = add.ChangeNo, //转换单号
  2014. // ChangeId = add.Id, //转换记录Id
  2015. // UserId = add.UserId, //创客
  2016. // }).Entity;
  2017. // db.SaveChanges();
  2018. // if (IsSend == 1)
  2019. // {
  2020. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2021. // {
  2022. // UserId = UserId, //接收创客
  2023. // MsgType = 2,
  2024. // Title = "坏机换新成功通知", //标题
  2025. // Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为您换为" + newPosBrand.Name + "SN:" + NewSn + "。",
  2026. // CreateDate = DateTime.Now,
  2027. // }));
  2028. // }
  2029. // }
  2030. foreach (string sub in opData)
  2031. {
  2032. string[] datalist = sub.Split(":");
  2033. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  2034. }
  2035. return "success";
  2036. }
  2037. #endregion
  2038. // #region 机具解绑
  2039. // public IActionResult Unbind(string right)
  2040. // {
  2041. // ViewBag.RightInfo = RightInfo;
  2042. // ViewBag.right = right;
  2043. // return View();
  2044. // }
  2045. // [HttpPost]
  2046. // public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  2047. // {
  2048. // if (string.IsNullOrEmpty(PosSn))
  2049. // {
  2050. // return "请输入机具SN";
  2051. // }
  2052. // if (string.IsNullOrEmpty(MakerCode))
  2053. // {
  2054. // return "请输入创客编号";
  2055. // }
  2056. // MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  2057. // if (forSnNo == null)
  2058. // {
  2059. // return "机具SN不存在";
  2060. // }
  2061. // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  2062. // if (pos == null)
  2063. // {
  2064. // return "机具SN不存在";
  2065. // }
  2066. // if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  2067. // {
  2068. // return "请输入商户编号";
  2069. // }
  2070. // UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2071. // if (forMakerCode == null)
  2072. // {
  2073. // return "创客不存在";
  2074. // }
  2075. // MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2076. // if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  2077. // {
  2078. // return "商户编号不存在";
  2079. // }
  2080. // if (pos.BuyUserId != forMakerCode.UserId)
  2081. // {
  2082. // return "机具SN和创客不匹配";
  2083. // }
  2084. // if (pos.ActivationState == 1)
  2085. // {
  2086. // return "机具已激活,不能解绑";
  2087. // }
  2088. // if (pos.BuyUserId == 0)
  2089. // {
  2090. // return "机具是仓库机,不支持解绑";
  2091. // }
  2092. // if (pos.BindingState == 0)
  2093. // {
  2094. // return "机具未绑定,不支持解绑";
  2095. // }
  2096. // if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  2097. // {
  2098. // return "机具绑定已超过30天,不支持解绑";
  2099. // }
  2100. // if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
  2101. // {
  2102. // return "该机具已交易,无法解绑";
  2103. // }
  2104. // if (forMerNo != null)
  2105. // {
  2106. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2107. // if (merchant != null)
  2108. // {
  2109. // //机具解绑删除客小爽企业版对应数据
  2110. // var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2111. // if (merInfo != null)
  2112. // {
  2113. // db.BusinessPartnerMerchant.Remove(merInfo);
  2114. // }
  2115. // var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2116. // if (posInfo != null)
  2117. // {
  2118. // db.BusinessPartnerPos.Remove(posInfo);
  2119. // }
  2120. // db.PosMerchantInfo.Remove(merchant);
  2121. // }
  2122. // db.MachineForMerNo.Remove(forMerNo);
  2123. // db.SaveChanges();
  2124. // }
  2125. // db.MachineUnBind.Add(new MachineUnBind()
  2126. // {
  2127. // CreateDate = DateTime.Now,
  2128. // SeoTitle = SysUserName + "-" + SysRealName,
  2129. // MerchantId = pos.BindMerchantId,
  2130. // AuditDate = DateTime.Now,
  2131. // AuditDesc = "平台操作解绑",
  2132. // AuditStatus = 1,
  2133. // SnNo = pos.PosSn,
  2134. // BrandId = pos.BrandId,
  2135. // UserId = pos.BuyUserId,
  2136. // ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2137. // });
  2138. // pos.BindMerchantId = 0;
  2139. // pos.BindingState = 0;
  2140. // pos.BindingTime = DateTime.Parse("1900-01-01");
  2141. // pos.UserId = pos.BuyUserId;
  2142. // string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2143. // db.SaveChanges();
  2144. // PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2145. // if (IsSend == 1)
  2146. // {
  2147. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2148. // {
  2149. // UserId = pos.BuyUserId, //接收创客
  2150. // MsgType = 2,
  2151. // Title = "解绑成功通知", //标题
  2152. // Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2153. // CreateDate = DateTime.Now,
  2154. // }));
  2155. // }
  2156. // return "success";
  2157. // }
  2158. // #endregion
  2159. #region 机具解绑
  2160. public IActionResult Unbind(string right)
  2161. {
  2162. ViewBag.RightInfo = RightInfo;
  2163. ViewBag.right = right;
  2164. return View();
  2165. }
  2166. [HttpPost]
  2167. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  2168. {
  2169. if (string.IsNullOrEmpty(PosSn))
  2170. {
  2171. return "请输入机具SN";
  2172. }
  2173. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  2174. if (forSnNo == null)
  2175. {
  2176. return "机具SN不存在";
  2177. }
  2178. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  2179. if (pos == null)
  2180. {
  2181. return "机具SN不存在";
  2182. }
  2183. if (pos.ActivationState == 1)
  2184. {
  2185. return "机具已激活,不能解绑";
  2186. }
  2187. if (pos.BuyUserId == 0)
  2188. {
  2189. return "机具是仓库机,不支持解绑";
  2190. }
  2191. if (pos.BindingState == 0)
  2192. {
  2193. return "机具未绑定,不支持解绑";
  2194. }
  2195. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  2196. {
  2197. return "机具绑定已超过30天,不支持解绑";
  2198. }
  2199. if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
  2200. {
  2201. return "该机具已交易,无法解绑";
  2202. }
  2203. if (pos.BrandId != 10 || pos.BrandId != 11)
  2204. {
  2205. if (string.IsNullOrEmpty(MakerCode))
  2206. {
  2207. return "请输入创客编号";
  2208. }
  2209. // if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  2210. if (string.IsNullOrEmpty(MerNo))
  2211. {
  2212. return "请输入商户编号";
  2213. }
  2214. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2215. if (forMakerCode == null)
  2216. {
  2217. return "创客不存在";
  2218. }
  2219. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2220. // if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  2221. if (forMerNo == null)
  2222. {
  2223. return "商户编号不存在";
  2224. }
  2225. if (pos.BuyUserId != forMakerCode.UserId)
  2226. {
  2227. return "机具SN和创客不匹配";
  2228. }
  2229. if (forMerNo != null)
  2230. {
  2231. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2232. if (merchant != null)
  2233. {
  2234. //机具解绑删除客小爽企业版对应数据
  2235. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2236. if (merInfo != null)
  2237. {
  2238. db.BusinessPartnerMerchant.Remove(merInfo);
  2239. }
  2240. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2241. if (posInfo != null)
  2242. {
  2243. db.BusinessPartnerPos.Remove(posInfo);
  2244. }
  2245. db.PosMerchantInfo.Remove(merchant);
  2246. }
  2247. db.MachineForMerNo.Remove(forMerNo);
  2248. db.SaveChanges();
  2249. }
  2250. }
  2251. else
  2252. {
  2253. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  2254. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2255. if (forMerNo != null && posMerchantInfo != null)
  2256. {
  2257. //机具解绑删除客小爽企业版对应数据
  2258. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == posMerchantInfo.Id);
  2259. if (merInfo != null)
  2260. {
  2261. db.BusinessPartnerMerchant.Remove(merInfo);
  2262. }
  2263. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2264. if (posInfo != null)
  2265. {
  2266. db.BusinessPartnerPos.Remove(posInfo);
  2267. }
  2268. db.PosMerchantInfo.Remove(posMerchantInfo);
  2269. db.MachineForMerNo.Remove(forMerNo);
  2270. db.SaveChanges();
  2271. }
  2272. }
  2273. db.MachineUnBind.Add(new MachineUnBind()
  2274. {
  2275. CreateDate = DateTime.Now,
  2276. SeoTitle = SysUserName + "-" + SysRealName,
  2277. MerchantId = pos.BindMerchantId,
  2278. AuditDate = DateTime.Now,
  2279. AuditDesc = "平台操作解绑",
  2280. AuditStatus = 1,
  2281. SnNo = pos.PosSn,
  2282. BrandId = pos.BrandId,
  2283. UserId = pos.BuyUserId,
  2284. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2285. });
  2286. pos.BindMerchantId = 0;
  2287. pos.BindingState = 0;
  2288. pos.BindingTime = DateTime.Parse("1900-01-01");
  2289. pos.UserId = pos.BuyUserId;
  2290. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2291. db.SaveChanges();
  2292. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2293. if (IsSend == 1)
  2294. {
  2295. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2296. {
  2297. UserId = pos.BuyUserId, //接收创客
  2298. MsgType = 2,
  2299. Title = "解绑成功通知", //标题
  2300. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2301. CreateDate = DateTime.Now,
  2302. }));
  2303. }
  2304. return "success";
  2305. }
  2306. #endregion
  2307. #region 通过券码修改盟主标记
  2308. public IActionResult ChangeSignQuan(string right)
  2309. {
  2310. ViewBag.RightInfo = RightInfo;
  2311. ViewBag.right = right;
  2312. return View();
  2313. }
  2314. [HttpPost]
  2315. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2316. {
  2317. if (string.IsNullOrEmpty(Coupons))
  2318. {
  2319. return "请输入机具券码,多个券码用回车分隔";
  2320. }
  2321. if (string.IsNullOrEmpty(MakerCode))
  2322. {
  2323. return "请输入创客编号";
  2324. }
  2325. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2326. if (forMakerCode == null)
  2327. {
  2328. return "创客不存在";
  2329. }
  2330. string[] SnList = Coupons.Split('\n');
  2331. foreach (var item in SnList)
  2332. {
  2333. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2334. if (coupos == null)
  2335. {
  2336. return "机具券不存在";
  2337. }
  2338. else
  2339. {
  2340. coupos.LeaderUserId = forMakerCode.UserId;
  2341. }
  2342. }
  2343. db.SaveChanges();
  2344. return "success";
  2345. }
  2346. #endregion
  2347. #region 通过机具SN修改盟主标记
  2348. public IActionResult ChangeSignSn(string right)
  2349. {
  2350. ViewBag.RightInfo = RightInfo;
  2351. ViewBag.right = right;
  2352. return View();
  2353. }
  2354. [HttpPost]
  2355. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2356. {
  2357. if (string.IsNullOrEmpty(PosSn))
  2358. {
  2359. return "请输入机具SN,多个SN用回车分隔";
  2360. }
  2361. if (string.IsNullOrEmpty(MakerCode))
  2362. {
  2363. return "请输入创客编号";
  2364. }
  2365. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2366. if (forMakerCode == null)
  2367. {
  2368. return "创客不存在";
  2369. }
  2370. string[] SnList = PosSn.Split('\n');
  2371. foreach (var item in SnList)
  2372. {
  2373. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2374. if (pos == null)
  2375. {
  2376. return "该机具不存在";
  2377. }
  2378. else
  2379. {
  2380. pos.LeaderUserId = forMakerCode.UserId;
  2381. }
  2382. }
  2383. db.SaveChanges();
  2384. return "success";
  2385. }
  2386. #endregion
  2387. #region 机具循环列表
  2388. /// <summary>
  2389. /// 根据条件查询机具循环列表
  2390. /// </summary>
  2391. /// <returns></returns>
  2392. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2393. {
  2394. ViewBag.RightInfo = RightInfo;
  2395. ViewBag.right = right;
  2396. ViewBag.SwapSnExpand = SwapSnExpand;
  2397. ViewBag.SnNos = SnNos;
  2398. return View();
  2399. }
  2400. #endregion
  2401. #region 根据条件查询机具循环列表
  2402. /// <summary>
  2403. /// 机具循环列表
  2404. /// </summary>
  2405. /// <returns></returns>
  2406. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2407. {
  2408. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2409. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2410. Fields.Add("SnNos", "1"); //发货机具SN
  2411. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2412. if (!string.IsNullOrEmpty(SwapSnExpand))
  2413. {
  2414. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2415. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2416. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2417. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2418. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2419. for (int i = 0; i < SnNoList.Length; i++)
  2420. {
  2421. Dictionary<string, object> data = new Dictionary<string, object>();
  2422. data["ApplyNo"] = apply.ApplyNo;
  2423. data["OrderNo"] = order.OrderNo;
  2424. data["MakerCode"] = user.MakerCode;
  2425. data["RealName"] = user.RealName;
  2426. if (SnNoList.Length > i)
  2427. {
  2428. string SourceSn = SnNoList[i].Split(':')[0];
  2429. data["ComeSn"] = SnNoList[i];
  2430. data["ComeSnParam"] = SourceSn;
  2431. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2432. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2433. if (pos.LeaderUserId > 0)
  2434. {
  2435. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2436. data["ComeSnMakerCode"] = leader.MakerCode;
  2437. data["ComeSnRealName"] = leader.RealName;
  2438. }
  2439. }
  2440. if (OrderSnNo.Length > i)
  2441. {
  2442. string SendSn = OrderSnNo[i];
  2443. data["SendSn"] = OrderSnNo[i];
  2444. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2445. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2446. if (pos.LeaderUserId > 0)
  2447. {
  2448. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2449. data["SendSnMakerCode"] = leader.MakerCode;
  2450. data["SendSnRealName"] = leader.RealName;
  2451. }
  2452. }
  2453. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2454. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2455. dataList.Add(data);
  2456. }
  2457. }
  2458. else if (!string.IsNullOrEmpty(SnNos))
  2459. {
  2460. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2461. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2462. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2463. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2464. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2465. for (int i = 0; i < OrderSnNo.Length; i++)
  2466. {
  2467. Dictionary<string, object> data = new Dictionary<string, object>();
  2468. data["ApplyNo"] = apply.ApplyNo;
  2469. data["OrderNo"] = order.OrderNo;
  2470. data["MakerCode"] = user.MakerCode;
  2471. data["RealName"] = user.RealName;
  2472. if (SnNoList.Length > i)
  2473. {
  2474. string SourceSn = SnNoList[i].Split(':')[0];
  2475. data["ComeSn"] = SnNoList[i];
  2476. data["ComeSnParam"] = SourceSn;
  2477. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2478. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2479. if (pos.LeaderUserId > 0)
  2480. {
  2481. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2482. data["ComeSnMakerCode"] = leader.MakerCode;
  2483. data["ComeSnRealName"] = leader.RealName;
  2484. }
  2485. }
  2486. if (OrderSnNo.Length > i)
  2487. {
  2488. string SendSn = OrderSnNo[i];
  2489. data["SendSn"] = OrderSnNo[i];
  2490. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2491. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2492. if (pos.LeaderUserId > 0)
  2493. {
  2494. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2495. data["SendSnMakerCode"] = leader.MakerCode;
  2496. data["SendSnRealName"] = leader.RealName;
  2497. }
  2498. }
  2499. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2500. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2501. dataList.Add(data);
  2502. }
  2503. }
  2504. Dictionary<string, object> obj = new Dictionary<string, object>();
  2505. obj.Add("code", 0);
  2506. obj.Add("msg", "");
  2507. obj.Add("count", dataList.Count);
  2508. obj.Add("data", dataList);
  2509. return Json(obj);
  2510. }
  2511. #endregion
  2512. #region 查询机具循环
  2513. /// <summary>
  2514. /// 根据条件查询机具来源机具和券码
  2515. /// </summary>
  2516. /// <returns></returns>
  2517. public IActionResult SourceLoop(string right, string SnNos)
  2518. {
  2519. ViewBag.RightInfo = RightInfo;
  2520. ViewBag.right = right;
  2521. ViewBag.SnNos = SnNos;
  2522. return View();
  2523. }
  2524. #endregion
  2525. #region 根据条件查询机具来源机具和券码
  2526. /// <summary>
  2527. /// 机具循环列表
  2528. /// </summary>
  2529. /// <returns></returns>
  2530. public string SourceLoopData(string SnNo, int page = 1, int limit = 30)
  2531. {
  2532. var result = "";
  2533. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  2534. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  2535. if (pos.Id == 0)
  2536. {
  2537. return "机具:" + SnNo + "不存在";
  2538. }
  2539. else
  2540. {
  2541. var stattime = pos.RecycStartDate == null ? "" : pos.RecycStartDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  2542. var endtime = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  2543. result += "循环开始时间:" + stattime + "\n";
  2544. result += "循环结束时间:" + endtime + "\n";
  2545. result += "来源机具/券:" + pos.SourcePosSn + "\n";
  2546. }
  2547. return result;
  2548. }
  2549. #endregion
  2550. #region 查询创客直推奖
  2551. public IActionResult Prize100(string right)
  2552. {
  2553. ViewBag.RightInfo = RightInfo;
  2554. ViewBag.right = right;
  2555. return View();
  2556. }
  2557. [HttpPost]
  2558. public Dictionary<string, string> Prize100Do(string MakerCode)
  2559. {
  2560. Dictionary<string, string> dic = new Dictionary<string, string>();
  2561. string result = "";
  2562. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2563. if (forMakerCode == null)
  2564. {
  2565. result += "创客编号不存在\n";
  2566. dic.Add("code", "1");
  2567. dic.Add("result", result);
  2568. return dic;
  2569. }
  2570. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2571. if (OrderCount == 0)
  2572. {
  2573. result += "该创客未下单\n";
  2574. dic.Add("code", "1");
  2575. dic.Add("result", result);
  2576. return dic;
  2577. }
  2578. if (OrderCount > 1)
  2579. {
  2580. result += "该创客已不是首笔下单\n";
  2581. dic.Add("code", "1");
  2582. dic.Add("result", result);
  2583. return dic;
  2584. }
  2585. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2586. if (order.PayStatus < 1)
  2587. {
  2588. result += "未付款\n";
  2589. dic.Add("code", "1");
  2590. dic.Add("result", result);
  2591. return dic;
  2592. }
  2593. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2594. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2595. result += "订单号:" + order.OrderNo + "\n";
  2596. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2597. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2598. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  2599. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2600. if (machineCount + ActiveCount >= 3)
  2601. {
  2602. string IsGet = "未发放";
  2603. int ToUserId = 0;
  2604. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2605. if (item == null)
  2606. {
  2607. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2608. DateTime end = order.PayDate.Value.AddMinutes(2);
  2609. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2610. }
  2611. if (item != null)
  2612. {
  2613. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2614. ToUserId = item.UserId;
  2615. dic.Add("code", "1");
  2616. }
  2617. else
  2618. {
  2619. dic.Add("id", order.Id.ToString());
  2620. dic.Add("code", "0");
  2621. }
  2622. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  2623. result += "是否发放:" + IsGet + "\n";
  2624. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2625. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  2626. }
  2627. else
  2628. {
  2629. result += "上级创客未满足条件\n兑换机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  2630. dic.Add("code", "1");
  2631. }
  2632. dic.Add("result", result);
  2633. return dic;
  2634. }
  2635. public string AddPrize100(int Id)
  2636. {
  2637. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  2638. if (order != null)
  2639. {
  2640. //机具券逻辑
  2641. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  2642. if (pro != null)
  2643. {
  2644. //推荐下单奖励
  2645. if (pro.ProductId == 10 || pro.ProductId == 11)
  2646. {
  2647. int OrderId = order.Id;
  2648. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  2649. if (!checkPrize)
  2650. {
  2651. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2652. if (user != null)
  2653. {
  2654. bool directPrize = false; //直推奖标记
  2655. int ParentUserId = user.ParentUserId;
  2656. // List<int> proids = new List<int>();
  2657. // proids.Add(10);
  2658. // proids.Add(11);
  2659. while (ParentUserId > 0)
  2660. {
  2661. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2662. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台兑换机
  2663. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2664. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2665. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2666. {
  2667. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2668. directPrize = true;
  2669. db.SaveChanges();
  2670. return "发放成功";
  2671. }
  2672. ParentUserId = puser.ParentUserId;
  2673. }
  2674. }
  2675. }
  2676. return "已发放,请勿重复发放";
  2677. }
  2678. }
  2679. }
  2680. return "操作失败";
  2681. }
  2682. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2683. {
  2684. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2685. if (account == null)
  2686. {
  2687. account = db.UserAccount.Add(new UserAccount()
  2688. {
  2689. Id = UserId,
  2690. UserId = UserId,
  2691. }).Entity;
  2692. db.SaveChanges();
  2693. }
  2694. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2695. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2696. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2697. account.BalanceAmount += 100 * Count;
  2698. account.TotalAmount += 100 * Count;
  2699. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2700. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2701. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2702. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2703. {
  2704. CreateDate = DateTime.Now,
  2705. UpdateDate = DateTime.Now,
  2706. UserId = UserId, //创客
  2707. ChangeType = 112, //变动类型
  2708. ChangeAmount = 100 * Count, //变更金额
  2709. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2710. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2711. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2712. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2713. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2714. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2715. QueryCount = OrderId,
  2716. }).Entity;
  2717. db.SaveChanges();
  2718. }
  2719. #endregion
  2720. #region 查询机具开机奖
  2721. public IActionResult OpenPrize(string right)
  2722. {
  2723. ViewBag.RightInfo = RightInfo;
  2724. ViewBag.right = right;
  2725. return View();
  2726. }
  2727. [HttpPost]
  2728. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2729. {
  2730. Dictionary<string, string> dic = new Dictionary<string, string>();
  2731. string result = "";
  2732. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2733. if (pos == null)
  2734. {
  2735. result += "机具SN号不存在\n";
  2736. dic.Add("code", "1");
  2737. dic.Add("result", result);
  2738. return dic;
  2739. }
  2740. if (pos.BindingState == 0)
  2741. {
  2742. result += "机具未绑定\n";
  2743. dic.Add("code", "1");
  2744. dic.Add("result", result);
  2745. return dic;
  2746. }
  2747. if (pos.ActivationState == 0)
  2748. {
  2749. result += "机具未激活\n";
  2750. dic.Add("code", "1");
  2751. dic.Add("result", result);
  2752. return dic;
  2753. }
  2754. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2755. if (merchant == null)
  2756. {
  2757. result += "商户不存在\n";
  2758. dic.Add("code", "1");
  2759. dic.Add("result", result);
  2760. return dic;
  2761. }
  2762. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2763. result += "机具号:" + PosSn + "\n";
  2764. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2765. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2766. string OpenUser10 = "未领取";
  2767. string OpenUser20 = "未领取";
  2768. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2769. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2770. if (openreward.Id > 0)
  2771. {
  2772. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2773. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2774. }
  2775. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2776. if (openreward.Id > 0)
  2777. {
  2778. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2779. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2780. }
  2781. result += "开机奖20:" + OpenUser20 + "\n";
  2782. // result += "开机奖10:" + OpenUser10 + "\n";
  2783. dic.Add("id", pos.Id.ToString());
  2784. dic.Add("code", "0");
  2785. dic.Add("result", result);
  2786. return dic;
  2787. }
  2788. public string AddOpenPrize(int Id)
  2789. {
  2790. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2791. if (pos == null)
  2792. {
  2793. return "机具未激活";
  2794. }
  2795. if (pos.BindingTime <= pos.TransferTime)
  2796. {
  2797. return "补录机,不能补发开机奖";
  2798. }
  2799. // if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2800. // {
  2801. // return "绑定已超过30天";
  2802. // }
  2803. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2804. if (ActPrize == 0)
  2805. {
  2806. return "机具无押金";
  2807. }
  2808. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2809. if (merchant == null)
  2810. {
  2811. return "商户不存在";
  2812. }
  2813. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2814. if (check)
  2815. {
  2816. return "开机奖励已发放,请勿重复操作";
  2817. }
  2818. // 从机具所属人上级开始分开机奖励
  2819. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2820. if (user != null)
  2821. {
  2822. if (!string.IsNullOrEmpty(user.ParentNav))
  2823. {
  2824. decimal Prize = 20;
  2825. List<string> PrizeFlag = new List<string>();
  2826. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2827. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2828. {
  2829. int UserId = int.Parse(ParentNavs[i]);
  2830. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2831. if (puser != null && Prize > 0)
  2832. {
  2833. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  2834. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2835. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2836. if (machineCount + ActiveCount + couponCount >= 3)
  2837. {
  2838. int pTopUserId = 0;
  2839. if (!string.IsNullOrEmpty(puser.ParentNav))
  2840. {
  2841. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2842. }
  2843. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2844. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2845. {
  2846. CreateDate = DateTime.Now,
  2847. UpdateDate = DateTime.Now,
  2848. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2849. TradeDate = pos.ActivationTime, //达标日期
  2850. UserId = puser.Id, //创客
  2851. BrandId = pos.BrandId, //品牌
  2852. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2853. MerchantId = pos.BindMerchantId, //商户
  2854. DirectUserId = merchant.UserId, //商户直属人
  2855. SnNo = pos.PosSn, //SN号
  2856. MerNo = merchant.KqMerNo, //渠道商户号
  2857. SnType = pos.PosSnType, //机具类型
  2858. StandardDate = pos.ActivationTime, //商户的激活日期
  2859. SnStoreId = pos.StoreId, //SN仓库
  2860. MerBuddyType = puser.MerchantType, //商户创客类型
  2861. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2862. RewardTips = "开机奖励", //奖励描述
  2863. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2864. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2865. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2866. RewardDesc = "开机奖励", //奖励描述
  2867. TopUserId = pTopUserId, //顶级创客
  2868. SeoTitle = machineUser.RealName,
  2869. }).Entity;
  2870. db.OpenReward.Add(new OpenReward()
  2871. {
  2872. CreateDate = DateTime.Now,
  2873. UpdateDate = DateTime.Now,
  2874. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2875. TradeDate = DateTime.Now, //达标日期
  2876. UserId = puser.Id, //创客
  2877. BrandId = pos.BrandId, //品牌
  2878. RewardType = 2, //奖励类型
  2879. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2880. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2881. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2882. RewardDesc = "开机奖励", //奖励描述
  2883. TopUserId = pTopUserId, //顶级创客
  2884. });
  2885. string IdBrand = puser.Id + "_" + pos.BrandId;
  2886. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2887. if (userData == null)
  2888. {
  2889. userData = db.UserMachineData.Add(new UserMachineData()
  2890. {
  2891. IdBrand = IdBrand,
  2892. }).Entity;
  2893. db.SaveChanges();
  2894. }
  2895. userData.OpenProfit += Prize;
  2896. db.SaveChanges();
  2897. //账户入库
  2898. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2899. if (account == null)
  2900. {
  2901. account = db.UserAccount.Add(new UserAccount()
  2902. {
  2903. Id = puser.Id,
  2904. UserId = puser.Id,
  2905. }).Entity;
  2906. db.SaveChanges();
  2907. }
  2908. //收支明细入库
  2909. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2910. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2911. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2912. account.BalanceAmount += Prize;
  2913. account.TotalAmount += Prize;
  2914. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2915. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2916. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2917. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2918. {
  2919. CreateDate = DateTime.Now,
  2920. UpdateDate = DateTime.Now,
  2921. UserId = puser.Id, //创客
  2922. ChangeType = 50, //变动类型
  2923. ProductType = pos.BrandId, //产品类型
  2924. ChangeAmount = Prize, //变更金额
  2925. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2926. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2927. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2928. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2929. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2930. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2931. }).Entity;
  2932. db.SaveChanges();
  2933. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  2934. string dateString = DateTime.Now.ToString("yyyyMMdd");
  2935. string monthString = DateTime.Now.ToString("yyyyMM");
  2936. // 开机奖励列表
  2937. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  2938. if (!dates.Contains(dateString))
  2939. {
  2940. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  2941. }
  2942. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  2943. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  2944. if (!months.Contains(monthString))
  2945. {
  2946. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  2947. }
  2948. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  2949. // 开机奖励详情
  2950. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  2951. //收支明细
  2952. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  2953. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  2954. Prize = 0;
  2955. PrizeFlag.Add(Prize.ToString("f0"));
  2956. }
  2957. }
  2958. }
  2959. string result = "";
  2960. // if (!PrizeFlag.Contains("20"))
  2961. // {
  2962. // result += "20元奖励未发,请检查上级是否满足条件\n";
  2963. // }
  2964. // if (!PrizeFlag.Contains("10"))
  2965. // {
  2966. // result += "10元奖励未发,请检查上级是否满足条件\n";
  2967. // }
  2968. if (string.IsNullOrEmpty(result))
  2969. {
  2970. return "发放成功";
  2971. }
  2972. return result;
  2973. }
  2974. }
  2975. db.Dispose();
  2976. return "操作失败";
  2977. }
  2978. #endregion
  2979. #region 查询机具流量费分佣
  2980. public IActionResult FluxPrize(string right)
  2981. {
  2982. ViewBag.RightInfo = RightInfo;
  2983. ViewBag.right = right;
  2984. return View();
  2985. }
  2986. [HttpPost]
  2987. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  2988. {
  2989. Dictionary<string, string> dic = new Dictionary<string, string>();
  2990. string result = "";
  2991. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2992. if (pos == null)
  2993. {
  2994. result += "机具SN号不存在\n";
  2995. dic.Add("code", "1");
  2996. dic.Add("result", result);
  2997. return dic;
  2998. }
  2999. if (pos.BindingState == 0)
  3000. {
  3001. result += "机具未绑定\n";
  3002. dic.Add("code", "1");
  3003. dic.Add("result", result);
  3004. return dic;
  3005. }
  3006. if (pos.ActivationState == 0)
  3007. {
  3008. result += "机具未激活\n";
  3009. dic.Add("code", "1");
  3010. dic.Add("result", result);
  3011. return dic;
  3012. }
  3013. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3014. if (merchant == null)
  3015. {
  3016. result += "商户不存在\n";
  3017. dic.Add("code", "1");
  3018. dic.Add("result", result);
  3019. return dic;
  3020. }
  3021. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3022. result += "机具号:" + PosSn + "\n";
  3023. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  3024. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  3025. string FluxGet6 = "未领取";
  3026. string FluxUser6 = "";
  3027. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  3028. if (flux.Id > 0)
  3029. {
  3030. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  3031. FluxGet6 = "已领取(金额:" + flux.FluxFeeAmt + ",领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  3032. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3033. }
  3034. result += "流量费:" + FluxGet6 + "\n";
  3035. result += "流量费发放对象:" + FluxUser6 + "\n";
  3036. dic.Add("id", pos.Id.ToString());
  3037. dic.Add("code", "0");
  3038. dic.Add("result", result);
  3039. return dic;
  3040. }
  3041. public string AddFluxPrize(int Id)
  3042. {
  3043. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  3044. if (pos == null)
  3045. {
  3046. return "机具未激活";
  3047. }
  3048. // if (pos.BindingTime < DateTime.Now.AddDays(-30))
  3049. // {
  3050. // return "绑定已超过30天";
  3051. // }
  3052. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  3053. if (ActPrize == 0)
  3054. {
  3055. return "机具无押金";
  3056. }
  3057. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3058. if (merchant == null)
  3059. {
  3060. return "商户不存在";
  3061. }
  3062. if (pos.BrandId == 6)
  3063. {
  3064. return "立刷不支持流量费分佣";
  3065. }
  3066. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  3067. {
  3068. return "无押金机,不支持流量费分佣";
  3069. }
  3070. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  3071. if (check)
  3072. {
  3073. return "流量费奖励已发放,请勿重复操作";
  3074. }
  3075. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  3076. if (trade != null)
  3077. {
  3078. try
  3079. {
  3080. string OrderNo = trade.TradeSerialNo; //单号
  3081. DateTime TradeDate = trade.CreateDate.Value;
  3082. string TradeMonth = TradeDate.ToString("yyyyMM");
  3083. decimal FeeAmount = trade.FeeAmount; //流量费
  3084. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  3085. {
  3086. FeeAmount = FeeAmount / 100;
  3087. }
  3088. string TradeSnNo = trade.TradeSnNo; //机具SN
  3089. decimal FluxProfit = 0;
  3090. if (trade.ProductType == "1" && FeeAmount == 60)
  3091. {
  3092. FluxProfit = 24;
  3093. }
  3094. else if (trade.ProductType == "7" && FeeAmount == 46)
  3095. {
  3096. FluxProfit = 10;
  3097. }
  3098. else if (trade.ProductType != "1" && FeeAmount == 48)
  3099. {
  3100. FluxProfit = 12;
  3101. }
  3102. if (FluxProfit > 0)
  3103. {
  3104. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3105. int GetUserId = user.Id;
  3106. int TopUserId = 0;
  3107. string ParentNav = user.ParentNav;
  3108. if (!string.IsNullOrEmpty(ParentNav))
  3109. {
  3110. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  3111. if (ParentNavList.Length > 1)
  3112. {
  3113. TopUserId = int.Parse(ParentNavList[1]);
  3114. }
  3115. else if (ParentNavList.Length == 1)
  3116. {
  3117. TopUserId = int.Parse(ParentNavList[0]);
  3118. }
  3119. }
  3120. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  3121. if (fluxProfit == null)
  3122. {
  3123. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  3124. {
  3125. CreateDate = DateTime.Now,
  3126. UpdateDate = DateTime.Now,
  3127. UserId = GetUserId, //创客
  3128. BrandId = pos.BrandId,
  3129. TopUserId = TopUserId, //顶级创客
  3130. TradeMonth = TradeMonth, //交易月
  3131. MerUserType = user.MerchantType, //商户创客类型
  3132. Remark = "流量卡分佣", //备注
  3133. }).Entity;
  3134. db.SaveChanges();
  3135. }
  3136. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  3137. db.FluxProfitDetail.Add(new FluxProfitDetail()
  3138. {
  3139. CreateDate = DateTime.Now,
  3140. UpdateDate = DateTime.Now,
  3141. RecordNo = OrderNo, //单号
  3142. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  3143. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  3144. TradeMonth = TradeMonth, //交易月
  3145. UserId = GetUserId, //创客
  3146. MerchantId = pos.BindMerchantId, //商户
  3147. MerchantUserId = pos.UserId, //商户直属人
  3148. MerNo = merchant.KqMerNo, //渠道商户编号
  3149. SnNo = pos.PosSn, //渠道SN号
  3150. FluxOrderNo = OrderNo, //流量扣费单号
  3151. TradeOrderNo = OrderNo, //交易流水号
  3152. TradeAmt = trade.TradeAmount, //商户交易额
  3153. FluxFeeAmt = FeeAmount, //流量费
  3154. FluxProfitAmt = FluxProfit, //流量分润总金额
  3155. PosType = pos.PosSnType.ToString(), //POS类型
  3156. Remark = "流量卡分佣", //备注
  3157. BrandId = pos.BrandId, //品牌
  3158. TopUserId = TopUserId, //顶级创客
  3159. MerUserType = user.MerchantType, //商户创客类型
  3160. });
  3161. string IdBrand = user.Id + "_" + pos.BrandId;
  3162. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  3163. if (userData == null)
  3164. {
  3165. userData = db.UserMachineData.Add(new UserMachineData()
  3166. {
  3167. IdBrand = IdBrand,
  3168. }).Entity;
  3169. db.SaveChanges();
  3170. }
  3171. userData.FluxProfit += FluxProfit;
  3172. db.SaveChanges();
  3173. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  3174. if (account == null)
  3175. {
  3176. account = db.UserAccount.Add(new UserAccount()
  3177. {
  3178. Id = GetUserId,
  3179. UserId = GetUserId,
  3180. }).Entity;
  3181. db.SaveChanges();
  3182. }
  3183. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  3184. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  3185. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  3186. account.BalanceAmount += FluxProfit;
  3187. account.TotalAmount += FluxProfit;
  3188. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  3189. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  3190. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  3191. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  3192. {
  3193. CreateDate = DateTime.Now,
  3194. UpdateDate = DateTime.Now,
  3195. UserId = GetUserId, //创客
  3196. ChangeType = 60, //变动类型
  3197. ProductType = pos.BrandId, //产品类型
  3198. ChangeAmount = FluxProfit, //变更金额
  3199. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3200. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3201. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3202. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3203. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3204. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3205. }).Entity;
  3206. db.SaveChanges();
  3207. spdb.Dispose();
  3208. db.Dispose();
  3209. return "发放成功";
  3210. }
  3211. }
  3212. catch (Exception ex)
  3213. {
  3214. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  3215. }
  3216. }
  3217. spdb.Dispose();
  3218. db.Dispose();
  3219. return "操作失败";
  3220. }
  3221. #endregion
  3222. #region 设置立刷费率
  3223. public IActionResult LisFee(string right)
  3224. {
  3225. ViewBag.RightInfo = RightInfo;
  3226. ViewBag.right = right;
  3227. return View();
  3228. }
  3229. [HttpPost]
  3230. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  3231. {
  3232. if (string.IsNullOrEmpty(PosSns))
  3233. {
  3234. return "请输入机具号";
  3235. }
  3236. string result = SysUserName + "设置\n";
  3237. string[] PosSnList = PosSns.Split('\n');
  3238. int total = PosSnList.Length;
  3239. int index = 0;
  3240. foreach (string SubPosSn in PosSnList)
  3241. {
  3242. index += 1;
  3243. string PosSn = SubPosSn.Replace("\r", "");
  3244. result += PosSn + ":" + Fee + "\n";
  3245. if (Kind == "M5")
  3246. {
  3247. result += SetLiSFee(PosSn, Fee) + "\n";
  3248. }
  3249. else if (Kind == "N1")
  3250. {
  3251. result += SetLiSDeposit(PosSn, (int)Fee);
  3252. }
  3253. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  3254. }
  3255. result += "\n\n";
  3256. function.WriteLog(result, "设置立刷费率");
  3257. return result;
  3258. }
  3259. public string LisFeeProcess()
  3260. {
  3261. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  3262. }
  3263. #region 立刷
  3264. string LiSAgentId = "50814834";
  3265. 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=";
  3266. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  3267. public string LiSSign(string data)
  3268. {
  3269. var rsa = RSA.Create();
  3270. var key = Convert.FromBase64String(LiSPrivateKey);
  3271. var content = Encoding.UTF8.GetBytes(data);
  3272. rsa.ImportPkcs8PrivateKey(key, out _);
  3273. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  3274. return Convert.ToBase64String(result);
  3275. }
  3276. // 设置费率
  3277. public string SetLiSFee(string sn, decimal serviceFee)
  3278. {
  3279. Dictionary<string, object> dic = new Dictionary<string, object>();
  3280. dic.Add("agentId", LiSAgentId);
  3281. dic.Add("deviceSn", sn);
  3282. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3283. Dictionary<string, object> item = new Dictionary<string, object>();
  3284. item.Add("feeCalcType", "M5");
  3285. item.Add("fixed", "0");
  3286. item.Add("rate", serviceFee);
  3287. feeList.Add(item);
  3288. dic.Add("feeList", feeList);
  3289. dic.Add("signMethod", "02");
  3290. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  3291. string signstr = LiSSign(content);
  3292. dic.Add("signData", signstr);
  3293. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3294. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3295. return result;
  3296. }
  3297. // 设置押金
  3298. public string SetLiSDeposit(string sn, int serviceFee)
  3299. {
  3300. serviceFee = serviceFee * 100;
  3301. Dictionary<string, object> dic = new Dictionary<string, object>();
  3302. dic.Add("agentId", LiSAgentId);
  3303. dic.Add("deviceSn", sn);
  3304. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3305. Dictionary<string, object> item = new Dictionary<string, object>();
  3306. item.Add("feeCalcType", "N1");
  3307. item.Add("fixed", "1");
  3308. item.Add("rate", serviceFee);
  3309. feeList.Add(item);
  3310. dic.Add("feeList", feeList);
  3311. dic.Add("signMethod", "02");
  3312. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  3313. string signstr = LiSSign(content);
  3314. dic.Add("signData", signstr);
  3315. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3316. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3317. return result;
  3318. }
  3319. #endregion
  3320. #endregion
  3321. #region 查询商户型创客设置信息
  3322. public IActionResult SeeMerchantType(string right)
  3323. {
  3324. ViewBag.RightInfo = RightInfo;
  3325. ViewBag.right = right;
  3326. return View();
  3327. }
  3328. [HttpPost]
  3329. public string SeeMerchantTypeDo(string PosSn)
  3330. {
  3331. if (string.IsNullOrEmpty(PosSn))
  3332. {
  3333. return "请输入机具SN或者创客编号";
  3334. }
  3335. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3336. if (PosSn.StartsWith("K"))
  3337. {
  3338. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3339. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3340. if (check)
  3341. {
  3342. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3343. }
  3344. }
  3345. else
  3346. {
  3347. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3348. if (check)
  3349. {
  3350. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3351. }
  3352. }
  3353. if (pos.Id == 0)
  3354. {
  3355. return "查无信息";
  3356. }
  3357. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3358. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3359. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3360. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3361. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3362. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3363. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3364. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3365. string result = "";
  3366. result += "机具SN:" + pos.PosSn + "\n";
  3367. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3368. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3369. result += "商户编号:" + pos.MerNo + "\n";
  3370. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3371. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3372. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3373. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3374. result += "是否循环:" + RecycFlag + "\n";
  3375. return result;
  3376. }
  3377. #endregion
  3378. #region 三要素验证
  3379. public IActionResult CheckThreeElements(string right)
  3380. {
  3381. ViewBag.RightInfo = RightInfo;
  3382. ViewBag.right = right;
  3383. return View();
  3384. }
  3385. [HttpPost]
  3386. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3387. {
  3388. var host = "https://bankcard3c.shumaidata.com";
  3389. var path = "/bankcard3c";
  3390. var method = "GET";
  3391. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3392. if (string.IsNullOrEmpty(bankcard))
  3393. {
  3394. return "结算银行卡号";
  3395. }
  3396. if (string.IsNullOrEmpty(idcard))
  3397. {
  3398. return "身份证号";
  3399. }
  3400. if (string.IsNullOrEmpty(name))
  3401. {
  3402. return "真实姓名";
  3403. }
  3404. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3405. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3406. function.WriteLog(querys, "验证三要素日志");
  3407. String bodys = "";
  3408. String url = host + path;
  3409. HttpWebRequest httpRequest = null;
  3410. HttpWebResponse httpResponse = null;
  3411. if (0 < querys.Length)
  3412. {
  3413. url = url + "?" + querys;
  3414. }
  3415. if (host.Contains("https://"))
  3416. {
  3417. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3418. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3419. }
  3420. else
  3421. {
  3422. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3423. }
  3424. httpRequest.Method = method;
  3425. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3426. if (0 < bodys.Length)
  3427. {
  3428. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3429. using (Stream stream = httpRequest.GetRequestStream())
  3430. {
  3431. stream.Write(data, 0, data.Length);
  3432. }
  3433. }
  3434. try
  3435. {
  3436. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3437. }
  3438. catch (WebException ex)
  3439. {
  3440. httpResponse = (HttpWebResponse)ex.Response;
  3441. }
  3442. Stream st = httpResponse.GetResponseStream();
  3443. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3444. string result = reader.ReadToEnd();
  3445. JsonData jsonObj = JsonMapper.ToObject(result);
  3446. result = jsonObj["data"]["desc"].ToString();
  3447. function.WriteLog(result, "验证三要素日志");
  3448. function.WriteLog("\n\n", "验证三要素日志");
  3449. return result;
  3450. }
  3451. #endregion
  3452. #region 四要素验证
  3453. public IActionResult CheckFourElements(string right)
  3454. {
  3455. ViewBag.RightInfo = RightInfo;
  3456. ViewBag.right = right;
  3457. return View();
  3458. }
  3459. [HttpPost]
  3460. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3461. {
  3462. var host = "https://bankcard4c.shumaidata.com";
  3463. var path = "/bankcard4c";
  3464. var method = "GET";
  3465. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3466. if (string.IsNullOrEmpty(bankcard))
  3467. {
  3468. return "请输入结算银行卡号";
  3469. }
  3470. if (string.IsNullOrEmpty(idcard))
  3471. {
  3472. return "请输入身份证号";
  3473. }
  3474. if (string.IsNullOrEmpty(mobile))
  3475. {
  3476. return "请输入银行预留手机号";
  3477. }
  3478. if (string.IsNullOrEmpty(name))
  3479. {
  3480. return "请输入真实姓名";
  3481. }
  3482. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3483. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3484. function.WriteLog(querys, "验证四要素日志");
  3485. String bodys = "";
  3486. String url = host + path;
  3487. HttpWebRequest httpRequest = null;
  3488. HttpWebResponse httpResponse = null;
  3489. if (0 < querys.Length)
  3490. {
  3491. url = url + "?" + querys;
  3492. }
  3493. if (host.Contains("https://"))
  3494. {
  3495. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3496. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3497. }
  3498. else
  3499. {
  3500. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3501. }
  3502. httpRequest.Method = method;
  3503. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3504. if (0 < bodys.Length)
  3505. {
  3506. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3507. using (Stream stream = httpRequest.GetRequestStream())
  3508. {
  3509. stream.Write(data, 0, data.Length);
  3510. }
  3511. }
  3512. try
  3513. {
  3514. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3515. }
  3516. catch (WebException ex)
  3517. {
  3518. httpResponse = (HttpWebResponse)ex.Response;
  3519. }
  3520. Stream st = httpResponse.GetResponseStream();
  3521. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3522. string result = reader.ReadToEnd();
  3523. JsonData jsonObj = JsonMapper.ToObject(result);
  3524. result = jsonObj["data"]["desc"].ToString();
  3525. function.WriteLog(result, "验证四要素日志");
  3526. function.WriteLog("\n\n", "验证四要素日志");
  3527. return result;
  3528. }
  3529. #endregion
  3530. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3531. {
  3532. return true;
  3533. }
  3534. #region 根据机具号同步商户激活状态
  3535. public IActionResult SyncMerchantStatus(string right)
  3536. {
  3537. ViewBag.RightInfo = RightInfo;
  3538. ViewBag.right = right;
  3539. return View();
  3540. }
  3541. [HttpPost]
  3542. public string SyncMerchantStatusDo(string PosSn)
  3543. {
  3544. if (string.IsNullOrEmpty(PosSn))
  3545. {
  3546. return "请输入机具号";
  3547. }
  3548. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3549. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3550. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
  3551. if (posInfo.Id == 0)
  3552. {
  3553. return "机具" + PosSn + "不存在";
  3554. }
  3555. if (posMerchant.Id == 0)
  3556. {
  3557. return "机具绑定商户不存在";
  3558. }
  3559. else
  3560. {
  3561. posMerchant.ActiveStatus = 1;
  3562. posMerchant.UpdateDate = DateTime.Now;
  3563. posMerchant.MerStandardDate = posInfo.ActivationTime;
  3564. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
  3565. db.SaveChanges();
  3566. }
  3567. return "success";
  3568. }
  3569. #endregion
  3570. #region 根据机具号补发开机奖励
  3571. public IActionResult PosRewardReissued(string right)
  3572. {
  3573. ViewBag.RightInfo = RightInfo;
  3574. ViewBag.right = right;
  3575. return View();
  3576. }
  3577. [HttpPost]
  3578. public string PosRewardReissuedDo(string PosSn)
  3579. {
  3580. if (string.IsNullOrEmpty(PosSn))
  3581. {
  3582. return "请输入机具SN";
  3583. }
  3584. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3585. var PosId = "";
  3586. var error = "";
  3587. foreach (var item in PosSnList)
  3588. {
  3589. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3590. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3591. bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
  3592. if (checkExist)
  3593. {
  3594. error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
  3595. }
  3596. else
  3597. {
  3598. if (posInfo.Id > 0)
  3599. {
  3600. PosId += posInfo.Id + ",";
  3601. }
  3602. }
  3603. }
  3604. if (!string.IsNullOrEmpty(error))
  3605. {
  3606. return "Warning|" + error;
  3607. }
  3608. PosId = PosId.TrimEnd(',');
  3609. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
  3610. RedisDbconn.Instance.AddList("OpenRewardQueue", PosId);
  3611. return "success";
  3612. }
  3613. #endregion
  3614. #region 根据机具号设置费率
  3615. public IActionResult SetPosFee(string right)
  3616. {
  3617. ViewBag.RightInfo = RightInfo;
  3618. ViewBag.right = right;
  3619. return View();
  3620. }
  3621. [HttpPost]
  3622. public string SetPosFeeDo(string PosSn, string FeeType)
  3623. {
  3624. if (string.IsNullOrEmpty(PosSn))
  3625. {
  3626. return "请输入机具SN";
  3627. }
  3628. if (string.IsNullOrEmpty(FeeType))
  3629. {
  3630. return "请输入选择费率";
  3631. }
  3632. if (FeeType == "0")
  3633. {
  3634. FeeType = "0.6";
  3635. }
  3636. if (FeeType == "1")
  3637. {
  3638. FeeType = "0.63";
  3639. }
  3640. string[] PosSnList = PosSn.Split('\n');
  3641. var PosId = "";
  3642. var RecordId = "";
  3643. var error = "";
  3644. foreach (var item in PosSnList)
  3645. {
  3646. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3647. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3648. if (posInfo.Id > 0)
  3649. {
  3650. var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  3651. {
  3652. Sort = posInfo.BrandId,
  3653. CreateDate = DateTime.Now,
  3654. PosId = posInfo.Id,
  3655. PosSn = posInfo.PosSn,
  3656. PosUserId = posInfo.UserId,
  3657. MerchantId = posInfo.BindMerchantId,
  3658. UserId = posInfo.UserId,
  3659. ChangeFee = decimal.Parse(FeeType),
  3660. }).Entity;
  3661. db.SaveChanges();
  3662. PosId += posInfo.Id + ",";
  3663. RecordId += query.Id + ",";
  3664. }
  3665. else
  3666. {
  3667. error += "机具" + PosSn + "不存在";
  3668. }
  3669. }
  3670. if (!string.IsNullOrEmpty(error))
  3671. {
  3672. return "Warning|" + error;
  3673. }
  3674. PosId = PosId.TrimEnd(',');
  3675. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
  3676. string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  3677. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  3678. return "success";
  3679. }
  3680. #endregion
  3681. #region 根据机具号、商户号、商户姓名关联商户和机具信息
  3682. public IActionResult RelationPosAndMerchant(string right)
  3683. {
  3684. ViewBag.RightInfo = RightInfo;
  3685. ViewBag.right = right;
  3686. return View();
  3687. }
  3688. [HttpPost]
  3689. public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
  3690. {
  3691. if (string.IsNullOrEmpty(PosSn))
  3692. {
  3693. return "请输入机具SN";
  3694. }
  3695. if (string.IsNullOrEmpty(MerchantNo))
  3696. {
  3697. return "请输入商户编号";
  3698. }
  3699. if (string.IsNullOrEmpty(MerchantName))
  3700. {
  3701. return "请输入商户姓名";
  3702. }
  3703. var query = PosSn + "," + MerchantNo + "," + MerchantName;
  3704. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
  3705. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
  3706. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3707. if (posMerchant.Id == 0)
  3708. {
  3709. return "商户" + MerchantNo + "不存在";
  3710. }
  3711. else if (pos.Id == 0)
  3712. {
  3713. return "机具" + PosSn + "不存在";
  3714. }
  3715. else
  3716. {
  3717. pos.BindMerchantId = posMerchant.Id;
  3718. db.SaveChanges();
  3719. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
  3720. }
  3721. return "success";
  3722. }
  3723. #endregion
  3724. #region 设置商户信息
  3725. public IActionResult SetMerchantInfo(string right)
  3726. {
  3727. ViewBag.RightInfo = RightInfo;
  3728. ViewBag.right = right;
  3729. return View();
  3730. }
  3731. [HttpPost]
  3732. public string SetMerchantInfoDo(string PosSn, string MerchantNo, string MerchantName, string MerIdcardNo, string MerchantMobile)
  3733. {
  3734. if (string.IsNullOrEmpty(PosSn))
  3735. {
  3736. return "请输入机具SN";
  3737. }
  3738. if (string.IsNullOrEmpty(MerchantNo))
  3739. {
  3740. return "请输入商户编号";
  3741. }
  3742. if (string.IsNullOrEmpty(MerchantName))
  3743. {
  3744. return "请输入商户姓名";
  3745. }
  3746. if (string.IsNullOrEmpty(MerIdcardNo))
  3747. {
  3748. return "请输入商户身份证号";
  3749. }
  3750. if (string.IsNullOrEmpty(MerchantMobile))
  3751. {
  3752. return "请输入商户手机号";
  3753. }
  3754. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo && m.KqSnNo == PosSn && m.MerchantName.StartsWith(MerchantName.Substring(0, 1))) ?? new PosMerchantInfo();
  3755. var query = "";
  3756. query += "修改前:" + posMerchant.KqSnNo + "," + posMerchant.MerchantNo + "," + posMerchant.MerchantName + "," + posMerchant.MerIdcardNo + "," + posMerchant.MerchantMobile;
  3757. query += "修改后:" + PosSn + "," + MerchantNo + "," + MerchantName + "," + MerIdcardNo + "," + MerchantMobile;
  3758. if (posMerchant.Id == 0)
  3759. {
  3760. return "商户" + MerchantNo + "不存在或不在" + MerchantName + "名下";
  3761. }
  3762. else
  3763. {
  3764. posMerchant.MerIdcardNo = MerIdcardNo;
  3765. posMerchant.MerchantName = MerchantName;
  3766. posMerchant.MerchantMobile = MerchantMobile;
  3767. db.SaveChanges();
  3768. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "设置商户信息");
  3769. }
  3770. return "success";
  3771. }
  3772. #endregion
  3773. #region 认证创客
  3774. public IActionResult AuthMaker(string right)
  3775. {
  3776. ViewBag.RightInfo = RightInfo;
  3777. ViewBag.right = right;
  3778. return View();
  3779. }
  3780. [HttpPost]
  3781. public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
  3782. {
  3783. if (string.IsNullOrEmpty(MakerCode))
  3784. {
  3785. return "请输入创客编号";
  3786. }
  3787. if (string.IsNullOrEmpty(RealName))
  3788. {
  3789. return "请输入真实姓名";
  3790. }
  3791. if (string.IsNullOrEmpty(CertId))
  3792. {
  3793. return "请输入身份证号";
  3794. }
  3795. if (string.IsNullOrEmpty(BackCard))
  3796. {
  3797. return "请输入银行卡号";
  3798. }
  3799. if (string.IsNullOrEmpty(BackName))
  3800. {
  3801. return "请输入银行名称";
  3802. }
  3803. var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
  3804. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3805. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3806. if (userInfo.AuthFlag == 1)
  3807. {
  3808. return "已认证";
  3809. }
  3810. else
  3811. {
  3812. userInfo.UpdateDate = DateTime.Now;
  3813. userInfo.RealName = RealName;
  3814. userInfo.AuthFlag = 1;
  3815. if (userInfo.AuthDate == null)
  3816. {
  3817. userInfo.AuthDate = DateTime.Now;
  3818. }
  3819. userInfo.CertId = CertId;
  3820. userInfo.SettleBankCardNo = BackCard;
  3821. userInfo.SettleBankCardName = BackName;
  3822. db.SaveChanges();
  3823. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
  3824. }
  3825. return "success";
  3826. }
  3827. #endregion
  3828. #region 划拨创客机具
  3829. public IActionResult TransferPos(string right)
  3830. {
  3831. ViewBag.RightInfo = RightInfo;
  3832. ViewBag.right = right;
  3833. return View();
  3834. }
  3835. [HttpPost]
  3836. public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  3837. {
  3838. if (string.IsNullOrEmpty(PosSn))
  3839. {
  3840. return "请输入机具SN";
  3841. }
  3842. if (string.IsNullOrEmpty(FromMakerCode))
  3843. {
  3844. return "请输入机具来源创客编号";
  3845. }
  3846. if (string.IsNullOrEmpty(ToMakerCode))
  3847. {
  3848. return "请输入划拨对象创客编号";
  3849. }
  3850. var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
  3851. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3852. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3853. if (posInfo.Id == 0)
  3854. {
  3855. return "机具" + PosSn + "不存在";
  3856. }
  3857. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3858. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3859. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3860. if (fUserId.Id == 0)
  3861. {
  3862. return "来源创客" + FromMakerCode + "不存在";
  3863. }
  3864. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3865. if (tUserId.Id == 0)
  3866. {
  3867. return "划拨创客" + ToMakerCode + "不存在";
  3868. }
  3869. if (posInfo.BindingState == 0)
  3870. {
  3871. if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  3872. {
  3873. posInfo.BuyUserId = tUserId.Id;
  3874. posInfo.UserId = tUserId.Id;
  3875. }
  3876. else
  3877. {
  3878. posInfo.BuyUserId = tUserId.Id;
  3879. }
  3880. var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3881. var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3882. fUserPos.TotalMachineCount -= 1;
  3883. fUserPos.UnBindCount -= 1;
  3884. tUserPos.TotalMachineCount += 1;
  3885. tUserPos.UnBindCount += 1;
  3886. db.SaveChanges();
  3887. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  3888. }
  3889. else
  3890. {
  3891. return "机具" + PosSn + "已使用";
  3892. }
  3893. return "success";
  3894. }
  3895. #endregion
  3896. #region 还原提现订单状态
  3897. public IActionResult RestoreStatus(string right)
  3898. {
  3899. ViewBag.RightInfo = RightInfo;
  3900. ViewBag.right = right;
  3901. return View();
  3902. }
  3903. [HttpPost]
  3904. public string RestoreStatusDo(string OrderNo)
  3905. {
  3906. if (string.IsNullOrEmpty(OrderNo))
  3907. {
  3908. return "请输入提现订单编号";
  3909. }
  3910. string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
  3911. var error = "";
  3912. foreach (var item in OrderNoList)
  3913. {
  3914. var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
  3915. if (cash.Id > 0)
  3916. {
  3917. cash.QueryCount = 0;
  3918. cash.Status = 0;
  3919. db.SaveChanges();
  3920. }
  3921. else
  3922. {
  3923. error += "订单" + item + "不存在" + '\n';
  3924. }
  3925. }
  3926. if (!string.IsNullOrEmpty(error))
  3927. {
  3928. return "Warning|" + error;
  3929. }
  3930. return "success";
  3931. }
  3932. #endregion
  3933. #region 查询创客循环资格
  3934. public IActionResult SeeUserLoop(string right)
  3935. {
  3936. ViewBag.RightInfo = RightInfo;
  3937. ViewBag.right = right;
  3938. return View();
  3939. }
  3940. [HttpPost]
  3941. public string SeeUserLoopDo(string MakerCode)
  3942. {
  3943. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3944. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3945. var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
  3946. var brandList = db.KqProducts.ToList();
  3947. var info = "";
  3948. foreach (var item in brandList)
  3949. {
  3950. var brand = item.Name;
  3951. //已过期
  3952. var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  3953. //可申请
  3954. var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  3955. //已使用
  3956. // var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id && m.PosSnType == 0);
  3957. // info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
  3958. info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + "\n";
  3959. }
  3960. return info;
  3961. }
  3962. #endregion
  3963. #region 提交到代付排除的创客名单
  3964. public IActionResult CashWithoutUser(string right)
  3965. {
  3966. ViewBag.RightInfo = RightInfo;
  3967. ViewBag.right = right;
  3968. return View();
  3969. }
  3970. public string CashWithoutUserDo(string Content)
  3971. {
  3972. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser");
  3973. if (set == null)
  3974. {
  3975. set = db.CustomTagSet.Add(new CustomTagSet()
  3976. {
  3977. Tags = "CashWithoutUser",
  3978. Title = "提交到代付排除的创客名单"
  3979. }).Entity;
  3980. db.SaveChanges();
  3981. }
  3982. set.Contents = Content;
  3983. db.SaveChanges();
  3984. db.Dispose();
  3985. return "success";
  3986. }
  3987. #endregion
  3988. #region 坏机回仓
  3989. public IActionResult BadPosToStore(string right)
  3990. {
  3991. ViewBag.RightInfo = RightInfo;
  3992. ViewBag.right = right;
  3993. return View();
  3994. }
  3995. [HttpPost]
  3996. public string BadPosToStoreDo(string OldSn)
  3997. {
  3998. string[] OldSnList;
  3999. OldSnList = OldSn.Replace("\r", "").Split('\n');
  4000. string error = "";
  4001. List<string> opData = new List<string>();
  4002. for (int i = 0; i < OldSnList.Length; i++)
  4003. {
  4004. string OldSnNum = OldSnList[i];
  4005. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  4006. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId) ?? new PosMachinesTwo();
  4007. var store = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId) ?? new StoreHouse();
  4008. if (store.UserId != 142237)//判断是否是属于坏机仓的机具
  4009. {
  4010. error += "以下操作失败" + OldSnNum + ',' + "该机具不在坏机仓或不存在" + '\n';
  4011. }
  4012. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  4013. {
  4014. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  4015. }
  4016. oldpos.Status = 1;
  4017. oldpos.QueryCount = 0;
  4018. oldpos.UpdateDate = null;
  4019. oldpos.ActivityList = null;
  4020. oldpos.SeoKeyword = null;
  4021. oldpos.SeoDescription = null;
  4022. oldpos.OrderId = 0;
  4023. oldpos.RecycEndDate = null;
  4024. oldpos.RecycBackCount = 0;
  4025. oldpos.PrizeParams = null;
  4026. oldpos.ScanQrTrade = 0;
  4027. oldpos.BindMerchantId = 0;
  4028. oldpos.CreditTrade = 0;
  4029. oldpos.DebitCardTrade = 0;
  4030. oldpos.IsVip = 0;
  4031. oldpos.UserNav = null;
  4032. oldpos.TransferTime = null;
  4033. oldpos.IsPurchase = 0;
  4034. oldpos.Detail = null;
  4035. oldpos.BindingTime = null;
  4036. oldpos.BindingState = 0;
  4037. oldpos.ActivationTime = null;
  4038. oldpos.ActivationState = 0;
  4039. oldpos.LeaderUserId = 0;
  4040. oldpos.PreUserId = 0;
  4041. oldpos.IsFirst = 0;
  4042. oldpos.DownFeeMan = null;
  4043. oldpos.DownFeeFlag = 0;
  4044. oldpos.DownFeeDate = null;
  4045. oldpos.UpFeeMan = null;
  4046. oldpos.UpFeeFlag = 0;
  4047. oldpos.UpFeeDate = null;
  4048. oldpos.OpReserve1 = 0;
  4049. oldpos.OpReserve2 = 0;
  4050. oldpos.OpReserve3 = 0;
  4051. oldpos.OpId = 0;
  4052. oldpos.RecycStartDate = null;
  4053. oldpos.SourcePosSn = null;
  4054. oldpos.BuyUserId = 0;
  4055. oldpos.UserId = 0;
  4056. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  4057. }
  4058. if (!string.IsNullOrEmpty(error))
  4059. {
  4060. return "Warning|" + error;
  4061. }
  4062. db.SaveChanges();
  4063. foreach (string sub in opData)
  4064. {
  4065. string[] datalist = sub.Split(":");
  4066. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4067. }
  4068. return "success";
  4069. }
  4070. #endregion
  4071. #region 划拨创客机具券
  4072. public IActionResult TransferPosCoupon(string right)
  4073. {
  4074. ViewBag.RightInfo = RightInfo;
  4075. ViewBag.right = right;
  4076. return View();
  4077. }
  4078. public string TransferPosCouponDo(string PosCouponCodes, string FromMakerCode, string ToMakerCode, string LeaderMakerCode = "")
  4079. {
  4080. if (string.IsNullOrEmpty(PosCouponCodes))
  4081. {
  4082. return "请输入机具券码";
  4083. }
  4084. if (string.IsNullOrEmpty(FromMakerCode))
  4085. {
  4086. return "请输入机具来源创客编号";
  4087. }
  4088. if (string.IsNullOrEmpty(ToMakerCode))
  4089. {
  4090. return "请输入划拨对象创客编号";
  4091. }
  4092. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4093. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4094. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4095. if (fUserId.Id == 0)
  4096. {
  4097. return "来源创客" + FromMakerCode + "不存在";
  4098. }
  4099. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4100. if (tUserId.Id == 0)
  4101. {
  4102. return "划拨创客" + ToMakerCode + "不存在";
  4103. }
  4104. int LeaderUserId = 0;
  4105. if (!string.IsNullOrEmpty(LeaderMakerCode))
  4106. {
  4107. UserForMakerCode leaderuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LeaderMakerCode) ?? new UserForMakerCode();
  4108. Users LeaderUserItem = db.Users.FirstOrDefault(m => m.Id == leaderuser.UserId) ?? new Users();
  4109. if (LeaderUserItem.Id == 0)
  4110. {
  4111. return "大盟主创客编号" + LeaderMakerCode + "不存在";
  4112. }
  4113. LeaderUserId = leaderuser.UserId;
  4114. }
  4115. var query = PosCouponCodes + "\n" + FromMakerCode + "," + ToMakerCode;
  4116. string[] PosCouponList = PosCouponCodes.Replace("\r", "").Replace("\n", ",").Split(',');
  4117. foreach (string PosCouponCode in PosCouponList)
  4118. {
  4119. PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == PosCouponCode) ?? new PosCoupons();
  4120. if (item.UserId != fUserId.Id)
  4121. {
  4122. return "机具券" + PosCouponCode + "不在创客" + FromMakerCode + "名下";
  4123. }
  4124. if (item.Id == 0)
  4125. {
  4126. return "机具券" + PosCouponCode + "不存在";
  4127. }
  4128. if (item.IsUse == 1)
  4129. {
  4130. return "机具券" + PosCouponCode + "已使用";
  4131. }
  4132. item.UserId = tUserId.Id;
  4133. if (LeaderUserId > 0 && item.LeaderUserId == 0)
  4134. {
  4135. item.LeaderUserId = LeaderUserId;
  4136. }
  4137. }
  4138. db.SaveChanges();
  4139. db.Dispose();
  4140. return "success";
  4141. }
  4142. #endregion
  4143. #region 机具回仓退款
  4144. public IActionResult RefundPosFee(string right)
  4145. {
  4146. ViewBag.RightInfo = RightInfo;
  4147. ViewBag.right = right;
  4148. return View();
  4149. }
  4150. [HttpPost]
  4151. public string RefundPosFeeDo(string PosSn, string BackStoreNo, int IsBack = 0)
  4152. {
  4153. if (string.IsNullOrEmpty(PosSn))
  4154. {
  4155. return "请输入机具SN";
  4156. }
  4157. if (IsBack == 1)
  4158. {
  4159. if (string.IsNullOrEmpty(BackStoreNo))
  4160. {
  4161. return "请输入仓库编号";
  4162. }
  4163. }
  4164. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  4165. WebCMSEntities db = new WebCMSEntities();
  4166. DateTime time = DateTime.Parse(DateTime.Now.ToString(("yyyy-MM-dd") + " 00:00:00"));
  4167. var endTime = time.AddDays(20 - time.Day).AddDays(-60);
  4168. StoreForCode storeForBack = new StoreForCode();
  4169. StoreHouse BackStore = new StoreHouse();
  4170. List<string> opData = new List<string>();
  4171. foreach (var item in PosSnList)
  4172. {
  4173. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  4174. if (machineForSnNo.SnId == 0)
  4175. {
  4176. return "未找到机具" + item + "关联数据";
  4177. }
  4178. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.Status > -1 && m.RecycEndDate < endTime && m.BindingState == 0) ?? new PosMachinesTwo();
  4179. if (pos.Id == 0)
  4180. {
  4181. return "机具" + item + "不存在或者不满足条件";
  4182. }
  4183. if (IsBack == 1)
  4184. {
  4185. storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  4186. if (storeForBack.StoreId == 0)
  4187. {
  4188. return "未找到" + BackStoreNo + "关联数据";
  4189. }
  4190. BackStore = db.StoreHouse.FirstOrDefault(m => m.Status > -1 && m.Id == storeForBack.StoreId && m.BrandId == pos.BrandId.ToString()) ?? new StoreHouse();
  4191. if (BackStore.Id == 0)
  4192. {
  4193. return "仓库" + BackStoreNo + "不存在或与机具品牌不符";
  4194. }
  4195. }
  4196. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BackStore.UserId) ?? new UserAccount();
  4197. var refundUserAccount = db.UserAccount.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new UserAccount();
  4198. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  4199. var amount = 0;
  4200. if (brandInfo.Name.Contains("电签"))
  4201. {
  4202. amount = 200;
  4203. }
  4204. if (brandInfo.Name.Contains("大POS"))
  4205. {
  4206. amount = 300;
  4207. }
  4208. if (IsBack == 1)
  4209. {
  4210. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  4211. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  4212. {
  4213. CreateDate = DateTime.Now,
  4214. CreateMan = SysUserName,
  4215. StoreId = pos.StoreId, //出货仓库
  4216. BrandId = pos.BrandId, //产品类型
  4217. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  4218. TransType = 5, //交易类型
  4219. SnNo = item, //SN编号
  4220. StockOpDirect = 0, //库存操作方向
  4221. SnStatus = 1, //SN状态
  4222. DeviceVendor = pos.DeviceName, //设备厂商
  4223. DeviceModel = pos.DeviceKind, //设备型号
  4224. DeviceType = pos.DeviceType, //设备类型
  4225. FromUserId = pos.BuyUserId, //来源创客
  4226. ToRemark = "过期机具回仓退款", //入库备注
  4227. ToStoreId = BackStore.Id, //退货收货仓库
  4228. SourceStoreId = pos.SourceStoreId, //源仓库编号
  4229. BrandType = pos.DeviceType, //品牌类型
  4230. }).Entity;
  4231. string ChangeNo = "HCTK";
  4232. int StoreStockChangeId = stockchange.Id;
  4233. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  4234. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  4235. {
  4236. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  4237. }
  4238. ChangeNo += StoreStockChangeIdString;
  4239. stockchange.ChangeNo = ChangeNo; //交易流水编号
  4240. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4241. {
  4242. CreateDate = DateTime.Now,
  4243. BrandId = pos.BrandId, //产品类型
  4244. ChangeRecordNo = ChangeNo, //变更记录单号
  4245. TransType = 5, //交易类型
  4246. SnNo = item, //SN编号
  4247. SnType = pos.PosSnType, //SN机具类型
  4248. StockOpDirect = 0, //库存操作方向
  4249. DeviceVendor = pos.DeviceName, //设备厂商
  4250. DeviceModel = pos.DeviceKind, //设备型号
  4251. DeviceType = pos.DeviceType, //设备类型
  4252. FromUserId = pos.BuyUserId, //来源创客
  4253. ToRemark = "过期机具回仓退款", //入库备注
  4254. SourceStoreId = pos.SourceStoreId, //源仓库
  4255. StoreId = pos.StoreId, //出货仓库
  4256. });
  4257. db.MachineReturn.Add(new MachineReturn()
  4258. {
  4259. CreateDate = DateTime.Now,
  4260. Operator = SysUserName + "_" + SysRealName,//操作人
  4261. BrandId = pos.BrandId, //产品类型
  4262. DeviceSnNos = pos.PosSn,
  4263. ToStoreId = BackStore.Id,
  4264. ApplyNo = ChangeNo, //变更记录单号
  4265. UserId = pos.BuyUserId, //来源创客
  4266. Remark = "过期机具回仓退款", //入库备注
  4267. });
  4268. if (pos.ScanQrTrade > 0)
  4269. {
  4270. decimal ChangeAmount = 0;
  4271. decimal BeforeBalanceAmount = 0;
  4272. decimal AfterBalanceAmount = 0;
  4273. if (pos.ScanQrTrade == 999)
  4274. {
  4275. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4276. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4277. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4278. ChangeAmount = amount;
  4279. }
  4280. else
  4281. {
  4282. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4283. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4284. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4285. ChangeAmount = pos.ScanQrTrade;
  4286. }
  4287. db.UserAccountRecord.Add(new UserAccountRecord()
  4288. {
  4289. CreateDate = DateTime.Now,
  4290. UpdateDate = DateTime.Now,
  4291. UserId = pos.BuyUserId, //创客
  4292. ChangeType = 126, //变动类型(机具货款退还)
  4293. ProductType = 0, //产品类型
  4294. ChangeAmount = ChangeAmount, //变更金额
  4295. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4296. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4297. });
  4298. }
  4299. var bInfo = BackStore.UserId + "_" + pos.BrandId;
  4300. var userMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == bInfo) ?? new UserMachineData();
  4301. userMachineData.TotalMachineCount += 1;
  4302. userMachineData.UnBindCount += 1;
  4303. BackStore.LaveNum += 1;
  4304. BackStore.TotalNum += 1;
  4305. var fInfo = pos.BuyUserId + "_" + pos.BrandId;
  4306. var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
  4307. userMachineDatas.TotalMachineCount -= 1;
  4308. userMachineDatas.UnBindCount -= 1;
  4309. if (!opData.Contains(pos.BuyUserId + ":" + pos.BrandId))
  4310. {
  4311. opData.Add(pos.BuyUserId + ":" + pos.BrandId);
  4312. }
  4313. pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
  4314. pos.Status = 1;
  4315. pos.QueryCount = 0;
  4316. pos.UpdateDate = null;
  4317. pos.ActivityList = null;
  4318. pos.SeoKeyword = null;
  4319. pos.SeoDescription = null;
  4320. pos.OrderId = 0;
  4321. pos.RecycEndDate = null;
  4322. pos.RecycBackCount = 0;
  4323. pos.PrizeParams = null;
  4324. pos.ScanQrTrade = 0;
  4325. pos.BindMerchantId = 0;
  4326. pos.CreditTrade = 0;
  4327. pos.DebitCardTrade = 0;
  4328. pos.IsVip = 0;
  4329. pos.UserNav = null;
  4330. pos.TransferTime = null;
  4331. pos.IsPurchase = 0;
  4332. pos.Detail = null;
  4333. pos.BindingTime = null;
  4334. pos.BindingState = 0;
  4335. pos.ActivationTime = null;
  4336. pos.ActivationState = 0;
  4337. pos.LeaderUserId = 0;
  4338. pos.PreUserId = 0;
  4339. pos.IsFirst = 0;
  4340. pos.DownFeeMan = null;
  4341. pos.DownFeeFlag = 0;
  4342. pos.DownFeeDate = null;
  4343. pos.UpFeeMan = null;
  4344. pos.UpFeeFlag = 0;
  4345. pos.UpFeeDate = null;
  4346. pos.OpReserve1 = 0;
  4347. pos.OpReserve2 = 0;
  4348. pos.OpReserve3 = 0;
  4349. pos.OpId = 0;
  4350. pos.RecycStartDate = null;
  4351. pos.SourcePosSn = null;
  4352. pos.BuyUserId = 0;
  4353. pos.UserId = 0;
  4354. PublicFunction.ClearPosHistory(db, pos.PosSn); //清除机具历史记录
  4355. }
  4356. else
  4357. {
  4358. if (pos.ScanQrTrade > 0)
  4359. {
  4360. decimal ChangeAmount = 0;
  4361. decimal BeforeBalanceAmount = 0;
  4362. decimal AfterBalanceAmount = 0;
  4363. if (pos.ScanQrTrade == 999)
  4364. {
  4365. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4366. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4367. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4368. ChangeAmount = amount;
  4369. }
  4370. else
  4371. {
  4372. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4373. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4374. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4375. ChangeAmount = pos.ScanQrTrade;
  4376. }
  4377. pos.ScanQrTrade = 0;
  4378. db.UserAccountRecord.Add(new UserAccountRecord()
  4379. {
  4380. CreateDate = DateTime.Now,
  4381. UpdateDate = DateTime.Now,
  4382. UserId = pos.BuyUserId, //创客
  4383. ChangeType = 126, //变动类型(机具货款退还)
  4384. ProductType = 0, //产品类型
  4385. ChangeAmount = ChangeAmount, //变更金额
  4386. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4387. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4388. });
  4389. }
  4390. }
  4391. }
  4392. db.SaveChanges();
  4393. foreach (string sub in opData)
  4394. {
  4395. string[] datalist = sub.Split(":");
  4396. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4397. }
  4398. return "success";
  4399. }
  4400. #endregion
  4401. #region 添加商户信息
  4402. public IActionResult AddMerchantnfo(string right)
  4403. {
  4404. ViewBag.RightInfo = RightInfo;
  4405. ViewBag.right = right;
  4406. return View();
  4407. }
  4408. [HttpPost]
  4409. public string AddMerchantnfoDo(string PosSn, string MerSn)
  4410. {
  4411. if (string.IsNullOrEmpty(PosSn))
  4412. {
  4413. return "请输入机具号";
  4414. }
  4415. if (string.IsNullOrEmpty(MerSn))
  4416. {
  4417. return "请输入商户号";
  4418. }
  4419. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4420. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4421. var merchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4422. if (machineForSnNo.SnId == 0)
  4423. {
  4424. return "未找到机具" + PosSn + "关联数据";
  4425. }
  4426. if (pos.Id == 0)
  4427. {
  4428. return "未找到机具" + PosSn;
  4429. }
  4430. if (merchantInfo.Id > 0)
  4431. {
  4432. return "机具" + PosSn + "以经存在绑定商户";
  4433. }
  4434. var spInfo = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerSn && m.MerSnNo == PosSn) ?? new SpModels.BindRecord();
  4435. if (spInfo.Id > 0)
  4436. {
  4437. var MerUserType = 0;
  4438. var ActiveStatus = 0;
  4439. if (pos.BuyUserId != pos.UserId)
  4440. {
  4441. MerUserType = 1;
  4442. }
  4443. if (string.IsNullOrEmpty(pos.ActivationTime.ToString()))
  4444. {
  4445. ActiveStatus = 1;
  4446. }
  4447. PosMerchantInfo posMerchantInfo = db.PosMerchantInfo.Add(new PosMerchantInfo()
  4448. {
  4449. CreateDate = pos.BindingTime,
  4450. TopUserId = 1,
  4451. BrandId = pos.BrandId,
  4452. SnStoreId = pos.StoreId,
  4453. MerStandardDate = pos.ActivationTime,
  4454. SnType = pos.PosSnType,
  4455. MerUserType = MerUserType,
  4456. UserId = pos.UserId,
  4457. ActiveStatus = ActiveStatus,
  4458. MerStatus = 1,
  4459. KqSnNo = PosSn,
  4460. KqMerNo = MerSn,
  4461. MerIdcardNo = spInfo.SeoKeyword,
  4462. MerchantMobile = spInfo.MerNewSnNo,
  4463. MerchantName = spInfo.MerName,
  4464. MerchantNo = spInfo.MerNo,
  4465. }).Entity;
  4466. db.SaveChanges();
  4467. string text = string.Format("设置商户信息,机具Sn: " + PosSn + ",商户编号: " + MerSn + ",操作人:" + SysUserName + "_" + SysRealName + ",时间:" + DateTime.Now + "");
  4468. function.WriteLog(text, "设置商户信息");
  4469. }
  4470. return "success";
  4471. }
  4472. #endregion
  4473. }
  4474. }