SysToolsController.cs 285 KB

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