SysToolsController.cs 239 KB

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