SysToolsController.cs 218 KB

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