SysToolsController.cs 226 KB

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