SysToolsController.cs 252 KB

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