SysToolsController.cs 226 KB

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