SysToolsController.cs 286 KB

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