SysToolsController.cs 288 KB

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