SysToolsController.cs 285 KB

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