SysToolsController.cs 282 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971
  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. {
  1371. Deposit = Deposit / 100;
  1372. }
  1373. string DepositGet = "未领取";
  1374. string DepositUser = "";
  1375. string DepositToUser = "";
  1376. decimal headAmount = 0;
  1377. decimal footAmount = 0;
  1378. string aDepositGet = "";
  1379. // ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1380. // if (reward.Id > 0)
  1381. // {
  1382. // Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1383. // DepositGet = "已领取";
  1384. // DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1385. // var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
  1386. // if (fAmount != null)
  1387. // {
  1388. // headAmount = fAmount.RewardAmount;
  1389. // }
  1390. // var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
  1391. // if (lAmount != null)
  1392. // {
  1393. // footAmount = lAmount.RewardAmount;
  1394. // }
  1395. // }
  1396. // string DepositGet6 = "未领取";
  1397. // string DepositUser6 = "";
  1398. var reward = db.ActiveReward.Where(m => m.KqSnNo == pos.PosSn).ToList();
  1399. foreach (var item in reward)
  1400. {
  1401. Users user = db.Users.FirstOrDefault(m => m.Id == item.UserId) ?? new Users();
  1402. var time = item.CreateDate == null ? "" : item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1403. aDepositGet += "已领取:" + item.RewardAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",领取时间:" + time + "\n";
  1404. }
  1405. string FluxGet6 = "未领取";
  1406. string FluxUser6 = "";
  1407. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1408. if (flux.Id > 0)
  1409. {
  1410. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1411. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1412. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1413. }
  1414. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1415. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName;
  1416. string OpenUser10 = "未领取";
  1417. string OpenUser20 = "未领取";
  1418. string Leader10 = "未领取";
  1419. string YYZX5 = "未领取";
  1420. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1421. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1422. if (openreward.Id > 0)
  1423. {
  1424. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1425. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发放时间:" + openreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1426. }
  1427. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1428. if (openreward.Id > 0)
  1429. {
  1430. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1431. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
  1432. }
  1433. var leader10 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 116) ?? new UserAccountRecord();
  1434. if (leader10.Id > 0)
  1435. {
  1436. Users user = db.Users.FirstOrDefault(m => m.Id == leader10.UserId) ?? new Users();
  1437. Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + leader10.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1438. }
  1439. var yyzx5 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 121) ?? new UserAccountRecord();
  1440. if (yyzx5.Id > 0)
  1441. {
  1442. Users user = db.Users.FirstOrDefault(m => m.Id == yyzx5.UserId) ?? new Users();
  1443. YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + yyzx5.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1444. }
  1445. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1446. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1447. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1448. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1449. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1450. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1451. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1452. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1453. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1454. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1455. // string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1456. // string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1457. string result = "";
  1458. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + "\n";
  1459. result += "\n";
  1460. result += "机具SN:" + pos.PosSn + "\n";
  1461. string PosSnType = pos.PosSnType == 0 ? "兑换机" : "循环机";
  1462. result += "机具类型:" + PosSnType + "\n";
  1463. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1464. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + "\n";
  1465. if (change.Id > 0)
  1466. {
  1467. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1468. }
  1469. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + "\n";
  1470. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1471. if (pos.PreUserId > 0)
  1472. {
  1473. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1474. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1475. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1476. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",预发时间:" + preSendDate + "\n";
  1477. }
  1478. else
  1479. {
  1480. result += "机具所属小分仓:暂无小分仓\n";
  1481. }
  1482. result += "入库时间:" + CreateDate + "\n";
  1483. result += "循环到期时间:" + RecycEndDate + "\n";
  1484. result += "划拨时间:" + TransferTime + "\n";
  1485. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1486. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1487. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1488. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1489. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1490. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1491. result += "服务费:" + Deposit + "\n";
  1492. // result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1493. result += "是否返现:" + aDepositGet + "\n";
  1494. // result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";
  1495. result += "服务费返现应返现对象:" + DepositToUser + "\n";
  1496. // result += "服务费返现实际返现对象:" + DepositUser + "\n";
  1497. // if (pos.BrandId == 6)
  1498. // {
  1499. // result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1500. // result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1501. // }
  1502. result += "流量费:" + FluxGet6 + "\n";
  1503. result += "流量费发放对象:" + FluxUser6 + "\n";
  1504. result += "开机奖20:" + OpenUser20 + "\n";
  1505. result += "盟主奖:" + Leader10 + "\n";
  1506. result += "运营中心奖:" + YYZX5 + "\n";
  1507. return result;
  1508. }
  1509. #endregion
  1510. #region 生成机具兑换码
  1511. public IActionResult MakeCoupons(string right)
  1512. {
  1513. ViewBag.RightInfo = RightInfo;
  1514. ViewBag.right = right;
  1515. return View();
  1516. }
  1517. [HttpPost]
  1518. public string MakeCouponsDo(int Kind, int Number)
  1519. {
  1520. DateTime checkTime = DateTime.Parse("1900-01-01");
  1521. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1522. if (!string.IsNullOrEmpty(checkTimeString))
  1523. {
  1524. checkTime = DateTime.Parse(checkTimeString);
  1525. }
  1526. if (checkTime.AddHours(1) < DateTime.Now)
  1527. {
  1528. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1529. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1530. return "生成程序已执行";
  1531. }
  1532. return "请稍后再试";
  1533. }
  1534. #endregion
  1535. #region 导出没有刷满1000的机具
  1536. public IActionResult ExportPos(string right)
  1537. {
  1538. ViewBag.RightInfo = RightInfo;
  1539. ViewBag.right = right;
  1540. return View();
  1541. }
  1542. [HttpPost]
  1543. public JsonResult ExportPosDo()
  1544. {
  1545. WebCMSEntities db = new WebCMSEntities();
  1546. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1547. int total = poses.Count;
  1548. int index = 0;
  1549. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1550. foreach (PosMachinesTwo pos in poses)
  1551. {
  1552. index += 1;
  1553. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1554. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1555. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1556. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1557. Dictionary<string, object> item = new Dictionary<string, object>();
  1558. string TopRealName = "";
  1559. string TopMakerCode = "";
  1560. string TopMobile = "";
  1561. string ParentNav = user.ParentNav;
  1562. if (!string.IsNullOrEmpty(ParentNav))
  1563. {
  1564. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1565. if (navlist.Length > 1)
  1566. {
  1567. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1568. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1569. TopRealName = tuser.RealName;
  1570. TopMakerCode = tuser.MakerCode;
  1571. TopMobile = tuser.Mobile;
  1572. }
  1573. }
  1574. item.Add("TopRealName", TopRealName); //顶级姓名
  1575. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1576. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1577. item.Add("UpRealName", puser.RealName); //上级姓名
  1578. item.Add("RealName", user.RealName); //代理姓名
  1579. item.Add("MakerCode", user.MakerCode); //代理编号
  1580. item.Add("Mobile", user.Mobile); //代理手机号
  1581. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1582. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1583. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1584. item.Add("Sn", pos.PosSn); //SN
  1585. list.Add(item);
  1586. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1587. }
  1588. db.Dispose();
  1589. Dictionary<string, object> result = new Dictionary<string, object>();
  1590. result.Add("Status", "1");
  1591. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1592. result.Add("Obj", list);
  1593. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1594. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1595. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1596. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1597. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1598. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1599. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1600. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1601. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1602. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1603. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1604. ReturnFields.Add("Sn", "SN"); //SN
  1605. result.Add("Fields", ReturnFields);
  1606. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1607. return Json(result);
  1608. }
  1609. public string ExportPosCheck()
  1610. {
  1611. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1612. if (content == "finish")
  1613. {
  1614. RedisDbconn.Instance.Clear("ExportPosCheck");
  1615. }
  1616. return content;
  1617. }
  1618. #endregion
  1619. #region 更换机具
  1620. public IActionResult ChangePos(string right)
  1621. {
  1622. ViewBag.RightInfo = RightInfo;
  1623. ViewBag.right = right;
  1624. return View();
  1625. }
  1626. [HttpPost]
  1627. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1628. {
  1629. if (string.IsNullOrEmpty(OldSn))
  1630. {
  1631. return "请输入原机具SN";
  1632. }
  1633. if (string.IsNullOrEmpty(NewSn))
  1634. {
  1635. return "请输入新机具SN";
  1636. }
  1637. if (string.IsNullOrEmpty(MerNo))
  1638. {
  1639. return "请输入商户编号";
  1640. }
  1641. string[] OldSnList = OldSn.Replace("\r", "").Split('\n');
  1642. string[] NewSnList = NewSn.Replace("\r", "").Split('\n');
  1643. if (OldSnList.Length != NewSnList.Length)
  1644. {
  1645. return "原机具SN数量和新机具SN数量不一致";
  1646. }
  1647. WebCMSEntities db = new WebCMSEntities();
  1648. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1649. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1650. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1651. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1652. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1653. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1654. KqProducts oldPosBrand = new KqProducts();
  1655. KqProducts newPosBrand = new KqProducts();
  1656. MachineChange add = db.MachineChange.Add(new MachineChange()
  1657. {
  1658. CreateDate = DateTime.Now,
  1659. UpdateDate = DateTime.Now,
  1660. CreateMan = SysUserName + "-" + SysRealName,
  1661. ChangeNo = ChangeNo, //转换单号
  1662. UserId = 0, //创客
  1663. ChangeTime = DateTime.Now, //转换时间
  1664. BackStoreId = BackStore.Id, //退回仓库
  1665. BackStoreName = BackStore.StoreName, //退回仓库名称
  1666. Remark = "机具更换", //订单备注
  1667. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1668. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1669. OutProductName = OutStore.ProductName, //出库产品名称
  1670. OutStoreId = OutStore.Id, //出库仓库
  1671. OutStoreName = OutStore.StoreName, //出库仓库名称
  1672. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1673. OutStoreAddress = OutStore.Address, //出库仓库地址
  1674. OutStoreManager = "", //出库仓库联系人
  1675. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1676. }).Entity;
  1677. db.SaveChanges();
  1678. int BackProductType = 0;
  1679. string BackProductName = "";
  1680. string ChangeDeviceName = "";
  1681. string ChangeSnExpand = "";
  1682. for (int i = 0; i < OldSnList.Length; i++)
  1683. {
  1684. string OldSnNum = OldSnList[i];
  1685. string NewSnNum = NewSnList[i];
  1686. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1687. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1688. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1689. if (oldpos == null)
  1690. {
  1691. return "原机具SN不正确";
  1692. }
  1693. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.PreUserId == 0);//添加新机是否为预发机判断
  1694. if (newpos == null)
  1695. {
  1696. return "新机具SN不正确或不满足条件";
  1697. }
  1698. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1699. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1700. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  1701. if (merchant == null)
  1702. {
  1703. CustomerSqlConn.op("insert into PosMerchantInfo select * from PosMerchantInfoBak where KqMerNo='" + MerNo + "'", MysqlConn.connstr);
  1704. }
  1705. if (oldpos.OpId > 0)
  1706. {
  1707. if (oldpos.ActivationState == 0)
  1708. {
  1709. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  1710. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  1711. opUserAccount.ValidAmount += oldpos.OpReserve3;
  1712. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  1713. opUserAccount.TotalAmt += oldpos.OpReserve1;
  1714. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  1715. {
  1716. CreateDate = DateTime.Now,
  1717. UserId = oldpos.OpId,
  1718. SeoDescription = "机具换绑",
  1719. OperateType = 1,
  1720. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  1721. BeforeAmount = TotalAmount,
  1722. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  1723. }).Entity;
  1724. oldpos.OpReserve1 = 0;
  1725. oldpos.OpReserve2 = 0;
  1726. oldpos.OpReserve3 = 0;
  1727. }
  1728. else
  1729. {
  1730. if (newpos.OpId > 0)
  1731. {
  1732. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == newpos.OpId && m.UserId == newpos.OpId) ?? new OpModels.UserAccount();
  1733. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  1734. opUserAccount.ValidAmount += newpos.OpReserve3;
  1735. opUserAccount.ValidForGetAmount += newpos.OpReserve2;
  1736. opUserAccount.TotalAmt += newpos.OpReserve1;
  1737. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  1738. {
  1739. CreateDate = DateTime.Now,
  1740. UserId = newpos.OpId,
  1741. SeoDescription = "机具换绑",
  1742. OperateType = 1,
  1743. UseAmount = newpos.OpReserve3 + newpos.OpReserve2 + newpos.OpReserve1,
  1744. BeforeAmount = TotalAmount,
  1745. AfterAmount = TotalAmount + newpos.OpReserve3 + newpos.OpReserve2 + newpos.OpReserve1,
  1746. }).Entity;
  1747. newpos.OpReserve1 = 0;
  1748. newpos.OpReserve2 = 0;
  1749. newpos.OpReserve3 = 0;
  1750. }
  1751. }
  1752. }
  1753. opdb.SaveChanges();
  1754. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1755. newpos.BindMerchantId = merchant.Id;
  1756. newpos.BuyUserId = oldpos.BuyUserId;
  1757. newpos.UserId = oldpos.UserId;
  1758. newpos.RecycEndDate = oldpos.RecycEndDate;
  1759. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1760. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1761. newpos.CreditTrade = oldpos.CreditTrade;
  1762. newpos.PosSnType = oldpos.PosSnType;
  1763. newpos.TransferTime = oldpos.TransferTime;
  1764. newpos.IsPurchase = oldpos.IsPurchase;
  1765. newpos.BindingState = oldpos.BindingState;
  1766. newpos.ActivationState = oldpos.ActivationState;
  1767. newpos.BindingTime = oldpos.BindingTime;
  1768. newpos.ActivationTime = oldpos.ActivationTime;
  1769. newpos.IsFirst = oldpos.IsFirst;
  1770. newpos.SeoKeyword = oldpos.SeoKeyword;
  1771. newpos.PrizeParams = oldpos.PrizeParams;
  1772. newpos.LeaderUserId = oldpos.LeaderUserId;
  1773. oldpos.Status = -1;
  1774. newpos.FirstFlag = oldpos.FirstFlag;
  1775. newpos.IsExecute = oldpos.IsExecute;
  1776. //对应调整客小爽企业版数据
  1777. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
  1778. if (posInfo != null)
  1779. {
  1780. posInfo.PosSn = newpos.PosSn;
  1781. posInfo.PosId = newpos.Id;
  1782. db.SaveChanges();
  1783. }
  1784. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1785. if (forMerNo != null)
  1786. {
  1787. forMerNo.SnId = newpos.Id;
  1788. }
  1789. merchant.KqSnNo = NewSn;
  1790. merchant.ActiveStatus = newpos.ActivationState;
  1791. merchant.MerStandardDate = newpos.ActivationTime;
  1792. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1793. {
  1794. CreateDate = DateTime.Now,
  1795. UpdateDate = DateTime.Now,
  1796. CreateMan = SysUserName + "-" + SysRealName,
  1797. ChangeNo = ChangeNo, //订单号
  1798. ChangeId = add.Id, //订单Id
  1799. BackProductType = oldpos.BrandId, //退回产品类型
  1800. BackProductName = oldPosBrand.Name, //退回产品名称
  1801. UserId = 0, //创客
  1802. BackSnNo = oldpos.PosSn, //设备SN编号
  1803. OutProductType = newpos.BrandId, //出库产品类型
  1804. OutProductName = newPosBrand.Name, //出库产品名称
  1805. OutSnNo = newpos.PosSn, //出库设备SN编号
  1806. OutSnType = newpos.PosSnType, //出库SN机具类型
  1807. Remark = "机具更换", //备注
  1808. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1809. });
  1810. db.SaveChanges();
  1811. BackProductType = oldpos.BrandId;
  1812. BackProductName = newPosBrand.Name;
  1813. ChangeDeviceName = oldpos.DeviceName;
  1814. ChangeSnExpand += oldpos.PosSn + "\n";
  1815. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1816. //同步商户交易额
  1817. RedisDbconn.Instance.AddList("SycnMerchantTradeQueue", "{\"OldPosId\":\"" + oldpos.LastMerchantId + "\",\"NewPosId\":\"" + newpos.LastMerchantId + "\"}");
  1818. }
  1819. add.BackProductType = BackProductType; //退回产品类型
  1820. add.BackProductName = BackProductName; //退回产品名称
  1821. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1822. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1823. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1824. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1825. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1826. db.SaveChanges();
  1827. db.Dispose();
  1828. if (IsSend == 1)
  1829. {
  1830. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1831. {
  1832. UserId = pos.BuyUserId, //接收创客
  1833. MsgType = 2,
  1834. Title = "换绑成功通知", //标题
  1835. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1836. CreateDate = DateTime.Now,
  1837. }));
  1838. }
  1839. if (BackStore.UserId != OutStore.UserId)
  1840. {
  1841. RedisDbconn.Instance.AddList("ResetStoreReserveQueue", BackStore.UserId);
  1842. RedisDbconn.Instance.AddList("ResetStoreReserveQueue", OutStore.UserId);
  1843. }
  1844. return "success";
  1845. }
  1846. #endregion
  1847. #region 坏机换新
  1848. public IActionResult ChangeBadPos(string right)
  1849. {
  1850. ViewBag.RightInfo = RightInfo;
  1851. ViewBag.right = right;
  1852. return View();
  1853. }
  1854. [HttpPost]
  1855. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1856. {
  1857. string[] OldSnList;
  1858. string[] NewSnList;
  1859. decimal amount = 0;
  1860. List<string> opData = new List<string>();
  1861. //创客坏机换新
  1862. if (ChangeType == "0")
  1863. {
  1864. if (string.IsNullOrEmpty(MakerCode))
  1865. {
  1866. return "请输入创客编号";
  1867. }
  1868. if (string.IsNullOrEmpty(OldSn))
  1869. {
  1870. return "请输入坏机SN";
  1871. }
  1872. if (string.IsNullOrEmpty(NewSn))
  1873. {
  1874. return "请输入新机SN";
  1875. }
  1876. if (string.IsNullOrEmpty(FromStoreNo))
  1877. {
  1878. return "请输入新机发货仓库编号";
  1879. }
  1880. if (string.IsNullOrEmpty(BackStoreNo))
  1881. {
  1882. return "请输入坏机退回仓库编号";
  1883. }
  1884. OldSnList = OldSn.Replace("\r", "").Split('\n');
  1885. NewSnList = NewSn.Replace("\r", "").Split('\n');
  1886. if (OldSnList.Length != NewSnList.Length)
  1887. {
  1888. return "原机具SN数量和新机具SN数量不一致";
  1889. }
  1890. for (int i = 0; i < OldSnList.Length; i++)
  1891. {
  1892. string OldSnNum = OldSnList[i];
  1893. string NewSnNum = NewSnList[i];
  1894. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1895. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1896. if (storeForCodeFrom.StoreId == 0)
  1897. {
  1898. return "您输入的新机发货仓库编号不存在";
  1899. }
  1900. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1901. if (storeForCodeBack.StoreId == 0)
  1902. {
  1903. return "您输入的坏机退回仓库编号不存在";
  1904. }
  1905. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1906. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1907. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1908. if (oldpos.Id == 0)
  1909. {
  1910. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1911. }
  1912. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  1913. if (newpos.Id == 0)
  1914. {
  1915. return "您输入的新机SN不存在或不满足条件";
  1916. }
  1917. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1918. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  1919. {
  1920. return "您输入的新机发货仓库不符新机机具对应品牌";
  1921. }
  1922. if (newpos.StoreId != storeFrom.Id)
  1923. {
  1924. return "您输入的新机SN不在新机发货仓库";
  1925. }
  1926. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1927. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1928. {
  1929. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1930. }
  1931. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
  1932. {
  1933. return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
  1934. }
  1935. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1936. if (brandInfo.Name.Contains("大POS"))
  1937. {
  1938. amount = 300;
  1939. }
  1940. if (brandInfo.Name.Contains("电签"))
  1941. {
  1942. amount = 200;
  1943. }
  1944. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1945. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1946. storeFromUserAcount.ValidAmount += amount;
  1947. storeBackUserAcount.ValidAmount -= amount;
  1948. if (oldpos.OpId > 0)
  1949. {
  1950. if (newpos.OpId > 0)
  1951. {
  1952. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  1953. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  1954. opUserAccount.ValidAmount += oldpos.OpReserve3;
  1955. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  1956. opUserAccount.TotalAmt += oldpos.OpReserve1;
  1957. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  1958. {
  1959. CreateDate = DateTime.Now,
  1960. UserId = oldpos.OpId,
  1961. SeoDescription = "坏机换新",
  1962. OperateType = 1,
  1963. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  1964. BeforeAmount = TotalAmount,
  1965. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  1966. }).Entity;
  1967. }
  1968. if (newpos.OpId == 0)
  1969. {
  1970. newpos.OpReserve1 = oldpos.OpReserve1;
  1971. newpos.OpReserve2 = oldpos.OpReserve3;
  1972. newpos.OpReserve3 = oldpos.OpReserve1;
  1973. newpos.OpId = oldpos.OpId;
  1974. }
  1975. }
  1976. newpos.BuyUserId = oldpos.BuyUserId;
  1977. newpos.UserId = oldpos.UserId;
  1978. newpos.RecycEndDate = oldpos.RecycEndDate;
  1979. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1980. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1981. newpos.CreditTrade = oldpos.CreditTrade;
  1982. newpos.PosSnType = oldpos.PosSnType;
  1983. newpos.TransferTime = oldpos.TransferTime;
  1984. newpos.IsPurchase = oldpos.IsPurchase;
  1985. newpos.BindingState = oldpos.BindingState;
  1986. newpos.ActivationState = oldpos.ActivationState;
  1987. newpos.BindingTime = oldpos.BindingTime;
  1988. newpos.ActivationTime = oldpos.ActivationTime;
  1989. newpos.IsFirst = oldpos.IsFirst;
  1990. newpos.SeoKeyword = oldpos.SeoKeyword;
  1991. newpos.PrizeParams = oldpos.PrizeParams;
  1992. newpos.LeaderUserId = oldpos.LeaderUserId;
  1993. newpos.BindMerchantId = oldpos.BindMerchantId;
  1994. newpos.StoreId = oldpos.StoreId;
  1995. newpos.PreUserId = oldpos.PreUserId;
  1996. newpos.FirstFlag = oldpos.FirstFlag;
  1997. newpos.IsExecute = oldpos.IsExecute;
  1998. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  1999. {
  2000. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  2001. }
  2002. oldpos.StoreId = storeBack.Id;
  2003. oldpos.QueryCount = 0;
  2004. oldpos.UpdateDate = null;
  2005. oldpos.ActivityList = null;
  2006. oldpos.SeoKeyword = null;
  2007. oldpos.SeoDescription = null;
  2008. oldpos.OrderId = 0;
  2009. oldpos.RecycEndDate = null;
  2010. oldpos.RecycBackCount = 0;
  2011. oldpos.PrizeParams = null;
  2012. oldpos.ScanQrTrade = 0;
  2013. oldpos.BindMerchantId = 0;
  2014. oldpos.CreditTrade = 0;
  2015. oldpos.DebitCardTrade = 0;
  2016. oldpos.IsVip = 0;
  2017. oldpos.UserNav = null;
  2018. oldpos.TransferTime = null;
  2019. oldpos.IsPurchase = 0;
  2020. oldpos.Detail = null;
  2021. oldpos.BindingTime = null;
  2022. oldpos.BindingState = 0;
  2023. oldpos.ActivationTime = null;
  2024. oldpos.ActivationState = 0;
  2025. oldpos.LeaderUserId = 0;
  2026. oldpos.PreUserId = 0;
  2027. oldpos.IsFirst = 0;
  2028. oldpos.DownFeeMan = null;
  2029. oldpos.DownFeeFlag = 0;
  2030. oldpos.DownFeeDate = null;
  2031. oldpos.UpFeeMan = null;
  2032. oldpos.UpFeeFlag = 0;
  2033. oldpos.UpFeeDate = null;
  2034. oldpos.OpReserve1 = 0;
  2035. oldpos.OpReserve2 = 0;
  2036. oldpos.OpReserve3 = 0;
  2037. oldpos.OpId = 0;
  2038. oldpos.RecycStartDate = null;
  2039. oldpos.SourcePosSn = null;
  2040. oldpos.BuyUserId = 0;
  2041. oldpos.UserId = 0;
  2042. oldpos.Status = -1;
  2043. oldpos.FirstFlag = 0;
  2044. oldpos.IsExecute = 0;
  2045. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  2046. db.SaveChanges();
  2047. opdb.SaveChanges();
  2048. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  2049. if (merchant != null)
  2050. {
  2051. merchant.KqSnNo = newpos.PosSn;
  2052. merchant.ActiveStatus = newpos.ActivationState;
  2053. }
  2054. db.SaveChanges();
  2055. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  2056. {
  2057. CreateDate = DateTime.Now,
  2058. CreateMan = SysUserName + "-" + SysRealName,
  2059. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  2060. OutStoreId = storeFrom.Id,
  2061. BackStoreId = storeBack.Id,
  2062. OutProductType = newpos.BrandId,
  2063. BackProductType = oldpos.BrandId,
  2064. UserId = userForMakerCode.UserId, //创客
  2065. }).Entity;
  2066. db.SaveChanges();
  2067. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  2068. {
  2069. CreateDate = DateTime.Now,
  2070. CreateMan = SysUserName + "-" + SysRealName,
  2071. OutSnNo = OldSnNum,
  2072. BackSnNo = NewSnNum,
  2073. ChangeNo = add.ChangeNo, //转换单号
  2074. ChangeId = add.Id, //转换记录Id
  2075. UserId = add.UserId, //创客
  2076. }).Entity;
  2077. db.SaveChanges();
  2078. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2079. if (IsSend == 1)
  2080. {
  2081. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2082. {
  2083. UserId = userForMakerCode.UserId, //接收创客
  2084. MsgType = 2,
  2085. Title = "坏机换新成功通知", //标题
  2086. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  2087. CreateDate = DateTime.Now,
  2088. }));
  2089. }
  2090. //同步商户交易额
  2091. RedisDbconn.Instance.AddList("SycnMerchantTradeQueue", "{\"OldPosId\":\"" + oldpos.LastMerchantId + "\",\"NewPosId\":\"" + newpos.LastMerchantId + "\"}");
  2092. }
  2093. }
  2094. //仓库坏机换新
  2095. else
  2096. {
  2097. if (string.IsNullOrEmpty(StoreCode))
  2098. {
  2099. return "请输入仓库编号";
  2100. }
  2101. if (string.IsNullOrEmpty(OldSn))
  2102. {
  2103. return "请输入坏机SN";
  2104. }
  2105. if (string.IsNullOrEmpty(NewSn))
  2106. {
  2107. return "请输入新机SN";
  2108. }
  2109. if (string.IsNullOrEmpty(FromStoreNo))
  2110. {
  2111. return "请输入新机发货仓库编号";
  2112. }
  2113. if (string.IsNullOrEmpty(BackStoreNo))
  2114. {
  2115. return "请输入坏机退回仓库编号";
  2116. }
  2117. OldSnList = OldSn.Replace("\r", "").Split('\n');
  2118. NewSnList = NewSn.Replace("\r", "").Split('\n');
  2119. if (OldSnList.Length != NewSnList.Length)
  2120. {
  2121. return "原机具SN数量和新机具SN数量不一致";
  2122. }
  2123. for (int i = 0; i < OldSnList.Length; i++)
  2124. {
  2125. string OldSnNum = OldSnList[i];
  2126. string NewSnNum = NewSnList[i];
  2127. StoreHouse store = new StoreHouse();
  2128. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  2129. if (storeForBadCode.StoreId > 0)
  2130. {
  2131. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  2132. }
  2133. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  2134. if (storeForCodeFrom.StoreId == 0)
  2135. {
  2136. return "您输入的新机发货仓库编号不存在";
  2137. }
  2138. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  2139. if (storeForCodeBack.StoreId == 0)
  2140. {
  2141. return "您输入的坏机退回仓库编号不存在";
  2142. }
  2143. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  2144. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  2145. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  2146. if (oldpos.Id == 0)
  2147. {
  2148. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  2149. }
  2150. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  2151. if (newpos.Id == 0)
  2152. {
  2153. return "您输入的新机SN不存在或不满足条件";
  2154. }
  2155. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  2156. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  2157. {
  2158. return "您输入的新机发货仓库不符新机机具对应品牌";
  2159. }
  2160. if (newpos.StoreId != storeFrom.Id)
  2161. {
  2162. return "您输入的新机SN不在新机发货仓库";
  2163. }
  2164. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  2165. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  2166. {
  2167. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  2168. }
  2169. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2170. if (brandInfo.Name.Contains("大POS"))
  2171. {
  2172. amount = 300;
  2173. }
  2174. if (brandInfo.Name.Contains("电签"))
  2175. {
  2176. amount = 200;
  2177. }
  2178. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  2179. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  2180. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  2181. storeFromUserAcount.ValidAmount += amount;
  2182. storeBackUserAcount.ValidAmount -= amount;
  2183. newpos.StoreId = oldpos.StoreId;
  2184. newpos.BuyUserId = oldpos.BuyUserId;
  2185. newpos.UserId = oldpos.UserId;
  2186. newpos.LeaderUserId = oldpos.LeaderUserId;
  2187. newpos.PreUserId = oldpos.PreUserId;
  2188. newpos.IsFirst = oldpos.IsFirst;
  2189. newpos.TransferTime = oldpos.TransferTime;
  2190. newpos.FirstFlag = oldpos.FirstFlag;
  2191. newpos.IsExecute = oldpos.IsExecute;
  2192. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  2193. {
  2194. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  2195. }
  2196. if (oldpos.OpId > 0)
  2197. {
  2198. if (newpos.OpId > 0)
  2199. {
  2200. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  2201. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  2202. opUserAccount.ValidAmount += oldpos.OpReserve3;
  2203. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  2204. opUserAccount.TotalAmt += oldpos.OpReserve1;
  2205. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  2206. {
  2207. CreateDate = DateTime.Now,
  2208. UserId = oldpos.OpId,
  2209. SeoDescription = "坏机换新",
  2210. OperateType = 1,
  2211. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2212. BeforeAmount = TotalAmount,
  2213. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2214. }).Entity;
  2215. }
  2216. if (newpos.OpId == 0)
  2217. {
  2218. newpos.OpReserve1 = oldpos.OpReserve1;
  2219. newpos.OpReserve2 = oldpos.OpReserve3;
  2220. newpos.OpReserve3 = oldpos.OpReserve1;
  2221. newpos.OpId = oldpos.OpId;
  2222. }
  2223. }
  2224. oldpos.StoreId = storeBack.Id;
  2225. oldpos.QueryCount = 0;
  2226. oldpos.UpdateDate = null;
  2227. oldpos.ActivityList = null;
  2228. oldpos.SeoKeyword = null;
  2229. oldpos.SeoDescription = null;
  2230. oldpos.OrderId = 0;
  2231. oldpos.RecycEndDate = null;
  2232. oldpos.RecycBackCount = 0;
  2233. oldpos.PrizeParams = null;
  2234. oldpos.ScanQrTrade = 0;
  2235. oldpos.BindMerchantId = 0;
  2236. oldpos.CreditTrade = 0;
  2237. oldpos.DebitCardTrade = 0;
  2238. oldpos.IsVip = 0;
  2239. oldpos.UserNav = null;
  2240. oldpos.TransferTime = null;
  2241. oldpos.IsPurchase = 0;
  2242. oldpos.Detail = null;
  2243. oldpos.BindingTime = null;
  2244. oldpos.BindingState = 0;
  2245. oldpos.ActivationTime = null;
  2246. oldpos.ActivationState = 0;
  2247. oldpos.LeaderUserId = 0;
  2248. oldpos.PreUserId = 0;
  2249. oldpos.IsFirst = 0;
  2250. oldpos.DownFeeMan = null;
  2251. oldpos.DownFeeFlag = 0;
  2252. oldpos.DownFeeDate = null;
  2253. oldpos.UpFeeMan = null;
  2254. oldpos.UpFeeFlag = 0;
  2255. oldpos.UpFeeDate = null;
  2256. oldpos.OpReserve1 = 0;
  2257. oldpos.OpReserve2 = 0;
  2258. oldpos.OpReserve3 = 0;
  2259. oldpos.OpId = 0;
  2260. oldpos.RecycStartDate = null;
  2261. oldpos.SourcePosSn = null;
  2262. oldpos.BuyUserId = 0;
  2263. oldpos.UserId = 0;
  2264. oldpos.Status = -1;
  2265. oldpos.FirstFlag = 0;
  2266. oldpos.IsExecute = 0;
  2267. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  2268. db.SaveChanges();
  2269. opdb.SaveChanges();
  2270. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  2271. {
  2272. CreateDate = DateTime.Now,
  2273. CreateMan = SysUserName + "-" + SysRealName,
  2274. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  2275. OutStoreId = storeFrom.Id,
  2276. BackStoreId = storeBack.Id,
  2277. OutProductType = newpos.BrandId,
  2278. BackProductType = oldpos.BrandId,
  2279. UserId = store.UserId, //创客
  2280. }).Entity;
  2281. db.SaveChanges();
  2282. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  2283. {
  2284. CreateDate = DateTime.Now,
  2285. CreateMan = SysUserName + "-" + SysRealName,
  2286. OutSnNo = OldSnNum,
  2287. BackSnNo = NewSnNum,
  2288. ChangeNo = add.ChangeNo, //转换单号
  2289. ChangeId = add.Id, //转换记录Id
  2290. UserId = add.UserId, //创客
  2291. }).Entity;
  2292. db.SaveChanges();
  2293. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2294. if (IsSend == 1)
  2295. {
  2296. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2297. {
  2298. UserId = store.UserId, //接收创客
  2299. MsgType = 2,
  2300. Title = "坏机换新成功通知", //标题
  2301. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  2302. CreateDate = DateTime.Now,
  2303. }));
  2304. }
  2305. //同步商户交易额
  2306. RedisDbconn.Instance.AddList("SycnMerchantTradeQueue", "{\"OldPosId\":\"" + oldpos.LastMerchantId + "\",\"NewPosId\":\"" + newpos.LastMerchantId + "\"}");
  2307. }
  2308. }
  2309. foreach (string sub in opData)
  2310. {
  2311. string[] datalist = sub.Split(":");
  2312. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  2313. }
  2314. return "success";
  2315. }
  2316. #endregion
  2317. #region 创客跨品牌换机
  2318. public IActionResult ChangePosCrossBrand(string right)
  2319. {
  2320. ViewBag.RightInfo = RightInfo;
  2321. ViewBag.right = right;
  2322. return View();
  2323. }
  2324. [HttpPost]
  2325. public string ChangePosCrossBrandDo(string MakerCode, string OldSn, string BackStoreNo, string NewSn, string FromStoreNo, int IsSend = 0)
  2326. {
  2327. string[] OldSnList;
  2328. string[] NewSnList;
  2329. decimal amount = 0;
  2330. List<string> opData = new List<string>();
  2331. if (string.IsNullOrEmpty(MakerCode))
  2332. {
  2333. return "请输入创客编号";
  2334. }
  2335. if (string.IsNullOrEmpty(OldSn))
  2336. {
  2337. return "请输入旧机SN";
  2338. }
  2339. if (string.IsNullOrEmpty(BackStoreNo))
  2340. {
  2341. return "请输入旧机退回仓库编号";
  2342. }
  2343. if (string.IsNullOrEmpty(NewSn))
  2344. {
  2345. return "请输入新机SN";
  2346. }
  2347. if (string.IsNullOrEmpty(FromStoreNo))
  2348. {
  2349. return "请输入新机发货仓库编号";
  2350. }
  2351. OldSnList = OldSn.Replace("\r", "").Replace("\n", ",").Split(',');
  2352. NewSnList = NewSn.Replace("\r", "").Replace("\n", ",").Split(',');
  2353. if (OldSnList.Length != NewSnList.Length)
  2354. {
  2355. return "原机具SN数量和新机具SN数量不一致";
  2356. }
  2357. var ChangeRecordNo = "KPHJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //变更记录单号
  2358. for (int i = 0; i < OldSnList.Length; i++)
  2359. {
  2360. string OldSnNum = OldSnList[i];
  2361. string NewSnNum = NewSnList[i];
  2362. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  2363. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  2364. if (userInfo.Id == 0)
  2365. {
  2366. return MakerCode + "不存在或关联信息缺失";
  2367. }
  2368. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  2369. if (storeForCodeFrom.StoreId == 0)
  2370. {
  2371. return "您输入的新机发货仓库编号不存在";
  2372. }
  2373. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  2374. if (storeForCodeBack.StoreId == 0)
  2375. {
  2376. return "您输入的旧机退回仓库编号不存在";
  2377. }
  2378. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  2379. if (oldForSnNo.SnId == 0)
  2380. {
  2381. return OldSnNum + "不存在或关联信息缺失";
  2382. }
  2383. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  2384. if (newForSnNo.SnId == 0)
  2385. {
  2386. return NewSnNum + "不存在或关联信息缺失";
  2387. }
  2388. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.ActivationState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  2389. if (oldpos.Id == 0)
  2390. {
  2391. return "您输入的旧机SN不存在或者不在" + MakerCode + "名下";
  2392. }
  2393. 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();
  2394. if (newpos.Id == 0)
  2395. {
  2396. return "您输入的新机SN不存在或不满足条件";
  2397. }
  2398. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  2399. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  2400. {
  2401. return "您输入的新机发货仓库不符新机机具对应品牌";
  2402. }
  2403. if (newpos.StoreId != storeFrom.Id)
  2404. {
  2405. return "您输入的新机SN不在新机发货仓库";
  2406. }
  2407. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  2408. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  2409. {
  2410. return "您输入的旧机退回仓库不符旧机机具对应品牌";
  2411. }
  2412. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2413. var brandNew = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  2414. if (brandInfo.Kind != brandNew.Kind)
  2415. {
  2416. return "原机具和新机具不是同种机型(电签或大POS)";
  2417. }
  2418. if (brandInfo.Name.Contains("大POS"))
  2419. {
  2420. amount = 300;
  2421. }
  2422. if (brandInfo.Name.Contains("电签"))
  2423. {
  2424. amount = 200;
  2425. }
  2426. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  2427. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  2428. storeFromUserAcount.ValidAmount += amount;
  2429. storeBackUserAcount.ValidAmount -= amount;
  2430. storeFrom.LaveNum -= 1;
  2431. storeBack.LaveNum += 1;
  2432. if (oldpos.OpId > 0)
  2433. {
  2434. if (newpos.OpId > 0)
  2435. {
  2436. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  2437. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  2438. opUserAccount.ValidAmount += oldpos.OpReserve3;
  2439. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  2440. opUserAccount.TotalAmt += oldpos.OpReserve1;
  2441. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  2442. {
  2443. CreateDate = DateTime.Now,
  2444. UserId = oldpos.OpId,
  2445. SeoDescription = "创客跨品牌换机",
  2446. OperateType = 1,
  2447. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2448. BeforeAmount = TotalAmount,
  2449. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2450. }).Entity;
  2451. }
  2452. if (newpos.OpId == 0)
  2453. {
  2454. newpos.OpReserve1 = oldpos.OpReserve1;
  2455. newpos.OpReserve2 = oldpos.OpReserve3;
  2456. newpos.OpReserve3 = oldpos.OpReserve1;
  2457. newpos.OpId = oldpos.OpId;
  2458. }
  2459. }
  2460. //发出方
  2461. db.StoreChangeHistory.Add(new StoreChangeHistory()
  2462. {
  2463. CreateDate = DateTime.Now,
  2464. UserId = userInfo.Id, //创客
  2465. BrandId = newpos.BrandId,//产品类型
  2466. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  2467. TransType = 6, //交易类型(0 采购 1 调拨 2 出货 3 退货 4 驳回 5 回仓退款 6 换机出库 7 换机入库)
  2468. SnNo = newpos.PosSn, //SN编号
  2469. SnType = newpos.PosSnType, //SN机具类型
  2470. StockOpDirect = 1, //库存操作方向(0 入库 1 出库)
  2471. DeviceVendor = newpos.DeviceName, //设备厂商
  2472. DeviceModel = newpos.DeviceKind, //设备型号
  2473. DeviceType = newpos.DeviceType, //设备类型
  2474. // FromUserId = storeFrom.UserId, //出货创客
  2475. StoreId = storeFrom.Id,//出货仓库
  2476. FromDate = DateTime.Now, //出库时间
  2477. FromRemark = "跨品牌换机,出库", //出库备注
  2478. SourceStoreId = newpos.SourceStoreId, //源仓库
  2479. ToUserId = userInfo.Id,//收货创客
  2480. });
  2481. //接收方
  2482. db.StoreChangeHistory.Add(new StoreChangeHistory()
  2483. {
  2484. CreateDate = DateTime.Now,
  2485. UserId = userInfo.Id, //创客
  2486. BrandId = oldpos.BrandId,//产品类型
  2487. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  2488. TransType = 7, //交易类型(0 采购 1 调拨 2 出货 3 退货 4 驳回 5 回仓退款 6 换机出库 7 换机入库)
  2489. SnNo = oldpos.PosSn, //SN编号
  2490. SnType = oldpos.PosSnType, //SN机具类型
  2491. StockOpDirect = 0, //库存操作方向(0 入库 1 出库)
  2492. DeviceVendor = oldpos.DeviceName, //设备厂商
  2493. DeviceModel = oldpos.DeviceKind, //设备型号
  2494. DeviceType = oldpos.DeviceType, //设备类型
  2495. StoreId = oldpos.StoreId,//出货仓库
  2496. FromDate = DateTime.Now, //出库时间
  2497. FromRemark = "跨品牌换机,入库", //出库备注
  2498. SourceStoreId = oldpos.SourceStoreId, //源仓库
  2499. ToStoreId = storeBack.Id,//收货仓库
  2500. });
  2501. newpos.BuyUserId = oldpos.BuyUserId;
  2502. newpos.UserId = oldpos.UserId;
  2503. newpos.RecycEndDate = oldpos.RecycEndDate;
  2504. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  2505. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  2506. newpos.CreditTrade = oldpos.CreditTrade;
  2507. newpos.PosSnType = oldpos.PosSnType;
  2508. newpos.TransferTime = oldpos.TransferTime;
  2509. newpos.IsPurchase = oldpos.IsPurchase;
  2510. newpos.BindingState = oldpos.BindingState;
  2511. newpos.ActivationState = oldpos.ActivationState;
  2512. newpos.BindingTime = oldpos.BindingTime;
  2513. newpos.ActivationTime = oldpos.ActivationTime;
  2514. newpos.IsFirst = oldpos.IsFirst;
  2515. newpos.SeoKeyword = oldpos.SeoKeyword;
  2516. newpos.PrizeParams = oldpos.PrizeParams;
  2517. newpos.LeaderUserId = oldpos.LeaderUserId;
  2518. newpos.BindMerchantId = oldpos.BindMerchantId;
  2519. newpos.FirstFlag = oldpos.FirstFlag;
  2520. newpos.IsExecute = oldpos.IsExecute;
  2521. newpos.PreUserId = oldpos.PreUserId;
  2522. if (!opData.Contains(newpos.BuyUserId + ":" + newpos.BrandId))
  2523. {
  2524. opData.Add(newpos.BuyUserId + ":" + newpos.BrandId);
  2525. }
  2526. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  2527. {
  2528. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  2529. }
  2530. oldpos.StoreId = storeBack.Id;
  2531. oldpos.QueryCount = 0;
  2532. oldpos.UpdateDate = null;
  2533. oldpos.ActivityList = null;
  2534. oldpos.SeoKeyword = null;
  2535. oldpos.SeoDescription = null;
  2536. oldpos.OrderId = 0;
  2537. oldpos.RecycEndDate = null;
  2538. oldpos.RecycBackCount = 0;
  2539. oldpos.PrizeParams = null;
  2540. oldpos.ScanQrTrade = 0;
  2541. oldpos.BindMerchantId = 0;
  2542. oldpos.CreditTrade = 0;
  2543. oldpos.DebitCardTrade = 0;
  2544. oldpos.IsVip = 0;
  2545. oldpos.UserNav = null;
  2546. oldpos.TransferTime = null;
  2547. oldpos.IsPurchase = 0;
  2548. oldpos.Detail = null;
  2549. oldpos.BindingTime = null;
  2550. oldpos.BindingState = 0;
  2551. oldpos.ActivationTime = null;
  2552. oldpos.ActivationState = 0;
  2553. oldpos.LeaderUserId = 0;
  2554. oldpos.PreUserId = 0;
  2555. oldpos.IsFirst = 0;
  2556. oldpos.DownFeeMan = null;
  2557. oldpos.DownFeeFlag = 0;
  2558. oldpos.DownFeeDate = null;
  2559. oldpos.UpFeeMan = null;
  2560. oldpos.UpFeeFlag = 0;
  2561. oldpos.UpFeeDate = null;
  2562. oldpos.OpReserve1 = 0;
  2563. oldpos.OpReserve2 = 0;
  2564. oldpos.OpReserve3 = 0;
  2565. oldpos.OpId = 0;
  2566. oldpos.RecycStartDate = null;
  2567. oldpos.SourcePosSn = null;
  2568. oldpos.BuyUserId = 0;
  2569. oldpos.UserId = 0;
  2570. oldpos.FirstFlag = 0;
  2571. oldpos.IsExecute = 0;
  2572. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  2573. db.SaveChanges();
  2574. opdb.SaveChanges();
  2575. if (IsSend == 1)
  2576. {
  2577. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2578. {
  2579. UserId = userForMakerCode.UserId, //接收创客
  2580. MsgType = 2,
  2581. Title = "创客跨品牌换机", //标题
  2582. Summary = "您的旧机 " + brandInfo.Name + " SN:" + OldSnNum + "已经成功为您换为" + brandNew.Name + "SN:" + NewSnNum + "。",
  2583. CreateDate = DateTime.Now,
  2584. }));
  2585. }
  2586. //同步商户交易额
  2587. RedisDbconn.Instance.AddList("SycnMerchantTradeQueue", "{\"OldPosId\":\"" + oldpos.LastMerchantId + "\",\"NewPosId\":\"" + newpos.LastMerchantId + "\"}");
  2588. }
  2589. foreach (string sub in opData)
  2590. {
  2591. string[] datalist = sub.Split(":");
  2592. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  2593. }
  2594. return "success";
  2595. }
  2596. #endregion
  2597. #region 机具解绑
  2598. public IActionResult Unbind(string right)
  2599. {
  2600. ViewBag.RightInfo = RightInfo;
  2601. ViewBag.right = right;
  2602. return View();
  2603. }
  2604. [HttpPost]
  2605. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  2606. {
  2607. if (string.IsNullOrEmpty(PosSn))
  2608. {
  2609. return "请输入机具SN";
  2610. }
  2611. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  2612. if (forSnNo == null)
  2613. {
  2614. return "机具SN不存在";
  2615. }
  2616. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  2617. if (pos == null)
  2618. {
  2619. return "机具SN不存在";
  2620. }
  2621. if (pos.ActivationState == 1)
  2622. {
  2623. return "机具已激活,不能解绑";
  2624. }
  2625. if (pos.BuyUserId == 0)
  2626. {
  2627. return "机具是仓库机,不支持解绑";
  2628. }
  2629. if (pos.BindingState == 0)
  2630. {
  2631. return "机具未绑定,不支持解绑";
  2632. }
  2633. // if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  2634. // {
  2635. // return "机具绑定已超过30天,不支持解绑";
  2636. // }
  2637. if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
  2638. {
  2639. return "该机具已交易,无法解绑";
  2640. }
  2641. if (pos.BrandId != 10 || pos.BrandId != 11)
  2642. {
  2643. if (string.IsNullOrEmpty(MakerCode))
  2644. {
  2645. return "请输入创客编号";
  2646. }
  2647. if (string.IsNullOrEmpty(MerNo))
  2648. {
  2649. return "请输入商户编号";
  2650. }
  2651. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2652. if (forMakerCode == null)
  2653. {
  2654. return "创客不存在";
  2655. }
  2656. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2657. if (forMerNo == null)
  2658. {
  2659. return "商户编号不存在";
  2660. }
  2661. if (pos.BuyUserId != forMakerCode.UserId)
  2662. {
  2663. return "机具SN和创客不匹配";
  2664. }
  2665. if (forMerNo != null)
  2666. {
  2667. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2668. if (merchant != null)
  2669. {
  2670. //机具解绑删除客小爽企业版对应数据
  2671. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2672. if (merInfo != null)
  2673. {
  2674. db.BusinessPartnerMerchant.Remove(merInfo);
  2675. }
  2676. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2677. if (posInfo != null)
  2678. {
  2679. db.BusinessPartnerPos.Remove(posInfo);
  2680. }
  2681. db.PosMerchantInfo.Remove(merchant);
  2682. }
  2683. db.MachineForMerNo.Remove(forMerNo);
  2684. db.SaveChanges();
  2685. }
  2686. }
  2687. else
  2688. {
  2689. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  2690. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2691. if (forMerNo != null && posMerchantInfo != null)
  2692. {
  2693. //机具解绑删除客小爽企业版对应数据
  2694. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == posMerchantInfo.Id);
  2695. if (merInfo != null)
  2696. {
  2697. db.BusinessPartnerMerchant.Remove(merInfo);
  2698. }
  2699. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2700. if (posInfo != null)
  2701. {
  2702. db.BusinessPartnerPos.Remove(posInfo);
  2703. }
  2704. db.PosMerchantInfo.Remove(posMerchantInfo);
  2705. db.MachineForMerNo.Remove(forMerNo);
  2706. db.SaveChanges();
  2707. }
  2708. }
  2709. db.MachineUnBind.Add(new MachineUnBind()
  2710. {
  2711. CreateDate = DateTime.Now,
  2712. SeoTitle = SysUserName + "-" + SysRealName,
  2713. MerchantId = pos.BindMerchantId,
  2714. AuditDate = DateTime.Now,
  2715. AuditDesc = "平台操作解绑",
  2716. AuditStatus = 1,
  2717. SnNo = pos.PosSn,
  2718. BrandId = pos.BrandId,
  2719. UserId = pos.BuyUserId,
  2720. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2721. });
  2722. pos.BindMerchantId = 0;
  2723. pos.BindingState = 0;
  2724. pos.BindingTime = null;
  2725. pos.UserId = pos.BuyUserId;
  2726. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2727. db.SaveChanges();
  2728. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2729. if (IsSend == 1)
  2730. {
  2731. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2732. {
  2733. UserId = pos.BuyUserId, //接收创客
  2734. MsgType = 2,
  2735. Title = "解绑成功通知", //标题
  2736. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2737. CreateDate = DateTime.Now,
  2738. }));
  2739. }
  2740. return "success";
  2741. }
  2742. #endregion
  2743. #region 通过券码修改盟主标记
  2744. public IActionResult ChangeSignQuan(string right)
  2745. {
  2746. ViewBag.RightInfo = RightInfo;
  2747. ViewBag.right = right;
  2748. return View();
  2749. }
  2750. [HttpPost]
  2751. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2752. {
  2753. if (string.IsNullOrEmpty(Coupons))
  2754. {
  2755. return "请输入机具券码,多个券码用回车分隔";
  2756. }
  2757. if (string.IsNullOrEmpty(MakerCode))
  2758. {
  2759. return "请输入创客编号";
  2760. }
  2761. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2762. if (forMakerCode == null)
  2763. {
  2764. return "创客不存在";
  2765. }
  2766. string[] SnList = Coupons.Replace("\r", "").Split('\n');
  2767. foreach (var item in SnList)
  2768. {
  2769. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2770. if (coupos == null)
  2771. {
  2772. return "机具券不存在";
  2773. }
  2774. else
  2775. {
  2776. coupos.LeaderUserId = forMakerCode.UserId;
  2777. }
  2778. }
  2779. db.SaveChanges();
  2780. return "success";
  2781. }
  2782. #endregion
  2783. #region 通过机具SN修改盟主标记
  2784. public IActionResult ChangeSignSn(string right)
  2785. {
  2786. ViewBag.RightInfo = RightInfo;
  2787. ViewBag.right = right;
  2788. return View();
  2789. }
  2790. [HttpPost]
  2791. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2792. {
  2793. if (string.IsNullOrEmpty(PosSn))
  2794. {
  2795. return "请输入机具SN,多个SN用回车分隔";
  2796. }
  2797. if (string.IsNullOrEmpty(MakerCode))
  2798. {
  2799. return "请输入创客编号";
  2800. }
  2801. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2802. if (forMakerCode == null)
  2803. {
  2804. return "创客不存在";
  2805. }
  2806. string[] SnList = PosSn.Replace("\r", "").Split('\n');
  2807. foreach (var item in SnList)
  2808. {
  2809. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2810. if (pos == null)
  2811. {
  2812. return "该机具不存在";
  2813. }
  2814. else
  2815. {
  2816. pos.LeaderUserId = forMakerCode.UserId;
  2817. }
  2818. }
  2819. db.SaveChanges();
  2820. return "success";
  2821. }
  2822. #endregion
  2823. #region 机具循环列表
  2824. /// <summary>
  2825. /// 根据条件查询机具循环列表
  2826. /// </summary>
  2827. /// <returns></returns>
  2828. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2829. {
  2830. ViewBag.RightInfo = RightInfo;
  2831. ViewBag.right = right;
  2832. ViewBag.SwapSnExpand = SwapSnExpand;
  2833. ViewBag.SnNos = SnNos;
  2834. return View();
  2835. }
  2836. #endregion
  2837. #region 根据条件查询机具循环列表
  2838. /// <summary>
  2839. /// 机具循环列表
  2840. /// </summary>
  2841. /// <returns></returns>
  2842. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2843. {
  2844. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2845. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2846. Fields.Add("SnNos", "1"); //发货机具SN
  2847. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2848. if (!string.IsNullOrEmpty(SwapSnExpand))
  2849. {
  2850. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2851. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2852. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2853. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2854. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2855. for (int i = 0; i < SnNoList.Length; i++)
  2856. {
  2857. Dictionary<string, object> data = new Dictionary<string, object>();
  2858. data["ApplyNo"] = apply.ApplyNo;
  2859. data["OrderNo"] = order.OrderNo;
  2860. data["MakerCode"] = user.MakerCode;
  2861. data["RealName"] = user.RealName;
  2862. if (SnNoList.Length > i)
  2863. {
  2864. string SourceSn = SnNoList[i].Split(':')[0];
  2865. data["ComeSn"] = SnNoList[i];
  2866. data["ComeSnParam"] = SourceSn;
  2867. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2868. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2869. if (pos.LeaderUserId > 0)
  2870. {
  2871. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2872. data["ComeSnMakerCode"] = leader.MakerCode;
  2873. data["ComeSnRealName"] = leader.RealName;
  2874. }
  2875. }
  2876. if (OrderSnNo.Length > i)
  2877. {
  2878. string SendSn = OrderSnNo[i];
  2879. data["SendSn"] = OrderSnNo[i];
  2880. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2881. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2882. if (pos.LeaderUserId > 0)
  2883. {
  2884. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2885. data["SendSnMakerCode"] = leader.MakerCode;
  2886. data["SendSnRealName"] = leader.RealName;
  2887. }
  2888. }
  2889. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2890. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2891. dataList.Add(data);
  2892. }
  2893. }
  2894. else if (!string.IsNullOrEmpty(SnNos))
  2895. {
  2896. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2897. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2898. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2899. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2900. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2901. for (int i = 0; i < OrderSnNo.Length; i++)
  2902. {
  2903. Dictionary<string, object> data = new Dictionary<string, object>();
  2904. data["ApplyNo"] = apply.ApplyNo;
  2905. data["OrderNo"] = order.OrderNo;
  2906. data["MakerCode"] = user.MakerCode;
  2907. data["RealName"] = user.RealName;
  2908. if (SnNoList.Length > i)
  2909. {
  2910. string SourceSn = SnNoList[i].Split(':')[0];
  2911. data["ComeSn"] = SnNoList[i];
  2912. data["ComeSnParam"] = SourceSn;
  2913. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2914. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2915. if (pos.LeaderUserId > 0)
  2916. {
  2917. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2918. data["ComeSnMakerCode"] = leader.MakerCode;
  2919. data["ComeSnRealName"] = leader.RealName;
  2920. }
  2921. }
  2922. if (OrderSnNo.Length > i)
  2923. {
  2924. string SendSn = OrderSnNo[i];
  2925. data["SendSn"] = OrderSnNo[i];
  2926. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2927. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2928. if (pos.LeaderUserId > 0)
  2929. {
  2930. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2931. data["SendSnMakerCode"] = leader.MakerCode;
  2932. data["SendSnRealName"] = leader.RealName;
  2933. }
  2934. }
  2935. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2936. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2937. dataList.Add(data);
  2938. }
  2939. }
  2940. Dictionary<string, object> obj = new Dictionary<string, object>();
  2941. obj.Add("code", 0);
  2942. obj.Add("msg", "");
  2943. obj.Add("count", dataList.Count);
  2944. obj.Add("data", dataList);
  2945. return Json(obj);
  2946. }
  2947. #endregion
  2948. #region 查询机具循环
  2949. /// <summary>
  2950. /// 根据条件查询机具来源机具和券码
  2951. /// </summary>
  2952. /// <returns></returns>
  2953. public IActionResult SourceLoop(string right, string SnNos)
  2954. {
  2955. ViewBag.RightInfo = RightInfo;
  2956. ViewBag.right = right;
  2957. ViewBag.SnNos = SnNos;
  2958. return View();
  2959. }
  2960. #endregion
  2961. #region 根据条件查询机具来源机具和券码
  2962. /// <summary>
  2963. /// 机具循环列表
  2964. /// </summary>
  2965. /// <returns></returns>
  2966. public string SourceLoopData(string SnNo, int page = 1, int limit = 30)
  2967. {
  2968. var result = "";
  2969. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  2970. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  2971. if (pos.Id == 0)
  2972. {
  2973. return "机具:" + SnNo + "不存在";
  2974. }
  2975. else
  2976. {
  2977. var stattime = pos.RecycStartDate == null ? "" : pos.RecycStartDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2978. var endtime = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2979. result += "循环开始时间:" + stattime + "\n";
  2980. result += "循环结束时间:" + endtime + "\n";
  2981. result += "来源机具/券:" + pos.SourcePosSn + "\n";
  2982. }
  2983. return result;
  2984. }
  2985. #endregion
  2986. #region 查询创客直推奖
  2987. public IActionResult Prize100(string right)
  2988. {
  2989. ViewBag.RightInfo = RightInfo;
  2990. ViewBag.right = right;
  2991. return View();
  2992. }
  2993. [HttpPost]
  2994. public Dictionary<string, string> Prize100Do(string MakerCode)
  2995. {
  2996. Dictionary<string, string> dic = new Dictionary<string, string>();
  2997. string result = "";
  2998. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2999. if (forMakerCode == null)
  3000. {
  3001. result += "创客编号不存在\n";
  3002. dic.Add("code", "1");
  3003. dic.Add("result", result);
  3004. return dic;
  3005. }
  3006. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  3007. if (OrderCount == 0)
  3008. {
  3009. result += "该创客未下单\n";
  3010. dic.Add("code", "1");
  3011. dic.Add("result", result);
  3012. return dic;
  3013. }
  3014. if (OrderCount > 1)
  3015. {
  3016. result += "该创客已不是首笔下单\n";
  3017. dic.Add("code", "1");
  3018. dic.Add("result", result);
  3019. return dic;
  3020. }
  3021. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  3022. if (order.PayStatus < 1)
  3023. {
  3024. result += "未付款\n";
  3025. dic.Add("code", "1");
  3026. dic.Add("result", result);
  3027. return dic;
  3028. }
  3029. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  3030. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  3031. result += "订单号:" + order.OrderNo + "\n";
  3032. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  3033. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  3034. int posCouponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张未使用的券
  3035. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  3036. if (posCouponCount + ActiveCount >= 3)
  3037. {
  3038. string IsGet = "未发放";
  3039. int ToUserId = 0;
  3040. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  3041. if (item == null)
  3042. {
  3043. DateTime start = order.PayDate.Value.AddMinutes(-2);
  3044. DateTime end = order.PayDate.Value.AddMinutes(2);
  3045. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  3046. }
  3047. if (item != null)
  3048. {
  3049. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  3050. ToUserId = item.UserId;
  3051. dic.Add("code", "1");
  3052. }
  3053. else
  3054. {
  3055. dic.Add("id", order.Id.ToString());
  3056. dic.Add("code", "0");
  3057. }
  3058. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  3059. result += "是否发放:" + IsGet + "\n";
  3060. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  3061. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  3062. }
  3063. else
  3064. {
  3065. result += "上级创客未满足条件\n手中有未使用券:" + posCouponCount + "张,激活机:" + ActiveCount + "台\n";
  3066. dic.Add("code", "1");
  3067. }
  3068. dic.Add("result", result);
  3069. return dic;
  3070. }
  3071. public string AddPrize100(int Id)
  3072. {
  3073. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  3074. if (order != null)
  3075. {
  3076. //机具券逻辑
  3077. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  3078. if (pro != null)
  3079. {
  3080. //推荐下单奖励
  3081. if (pro.ProductId == 10 || pro.ProductId == 11)
  3082. {
  3083. int OrderId = order.Id;
  3084. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  3085. if (!checkPrize)
  3086. {
  3087. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  3088. if (user != null)
  3089. {
  3090. bool directPrize = false; //直推奖标记
  3091. int ParentUserId = user.ParentUserId;
  3092. while (ParentUserId > 0)
  3093. {
  3094. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  3095. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台兑换机
  3096. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  3097. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  3098. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  3099. {
  3100. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  3101. directPrize = true;
  3102. db.SaveChanges();
  3103. return "发放成功";
  3104. }
  3105. ParentUserId = puser.ParentUserId;
  3106. }
  3107. }
  3108. }
  3109. return "已发放,请勿重复发放";
  3110. }
  3111. }
  3112. }
  3113. return "操作失败";
  3114. }
  3115. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  3116. {
  3117. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  3118. if (account == null)
  3119. {
  3120. account = db.UserAccount.Add(new UserAccount()
  3121. {
  3122. Id = UserId,
  3123. UserId = UserId,
  3124. }).Entity;
  3125. db.SaveChanges();
  3126. }
  3127. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  3128. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  3129. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  3130. account.BalanceAmount += 100 * Count;
  3131. account.TotalAmount += 100 * Count;
  3132. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  3133. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  3134. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  3135. UserAccountRecord add = db.UserAccountRecord.Add(new UserAccountRecord()
  3136. {
  3137. CreateDate = DateTime.Now,
  3138. UpdateDate = DateTime.Now,
  3139. UserId = UserId, //创客
  3140. ChangeType = 112, //变动类型
  3141. ChangeAmount = 100 * Count, //变更金额
  3142. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3143. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3144. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3145. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3146. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3147. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3148. QueryCount = OrderId,
  3149. }).Entity;
  3150. db.SaveChanges();
  3151. PublicFunction.SplitUserAccountRecord(add);
  3152. }
  3153. #endregion
  3154. #region 查询机具开机奖
  3155. public IActionResult OpenPrize(string right)
  3156. {
  3157. ViewBag.RightInfo = RightInfo;
  3158. ViewBag.right = right;
  3159. return View();
  3160. }
  3161. [HttpPost]
  3162. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  3163. {
  3164. Dictionary<string, string> dic = new Dictionary<string, string>();
  3165. string result = "";
  3166. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  3167. if (pos == null)
  3168. {
  3169. result += "机具SN号不存在\n";
  3170. dic.Add("code", "1");
  3171. dic.Add("result", result);
  3172. return dic;
  3173. }
  3174. if (pos.BindingState == 0)
  3175. {
  3176. result += "机具未绑定\n";
  3177. dic.Add("code", "1");
  3178. dic.Add("result", result);
  3179. return dic;
  3180. }
  3181. if (pos.ActivationState == 0)
  3182. {
  3183. result += "机具未激活\n";
  3184. dic.Add("code", "1");
  3185. dic.Add("result", result);
  3186. return dic;
  3187. }
  3188. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3189. if (merchant == null)
  3190. {
  3191. result += "商户不存在\n";
  3192. dic.Add("code", "1");
  3193. dic.Add("result", result);
  3194. return dic;
  3195. }
  3196. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3197. result += "机具号:" + PosSn + "\n";
  3198. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  3199. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  3200. string OpenUser10 = "未领取";
  3201. string OpenUser20 = "未领取";
  3202. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  3203. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  3204. if (openreward.Id > 0)
  3205. {
  3206. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  3207. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3208. }
  3209. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  3210. if (openreward.Id > 0)
  3211. {
  3212. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  3213. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3214. }
  3215. result += "开机奖20:" + OpenUser20 + "\n";
  3216. dic.Add("id", pos.Id.ToString());
  3217. dic.Add("code", "0");
  3218. dic.Add("result", result);
  3219. return dic;
  3220. }
  3221. public string AddOpenPrize(int Id)
  3222. {
  3223. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  3224. if (pos == null)
  3225. {
  3226. return "机具未激活";
  3227. }
  3228. if (pos.BindingTime <= pos.TransferTime)
  3229. {
  3230. return "补录机,不能补发开机奖";
  3231. }
  3232. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  3233. if (ActPrize == 0)
  3234. {
  3235. return "机具无押金";
  3236. }
  3237. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3238. if (merchant == null)
  3239. {
  3240. return "商户不存在";
  3241. }
  3242. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  3243. if (check)
  3244. {
  3245. return "开机奖励已发放,请勿重复操作";
  3246. }
  3247. // 从机具所属人上级开始分开机奖励
  3248. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  3249. if (user != null)
  3250. {
  3251. RedisDbconn.Instance.AddList("OpenRewardQueue", Id.ToString());
  3252. return "操作成功,请稍后查询";
  3253. }
  3254. db.Dispose();
  3255. return "操作失败";
  3256. }
  3257. #endregion
  3258. #region 查询机具流量费分佣
  3259. public IActionResult FluxPrize(string right)
  3260. {
  3261. ViewBag.RightInfo = RightInfo;
  3262. ViewBag.right = right;
  3263. return View();
  3264. }
  3265. [HttpPost]
  3266. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  3267. {
  3268. Dictionary<string, string> dic = new Dictionary<string, string>();
  3269. string result = "";
  3270. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  3271. if (pos == null)
  3272. {
  3273. result += "机具SN号不存在\n";
  3274. dic.Add("code", "1");
  3275. dic.Add("result", result);
  3276. return dic;
  3277. }
  3278. if (pos.BindingState == 0)
  3279. {
  3280. result += "机具未绑定\n";
  3281. dic.Add("code", "1");
  3282. dic.Add("result", result);
  3283. return dic;
  3284. }
  3285. if (pos.ActivationState == 0)
  3286. {
  3287. result += "机具未激活\n";
  3288. dic.Add("code", "1");
  3289. dic.Add("result", result);
  3290. return dic;
  3291. }
  3292. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3293. if (merchant == null)
  3294. {
  3295. result += "商户不存在\n";
  3296. dic.Add("code", "1");
  3297. dic.Add("result", result);
  3298. return dic;
  3299. }
  3300. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3301. result += "机具号:" + PosSn + "\n";
  3302. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  3303. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  3304. string FluxGet6 = "未领取";
  3305. string FluxUser6 = "";
  3306. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  3307. if (flux.Id > 0)
  3308. {
  3309. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  3310. FluxGet6 = "已领取(金额:" + flux.FluxFeeAmt + ",领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  3311. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3312. }
  3313. result += "流量费:" + FluxGet6 + "\n";
  3314. result += "流量费发放对象:" + FluxUser6 + "\n";
  3315. dic.Add("id", pos.Id.ToString());
  3316. dic.Add("code", "0");
  3317. dic.Add("result", result);
  3318. return dic;
  3319. }
  3320. public string AddFluxPrize(int Id)
  3321. {
  3322. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  3323. if (pos == null)
  3324. {
  3325. return "机具未激活";
  3326. }
  3327. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  3328. if (ActPrize == 0)
  3329. {
  3330. return "机具无押金";
  3331. }
  3332. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3333. if (merchant == null)
  3334. {
  3335. return "商户不存在";
  3336. }
  3337. if (pos.BrandId == 6)
  3338. {
  3339. return "立刷不支持流量费分佣";
  3340. }
  3341. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  3342. {
  3343. return "无押金机,不支持流量费分佣";
  3344. }
  3345. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  3346. if (check)
  3347. {
  3348. return "流量费奖励已发放,请勿重复操作";
  3349. }
  3350. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  3351. if (trade != null)
  3352. {
  3353. try
  3354. {
  3355. string OrderNo = trade.TradeSerialNo; //单号
  3356. DateTime TradeDate = trade.CreateDate.Value;
  3357. string TradeMonth = TradeDate.ToString("yyyyMM");
  3358. decimal FeeAmount = trade.FeeAmount; //流量费
  3359. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  3360. {
  3361. FeeAmount = FeeAmount / 100;
  3362. }
  3363. string TradeSnNo = trade.TradeSnNo; //机具SN
  3364. decimal FluxProfit = 0;
  3365. if (trade.ProductType == "1" && FeeAmount == 60)
  3366. {
  3367. FluxProfit = 24;
  3368. }
  3369. else if (trade.ProductType == "7" && FeeAmount == 46)
  3370. {
  3371. FluxProfit = 10;
  3372. }
  3373. else if (trade.ProductType != "1" && FeeAmount == 48)
  3374. {
  3375. FluxProfit = 12;
  3376. }
  3377. if (FluxProfit > 0)
  3378. {
  3379. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3380. int GetUserId = user.Id;
  3381. int TopUserId = 0;
  3382. string ParentNav = user.ParentNav;
  3383. if (!string.IsNullOrEmpty(ParentNav))
  3384. {
  3385. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  3386. if (ParentNavList.Length > 1)
  3387. {
  3388. TopUserId = int.Parse(ParentNavList[1]);
  3389. }
  3390. else if (ParentNavList.Length == 1)
  3391. {
  3392. TopUserId = int.Parse(ParentNavList[0]);
  3393. }
  3394. }
  3395. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  3396. if (fluxProfit == null)
  3397. {
  3398. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  3399. {
  3400. CreateDate = DateTime.Now,
  3401. UpdateDate = DateTime.Now,
  3402. UserId = GetUserId, //创客
  3403. BrandId = pos.BrandId,
  3404. TopUserId = TopUserId, //顶级创客
  3405. TradeMonth = TradeMonth, //交易月
  3406. MerUserType = user.MerchantType, //商户创客类型
  3407. Remark = "流量卡分佣", //备注
  3408. }).Entity;
  3409. db.SaveChanges();
  3410. }
  3411. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  3412. db.FluxProfitDetail.Add(new FluxProfitDetail()
  3413. {
  3414. CreateDate = DateTime.Now,
  3415. UpdateDate = DateTime.Now,
  3416. RecordNo = OrderNo, //单号
  3417. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  3418. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  3419. TradeMonth = TradeMonth, //交易月
  3420. UserId = GetUserId, //创客
  3421. MerchantId = pos.BindMerchantId, //商户
  3422. MerchantUserId = pos.UserId, //商户直属人
  3423. MerNo = merchant.KqMerNo, //渠道商户编号
  3424. SnNo = pos.PosSn, //渠道SN号
  3425. FluxOrderNo = OrderNo, //流量扣费单号
  3426. TradeOrderNo = OrderNo, //交易流水号
  3427. TradeAmt = trade.TradeAmount, //商户交易额
  3428. FluxFeeAmt = FeeAmount, //流量费
  3429. FluxProfitAmt = FluxProfit, //流量分润总金额
  3430. PosType = pos.PosSnType.ToString(), //POS类型
  3431. Remark = "流量卡分佣", //备注
  3432. BrandId = pos.BrandId, //品牌
  3433. TopUserId = TopUserId, //顶级创客
  3434. MerUserType = user.MerchantType, //商户创客类型
  3435. });
  3436. string IdBrand = user.Id + "_" + pos.BrandId;
  3437. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  3438. if (userData == null)
  3439. {
  3440. userData = db.UserMachineData.Add(new UserMachineData()
  3441. {
  3442. IdBrand = IdBrand,
  3443. }).Entity;
  3444. db.SaveChanges();
  3445. }
  3446. userData.FluxProfit += FluxProfit;
  3447. db.SaveChanges();
  3448. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  3449. if (account == null)
  3450. {
  3451. account = db.UserAccount.Add(new UserAccount()
  3452. {
  3453. Id = GetUserId,
  3454. UserId = GetUserId,
  3455. }).Entity;
  3456. db.SaveChanges();
  3457. }
  3458. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  3459. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  3460. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  3461. account.BalanceAmount += FluxProfit;
  3462. account.TotalAmount += FluxProfit;
  3463. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  3464. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  3465. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  3466. UserAccountRecord add = db.UserAccountRecord.Add(new UserAccountRecord()
  3467. {
  3468. CreateDate = DateTime.Now,
  3469. UpdateDate = DateTime.Now,
  3470. UserId = GetUserId, //创客
  3471. ChangeType = 60, //变动类型
  3472. ProductType = pos.BrandId, //产品类型
  3473. ChangeAmount = FluxProfit, //变更金额
  3474. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3475. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3476. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3477. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3478. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3479. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3480. }).Entity;
  3481. db.SaveChanges();
  3482. spdb.Dispose();
  3483. db.Dispose();
  3484. PublicFunction.SplitUserAccountRecord(add);
  3485. return "发放成功";
  3486. }
  3487. }
  3488. catch (Exception ex)
  3489. {
  3490. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  3491. }
  3492. }
  3493. spdb.Dispose();
  3494. db.Dispose();
  3495. return "操作失败";
  3496. }
  3497. #endregion
  3498. #region 设置立刷费率
  3499. public IActionResult LisFee(string right)
  3500. {
  3501. ViewBag.RightInfo = RightInfo;
  3502. ViewBag.right = right;
  3503. return View();
  3504. }
  3505. [HttpPost]
  3506. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  3507. {
  3508. if (string.IsNullOrEmpty(PosSns))
  3509. {
  3510. return "请输入机具号";
  3511. }
  3512. string result = SysUserName + "设置\n";
  3513. string[] PosSnList = PosSns.Replace("\r", "").Split('\n');
  3514. int total = PosSnList.Length;
  3515. int index = 0;
  3516. foreach (string SubPosSn in PosSnList)
  3517. {
  3518. index += 1;
  3519. string PosSn = SubPosSn.Replace("\r", "");
  3520. result += PosSn + ":" + Fee + "\n";
  3521. if (Kind == "M5")
  3522. {
  3523. result += SetLiSFee(PosSn, Fee) + "\n";
  3524. }
  3525. else if (Kind == "N1")
  3526. {
  3527. result += SetLiSDeposit(PosSn, (int)Fee);
  3528. }
  3529. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  3530. }
  3531. result += "\n\n";
  3532. function.WriteLog(result, "设置立刷费率");
  3533. return result;
  3534. }
  3535. public string LisFeeProcess()
  3536. {
  3537. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  3538. }
  3539. #region 立刷
  3540. string LiSAgentId = "50814834";
  3541. 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=";
  3542. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  3543. public string LiSSign(string data)
  3544. {
  3545. var rsa = RSA.Create();
  3546. var key = Convert.FromBase64String(LiSPrivateKey);
  3547. var content = Encoding.UTF8.GetBytes(data);
  3548. rsa.ImportPkcs8PrivateKey(key, out _);
  3549. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  3550. return Convert.ToBase64String(result);
  3551. }
  3552. // 设置费率
  3553. public string SetLiSFee(string sn, decimal serviceFee)
  3554. {
  3555. Dictionary<string, object> dic = new Dictionary<string, object>();
  3556. dic.Add("agentId", LiSAgentId);
  3557. dic.Add("deviceSn", sn);
  3558. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3559. Dictionary<string, object> item = new Dictionary<string, object>();
  3560. item.Add("feeCalcType", "M5");
  3561. item.Add("fixed", "0");
  3562. item.Add("rate", serviceFee);
  3563. feeList.Add(item);
  3564. dic.Add("feeList", feeList);
  3565. dic.Add("signMethod", "02");
  3566. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  3567. string signstr = LiSSign(content);
  3568. dic.Add("signData", signstr);
  3569. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3570. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3571. return result;
  3572. }
  3573. // 设置押金
  3574. public string SetLiSDeposit(string sn, int serviceFee)
  3575. {
  3576. serviceFee = serviceFee * 100;
  3577. Dictionary<string, object> dic = new Dictionary<string, object>();
  3578. dic.Add("agentId", LiSAgentId);
  3579. dic.Add("deviceSn", sn);
  3580. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3581. Dictionary<string, object> item = new Dictionary<string, object>();
  3582. item.Add("feeCalcType", "N1");
  3583. item.Add("fixed", "1");
  3584. item.Add("rate", serviceFee);
  3585. feeList.Add(item);
  3586. dic.Add("feeList", feeList);
  3587. dic.Add("signMethod", "02");
  3588. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  3589. string signstr = LiSSign(content);
  3590. dic.Add("signData", signstr);
  3591. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3592. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3593. return result;
  3594. }
  3595. #endregion
  3596. #endregion
  3597. #region 查询商户型创客设置信息
  3598. public IActionResult SeeMerchantType(string right)
  3599. {
  3600. ViewBag.RightInfo = RightInfo;
  3601. ViewBag.right = right;
  3602. return View();
  3603. }
  3604. [HttpPost]
  3605. public string SeeMerchantTypeDo(string PosSn)
  3606. {
  3607. if (string.IsNullOrEmpty(PosSn))
  3608. {
  3609. return "请输入机具SN或者创客编号";
  3610. }
  3611. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3612. if (PosSn.StartsWith("K"))
  3613. {
  3614. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3615. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3616. if (check)
  3617. {
  3618. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3619. }
  3620. }
  3621. else
  3622. {
  3623. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3624. if (check)
  3625. {
  3626. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3627. }
  3628. }
  3629. if (pos.Id == 0)
  3630. {
  3631. return "查无信息";
  3632. }
  3633. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3634. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3635. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3636. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3637. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3638. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3639. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3640. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3641. string result = "";
  3642. result += "机具SN:" + pos.PosSn + "\n";
  3643. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3644. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3645. result += "商户编号:" + pos.MerNo + "\n";
  3646. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3647. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3648. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3649. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3650. result += "是否循环:" + RecycFlag + "\n";
  3651. return result;
  3652. }
  3653. #endregion
  3654. #region 三要素验证
  3655. public IActionResult CheckThreeElements(string right)
  3656. {
  3657. ViewBag.RightInfo = RightInfo;
  3658. ViewBag.right = right;
  3659. return View();
  3660. }
  3661. [HttpPost]
  3662. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3663. {
  3664. var host = "https://bankcard3c.shumaidata.com";
  3665. var path = "/bankcard3c";
  3666. var method = "GET";
  3667. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3668. if (string.IsNullOrEmpty(bankcard))
  3669. {
  3670. return "结算银行卡号";
  3671. }
  3672. if (string.IsNullOrEmpty(idcard))
  3673. {
  3674. return "身份证号";
  3675. }
  3676. if (string.IsNullOrEmpty(name))
  3677. {
  3678. return "真实姓名";
  3679. }
  3680. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3681. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3682. function.WriteLog(querys, "验证三要素日志");
  3683. String bodys = "";
  3684. String url = host + path;
  3685. HttpWebRequest httpRequest = null;
  3686. HttpWebResponse httpResponse = null;
  3687. if (0 < querys.Length)
  3688. {
  3689. url = url + "?" + querys;
  3690. }
  3691. if (host.Contains("https://"))
  3692. {
  3693. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3694. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3695. }
  3696. else
  3697. {
  3698. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3699. }
  3700. httpRequest.Method = method;
  3701. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3702. if (0 < bodys.Length)
  3703. {
  3704. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3705. using (Stream stream = httpRequest.GetRequestStream())
  3706. {
  3707. stream.Write(data, 0, data.Length);
  3708. }
  3709. }
  3710. try
  3711. {
  3712. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3713. }
  3714. catch (WebException ex)
  3715. {
  3716. httpResponse = (HttpWebResponse)ex.Response;
  3717. }
  3718. Stream st = httpResponse.GetResponseStream();
  3719. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3720. string result = reader.ReadToEnd();
  3721. JsonData jsonObj = JsonMapper.ToObject(result);
  3722. result = jsonObj["data"]["desc"].ToString();
  3723. function.WriteLog(result, "验证三要素日志");
  3724. function.WriteLog("\n\n", "验证三要素日志");
  3725. return result;
  3726. }
  3727. #endregion
  3728. #region 四要素验证
  3729. public IActionResult CheckFourElements(string right)
  3730. {
  3731. ViewBag.RightInfo = RightInfo;
  3732. ViewBag.right = right;
  3733. return View();
  3734. }
  3735. [HttpPost]
  3736. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3737. {
  3738. var host = "https://bankcard4c.shumaidata.com";
  3739. var path = "/bankcard4c";
  3740. var method = "GET";
  3741. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3742. if (string.IsNullOrEmpty(bankcard))
  3743. {
  3744. return "请输入结算银行卡号";
  3745. }
  3746. if (string.IsNullOrEmpty(idcard))
  3747. {
  3748. return "请输入身份证号";
  3749. }
  3750. if (string.IsNullOrEmpty(mobile))
  3751. {
  3752. return "请输入银行预留手机号";
  3753. }
  3754. if (string.IsNullOrEmpty(name))
  3755. {
  3756. return "请输入真实姓名";
  3757. }
  3758. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3759. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3760. function.WriteLog(querys, "验证四要素日志");
  3761. String bodys = "";
  3762. String url = host + path;
  3763. HttpWebRequest httpRequest = null;
  3764. HttpWebResponse httpResponse = null;
  3765. if (0 < querys.Length)
  3766. {
  3767. url = url + "?" + querys;
  3768. }
  3769. if (host.Contains("https://"))
  3770. {
  3771. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3772. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3773. }
  3774. else
  3775. {
  3776. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3777. }
  3778. httpRequest.Method = method;
  3779. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3780. if (0 < bodys.Length)
  3781. {
  3782. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3783. using (Stream stream = httpRequest.GetRequestStream())
  3784. {
  3785. stream.Write(data, 0, data.Length);
  3786. }
  3787. }
  3788. try
  3789. {
  3790. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3791. }
  3792. catch (WebException ex)
  3793. {
  3794. httpResponse = (HttpWebResponse)ex.Response;
  3795. }
  3796. Stream st = httpResponse.GetResponseStream();
  3797. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3798. string result = reader.ReadToEnd();
  3799. JsonData jsonObj = JsonMapper.ToObject(result);
  3800. result = jsonObj["data"]["desc"].ToString();
  3801. function.WriteLog(result, "验证四要素日志");
  3802. function.WriteLog("\n\n", "验证四要素日志");
  3803. return result;
  3804. }
  3805. #endregion
  3806. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3807. {
  3808. return true;
  3809. }
  3810. #region 根据机具号同步商户激活状态
  3811. public IActionResult SyncMerchantStatus(string right)
  3812. {
  3813. ViewBag.RightInfo = RightInfo;
  3814. ViewBag.right = right;
  3815. return View();
  3816. }
  3817. [HttpPost]
  3818. public string SyncMerchantStatusDo(string PosSn)
  3819. {
  3820. if (string.IsNullOrEmpty(PosSn))
  3821. {
  3822. return "请输入机具号";
  3823. }
  3824. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3825. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3826. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
  3827. if (posInfo.Id == 0)
  3828. {
  3829. return "机具" + PosSn + "不存在";
  3830. }
  3831. if (posMerchant.Id == 0)
  3832. {
  3833. return "机具绑定商户不存在";
  3834. }
  3835. else
  3836. {
  3837. posMerchant.ActiveStatus = 1;
  3838. posMerchant.UpdateDate = DateTime.Now;
  3839. posMerchant.MerStandardDate = posInfo.ActivationTime;
  3840. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
  3841. db.SaveChanges();
  3842. }
  3843. return "success";
  3844. }
  3845. #endregion
  3846. #region 根据机具号补发开机奖励
  3847. public IActionResult PosRewardReissued(string right)
  3848. {
  3849. ViewBag.RightInfo = RightInfo;
  3850. ViewBag.right = right;
  3851. return View();
  3852. }
  3853. [HttpPost]
  3854. public string PosRewardReissuedDo(string PosSn)
  3855. {
  3856. if (string.IsNullOrEmpty(PosSn))
  3857. {
  3858. return "请输入机具SN";
  3859. }
  3860. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3861. var PosId = "";
  3862. var error = "";
  3863. foreach (var item in PosSnList)
  3864. {
  3865. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3866. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3867. bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
  3868. if (checkExist)
  3869. {
  3870. error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
  3871. }
  3872. else
  3873. {
  3874. if (posInfo.Id > 0)
  3875. {
  3876. RedisDbconn.Instance.AddList("OpenRewardQueue", posInfo.Id.ToString());
  3877. }
  3878. }
  3879. }
  3880. if (!string.IsNullOrEmpty(error))
  3881. {
  3882. return "Warning|" + error;
  3883. }
  3884. PosId = PosId.TrimEnd(',');
  3885. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
  3886. return "success";
  3887. }
  3888. #endregion
  3889. #region 根据机具号设置费率
  3890. public IActionResult SetPosFee(string right)
  3891. {
  3892. ViewBag.RightInfo = RightInfo;
  3893. ViewBag.right = right;
  3894. return View();
  3895. }
  3896. [HttpPost]
  3897. public string SetPosFeeDo(string PosSn, string FeeType)
  3898. {
  3899. if (string.IsNullOrEmpty(PosSn))
  3900. {
  3901. return "请输入机具SN";
  3902. }
  3903. if (string.IsNullOrEmpty(FeeType))
  3904. {
  3905. return "请输入选择费率";
  3906. }
  3907. if (FeeType == "0")
  3908. {
  3909. FeeType = "0.6";
  3910. }
  3911. if (FeeType == "1")
  3912. {
  3913. FeeType = "0.63";
  3914. }
  3915. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3916. var PosId = "";
  3917. var RecordId = "";
  3918. var error = "";
  3919. foreach (var item in PosSnList)
  3920. {
  3921. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3922. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3923. if (posInfo.Id > 0)
  3924. {
  3925. var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  3926. {
  3927. Sort = posInfo.BrandId,
  3928. CreateDate = DateTime.Now,
  3929. PosId = posInfo.Id,
  3930. PosSn = posInfo.PosSn,
  3931. PosUserId = posInfo.UserId,
  3932. MerchantId = posInfo.BindMerchantId,
  3933. UserId = posInfo.UserId,
  3934. ChangeFee = decimal.Parse(FeeType),
  3935. }).Entity;
  3936. db.SaveChanges();
  3937. PosId += posInfo.Id + ",";
  3938. RecordId += query.Id + ",";
  3939. }
  3940. else
  3941. {
  3942. error += "机具" + PosSn + "不存在";
  3943. }
  3944. }
  3945. if (!string.IsNullOrEmpty(error))
  3946. {
  3947. return "Warning|" + error;
  3948. }
  3949. PosId = PosId.TrimEnd(',');
  3950. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
  3951. string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  3952. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  3953. return "success";
  3954. }
  3955. #endregion
  3956. #region 根据机具号、商户号、商户姓名关联商户和机具信息
  3957. public IActionResult RelationPosAndMerchant(string right)
  3958. {
  3959. ViewBag.RightInfo = RightInfo;
  3960. ViewBag.right = right;
  3961. return View();
  3962. }
  3963. [HttpPost]
  3964. public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
  3965. {
  3966. if (string.IsNullOrEmpty(PosSn))
  3967. {
  3968. return "请输入机具SN";
  3969. }
  3970. if (string.IsNullOrEmpty(MerchantNo))
  3971. {
  3972. return "请输入商户编号";
  3973. }
  3974. if (string.IsNullOrEmpty(MerchantName))
  3975. {
  3976. return "请输入商户姓名";
  3977. }
  3978. var query = PosSn + "," + MerchantNo + "," + MerchantName;
  3979. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
  3980. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
  3981. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3982. if (posMerchant.Id == 0)
  3983. {
  3984. return "商户" + MerchantNo + "不存在";
  3985. }
  3986. else if (pos.Id == 0)
  3987. {
  3988. return "机具" + PosSn + "不存在";
  3989. }
  3990. else
  3991. {
  3992. pos.BindMerchantId = posMerchant.Id;
  3993. db.SaveChanges();
  3994. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
  3995. }
  3996. return "success";
  3997. }
  3998. #endregion
  3999. #region 设置商户信息
  4000. public IActionResult SetMerchantInfo(string right)
  4001. {
  4002. ViewBag.RightInfo = RightInfo;
  4003. ViewBag.right = right;
  4004. return View();
  4005. }
  4006. [HttpPost]
  4007. public string SetMerchantInfoDo(string PosSn, string MerchantNo, string MerchantName, string MerIdcardNo, string MerchantMobile)
  4008. {
  4009. if (string.IsNullOrEmpty(PosSn))
  4010. {
  4011. return "请输入机具SN";
  4012. }
  4013. if (string.IsNullOrEmpty(MerchantNo))
  4014. {
  4015. return "请输入商户编号";
  4016. }
  4017. if (string.IsNullOrEmpty(MerchantName))
  4018. {
  4019. return "请输入商户姓名";
  4020. }
  4021. if (string.IsNullOrEmpty(MerIdcardNo))
  4022. {
  4023. return "请输入商户身份证号";
  4024. }
  4025. if (string.IsNullOrEmpty(MerchantMobile))
  4026. {
  4027. return "请输入商户手机号";
  4028. }
  4029. 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();
  4030. var query = "";
  4031. query += "修改前:" + posMerchant.KqSnNo + "," + posMerchant.MerchantNo + "," + posMerchant.MerchantName + "," + posMerchant.MerIdcardNo + "," + posMerchant.MerchantMobile;
  4032. query += "修改后:" + PosSn + "," + MerchantNo + "," + MerchantName + "," + MerIdcardNo + "," + MerchantMobile;
  4033. if (posMerchant.Id == 0)
  4034. {
  4035. return "商户" + MerchantNo + "不存在或不在" + MerchantName + "名下";
  4036. }
  4037. else
  4038. {
  4039. posMerchant.MerIdcardNo = MerIdcardNo;
  4040. posMerchant.MerchantName = MerchantName;
  4041. posMerchant.MerRealName = MerchantName;
  4042. posMerchant.MerchantMobile = MerchantMobile;
  4043. db.SaveChanges();
  4044. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "设置商户信息");
  4045. }
  4046. return "success";
  4047. }
  4048. #endregion
  4049. #region 认证创客
  4050. public IActionResult AuthMaker(string right)
  4051. {
  4052. ViewBag.RightInfo = RightInfo;
  4053. ViewBag.right = right;
  4054. return View();
  4055. }
  4056. [HttpPost]
  4057. public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
  4058. {
  4059. if (string.IsNullOrEmpty(MakerCode))
  4060. {
  4061. return "请输入创客编号";
  4062. }
  4063. if (string.IsNullOrEmpty(RealName))
  4064. {
  4065. return "请输入真实姓名";
  4066. }
  4067. if (string.IsNullOrEmpty(CertId))
  4068. {
  4069. return "请输入身份证号";
  4070. }
  4071. if (string.IsNullOrEmpty(BackCard))
  4072. {
  4073. return "请输入银行卡号";
  4074. }
  4075. if (string.IsNullOrEmpty(BackName))
  4076. {
  4077. return "请输入银行名称";
  4078. }
  4079. var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
  4080. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  4081. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  4082. if (userInfo.AuthFlag == 1)
  4083. {
  4084. return "已认证";
  4085. }
  4086. else
  4087. {
  4088. userInfo.UpdateDate = DateTime.Now;
  4089. userInfo.RealName = RealName;
  4090. userInfo.AuthFlag = 1;
  4091. if (userInfo.AuthDate == null)
  4092. {
  4093. userInfo.AuthDate = DateTime.Now;
  4094. }
  4095. userInfo.CertId = CertId;
  4096. userInfo.SettleBankCardNo = BackCard;
  4097. userInfo.SettleBankName = BackName;
  4098. db.SaveChanges();
  4099. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
  4100. }
  4101. return "success";
  4102. }
  4103. #endregion
  4104. #region 划拨创客机具
  4105. public IActionResult TransferPos(string right)
  4106. {
  4107. ViewBag.RightInfo = RightInfo;
  4108. ViewBag.right = right;
  4109. return View();
  4110. }
  4111. [HttpPost]
  4112. // public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  4113. // {
  4114. // if (string.IsNullOrEmpty(PosSn))
  4115. // {
  4116. // return "请输入机具SN";
  4117. // }
  4118. // if (string.IsNullOrEmpty(FromMakerCode))
  4119. // {
  4120. // return "请输入机具来源创客编号";
  4121. // }
  4122. // if (string.IsNullOrEmpty(ToMakerCode))
  4123. // {
  4124. // return "请输入划拨对象创客编号";
  4125. // }
  4126. // var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
  4127. // var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4128. // var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4129. // if (posInfo.Id == 0)
  4130. // {
  4131. // return "机具" + PosSn + "不存在";
  4132. // }
  4133. // var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4134. // var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4135. // var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4136. // if (fUserId.Id == 0)
  4137. // {
  4138. // return "来源创客" + FromMakerCode + "不存在";
  4139. // }
  4140. // var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4141. // if (tUserId.Id == 0)
  4142. // {
  4143. // return "划拨创客" + ToMakerCode + "不存在";
  4144. // }
  4145. // if (posInfo.BindingState == 0)
  4146. // {
  4147. // if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  4148. // {
  4149. // posInfo.BuyUserId = tUserId.Id;
  4150. // posInfo.UserId = tUserId.Id;
  4151. // }
  4152. // else
  4153. // {
  4154. // posInfo.BuyUserId = tUserId.Id;
  4155. // }
  4156. // var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4157. // var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4158. // fUserPos.TotalMachineCount -= 1;
  4159. // fUserPos.UnBindCount -= 1;
  4160. // tUserPos.TotalMachineCount += 1;
  4161. // tUserPos.UnBindCount += 1;
  4162. // db.SaveChanges();
  4163. // function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  4164. // }
  4165. // else
  4166. // {
  4167. // return "机具" + PosSn + "已使用";
  4168. // }
  4169. // return "success";
  4170. // }
  4171. // #endregion
  4172. public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  4173. {
  4174. if (string.IsNullOrEmpty(PosSn))
  4175. {
  4176. return "请输入机具SN";
  4177. }
  4178. if (string.IsNullOrEmpty(FromMakerCode))
  4179. {
  4180. return "请输入机具来源创客编号";
  4181. }
  4182. if (string.IsNullOrEmpty(ToMakerCode))
  4183. {
  4184. return "请输入划拨对象创客编号";
  4185. }
  4186. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4187. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4188. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4189. if (fUserId.Id == 0)
  4190. {
  4191. return "来源创客" + FromMakerCode + "不存在";
  4192. }
  4193. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4194. if (tUserId.Id == 0)
  4195. {
  4196. return "划拨创客" + ToMakerCode + "不存在";
  4197. }
  4198. List<int> SnIds = new List<int>();
  4199. string[] PosSnList = PosSn.Replace("\r", "").Replace("\n", ",").Split(',');
  4200. string error = "";
  4201. foreach (string Sn in PosSnList)
  4202. {
  4203. 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();
  4204. if (posInfo.Id == 0)
  4205. {
  4206. error += "以下操作失败" + Sn + ',' + "不存在或者不符合条件" + '\n';
  4207. }
  4208. else
  4209. {
  4210. SnIds.Add(posInfo.Id);
  4211. }
  4212. }
  4213. if (!string.IsNullOrEmpty(error))
  4214. {
  4215. return "Warning|" + error;
  4216. }
  4217. else
  4218. {
  4219. var ChangeRecordNo = "HBJJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //变更记录单号
  4220. foreach (int SnId in SnIds)
  4221. {
  4222. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
  4223. if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  4224. {
  4225. posInfo.BuyUserId = tUserId.Id;
  4226. posInfo.UserId = tUserId.Id;
  4227. }
  4228. else
  4229. {
  4230. posInfo.BuyUserId = tUserId.Id;
  4231. }
  4232. var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4233. var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4234. fUserPos.TotalMachineCount -= 1;
  4235. fUserPos.UnBindCount -= 1;
  4236. tUserPos.TotalMachineCount += 1;
  4237. tUserPos.UnBindCount += 1;
  4238. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4239. {
  4240. CreateDate = DateTime.Now,
  4241. UserId = fUserId.Id, //创客
  4242. BrandId = posInfo.BrandId,//产品类型
  4243. // ChangeRecordNo = "HBJJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  4244. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  4245. TransType = 1, //交易类型
  4246. SnNo = posInfo.PosSn, //SN编号
  4247. SnType = posInfo.PosSnType, //SN机具类型
  4248. StockOpDirect = 1, //库存操作方向
  4249. DeviceVendor = posInfo.DeviceName, //设备厂商
  4250. DeviceModel = posInfo.DeviceKind, //设备型号
  4251. DeviceType = posInfo.DeviceType, //设备类型
  4252. FromUserId = fUserId.Id, //出货创客
  4253. FromDate = DateTime.Now, //出库时间
  4254. FromRemark = "划拨创客机具", //出库备注
  4255. SourceStoreId = posInfo.SourceStoreId, //源仓库
  4256. ToUserId = tUserId.Id,//收货创客
  4257. });
  4258. UserStoreChange userstore = db.UserStoreChange.Add(new UserStoreChange()
  4259. {
  4260. CreateDate = DateTime.Now,
  4261. UserId = fUserId.Id, //创客
  4262. BrandId = posInfo.BrandId, //产品类型
  4263. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  4264. TransType = 0, //交易类型
  4265. SnNo = posInfo.PosSn, //SN编号
  4266. SnType = posInfo.PosSnType, //SN机具类型
  4267. StockOpDirect = 0, //库存操作方向
  4268. DeviceVendor = posInfo.DeviceName, //设备厂商
  4269. DeviceType = posInfo.DeviceKind, //设备类型
  4270. DeviceModel = posInfo.DeviceType, //设备型号
  4271. ToUserId = tUserId.Id, //收货创客
  4272. ToDate = DateTime.Now, //入库时间
  4273. SourceStoreId = posInfo.SourceStoreId, //源仓库
  4274. SnStatus = 1, //SN状态
  4275. BindStatus = (int)posInfo.BindingState, //绑定状态
  4276. BindMerchantId = posInfo.BindMerchantId, //绑定商户
  4277. ActiveStatus = (int)posInfo.ActivationState, //激活状态
  4278. ActRewardUserId = posInfo.BuyUserId, //激活奖励创客
  4279. BrandType = posInfo.DeviceType, //品牌类型
  4280. }).Entity;
  4281. }
  4282. var query = SnIds + ";" + FromMakerCode + ";" + ToMakerCode;
  4283. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  4284. db.SaveChanges();
  4285. db.Dispose();
  4286. }
  4287. return "success";
  4288. }
  4289. #endregion
  4290. #region 还原提现订单状态
  4291. public IActionResult RestoreStatus(string right)
  4292. {
  4293. ViewBag.RightInfo = RightInfo;
  4294. ViewBag.right = right;
  4295. return View();
  4296. }
  4297. [HttpPost]
  4298. public string RestoreStatusDo(string OrderNo)
  4299. {
  4300. if (string.IsNullOrEmpty(OrderNo))
  4301. {
  4302. return "请输入提现订单编号";
  4303. }
  4304. string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
  4305. var error = "";
  4306. foreach (var item in OrderNoList)
  4307. {
  4308. var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
  4309. if (cash.Id > 0)
  4310. {
  4311. cash.QueryCount = 0;
  4312. cash.Status = 0;
  4313. db.SaveChanges();
  4314. }
  4315. else
  4316. {
  4317. error += "订单" + item + "不存在" + '\n';
  4318. }
  4319. }
  4320. if (!string.IsNullOrEmpty(error))
  4321. {
  4322. return "Warning|" + error;
  4323. }
  4324. return "success";
  4325. }
  4326. #endregion
  4327. #region 查询创客循环资格
  4328. public IActionResult SeeUserLoop(string right)
  4329. {
  4330. ViewBag.RightInfo = RightInfo;
  4331. ViewBag.right = right;
  4332. return View();
  4333. }
  4334. [HttpPost]
  4335. public string SeeUserLoopDo(string MakerCode)
  4336. {
  4337. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  4338. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  4339. var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
  4340. var brandList = db.KqProducts.ToList();
  4341. var info = "";
  4342. foreach (var item in brandList)
  4343. {
  4344. var brand = item.Name;
  4345. //已过期
  4346. var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  4347. //可申请
  4348. var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  4349. //已使用
  4350. // var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id && m.PosSnType == 0);
  4351. // info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
  4352. info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + "\n";
  4353. }
  4354. return info;
  4355. }
  4356. #endregion
  4357. #region 提交到代付排除的创客名单
  4358. public IActionResult CashWithoutUser(string right)
  4359. {
  4360. ViewBag.RightInfo = RightInfo;
  4361. ViewBag.right = right;
  4362. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser") ?? new CustomTagSet();
  4363. ViewBag.set = set;
  4364. return View();
  4365. }
  4366. public string CashWithoutUserDo(string Content)
  4367. {
  4368. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser");
  4369. if (set == null)
  4370. {
  4371. set = db.CustomTagSet.Add(new CustomTagSet()
  4372. {
  4373. Tags = "CashWithoutUser",
  4374. Title = "提交到代付排除的创客名单"
  4375. }).Entity;
  4376. db.SaveChanges();
  4377. }
  4378. set.Contents = Content;
  4379. db.SaveChanges();
  4380. db.Dispose();
  4381. return "success";
  4382. }
  4383. #endregion
  4384. #region 坏机回仓
  4385. public IActionResult BadPosToStore(string right)
  4386. {
  4387. ViewBag.RightInfo = RightInfo;
  4388. ViewBag.right = right;
  4389. return View();
  4390. }
  4391. [HttpPost]
  4392. public string BadPosToStoreDo(string OldSn)
  4393. {
  4394. string[] OldSnList;
  4395. OldSnList = OldSn.Replace("\r", "").Split('\n');
  4396. string error = "";
  4397. List<string> opData = new List<string>();
  4398. for (int i = 0; i < OldSnList.Length; i++)
  4399. {
  4400. string OldSnNum = OldSnList[i];
  4401. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  4402. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId) ?? new PosMachinesTwo();
  4403. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  4404. {
  4405. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  4406. }
  4407. oldpos.Status = 1;
  4408. oldpos.PosSnType = 0;
  4409. oldpos.QueryCount = 0;
  4410. oldpos.UpdateDate = null;
  4411. oldpos.ActivityList = null;
  4412. oldpos.SeoKeyword = null;
  4413. oldpos.SeoDescription = null;
  4414. oldpos.OrderId = 0;
  4415. oldpos.RecycEndDate = null;
  4416. oldpos.RecycBackCount = 0;
  4417. oldpos.PrizeParams = null;
  4418. oldpos.ScanQrTrade = 0;
  4419. oldpos.BindMerchantId = 0;
  4420. oldpos.CreditTrade = 0;
  4421. oldpos.DebitCardTrade = 0;
  4422. oldpos.IsVip = 0;
  4423. oldpos.UserNav = null;
  4424. oldpos.TransferTime = null;
  4425. oldpos.IsPurchase = 0;
  4426. oldpos.Detail = null;
  4427. oldpos.BindingTime = null;
  4428. oldpos.BindingState = 0;
  4429. oldpos.ActivationTime = null;
  4430. oldpos.ActivationState = 0;
  4431. oldpos.LeaderUserId = 0;
  4432. oldpos.PreUserId = 0;
  4433. oldpos.IsFirst = 0;
  4434. oldpos.DownFeeMan = null;
  4435. oldpos.DownFeeFlag = 0;
  4436. oldpos.DownFeeDate = null;
  4437. oldpos.UpFeeMan = null;
  4438. oldpos.UpFeeFlag = 0;
  4439. oldpos.UpFeeDate = null;
  4440. oldpos.OpReserve1 = 0;
  4441. oldpos.OpReserve2 = 0;
  4442. oldpos.OpReserve3 = 0;
  4443. oldpos.OpId = 0;
  4444. oldpos.RecycStartDate = null;
  4445. oldpos.SourcePosSn = null;
  4446. oldpos.BuyUserId = 0;
  4447. oldpos.UserId = 0;
  4448. oldpos.FirstFlag = 0;
  4449. oldpos.IsExecute = 0;
  4450. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  4451. }
  4452. if (!string.IsNullOrEmpty(error))
  4453. {
  4454. return "Warning|" + error;
  4455. }
  4456. db.SaveChanges();
  4457. foreach (string sub in opData)
  4458. {
  4459. string[] datalist = sub.Split(":");
  4460. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4461. }
  4462. return "success";
  4463. }
  4464. #endregion
  4465. #region 划拨创客机具券
  4466. public IActionResult TransferPosCoupon(string right)
  4467. {
  4468. ViewBag.RightInfo = RightInfo;
  4469. ViewBag.right = right;
  4470. return View();
  4471. }
  4472. public string TransferPosCouponDo(string Kind, string PosCouponCodes, string FromMakerCode, string ToMakerCode, string LeaderMakerCode = "")
  4473. {
  4474. if (string.IsNullOrEmpty(Kind))
  4475. {
  4476. return "请选择划拨的券类型";
  4477. }
  4478. if (string.IsNullOrEmpty(PosCouponCodes))
  4479. {
  4480. return "请输入机具券码";
  4481. }
  4482. if (string.IsNullOrEmpty(FromMakerCode))
  4483. {
  4484. return "请输入机具来源创客编号";
  4485. }
  4486. if (string.IsNullOrEmpty(ToMakerCode))
  4487. {
  4488. return "请输入划拨对象创客编号";
  4489. }
  4490. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4491. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4492. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4493. if (fUserId.Id == 0)
  4494. {
  4495. return "来源创客" + FromMakerCode + "不存在";
  4496. }
  4497. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4498. if (tUserId.Id == 0)
  4499. {
  4500. return "划拨创客" + ToMakerCode + "不存在";
  4501. }
  4502. int LeaderUserId = 0;
  4503. if (!string.IsNullOrEmpty(LeaderMakerCode))
  4504. {
  4505. UserForMakerCode leaderuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LeaderMakerCode) ?? new UserForMakerCode();
  4506. Users LeaderUserItem = db.Users.FirstOrDefault(m => m.Id == leaderuser.UserId) ?? new Users();
  4507. if (LeaderUserItem.Id == 0)
  4508. {
  4509. return "大盟主创客编号" + LeaderMakerCode + "不存在";
  4510. }
  4511. LeaderUserId = leaderuser.UserId;
  4512. }
  4513. string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  4514. var query = PosCouponCodes + "\n" + FromMakerCode + "," + ToMakerCode;
  4515. string[] PosCouponList = PosCouponCodes.Replace("\r", "").Replace("\n", ",").Split(',');
  4516. foreach (string PosCouponCode in PosCouponList)
  4517. {
  4518. PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == PosCouponCode) ?? new PosCoupons();
  4519. if (item.UserId != fUserId.Id)
  4520. {
  4521. return "机具券" + PosCouponCode + "不在创客" + FromMakerCode + "名下";
  4522. }
  4523. if (item.Id == 0)
  4524. {
  4525. return "机具券" + PosCouponCode + "不存在";
  4526. }
  4527. if (item.IsUse == 1)
  4528. {
  4529. return "机具券" + PosCouponCode + "已使用";
  4530. }
  4531. if (item.QueryCount != int.Parse(Kind))
  4532. {
  4533. return "机具券" + PosCouponCode + "类型和您选择的类型不同";
  4534. }
  4535. item.UserId = tUserId.Id;
  4536. if (LeaderUserId > 0 && item.LeaderUserId == 0)
  4537. {
  4538. item.LeaderUserId = LeaderUserId;
  4539. }
  4540. PosCouponRecord posCouponRecord = db.PosCouponRecord.Add(new PosCouponRecord()
  4541. {
  4542. QueryCount = item.QueryCount,//券类型(1 电签 2 大POS)
  4543. CreateDate = DateTime.Now,
  4544. ChangeKind = 1,//类型(0购买,1划拨,2使⽤,3申请机具循环驳回)
  4545. OrderNo = ChangeRecordNo,
  4546. ToUserId = tUserId.Id,
  4547. FromUserId = fUserId.Id,
  4548. PosCouponId = item.Id,
  4549. }).Entity;
  4550. }
  4551. int CouponCount = PosCouponList.Length;
  4552. PosCouponOrders stat = db.PosCouponOrders.Add(new PosCouponOrders()
  4553. {
  4554. QueryCount = int.Parse(Kind),
  4555. CreateDate = DateTime.Now,
  4556. ChangeKind = 2,
  4557. ChangeCount = CouponCount,
  4558. // AfterOut = AfterOut,
  4559. // AfterTotal = AfterTotal,
  4560. // AfterStock = AfterStock,
  4561. // BeforeOut = BeforeOut,
  4562. // BeforeTotal = BeforeTotal,
  4563. // BeforeStock = BeforeStock,
  4564. OrderNo = ChangeRecordNo,
  4565. ToUserId = tUserId.Id,
  4566. FromUserId = fUserId.Id,
  4567. }).Entity;
  4568. PosCouponOrders tostat = db.PosCouponOrders.Add(new PosCouponOrders()
  4569. {
  4570. QueryCount = int.Parse(Kind),
  4571. CreateDate = DateTime.Now,
  4572. ChangeKind = 1,
  4573. ChangeCount = CouponCount,
  4574. // AfterOut = AfterOut,
  4575. // AfterTotal = AfterTotal,
  4576. // AfterStock = AfterStock,
  4577. // BeforeOut = BeforeOut,
  4578. // BeforeTotal = BeforeTotal,
  4579. // BeforeStock = BeforeStock,
  4580. OrderNo = ChangeRecordNo,
  4581. ToUserId = fUserId.Id,
  4582. FromUserId = tUserId.Id,
  4583. }).Entity;
  4584. db.SaveChanges();
  4585. db.Dispose();
  4586. return "success";
  4587. }
  4588. #endregion
  4589. #region 机具回仓退款
  4590. public IActionResult RefundPosFee(string right)
  4591. {
  4592. ViewBag.RightInfo = RightInfo;
  4593. ViewBag.right = right;
  4594. return View();
  4595. }
  4596. [HttpPost]
  4597. public string RefundPosFeeDo(string PosSn, string BackStoreNo, int IsBack = 0)
  4598. {
  4599. if (string.IsNullOrEmpty(PosSn))
  4600. {
  4601. return "请输入机具SN";
  4602. }
  4603. if (IsBack == 1)
  4604. {
  4605. if (string.IsNullOrEmpty(BackStoreNo))
  4606. {
  4607. return "请输入仓库编号";
  4608. }
  4609. }
  4610. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  4611. WebCMSEntities db = new WebCMSEntities();
  4612. DateTime time = DateTime.Parse(DateTime.Now.ToString(("yyyy-MM-dd") + " 00:00:00"));
  4613. var endTime = time.AddDays(20 - time.Day).AddDays(-60);
  4614. StoreForCode storeForBack = new StoreForCode();
  4615. StoreHouse BackStore = new StoreHouse();
  4616. List<string> opData = new List<string>();
  4617. foreach (var item in PosSnList)
  4618. {
  4619. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  4620. if (machineForSnNo.SnId == 0)
  4621. {
  4622. return "未找到机具" + item + "关联数据";
  4623. }
  4624. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.Status > -1 && m.RecycEndDate < endTime && m.BindingState == 0) ?? new PosMachinesTwo();
  4625. if (pos.Id == 0)
  4626. {
  4627. return "机具" + item + "不存在或者不满足条件";
  4628. }
  4629. if (IsBack == 1)
  4630. {
  4631. storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  4632. if (storeForBack.StoreId == 0)
  4633. {
  4634. return "未找到" + BackStoreNo + "关联数据";
  4635. }
  4636. BackStore = db.StoreHouse.FirstOrDefault(m => m.Status > -1 && m.Id == storeForBack.StoreId && m.BrandId == pos.BrandId.ToString()) ?? new StoreHouse();
  4637. if (BackStore.Id == 0)
  4638. {
  4639. return "仓库" + BackStoreNo + "不存在或与机具品牌不符";
  4640. }
  4641. }
  4642. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BackStore.UserId) ?? new UserAccount();
  4643. var refundUserAccount = db.UserAccount.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new UserAccount();
  4644. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  4645. var amount = 0;
  4646. if (brandInfo.Name.Contains("电签"))
  4647. {
  4648. amount = 200;
  4649. }
  4650. if (brandInfo.Name.Contains("大POS"))
  4651. {
  4652. amount = 300;
  4653. }
  4654. if (IsBack == 1)
  4655. {
  4656. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  4657. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  4658. {
  4659. CreateDate = DateTime.Now,
  4660. CreateMan = SysUserName,
  4661. StoreId = pos.StoreId, //出货仓库
  4662. BrandId = pos.BrandId, //产品类型
  4663. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  4664. TransType = 5, //交易类型
  4665. SnNo = item, //SN编号
  4666. StockOpDirect = 0, //库存操作方向
  4667. SnStatus = 1, //SN状态
  4668. DeviceVendor = pos.DeviceName, //设备厂商
  4669. DeviceModel = pos.DeviceKind, //设备型号
  4670. DeviceType = pos.DeviceType, //设备类型
  4671. FromUserId = pos.BuyUserId, //来源创客
  4672. ToRemark = "过期机具回仓退款", //入库备注
  4673. ToStoreId = BackStore.Id, //退货收货仓库
  4674. SourceStoreId = pos.SourceStoreId, //源仓库编号
  4675. BrandType = pos.DeviceType, //品牌类型
  4676. }).Entity;
  4677. string ChangeNo = "HCTK";
  4678. int StoreStockChangeId = stockchange.Id;
  4679. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  4680. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  4681. {
  4682. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  4683. }
  4684. ChangeNo += StoreStockChangeIdString;
  4685. stockchange.ChangeNo = ChangeNo; //交易流水编号
  4686. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4687. {
  4688. CreateDate = DateTime.Now,
  4689. BrandId = pos.BrandId, //产品类型
  4690. ChangeRecordNo = ChangeNo, //变更记录单号
  4691. TransType = 5, //交易类型
  4692. SnNo = item, //SN编号
  4693. SnType = pos.PosSnType, //SN机具类型
  4694. StockOpDirect = 0, //库存操作方向
  4695. DeviceVendor = pos.DeviceName, //设备厂商
  4696. DeviceModel = pos.DeviceKind, //设备型号
  4697. DeviceType = pos.DeviceType, //设备类型
  4698. FromUserId = pos.BuyUserId, //来源创客
  4699. ToRemark = "过期机具回仓退款", //入库备注
  4700. SourceStoreId = pos.SourceStoreId, //源仓库
  4701. StoreId = pos.StoreId, //出货仓库
  4702. });
  4703. db.MachineReturn.Add(new MachineReturn()
  4704. {
  4705. CreateDate = DateTime.Now,
  4706. Operator = SysUserName + "_" + SysRealName,//操作人
  4707. BrandId = pos.BrandId, //产品类型
  4708. DeviceSnNos = pos.PosSn,
  4709. ToStoreId = BackStore.Id,
  4710. ApplyNo = ChangeNo, //变更记录单号
  4711. UserId = pos.BuyUserId, //来源创客
  4712. Remark = "过期机具回仓退款", //入库备注
  4713. });
  4714. if (pos.ScanQrTrade > 0)
  4715. {
  4716. decimal ChangeAmount = 0;
  4717. decimal BeforeBalanceAmount = 0;
  4718. decimal AfterBalanceAmount = 0;
  4719. if (pos.ScanQrTrade == 999)
  4720. {
  4721. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4722. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4723. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4724. ChangeAmount = amount;
  4725. }
  4726. else
  4727. {
  4728. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4729. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4730. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4731. ChangeAmount = pos.ScanQrTrade;
  4732. }
  4733. db.UserAccountRecord.Add(new UserAccountRecord()
  4734. {
  4735. CreateDate = DateTime.Now,
  4736. UpdateDate = DateTime.Now,
  4737. UserId = pos.BuyUserId, //创客
  4738. ChangeType = 126, //变动类型(机具货款退还)
  4739. ProductType = 0, //产品类型
  4740. ChangeAmount = ChangeAmount, //变更金额
  4741. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4742. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4743. });
  4744. }
  4745. var bInfo = BackStore.UserId + "_" + pos.BrandId;
  4746. var userMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == bInfo) ?? new UserMachineData();
  4747. userMachineData.TotalMachineCount += 1;
  4748. userMachineData.UnBindCount += 1;
  4749. BackStore.LaveNum += 1;
  4750. BackStore.TotalNum += 1;
  4751. var fInfo = pos.BuyUserId + "_" + pos.BrandId;
  4752. var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
  4753. userMachineDatas.TotalMachineCount -= 1;
  4754. userMachineDatas.UnBindCount -= 1;
  4755. if (!opData.Contains(pos.BuyUserId + ":" + pos.BrandId))
  4756. {
  4757. opData.Add(pos.BuyUserId + ":" + pos.BrandId);
  4758. }
  4759. pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
  4760. pos.Status = 1;
  4761. pos.QueryCount = 0;
  4762. pos.UpdateDate = null;
  4763. pos.ActivityList = null;
  4764. pos.SeoKeyword = null;
  4765. pos.SeoDescription = null;
  4766. pos.OrderId = 0;
  4767. pos.RecycEndDate = null;
  4768. pos.RecycBackCount = 0;
  4769. pos.PrizeParams = null;
  4770. pos.ScanQrTrade = 0;
  4771. pos.BindMerchantId = 0;
  4772. pos.CreditTrade = 0;
  4773. pos.DebitCardTrade = 0;
  4774. pos.IsVip = 0;
  4775. pos.UserNav = null;
  4776. pos.TransferTime = null;
  4777. pos.IsPurchase = 0;
  4778. pos.Detail = null;
  4779. pos.BindingTime = null;
  4780. pos.BindingState = 0;
  4781. pos.ActivationTime = null;
  4782. pos.ActivationState = 0;
  4783. pos.LeaderUserId = 0;
  4784. pos.PreUserId = 0;
  4785. pos.IsFirst = 0;
  4786. pos.DownFeeMan = null;
  4787. pos.DownFeeFlag = 0;
  4788. pos.DownFeeDate = null;
  4789. pos.UpFeeMan = null;
  4790. pos.UpFeeFlag = 0;
  4791. pos.UpFeeDate = null;
  4792. pos.OpReserve1 = 0;
  4793. pos.OpReserve2 = 0;
  4794. pos.OpReserve3 = 0;
  4795. pos.OpId = 0;
  4796. pos.RecycStartDate = null;
  4797. pos.SourcePosSn = null;
  4798. pos.BuyUserId = 0;
  4799. pos.UserId = 0;
  4800. pos.FirstFlag = 0;
  4801. pos.IsExecute = 0;
  4802. PublicFunction.ClearPosHistory(db, pos.PosSn); //清除机具历史记录
  4803. }
  4804. else
  4805. {
  4806. if (pos.ScanQrTrade > 0)
  4807. {
  4808. decimal ChangeAmount = 0;
  4809. decimal BeforeBalanceAmount = 0;
  4810. decimal AfterBalanceAmount = 0;
  4811. if (pos.ScanQrTrade == 999)
  4812. {
  4813. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4814. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4815. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4816. ChangeAmount = amount;
  4817. }
  4818. else
  4819. {
  4820. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4821. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4822. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4823. ChangeAmount = pos.ScanQrTrade;
  4824. }
  4825. pos.ScanQrTrade = 0;
  4826. db.UserAccountRecord.Add(new UserAccountRecord()
  4827. {
  4828. CreateDate = DateTime.Now,
  4829. UpdateDate = DateTime.Now,
  4830. UserId = pos.BuyUserId, //创客
  4831. ChangeType = 126, //变动类型(机具货款退还)
  4832. ProductType = 0, //产品类型
  4833. ChangeAmount = ChangeAmount, //变更金额
  4834. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4835. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4836. });
  4837. }
  4838. }
  4839. }
  4840. db.SaveChanges();
  4841. foreach (string sub in opData)
  4842. {
  4843. string[] datalist = sub.Split(":");
  4844. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4845. }
  4846. return "success";
  4847. }
  4848. #endregion
  4849. #region 添加商户信息
  4850. public IActionResult AddMerchantnfo(string right)
  4851. {
  4852. ViewBag.RightInfo = RightInfo;
  4853. ViewBag.right = right;
  4854. return View();
  4855. }
  4856. [HttpPost]
  4857. public string AddMerchantnfoDo(string PosSn, string MerSn)
  4858. {
  4859. if (string.IsNullOrEmpty(PosSn))
  4860. {
  4861. return "请输入机具号";
  4862. }
  4863. if (string.IsNullOrEmpty(MerSn))
  4864. {
  4865. return "请输入商户号";
  4866. }
  4867. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4868. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4869. var merchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4870. if (machineForSnNo.SnId == 0)
  4871. {
  4872. return "未找到机具" + PosSn + "关联数据";
  4873. }
  4874. if (pos.Id == 0)
  4875. {
  4876. return "未找到机具" + PosSn;
  4877. }
  4878. if (merchantInfo.Id > 0)
  4879. {
  4880. return "机具" + PosSn + "以经存在绑定商户";
  4881. }
  4882. var spInfo = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerSn && m.MerSnNo == PosSn) ?? new SpModels.BindRecord();
  4883. if (spInfo.Id > 0)
  4884. {
  4885. var MerUserType = 0;
  4886. var ActiveStatus = 0;
  4887. if (pos.BuyUserId != pos.UserId)
  4888. {
  4889. MerUserType = 1;
  4890. }
  4891. if (string.IsNullOrEmpty(pos.ActivationTime.ToString()))
  4892. {
  4893. ActiveStatus = 1;
  4894. }
  4895. PosMerchantInfo posMerchantInfo = db.PosMerchantInfo.Add(new PosMerchantInfo()
  4896. {
  4897. CreateDate = pos.BindingTime,
  4898. TopUserId = 1,
  4899. BrandId = pos.BrandId,
  4900. SnStoreId = pos.StoreId,
  4901. MerStandardDate = pos.ActivationTime,
  4902. SnType = pos.PosSnType,
  4903. MerUserType = MerUserType,
  4904. UserId = pos.UserId,
  4905. ActiveStatus = ActiveStatus,
  4906. MerStatus = 1,
  4907. KqSnNo = PosSn,
  4908. KqMerNo = MerSn,
  4909. MerIdcardNo = spInfo.SeoKeyword,
  4910. MerchantMobile = spInfo.MerNewSnNo,
  4911. MerchantName = spInfo.MerName,
  4912. MerchantNo = spInfo.MerNo,
  4913. }).Entity;
  4914. db.SaveChanges();
  4915. string text = string.Format("设置商户信息,机具Sn: " + PosSn + ",商户编号: " + MerSn + ",操作人:" + SysUserName + "_" + SysRealName + ",时间:" + DateTime.Now + "");
  4916. function.WriteLog(text, "设置商户信息");
  4917. }
  4918. return "success";
  4919. }
  4920. #endregion
  4921. #region 查询商户达标明细
  4922. public IActionResult SeeMerchantTradeDetail(string right)
  4923. {
  4924. ViewBag.RightInfo = RightInfo;
  4925. ViewBag.right = right;
  4926. return View();
  4927. }
  4928. [HttpPost]
  4929. public string SeeMerchantTradeDetailDo(string PosSn)
  4930. {
  4931. if (string.IsNullOrEmpty(PosSn))
  4932. {
  4933. return "请输入机具SN";
  4934. }
  4935. var result = "";
  4936. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  4937. if (pos.Id > 0)
  4938. {
  4939. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4940. if (mer.Id > 0)
  4941. {
  4942. var info = "";
  4943. var IsFirst = "";//是否首台机具
  4944. if (function.CheckNull(mer.MerIdcardNo).Contains("*") || function.CheckNull(mer.MerchantMobile).Contains("*") || function.CheckNull(mer.MerRealName).Contains("*") || string.IsNullOrEmpty(mer.MerRealName))
  4945. {
  4946. info = "机具" + PosSn + "所对应的商户未认证";
  4947. }
  4948. var merchantId = db.PosMerchantInfo.Where(m => m.MerIdcardNo == mer.MerIdcardNo && m.MerRealName == mer.MerRealName && m.MerchantMobile == mer.MerchantMobile).Min(m => m.Id);
  4949. // if (mer.Id <= merchantId)
  4950. // {
  4951. // IsFirst = "首台";
  4952. // }
  4953. // else
  4954. // {
  4955. // IsFirst = "非首台";
  4956. // }
  4957. if (pos.FirstFlag == 1)
  4958. {
  4959. IsFirst = "首台";
  4960. }
  4961. else
  4962. {
  4963. IsFirst = "非首台";
  4964. }
  4965. var depositRreturn = db.MerchantDepositReturns.Where(m => m.MerchantId == mer.Id).OrderByDescending(m => m.CreateDate).FirstOrDefault() ?? new MerchantDepositReturns();
  4966. var IsOk = "";//是否达标
  4967. var timeInfo = "";
  4968. if (mer.StandardStatus == -2)
  4969. {
  4970. IsOk = "人工已退";
  4971. }
  4972. else
  4973. {
  4974. if (mer.StandardMonths < 10)
  4975. {
  4976. IsOk = "未达标";
  4977. }
  4978. if (mer.StandardMonths == 10)
  4979. {
  4980. IsOk = "已达标";
  4981. }
  4982. if (mer.StandardMonths >= 0 && mer.StandardStatus == -1)
  4983. {
  4984. IsOk = "达标失败";
  4985. }
  4986. if (mer.StandardStatus == 1 && depositRreturn.Status == 1)
  4987. {
  4988. IsOk = "已返还";
  4989. }
  4990. if (mer.StandardStatus == 101)
  4991. {
  4992. IsOk = "待领取达标奖";
  4993. }
  4994. if (mer.StandardStatus == 1 && depositRreturn.Status == 0)
  4995. {
  4996. IsOk = "达标奖发放中";
  4997. }
  4998. }
  4999. result += info + "\n";
  5000. result += IsFirst + "\n";
  5001. result += IsOk + "\n";
  5002. var BindingTime = pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  5003. var ActivationTime = pos.ActivationTime == null ? "" : pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  5004. result += "开机时间:" + BindingTime + "\n";
  5005. result += "激活时间:" + ActivationTime + "\n";
  5006. result += "商户姓名:" + mer.MerRealName + "\n";
  5007. if (pos.ActivationTime != null)
  5008. {
  5009. result += "明细:\n";
  5010. for (int i = 0; i < 12; i++)
  5011. {
  5012. var time = pos.ActivationTime.Value.AddMonths(i + 1).ToString("yyyyMM");//达标计算开始时间
  5013. timeInfo += "," + time;
  5014. }
  5015. timeInfo = timeInfo + ",";
  5016. var merTradeInfo = db.PosMerchantTradeSummay.Where(m => m.MerchantId == mer.Id && timeInfo.Contains("," + m.TradeMonth + ",")).ToList();
  5017. string[] month = timeInfo.TrimStart(',').TrimEnd(',').Split(',');
  5018. foreach (var item in month)
  5019. {
  5020. var tradeAmount = merTradeInfo.Where(m => m.TradeMonth == item).Sum(m => m.TradeAmount);
  5021. result += item + "交易额:" + tradeAmount + "\n";
  5022. }
  5023. }
  5024. }
  5025. else
  5026. {
  5027. return "未找到机具" + PosSn + "所对应的商户";
  5028. }
  5029. }
  5030. else
  5031. {
  5032. return "未找到机具" + PosSn;
  5033. }
  5034. return result;
  5035. }
  5036. #endregion
  5037. #region 指定文件Excel导出
  5038. public IActionResult ExportExcel(string right)
  5039. {
  5040. ViewBag.RightInfo = RightInfo;
  5041. ViewBag.right = right;
  5042. return View();
  5043. }
  5044. [HttpPost]
  5045. public string ExportExcelDo(string FileName, string Operator, string Sql, int Number = 0)
  5046. {
  5047. if (string.IsNullOrEmpty(FileName))
  5048. {
  5049. return "请输入文件名";
  5050. }
  5051. if (string.IsNullOrEmpty(Operator))
  5052. {
  5053. return "请输入后台操作人";
  5054. }
  5055. if (string.IsNullOrEmpty(Sql))
  5056. {
  5057. return "请输入SQL语句";
  5058. }
  5059. var SqlString = "";
  5060. if (Number == 0)
  5061. {
  5062. SqlString = Sql;
  5063. }
  5064. if (Number > 0)
  5065. {
  5066. SqlString = Sql + " LIMIT " + Number;
  5067. }
  5068. string[] Operators = Operator.Replace("\r", "").Replace("\n", ",").Split(',');
  5069. foreach (var item in Operators)
  5070. {
  5071. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == item && m.Status > -1);
  5072. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + SqlString + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"" + Number + "\"}";
  5073. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  5074. }
  5075. return "success";
  5076. }
  5077. #endregion
  5078. #region 服务费返现注册查询
  5079. public IActionResult SeeMerchantAuthInfo(string right)
  5080. {
  5081. ViewBag.RightInfo = RightInfo;
  5082. ViewBag.right = right;
  5083. return View();
  5084. }
  5085. #endregion
  5086. #region 服务费返现注册查询
  5087. public JsonResult SeeMerchantAuthInfoDo(string RealName, string Mobile, string CertId, int page = 1, int limit = 30)
  5088. {
  5089. var query = db.UserFamilyMember.Where(m => m.Status > -1);
  5090. if (string.IsNullOrEmpty(RealName) && string.IsNullOrEmpty(Mobile) && string.IsNullOrEmpty(CertId))
  5091. {
  5092. Dictionary<string, object> objs = new Dictionary<string, object>();
  5093. return Json(objs);
  5094. }
  5095. else
  5096. {
  5097. if (!string.IsNullOrEmpty(RealName))
  5098. {
  5099. query = query.Where(m => m.Name == RealName);
  5100. }
  5101. if (!string.IsNullOrEmpty(Mobile))
  5102. {
  5103. query = query.Where(m => m.Mobile == Mobile);
  5104. }
  5105. if (!string.IsNullOrEmpty(CertId))
  5106. {
  5107. query = query.Where(m => m.IdCardNo.ToUpper() == CertId.ToUpper());
  5108. }
  5109. }
  5110. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  5111. foreach (var subdata in query.ToList())
  5112. {
  5113. Dictionary<string, object> data = new Dictionary<string, object>();
  5114. if (subdata.Id > 0)
  5115. {
  5116. data["IsRegist"] = "已注册";
  5117. if (subdata.Status == 1)
  5118. {
  5119. data["IsAuth"] = "已认证";
  5120. data["Name"] = subdata.Name;
  5121. data["Mobile"] = subdata.Mobile;
  5122. data["IdcardNo"] = subdata.IdCardNo;
  5123. var linkCount = db.PosMerchantInfo.Count(m => m.MerRealName == subdata.Name && m.MerchantMobile == subdata.Mobile && m.MerIdcardNo.ToUpper() == subdata.IdCardNo.ToUpper());
  5124. data["Count"] = linkCount;
  5125. }
  5126. else
  5127. {
  5128. data["IsAuth"] = "未认证";
  5129. data["Name"] = "";
  5130. data["Mobile"] = subdata.Mobile;
  5131. data["IdcardNo"] = "";
  5132. data["Count"] = "";
  5133. }
  5134. }
  5135. else
  5136. {
  5137. data["IsRegist"] = "未注册";
  5138. data["IsAuth"] = "未认证";
  5139. data["Name"] = "";
  5140. data["Mobile"] = "";
  5141. data["IdcardNo"] = "";
  5142. data["Count"] = "";
  5143. }
  5144. dataList.Add(data);
  5145. }
  5146. Dictionary<string, object> obj = new Dictionary<string, object>();
  5147. obj.Add("code", 0);
  5148. obj.Add("msg", "");
  5149. obj.Add("count", dataList.Count);
  5150. obj.Add("data", dataList);
  5151. return Json(obj);
  5152. }
  5153. #endregion
  5154. #region 注销30天内恢复创客信息
  5155. public IActionResult RestoreUserInfo(string right)
  5156. {
  5157. ViewBag.RightInfo = RightInfo;
  5158. ViewBag.right = right;
  5159. return View();
  5160. }
  5161. [HttpPost]
  5162. public string RestoreUserInfoDo(string MakerCode)
  5163. {
  5164. var user = db.Users.FirstOrDefault(m => m.Status == -1 && m.MakerCode == MakerCode) ?? new Users();
  5165. if (user.Id == 0)
  5166. {
  5167. return "创客" + MakerCode + "不存在";
  5168. }
  5169. else
  5170. {
  5171. if (user.LogOutDate.Value.ToString("yyyyMM") == DateTime.Now.ToString("yyyyMM"))
  5172. {
  5173. user.Status = 0;
  5174. user.LogOutDate = null;
  5175. user.Mobile = user.Mobile.TrimEnd('d');
  5176. user.CertId = user.CertId.TrimEnd('d');
  5177. db.UserForMobile.Add(new UserForMobile()
  5178. {
  5179. Mobile = user.Mobile,
  5180. UserId = user.Id,
  5181. });
  5182. db.UserForMakerCode.Add(new UserForMakerCode()
  5183. {
  5184. MakerCode = user.MakerCode,
  5185. UserId = user.Id,
  5186. });
  5187. AddSysLog(user.Id.ToString(), "注销30天内恢复创客信息", "修改" + SysUserName + "_" + SysRealName);
  5188. db.SaveChanges();
  5189. }
  5190. else
  5191. {
  5192. return "创客" + MakerCode + "不满足恢复条件";
  5193. }
  5194. }
  5195. return "success";
  5196. }
  5197. #endregion
  5198. #region 码牌加密
  5199. public IActionResult QrCodeEncryption(string right)
  5200. {
  5201. ViewBag.RightInfo = RightInfo;
  5202. ViewBag.right = right;
  5203. return View();
  5204. }
  5205. [HttpPost]
  5206. public string QrCodeEncryptionDo(string SnNos)
  5207. {
  5208. string[] SnNo = SnNos.Replace("\r", "").Replace("\n", ",").Split(',');
  5209. string code = "";
  5210. string sn = "";
  5211. for (int a = 0; a < SnNo.Length; a++)
  5212. {
  5213. string start = SnNo[a];
  5214. for (int i = 0; i <= 9999; i++)
  5215. {
  5216. string num = i.ToString();
  5217. for (int j = 0; j < 4 - i.ToString().Length; j++)
  5218. {
  5219. num = "0" + num;
  5220. }
  5221. sn = dbconn.Encrypt3DES(start + num + function.get_Random(8), "l2k0b2#3");
  5222. sn = sn.Substring(0, sn.Length - 1);
  5223. }
  5224. code += System.Web.HttpUtility.UrlEncode(sn) + "<br />\n";
  5225. }
  5226. return "success" + "|" + code;
  5227. }
  5228. #endregion
  5229. #region 码牌解密
  5230. public IActionResult QrCodeDescryption(string right)
  5231. {
  5232. ViewBag.RightInfo = RightInfo;
  5233. ViewBag.right = right;
  5234. return View();
  5235. }
  5236. [HttpPost]
  5237. public string QrCodeDescryptionDo(string SnNos)
  5238. {
  5239. string[] SnNo = SnNos.Replace("\r", "").Replace("\n", ",").Split(',');
  5240. string code = "";
  5241. string sn = "";
  5242. for (int a = 0; a < SnNo.Length; a++)
  5243. {
  5244. sn = SnNo[a];
  5245. if (sn.Length > 20)
  5246. {
  5247. sn = System.Web.HttpUtility.UrlDecode(sn);
  5248. if (!sn.EndsWith("="))
  5249. {
  5250. sn += "=";
  5251. }
  5252. sn = dbconn.Decrypt3DES(sn, "l2k0b2#3");
  5253. sn = sn.TrimEnd('\0');
  5254. sn = sn.Substring(0, 20);
  5255. }
  5256. code += sn + "<br />\n";
  5257. }
  5258. return "success" + "|" + code;
  5259. }
  5260. #endregion
  5261. #region 查询指定创客下四级信息
  5262. public IActionResult SeeUserLevel4Info(string right)
  5263. {
  5264. ViewBag.RightInfo = RightInfo;
  5265. ViewBag.right = right;
  5266. return View();
  5267. }
  5268. public string SeeUserLevel4InfoDo(string MakerCode, string MakerCodes)
  5269. {
  5270. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
  5271. string[] SnNo = MakerCodes.Replace("\r", "").Replace("\n", ",").Split(',');
  5272. string code = "";
  5273. for (int i = 0; i < SnNo.Length; i++)
  5274. {
  5275. code += "'" + SnNo[i] + "',";
  5276. }
  5277. code = code.TrimEnd(',');
  5278. 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";
  5279. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  5280. var FileName = "查询指定创客下四级信息" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  5281. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  5282. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  5283. return "success";
  5284. }
  5285. #endregion
  5286. #region 直营团队数据
  5287. public IActionResult Team1Info(string right)
  5288. {
  5289. ViewBag.RightInfo = RightInfo;
  5290. ViewBag.right = right;
  5291. return View();
  5292. }
  5293. #endregion
  5294. #region 直营团队数据
  5295. public JsonResult Team1InfoDo(string MakerCode, string BindingTime, string ActivationTime, string PosFeeSelect, string BrandId, int page = 1, int limit = 30)
  5296. {
  5297. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  5298. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  5299. string condition = " where 1=1";
  5300. var UserId = 0;
  5301. var bstart = "";
  5302. var bend = "";
  5303. var astart = "";
  5304. var aend = "";
  5305. if (!string.IsNullOrEmpty(MakerCode))
  5306. {
  5307. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
  5308. UserId = user.Id;
  5309. }
  5310. if (!string.IsNullOrEmpty(BindingTime))
  5311. {
  5312. string[] datelist = BindingTime.Split(new string[] { " - " }, StringSplitOptions.None);
  5313. bstart = datelist[0] + " 00:00:00";
  5314. bend = datelist[1] + " 23:59:59";
  5315. condition += " and tb.BindingTime>='" + bstart + "' and tb.BindingTime<='" + bend + "'";
  5316. }
  5317. if (!string.IsNullOrEmpty(ActivationTime))
  5318. {
  5319. string[] datelist = ActivationTime.Split(new string[] { " - " }, StringSplitOptions.None);
  5320. astart = datelist[0] + " 00:00:00";
  5321. aend = datelist[1] + " 23:59:59";
  5322. condition += " and tb.ActivationTime>='" + astart + "' and tb.ActivationTime<='" + aend + "'";
  5323. }
  5324. if (!string.IsNullOrEmpty(PosFeeSelect))
  5325. {
  5326. if (PosFeeSelect == "0")
  5327. {
  5328. condition += " and tb.SeoKeyword is null";
  5329. }
  5330. else
  5331. {
  5332. condition += " and tb.SeoKeyword=" + PosFeeSelect;
  5333. }
  5334. }
  5335. if (!string.IsNullOrEmpty(BrandId))
  5336. {
  5337. condition += " and tb.BrandId=" + BrandId;
  5338. }
  5339. 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);
  5340. foreach (DataRow item in dt.Rows)
  5341. {
  5342. Dictionary<string, object> curData = new Dictionary<string, object>();
  5343. curData.Add("wname", item["wname"].ToString()); //伙伴名称
  5344. curData.Add("Name", item["Name"].ToString()); //机具品牌
  5345. curData.Add("PosSn", item["PosSn"].ToString()); //机具Sn
  5346. curData.Add("merchantname", item["merchantname"].ToString()); //商户姓名
  5347. curData.Add("SeoKeyword", item["SeoKeyword"].ToString()); //服务费
  5348. curData.Add("BindingTime", string.IsNullOrEmpty(item["BindingTime"].ToString()) ? "" : Convert.ToDateTime(item["BindingTime"]).ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  5349. curData.Add("ActivationTime", string.IsNullOrEmpty(item["ActivationTime"].ToString()) ? "" : Convert.ToDateTime(item["ActivationTime"]).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  5350. curData.Add("amount", item["amount"].ToString()); //返现金额
  5351. curData.Add("maxdate", string.IsNullOrEmpty(item["maxdate"].ToString()) ? "" : Convert.ToDateTime(item["maxdate"]).ToString("yyyy-MM-dd HH:mm:ss")); //返现时间
  5352. curData.Add("CreditRewardAmount", item["CreditRewardAmount"].ToString()); //开机奖
  5353. curData.Add("opdate", string.IsNullOrEmpty(item["opdate"].ToString()) ? "" : Convert.ToDateTime(item["opdate"]).ToString("yyyy-MM-dd HH:mm:ss")); //开机奖发放时间
  5354. curData.Add("info", item["info"].ToString()); //发放对象
  5355. dataList.Add(curData);
  5356. }
  5357. Dictionary<string, object> obj = new Dictionary<string, object>();
  5358. obj.Add("code", 0);
  5359. obj.Add("msg", "");
  5360. obj.Add("count", dataList.Count);
  5361. obj.Add("data", dataList);
  5362. return Json(obj);
  5363. }
  5364. #endregion
  5365. #region 直营团队数据导出
  5366. public IActionResult ExportTeam1InfoExcel(string right)
  5367. {
  5368. ViewBag.RightInfo = RightInfo;
  5369. ViewBag.right = right;
  5370. return View();
  5371. }
  5372. [HttpPost]
  5373. public string ExportTeam1InfoExcelDo(string MakerCode, string BindingTime, string ActivationTime, string PosFeeSelect, string BrandId)
  5374. {
  5375. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  5376. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  5377. var RealName = "";
  5378. string condition = " where 1=1";
  5379. var UserId = 0;
  5380. var bstart = "";
  5381. var bend = "";
  5382. var astart = "";
  5383. var aend = "";
  5384. if (!string.IsNullOrEmpty(MakerCode))
  5385. {
  5386. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
  5387. UserId = user.Id;
  5388. RealName = user.RealName;
  5389. }
  5390. if (!string.IsNullOrEmpty(BindingTime))
  5391. {
  5392. string[] datelist = BindingTime.Split(new string[] { " - " }, StringSplitOptions.None);
  5393. bstart = datelist[0] + " 00:00:00";
  5394. bend = datelist[1] + " 23:59:59";
  5395. condition += " and tb.BindingTime>='" + bstart + "' and tb.BindingTime<='" + bend + "'";
  5396. }
  5397. if (!string.IsNullOrEmpty(ActivationTime))
  5398. {
  5399. string[] datelist = ActivationTime.Split(new string[] { " - " }, StringSplitOptions.None);
  5400. astart = datelist[0] + " 00:00:00";
  5401. aend = datelist[1] + " 23:59:59";
  5402. condition += " and tb.ActivationTime>='" + astart + "' and tb.ActivationTime<='" + aend + "'";
  5403. }
  5404. if (!string.IsNullOrEmpty(PosFeeSelect))
  5405. {
  5406. if (PosFeeSelect == "0")
  5407. {
  5408. condition += " and tb.SeoKeyword is null";
  5409. }
  5410. else
  5411. {
  5412. condition += " and tb.SeoKeyword=" + PosFeeSelect;
  5413. }
  5414. }
  5415. if (!string.IsNullOrEmpty(BrandId))
  5416. {
  5417. condition += " and tb.BrandId=" + BrandId;
  5418. }
  5419. 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;
  5420. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  5421. var FileName = MakerCode + RealName + "直营团队数据记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  5422. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  5423. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  5424. return "success";
  5425. }
  5426. #endregion
  5427. #region 调整机具服务费
  5428. public IActionResult ChangePosFee(string right)
  5429. {
  5430. ViewBag.RightInfo = RightInfo;
  5431. ViewBag.right = right;
  5432. return View();
  5433. }
  5434. [HttpPost]
  5435. public string ChangePosFeeDo(string PosSn, string BrandId, string Deposit)
  5436. {
  5437. if (string.IsNullOrEmpty(PosSn))
  5438. {
  5439. return "请输入机具SN";
  5440. }
  5441. var brandId = int.Parse(BrandId);
  5442. List<int> SnIds = new List<int>();
  5443. string[] PosSnList = PosSn.Replace("\r", "").Replace("\n", ",").Split(',');
  5444. string error = "";
  5445. foreach (string Sn in PosSnList)
  5446. {
  5447. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.BindingState == 0 && m.ActivationState == 0 && m.PosSn == Sn && m.BrandId == brandId) ?? new PosMachinesTwo();
  5448. if (posInfo.Id == 0)
  5449. {
  5450. error += "以下操作失败" + Sn + ',' + "不存在或者不符合条件" + '\n';
  5451. }
  5452. else
  5453. {
  5454. SnIds.Add(posInfo.Id);
  5455. }
  5456. }
  5457. if (!string.IsNullOrEmpty(error))
  5458. {
  5459. return "Warning|" + error;
  5460. }
  5461. else
  5462. {
  5463. foreach (int SnId in SnIds)
  5464. {
  5465. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
  5466. //金控
  5467. if (posInfo.BrandId == 1 || posInfo.BrandId == 3)
  5468. {
  5469. if (Deposit == "0") Deposit = "0";
  5470. else if (Deposit == "99") Deposit = "99";
  5471. else if (Deposit == "199") Deposit = "199";
  5472. else if (Deposit == "299") Deposit = "299";
  5473. else
  5474. {
  5475. return "失败,无" + Deposit + "服务费相关设置权限";
  5476. }
  5477. var info = PublicChangePosFee.SetJKDeposit(SnId.ToString(), Deposit);
  5478. if (info != "设置成功")
  5479. {
  5480. return info;
  5481. }
  5482. }
  5483. //开店宝
  5484. if (posInfo.BrandId == 2)
  5485. {
  5486. if (Deposit == "0") Deposit = "470";
  5487. else if (Deposit == "99") Deposit = "471";
  5488. else if (Deposit == "199") Deposit = "472";
  5489. else if (Deposit == "299") Deposit = "473";
  5490. else
  5491. {
  5492. return "失败,无" + Deposit + "服务费相关设置权限";
  5493. }
  5494. var info = PublicChangePosFee.SetKDBDeposit(SnId.ToString(), Deposit);
  5495. if (info != "设置成功")
  5496. {
  5497. return info;
  5498. }
  5499. }
  5500. //乐刷
  5501. if (posInfo.BrandId == 4 || posInfo.BrandId == 5)
  5502. {
  5503. if (Deposit == "99") Deposit = "100";
  5504. else if (Deposit == "199") Deposit = "200";
  5505. else if (Deposit == "299") Deposit = "300";
  5506. else
  5507. {
  5508. return "失败,无" + Deposit + "服务费相关设置权限";
  5509. }
  5510. var info = PublicChangePosFee.SetLSDeposit(SnId.ToString(), Deposit);
  5511. if (info != "设置成功")
  5512. {
  5513. return info;
  5514. }
  5515. }
  5516. //立刷
  5517. if (posInfo.BrandId == 6)
  5518. {
  5519. if (Deposit == "0") Deposit = "0";
  5520. else if (Deposit == "99") Deposit = "99";
  5521. else if (Deposit == "199") Deposit = "199";
  5522. else if (Deposit == "249") Deposit = "249";
  5523. else
  5524. {
  5525. return "失败,无" + Deposit + "服务费相关设置权限";
  5526. }
  5527. var info = PublicChangePosFee.SetLISDeposit(SnId.ToString(), Deposit);
  5528. if (info != "设置成功")
  5529. {
  5530. return info;
  5531. }
  5532. }
  5533. //盛付通
  5534. if (posInfo.BrandId == 7)
  5535. {
  5536. if (Deposit == "0") Deposit = "0";
  5537. else if (Deposit == "99") Deposit = "99";
  5538. else if (Deposit == "199") Deposit = "199";
  5539. else if (Deposit == "299") Deposit = "299";
  5540. else
  5541. {
  5542. return "失败,无" + Deposit + "服务费相关设置权限";
  5543. }
  5544. var info = PublicChangePosFee.SetSFTDeposit(SnId.ToString(), Deposit);
  5545. if (info != "设置成功")
  5546. {
  5547. return info;
  5548. }
  5549. }
  5550. //海科
  5551. if (posInfo.BrandId == 8 || posInfo.BrandId == 9)
  5552. {
  5553. if (Deposit == "99") Deposit = "100";
  5554. else if (Deposit == "199") Deposit = "200";
  5555. else if (Deposit == "299") Deposit = "300";
  5556. else
  5557. {
  5558. return "失败,无" + Deposit + "服务费相关设置权限";
  5559. }
  5560. var info = PublicChangePosFee.SetHKDeposit(SnId.ToString(), Deposit);
  5561. if (info != "设置成功")
  5562. {
  5563. return info;
  5564. }
  5565. }
  5566. //联动
  5567. if (posInfo.BrandId == 10 || posInfo.BrandId == 11)
  5568. {
  5569. if (Deposit == "0") Deposit = "0";
  5570. else if (Deposit == "99") Deposit = "99";
  5571. else if (Deposit == "199") Deposit = "199";
  5572. else if (Deposit == "299") Deposit = "299";
  5573. else
  5574. {
  5575. return "失败,无" + Deposit + "服务费相关设置权限";
  5576. }
  5577. var info = PublicChangePosFee.SetLDDeposit(SnId.ToString(), Deposit);
  5578. if (info != "设置成功")
  5579. {
  5580. return info;
  5581. }
  5582. }
  5583. //盒易付
  5584. if (posInfo.BrandId == 12 || posInfo.BrandId == 13)
  5585. {
  5586. if (Deposit == "0") Deposit = "0";
  5587. else if (Deposit == "99") Deposit = "99";
  5588. else if (Deposit == "199") Deposit = "199";
  5589. else if (Deposit == "299") Deposit = "299";
  5590. else
  5591. {
  5592. return "失败,无" + Deposit + "服务费相关设置权限";
  5593. }
  5594. var info = PublicChangePosFee.SetHYFDeposit(SnId.ToString(), Deposit);
  5595. if (info != "设置成功")
  5596. {
  5597. return info;
  5598. }
  5599. }
  5600. }
  5601. var query = SnIds + ";";
  5602. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "调整机具服务费");
  5603. db.SaveChanges();
  5604. db.Dispose();
  5605. }
  5606. return "success";
  5607. }
  5608. #endregion
  5609. }
  5610. }