SysToolsController.cs 280 KB

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