SysToolsController.cs 263 KB

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