SysToolsController.cs 281 KB

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