SysToolsController.cs 277 KB

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