SysToolsController.cs 239 KB

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