SysToolsController.cs 278 KB

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