SysToolsController.cs 228 KB

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