SysToolsController.cs 225 KB

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