SysToolsController.cs 217 KB

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