SysToolsController.cs 271 KB

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