SysToolsController.cs 229 KB

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