SysToolsController.cs 284 KB

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