SysToolsController.cs 216 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552
  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);
  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. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1478. {
  1479. CreateDate = DateTime.Now,
  1480. UpdateDate = DateTime.Now,
  1481. CreateMan = SysUserName + "-" + SysRealName,
  1482. ChangeNo = ChangeNo, //订单号
  1483. ChangeId = add.Id, //订单Id
  1484. BackProductType = oldpos.BrandId, //退回产品类型
  1485. BackProductName = oldPosBrand.Name, //退回产品名称
  1486. UserId = 0, //创客
  1487. BackSnNo = oldpos.PosSn, //设备SN编号
  1488. OutProductType = newpos.BrandId, //出库产品类型
  1489. OutProductName = newPosBrand.Name, //出库产品名称
  1490. OutSnNo = newpos.PosSn, //出库设备SN编号
  1491. OutSnType = newpos.PosSnType, //出库SN机具类型
  1492. Remark = "机具更换", //备注
  1493. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1494. });
  1495. db.SaveChanges();
  1496. BackProductType = oldpos.BrandId;
  1497. BackProductName = newPosBrand.Name;
  1498. ChangeDeviceName = oldpos.DeviceName;
  1499. ChangeSnExpand += oldpos.PosSn + "\n";
  1500. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1501. }
  1502. add.BackProductType = BackProductType; //退回产品类型
  1503. add.BackProductName = BackProductName; //退回产品名称
  1504. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1505. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1506. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1507. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1508. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1509. db.SaveChanges();
  1510. db.Dispose();
  1511. if (IsSend == 1)
  1512. {
  1513. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1514. {
  1515. UserId = pos.BuyUserId, //接收创客
  1516. MsgType = 2,
  1517. Title = "换绑成功通知", //标题
  1518. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1519. CreateDate = DateTime.Now,
  1520. }));
  1521. }
  1522. return "success";
  1523. }
  1524. #endregion
  1525. #region 坏机换新
  1526. public IActionResult ChangeBadPos(string right)
  1527. {
  1528. ViewBag.RightInfo = RightInfo;
  1529. ViewBag.right = right;
  1530. return View();
  1531. }
  1532. [HttpPost]
  1533. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1534. {
  1535. string[] OldSnList;
  1536. string[] NewSnList;
  1537. decimal amount = 0;
  1538. //创客坏机换新
  1539. if (ChangeType == "0")
  1540. {
  1541. if (string.IsNullOrEmpty(MakerCode))
  1542. {
  1543. return "请输入创客编号";
  1544. }
  1545. if (string.IsNullOrEmpty(OldSn))
  1546. {
  1547. return "请输入坏机SN";
  1548. }
  1549. if (string.IsNullOrEmpty(NewSn))
  1550. {
  1551. return "请输入新机SN";
  1552. }
  1553. if (string.IsNullOrEmpty(FromStoreNo))
  1554. {
  1555. return "请输入新机发货仓库编号";
  1556. }
  1557. if (string.IsNullOrEmpty(BackStoreNo))
  1558. {
  1559. return "请输入坏机退回仓库编号";
  1560. }
  1561. OldSnList = OldSn.Split('\n');
  1562. NewSnList = NewSn.Split('\n');
  1563. if (OldSnList.Length != NewSnList.Length)
  1564. {
  1565. return "原机具SN数量和新机具SN数量不一致";
  1566. }
  1567. for (int i = 0; i < OldSnList.Length; i++)
  1568. {
  1569. string OldSnNum = OldSnList[i];
  1570. string NewSnNum = NewSnList[i];
  1571. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1572. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1573. if (storeForCodeFrom.StoreId == 0)
  1574. {
  1575. return "您输入的新机发货仓库编号不存在";
  1576. }
  1577. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1578. if (storeForCodeBack.StoreId == 0)
  1579. {
  1580. return "您输入的坏机退回仓库编号不存在";
  1581. }
  1582. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1583. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1584. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1585. if (oldpos.Id == 0)
  1586. {
  1587. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1588. }
  1589. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0) ?? new PosMachinesTwo();
  1590. if (newpos.Id == 0)
  1591. {
  1592. return "您输入的新机SN不存在";
  1593. }
  1594. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1595. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  1596. {
  1597. return "您输入的新机发货仓库不符新机机具对应品牌";
  1598. }
  1599. if (newpos.StoreId != storeFrom.Id)
  1600. {
  1601. return "您输入的新机SN不在新机发货仓库";
  1602. }
  1603. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1604. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1605. {
  1606. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1607. }
  1608. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
  1609. {
  1610. return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
  1611. }
  1612. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1613. if (brandInfo.Name.Contains("大POS"))
  1614. {
  1615. amount = 300;
  1616. }
  1617. if (brandInfo.Name.Contains("电签"))
  1618. {
  1619. amount = 200;
  1620. }
  1621. // var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1622. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1623. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1624. // storeUserAcount.ValidAmount += amount;
  1625. storeFromUserAcount.ValidAmount += amount;
  1626. storeBackUserAcount.ValidAmount -= amount;
  1627. newpos.BuyUserId = oldpos.BuyUserId;
  1628. newpos.UserId = oldpos.UserId;
  1629. newpos.RecycEndDate = oldpos.RecycEndDate;
  1630. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1631. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1632. newpos.CreditTrade = oldpos.CreditTrade;
  1633. newpos.PosSnType = oldpos.PosSnType;
  1634. newpos.TransferTime = oldpos.TransferTime;
  1635. newpos.IsPurchase = oldpos.IsPurchase;
  1636. newpos.BindingState = oldpos.BindingState;
  1637. newpos.ActivationState = oldpos.ActivationState;
  1638. newpos.BindingTime = oldpos.BindingTime;
  1639. newpos.ActivationTime = oldpos.ActivationTime;
  1640. newpos.IsFirst = oldpos.IsFirst;
  1641. newpos.SeoKeyword = oldpos.SeoKeyword;
  1642. newpos.PrizeParams = oldpos.PrizeParams;
  1643. newpos.LeaderUserId = oldpos.LeaderUserId;
  1644. newpos.BindMerchantId = oldpos.BindMerchantId;
  1645. newpos.StoreId = oldpos.StoreId;
  1646. newpos.UserId = oldpos.UserId;
  1647. newpos.PreUserId = oldpos.PreUserId;
  1648. oldpos.StoreId = storeBack.Id;
  1649. oldpos.QueryCount = 0;
  1650. oldpos.UpdateDate = null;
  1651. oldpos.ActivityList = null;
  1652. oldpos.SeoKeyword = null;
  1653. oldpos.SeoDescription = null;
  1654. oldpos.OrderId = 0;
  1655. oldpos.RecycEndDate = null;
  1656. oldpos.RecycBackCount = 0;
  1657. oldpos.PrizeParams = null;
  1658. oldpos.ScanQrTrade = 0;
  1659. oldpos.BindMerchantId = 0;
  1660. oldpos.CreditTrade = 0;
  1661. oldpos.DebitCardTrade = 0;
  1662. oldpos.IsVip = 0;
  1663. oldpos.UserNav = null;
  1664. oldpos.TransferTime = null;
  1665. oldpos.IsPurchase = 0;
  1666. oldpos.Detail = null;
  1667. oldpos.BindingTime = null;
  1668. oldpos.BindingState = 0;
  1669. oldpos.ActivationTime = null;
  1670. oldpos.ActivationState = 0;
  1671. oldpos.LeaderUserId = 0;
  1672. oldpos.PreUserId = 0;
  1673. oldpos.IsFirst = 0;
  1674. oldpos.DownFeeMan = null;
  1675. oldpos.DownFeeFlag = 0;
  1676. oldpos.DownFeeDate = null;
  1677. oldpos.UpFeeMan = null;
  1678. oldpos.UpFeeFlag = 0;
  1679. oldpos.UpFeeDate = null;
  1680. oldpos.OpReserve1 = 0;
  1681. oldpos.OpReserve2 = 0;
  1682. oldpos.OpReserve3 = 0;
  1683. oldpos.OpId = 0;
  1684. oldpos.RecycStartDate = null;
  1685. oldpos.SourcePosSn = null;
  1686. oldpos.BuyUserId = 0;
  1687. oldpos.UserId = 0;
  1688. oldpos.Status = -1;
  1689. db.SaveChanges();
  1690. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  1691. if (merchant != null)
  1692. {
  1693. merchant.KqSnNo = newpos.PosSn;
  1694. merchant.ActiveStatus = newpos.ActivationState;
  1695. }
  1696. db.SaveChanges();
  1697. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1698. {
  1699. CreateDate = DateTime.Now,
  1700. CreateMan = SysUserName + "-" + SysRealName,
  1701. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1702. OutStoreId = storeFrom.Id,
  1703. BackStoreId = storeBack.Id,
  1704. OutProductType = newpos.BrandId,
  1705. BackProductType = oldpos.BrandId,
  1706. UserId = userForMakerCode.UserId, //创客
  1707. }).Entity;
  1708. db.SaveChanges();
  1709. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1710. {
  1711. CreateDate = DateTime.Now,
  1712. CreateMan = SysUserName + "-" + SysRealName,
  1713. OutSnNo = OldSnNum,
  1714. BackSnNo = NewSnNum,
  1715. ChangeNo = add.ChangeNo, //转换单号
  1716. ChangeId = add.Id, //转换记录Id
  1717. UserId = add.UserId, //创客
  1718. }).Entity;
  1719. db.SaveChanges();
  1720. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1721. if (IsSend == 1)
  1722. {
  1723. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1724. {
  1725. UserId = userForMakerCode.UserId, //接收创客
  1726. MsgType = 2,
  1727. Title = "坏机换新成功通知", //标题
  1728. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1729. CreateDate = DateTime.Now,
  1730. }));
  1731. }
  1732. }
  1733. }
  1734. //仓库坏机换新
  1735. else
  1736. {
  1737. if (string.IsNullOrEmpty(StoreCode))
  1738. {
  1739. return "请输入仓库编号";
  1740. }
  1741. if (string.IsNullOrEmpty(OldSn))
  1742. {
  1743. return "请输入坏机SN";
  1744. }
  1745. if (string.IsNullOrEmpty(NewSn))
  1746. {
  1747. return "请输入新机SN";
  1748. }
  1749. if (string.IsNullOrEmpty(FromStoreNo))
  1750. {
  1751. return "请输入新机发货仓库编号";
  1752. }
  1753. if (string.IsNullOrEmpty(BackStoreNo))
  1754. {
  1755. return "请输入坏机退回仓库编号";
  1756. }
  1757. OldSnList = OldSn.Split('\n');
  1758. NewSnList = NewSn.Split('\n');
  1759. if (OldSnList.Length != NewSnList.Length)
  1760. {
  1761. return "原机具SN数量和新机具SN数量不一致";
  1762. }
  1763. for (int i = 0; i < OldSnList.Length; i++)
  1764. {
  1765. string OldSnNum = OldSnList[i];
  1766. string NewSnNum = NewSnList[i];
  1767. StoreHouse store = new StoreHouse();
  1768. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  1769. if (storeForBadCode.StoreId > 0)
  1770. {
  1771. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  1772. }
  1773. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1774. if (storeForCodeFrom.StoreId == 0)
  1775. {
  1776. return "您输入的新机发货仓库编号不存在";
  1777. }
  1778. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1779. if (storeForCodeBack.StoreId == 0)
  1780. {
  1781. return "您输入的坏机退回仓库编号不存在";
  1782. }
  1783. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1784. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1785. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  1786. if (oldpos.Id == 0)
  1787. {
  1788. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  1789. }
  1790. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0) ?? new PosMachinesTwo();
  1791. if (newpos.Id == 0)
  1792. {
  1793. return "您输入的新机SN不存在";
  1794. }
  1795. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1796. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1797. {
  1798. return "您输入的新机发货仓库不符新机机具对应品牌";
  1799. }
  1800. if (newpos.StoreId != storeFrom.Id)
  1801. {
  1802. return "您输入的新机SN不在新机发货仓库";
  1803. }
  1804. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1805. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1806. {
  1807. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1808. }
  1809. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1810. if (brandInfo.Name.Contains("大POS"))
  1811. {
  1812. amount = 300;
  1813. }
  1814. if (brandInfo.Name.Contains("电签"))
  1815. {
  1816. amount = 200;
  1817. }
  1818. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1819. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1820. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1821. // storeUserAcount.ValidAmount += amount;
  1822. storeFromUserAcount.ValidAmount += amount;
  1823. storeBackUserAcount.ValidAmount -= amount;
  1824. newpos.StoreId = oldpos.StoreId;
  1825. newpos.BuyUserId = oldpos.BuyUserId;
  1826. newpos.UserId = oldpos.UserId;
  1827. newpos.LeaderUserId = oldpos.LeaderUserId;
  1828. newpos.PreUserId = oldpos.PreUserId;
  1829. newpos.IsFirst = oldpos.IsFirst;
  1830. newpos.TransferTime = oldpos.TransferTime;
  1831. oldpos.StoreId = storeBack.Id;
  1832. oldpos.QueryCount = 0;
  1833. oldpos.UpdateDate = null;
  1834. oldpos.ActivityList = null;
  1835. oldpos.SeoKeyword = null;
  1836. oldpos.SeoDescription = null;
  1837. oldpos.OrderId = 0;
  1838. oldpos.RecycEndDate = null;
  1839. oldpos.RecycBackCount = 0;
  1840. oldpos.PrizeParams = null;
  1841. oldpos.ScanQrTrade = 0;
  1842. oldpos.BindMerchantId = 0;
  1843. oldpos.CreditTrade = 0;
  1844. oldpos.DebitCardTrade = 0;
  1845. oldpos.IsVip = 0;
  1846. oldpos.UserNav = null;
  1847. oldpos.TransferTime = null;
  1848. oldpos.IsPurchase = 0;
  1849. oldpos.Detail = null;
  1850. oldpos.BindingTime = null;
  1851. oldpos.BindingState = 0;
  1852. oldpos.ActivationTime = null;
  1853. oldpos.ActivationState = 0;
  1854. oldpos.LeaderUserId = 0;
  1855. oldpos.PreUserId = 0;
  1856. oldpos.IsFirst = 0;
  1857. oldpos.DownFeeMan = null;
  1858. oldpos.DownFeeFlag = 0;
  1859. oldpos.DownFeeDate = null;
  1860. oldpos.UpFeeMan = null;
  1861. oldpos.UpFeeFlag = 0;
  1862. oldpos.UpFeeDate = null;
  1863. oldpos.OpReserve1 = 0;
  1864. oldpos.OpReserve2 = 0;
  1865. oldpos.OpReserve3 = 0;
  1866. oldpos.OpId = 0;
  1867. oldpos.RecycStartDate = null;
  1868. oldpos.SourcePosSn = null;
  1869. oldpos.BuyUserId = 0;
  1870. oldpos.UserId = 0;
  1871. oldpos.Status = -1;
  1872. db.SaveChanges();
  1873. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1874. {
  1875. CreateDate = DateTime.Now,
  1876. CreateMan = SysUserName + "-" + SysRealName,
  1877. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1878. OutStoreId = storeFrom.Id,
  1879. BackStoreId = storeBack.Id,
  1880. OutProductType = newpos.BrandId,
  1881. BackProductType = oldpos.BrandId,
  1882. UserId = store.UserId, //创客
  1883. }).Entity;
  1884. db.SaveChanges();
  1885. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1886. {
  1887. CreateDate = DateTime.Now,
  1888. CreateMan = SysUserName + "-" + SysRealName,
  1889. OutSnNo = OldSnNum,
  1890. BackSnNo = NewSnNum,
  1891. ChangeNo = add.ChangeNo, //转换单号
  1892. ChangeId = add.Id, //转换记录Id
  1893. UserId = add.UserId, //创客
  1894. }).Entity;
  1895. db.SaveChanges();
  1896. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1897. if (IsSend == 1)
  1898. {
  1899. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1900. {
  1901. UserId = store.UserId, //接收创客
  1902. MsgType = 2,
  1903. Title = "坏机换新成功通知", //标题
  1904. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1905. CreateDate = DateTime.Now,
  1906. }));
  1907. }
  1908. }
  1909. }
  1910. // for (int i = 0; i < OldSnList.Length; i++)
  1911. // {
  1912. // string OldSnNum = OldSnList[i];
  1913. // string NewSnNum = NewSnList[i];
  1914. // StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1915. // MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1916. // MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1917. // StoreHouse oldStore = new StoreHouse();
  1918. // PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0);
  1919. // if (storeForCode.StoreId > 0)
  1920. // {
  1921. // StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId);
  1922. // if (Convert.ToInt32(store.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1923. // {
  1924. // return "您输入的仓库不符机具对应品牌";
  1925. // }
  1926. // oldStore = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId);
  1927. // oldpos.Status = -1;
  1928. // oldpos.StoreId = store.Id;
  1929. // }
  1930. // if (oldpos == null)
  1931. // {
  1932. // return "原机具SN不正确或者不符合换机条件";
  1933. // }
  1934. // PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BuyUserId == 0 && m.UserId == 0 && m.BindingState == 0);
  1935. // if (newpos == null)
  1936. // {
  1937. // return "新机具SN不正确或者不为仓库机";
  1938. // }
  1939. // if (oldpos.BrandId != newpos.BrandId)
  1940. // {
  1941. // return "新机具和旧机具品牌不相同";
  1942. // }
  1943. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1944. // if (brandInfo.Name.Contains("大POS"))
  1945. // {
  1946. // amount = 300;
  1947. // }
  1948. // if (brandInfo.Name.Contains("电签"))
  1949. // {
  1950. // amount = 200;
  1951. // }
  1952. // var storehouse = db.StoreHouse.FirstOrDefault(m => m.Id == newpos.StoreId) ?? new StoreHouse();
  1953. // storehouse.LaveNum -= 1;
  1954. // var userAcount = db.UserAccount.FirstOrDefault(m => m.Id == storehouse.UserId) ?? new UserAccount();
  1955. // if (oldpos.StoreId != newpos.StoreId)
  1956. // {
  1957. // userAcount.ValidAmount += amount;
  1958. // newpos.StoreId = oldpos.StoreId;
  1959. // newpos.BuyUserId = oldpos.BuyUserId;
  1960. // newpos.UserId = oldpos.UserId;
  1961. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1962. // newpos.PreUserId = oldpos.PreUserId;
  1963. // newpos.IsFirst = oldpos.IsFirst;
  1964. // newpos.TransferTime = oldpos.TransferTime;
  1965. // }
  1966. // else
  1967. // {
  1968. // newpos.BuyUserId = oldpos.BuyUserId;
  1969. // newpos.UserId = oldpos.UserId;
  1970. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1971. // newpos.PreUserId = oldpos.PreUserId;
  1972. // newpos.IsFirst = oldpos.IsFirst;
  1973. // newpos.TransferTime = oldpos.TransferTime;
  1974. // }
  1975. // db.SaveChanges();
  1976. // var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1977. // var newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1978. // var UserId = 0;
  1979. // if (oldpos.BuyUserId == 0)
  1980. // {
  1981. // UserId = oldStore.UserId;
  1982. // }
  1983. // else
  1984. // {
  1985. // UserId = oldpos.BuyUserId;
  1986. // }
  1987. // BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1988. // {
  1989. // CreateDate = DateTime.Now,
  1990. // CreateMan = SysUserName + "-" + SysRealName,
  1991. // ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1992. // UserId = UserId, //创客
  1993. // }).Entity;
  1994. // db.SaveChanges();
  1995. // BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1996. // {
  1997. // CreateDate = DateTime.Now,
  1998. // CreateMan = SysUserName + "-" + SysRealName,
  1999. // OutSnNo = OldSnNum,
  2000. // BackSnNo = NewSnNum,
  2001. // ChangeNo = add.ChangeNo, //转换单号
  2002. // ChangeId = add.Id, //转换记录Id
  2003. // UserId = add.UserId, //创客
  2004. // }).Entity;
  2005. // db.SaveChanges();
  2006. // if (IsSend == 1)
  2007. // {
  2008. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2009. // {
  2010. // UserId = UserId, //接收创客
  2011. // MsgType = 2,
  2012. // Title = "坏机换新成功通知", //标题
  2013. // Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为您换为" + newPosBrand.Name + "SN:" + NewSn + "。",
  2014. // CreateDate = DateTime.Now,
  2015. // }));
  2016. // }
  2017. // }
  2018. return "success";
  2019. }
  2020. #endregion
  2021. #region 机具解绑
  2022. public IActionResult Unbind(string right)
  2023. {
  2024. ViewBag.RightInfo = RightInfo;
  2025. ViewBag.right = right;
  2026. return View();
  2027. }
  2028. [HttpPost]
  2029. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  2030. {
  2031. if (string.IsNullOrEmpty(PosSn))
  2032. {
  2033. return "请输入机具SN";
  2034. }
  2035. if (string.IsNullOrEmpty(MakerCode))
  2036. {
  2037. return "请输入创客编号";
  2038. }
  2039. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  2040. if (forSnNo == null)
  2041. {
  2042. return "机具SN不存在";
  2043. }
  2044. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  2045. if (pos == null)
  2046. {
  2047. return "机具SN不存在";
  2048. }
  2049. if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  2050. {
  2051. return "请输入商户编号";
  2052. }
  2053. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2054. if (forMakerCode == null)
  2055. {
  2056. return "创客不存在";
  2057. }
  2058. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2059. if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  2060. {
  2061. return "商户编号不存在";
  2062. }
  2063. if (pos.BuyUserId != forMakerCode.UserId)
  2064. {
  2065. return "机具SN和创客不匹配";
  2066. }
  2067. if (pos.ActivationState == 1)
  2068. {
  2069. return "机具已激活,不能解绑";
  2070. }
  2071. if (pos.BuyUserId == 0)
  2072. {
  2073. return "机具是仓库机,不支持解绑";
  2074. }
  2075. if (pos.BindingState == 0)
  2076. {
  2077. return "机具未绑定,不支持解绑";
  2078. }
  2079. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  2080. {
  2081. return "机具绑定已超过30天,不支持解绑";
  2082. }
  2083. if (pos.CreditTrade > 0)
  2084. {
  2085. return "该机具已交易,无法解绑";
  2086. }
  2087. if (forMerNo != null)
  2088. {
  2089. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2090. if (merchant != null)
  2091. {
  2092. //机具解绑删除客小爽企业版对应数据
  2093. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2094. if (merInfo != null)
  2095. {
  2096. db.BusinessPartnerMerchant.Remove(merInfo);
  2097. }
  2098. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2099. if (posInfo != null)
  2100. {
  2101. db.BusinessPartnerPos.Remove(posInfo);
  2102. }
  2103. db.PosMerchantInfo.Remove(merchant);
  2104. }
  2105. db.MachineForMerNo.Remove(forMerNo);
  2106. db.SaveChanges();
  2107. }
  2108. db.MachineUnBind.Add(new MachineUnBind()
  2109. {
  2110. CreateDate = DateTime.Now,
  2111. SeoTitle = SysUserName + "-" + SysRealName,
  2112. MerchantId = pos.BindMerchantId,
  2113. AuditDate = DateTime.Now,
  2114. AuditDesc = "平台操作解绑",
  2115. AuditStatus = 1,
  2116. SnNo = pos.PosSn,
  2117. BrandId = pos.BrandId,
  2118. UserId = pos.BuyUserId,
  2119. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2120. });
  2121. pos.BindMerchantId = 0;
  2122. pos.BindingState = 0;
  2123. pos.BindingTime = DateTime.Parse("1900-01-01");
  2124. pos.UserId = pos.BuyUserId;
  2125. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2126. db.SaveChanges();
  2127. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2128. if (IsSend == 1)
  2129. {
  2130. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2131. {
  2132. UserId = pos.BuyUserId, //接收创客
  2133. MsgType = 2,
  2134. Title = "解绑成功通知", //标题
  2135. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2136. CreateDate = DateTime.Now,
  2137. }));
  2138. }
  2139. return "success";
  2140. }
  2141. #endregion
  2142. #region 通过券码修改盟主标记
  2143. public IActionResult ChangeSignQuan(string right)
  2144. {
  2145. ViewBag.RightInfo = RightInfo;
  2146. ViewBag.right = right;
  2147. return View();
  2148. }
  2149. [HttpPost]
  2150. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2151. {
  2152. if (string.IsNullOrEmpty(Coupons))
  2153. {
  2154. return "请输入机具券码,多个券码用回车分隔";
  2155. }
  2156. if (string.IsNullOrEmpty(MakerCode))
  2157. {
  2158. return "请输入创客编号";
  2159. }
  2160. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2161. if (forMakerCode == null)
  2162. {
  2163. return "创客不存在";
  2164. }
  2165. string[] SnList = Coupons.Split('\n');
  2166. foreach (var item in SnList)
  2167. {
  2168. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2169. if (coupos == null)
  2170. {
  2171. return "机具券不存在";
  2172. }
  2173. else
  2174. {
  2175. coupos.LeaderUserId = forMakerCode.UserId;
  2176. }
  2177. }
  2178. db.SaveChanges();
  2179. return "success";
  2180. }
  2181. #endregion
  2182. #region 通过机具SN修改盟主标记
  2183. public IActionResult ChangeSignSn(string right)
  2184. {
  2185. ViewBag.RightInfo = RightInfo;
  2186. ViewBag.right = right;
  2187. return View();
  2188. }
  2189. [HttpPost]
  2190. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2191. {
  2192. if (string.IsNullOrEmpty(PosSn))
  2193. {
  2194. return "请输入机具SN,多个SN用回车分隔";
  2195. }
  2196. if (string.IsNullOrEmpty(MakerCode))
  2197. {
  2198. return "请输入创客编号";
  2199. }
  2200. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2201. if (forMakerCode == null)
  2202. {
  2203. return "创客不存在";
  2204. }
  2205. string[] SnList = PosSn.Split('\n');
  2206. foreach (var item in SnList)
  2207. {
  2208. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2209. if (pos == null)
  2210. {
  2211. return "该机具不存在";
  2212. }
  2213. else
  2214. {
  2215. pos.LeaderUserId = forMakerCode.UserId;
  2216. }
  2217. }
  2218. db.SaveChanges();
  2219. return "success";
  2220. }
  2221. #endregion
  2222. #region 机具循环列表
  2223. /// <summary>
  2224. /// 根据条件查询机具循环列表
  2225. /// </summary>
  2226. /// <returns></returns>
  2227. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2228. {
  2229. ViewBag.RightInfo = RightInfo;
  2230. ViewBag.right = right;
  2231. ViewBag.SwapSnExpand = SwapSnExpand;
  2232. ViewBag.SnNos = SnNos;
  2233. return View();
  2234. }
  2235. #endregion
  2236. #region 根据条件查询机具循环列表
  2237. /// <summary>
  2238. /// 机具循环列表
  2239. /// </summary>
  2240. /// <returns></returns>
  2241. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2242. {
  2243. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2244. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2245. Fields.Add("SnNos", "1"); //发货机具SN
  2246. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2247. if (!string.IsNullOrEmpty(SwapSnExpand))
  2248. {
  2249. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2250. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2251. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2252. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2253. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2254. for (int i = 0; i < SnNoList.Length; i++)
  2255. {
  2256. Dictionary<string, object> data = new Dictionary<string, object>();
  2257. data["ApplyNo"] = apply.ApplyNo;
  2258. data["OrderNo"] = order.OrderNo;
  2259. data["MakerCode"] = user.MakerCode;
  2260. data["RealName"] = user.RealName;
  2261. if (SnNoList.Length > i)
  2262. {
  2263. string SourceSn = SnNoList[i].Split(':')[0];
  2264. data["ComeSn"] = SnNoList[i];
  2265. data["ComeSnParam"] = SourceSn;
  2266. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2267. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2268. if (pos.LeaderUserId > 0)
  2269. {
  2270. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2271. data["ComeSnMakerCode"] = leader.MakerCode;
  2272. data["ComeSnRealName"] = leader.RealName;
  2273. }
  2274. }
  2275. if (OrderSnNo.Length > i)
  2276. {
  2277. string SendSn = OrderSnNo[i];
  2278. data["SendSn"] = OrderSnNo[i];
  2279. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2280. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2281. if (pos.LeaderUserId > 0)
  2282. {
  2283. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2284. data["SendSnMakerCode"] = leader.MakerCode;
  2285. data["SendSnRealName"] = leader.RealName;
  2286. }
  2287. }
  2288. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2289. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2290. dataList.Add(data);
  2291. }
  2292. }
  2293. else if (!string.IsNullOrEmpty(SnNos))
  2294. {
  2295. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2296. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2297. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2298. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2299. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2300. for (int i = 0; i < OrderSnNo.Length; i++)
  2301. {
  2302. Dictionary<string, object> data = new Dictionary<string, object>();
  2303. data["ApplyNo"] = apply.ApplyNo;
  2304. data["OrderNo"] = order.OrderNo;
  2305. data["MakerCode"] = user.MakerCode;
  2306. data["RealName"] = user.RealName;
  2307. if (SnNoList.Length > i)
  2308. {
  2309. string SourceSn = SnNoList[i].Split(':')[0];
  2310. data["ComeSn"] = SnNoList[i];
  2311. data["ComeSnParam"] = SourceSn;
  2312. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2313. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2314. if (pos.LeaderUserId > 0)
  2315. {
  2316. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2317. data["ComeSnMakerCode"] = leader.MakerCode;
  2318. data["ComeSnRealName"] = leader.RealName;
  2319. }
  2320. }
  2321. if (OrderSnNo.Length > i)
  2322. {
  2323. string SendSn = OrderSnNo[i];
  2324. data["SendSn"] = OrderSnNo[i];
  2325. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2326. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2327. if (pos.LeaderUserId > 0)
  2328. {
  2329. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2330. data["SendSnMakerCode"] = leader.MakerCode;
  2331. data["SendSnRealName"] = leader.RealName;
  2332. }
  2333. }
  2334. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2335. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2336. dataList.Add(data);
  2337. }
  2338. }
  2339. Dictionary<string, object> obj = new Dictionary<string, object>();
  2340. obj.Add("code", 0);
  2341. obj.Add("msg", "");
  2342. obj.Add("count", dataList.Count);
  2343. obj.Add("data", dataList);
  2344. return Json(obj);
  2345. }
  2346. #endregion
  2347. #region 查询机具循环
  2348. /// <summary>
  2349. /// 根据条件查询机具来源机具和券码
  2350. /// </summary>
  2351. /// <returns></returns>
  2352. public IActionResult SourceLoop(string right, string SnNos)
  2353. {
  2354. ViewBag.RightInfo = RightInfo;
  2355. ViewBag.right = right;
  2356. ViewBag.SnNos = SnNos;
  2357. return View();
  2358. }
  2359. #endregion
  2360. #region 根据条件查询机具来源机具和券码
  2361. /// <summary>
  2362. /// 机具循环列表
  2363. /// </summary>
  2364. /// <returns></returns>
  2365. public string SourceLoopData(string SnNo, int page = 1, int limit = 30)
  2366. {
  2367. var result = "";
  2368. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  2369. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  2370. if (pos.Id == 0)
  2371. {
  2372. return "机具:" + SnNo + "不存在";
  2373. }
  2374. else
  2375. {
  2376. var stattime = pos.RecycStartDate == null ? "" : pos.RecycStartDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  2377. var endtime = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
  2378. result += "循环开始时间:" + stattime + "\n";
  2379. result += "循环结束时间:" + endtime + "\n";
  2380. result += "来源机具/券:" + pos.SourcePosSn + "\n";
  2381. }
  2382. return result;
  2383. }
  2384. #endregion
  2385. #region 查询创客直推奖
  2386. public IActionResult Prize100(string right)
  2387. {
  2388. ViewBag.RightInfo = RightInfo;
  2389. ViewBag.right = right;
  2390. return View();
  2391. }
  2392. [HttpPost]
  2393. public Dictionary<string, string> Prize100Do(string MakerCode)
  2394. {
  2395. Dictionary<string, string> dic = new Dictionary<string, string>();
  2396. string result = "";
  2397. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2398. if (forMakerCode == null)
  2399. {
  2400. result += "创客编号不存在\n";
  2401. dic.Add("code", "1");
  2402. dic.Add("result", result);
  2403. return dic;
  2404. }
  2405. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2406. if (OrderCount == 0)
  2407. {
  2408. result += "该创客未下单\n";
  2409. dic.Add("code", "1");
  2410. dic.Add("result", result);
  2411. return dic;
  2412. }
  2413. if (OrderCount > 1)
  2414. {
  2415. result += "该创客已不是首笔下单\n";
  2416. dic.Add("code", "1");
  2417. dic.Add("result", result);
  2418. return dic;
  2419. }
  2420. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2421. if (order.PayStatus < 1)
  2422. {
  2423. result += "未付款\n";
  2424. dic.Add("code", "1");
  2425. dic.Add("result", result);
  2426. return dic;
  2427. }
  2428. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2429. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2430. result += "订单号:" + order.OrderNo + "\n";
  2431. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2432. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2433. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2434. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2435. if (machineCount + ActiveCount >= 3)
  2436. {
  2437. string IsGet = "未发放";
  2438. int ToUserId = 0;
  2439. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2440. if (item == null)
  2441. {
  2442. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2443. DateTime end = order.PayDate.Value.AddMinutes(2);
  2444. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2445. }
  2446. if (item != null)
  2447. {
  2448. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2449. ToUserId = item.UserId;
  2450. dic.Add("code", "1");
  2451. }
  2452. else
  2453. {
  2454. dic.Add("id", order.Id.ToString());
  2455. dic.Add("code", "0");
  2456. }
  2457. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  2458. result += "是否发放:" + IsGet + "\n";
  2459. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2460. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  2461. }
  2462. else
  2463. {
  2464. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  2465. dic.Add("code", "1");
  2466. }
  2467. dic.Add("result", result);
  2468. return dic;
  2469. }
  2470. public string AddPrize100(int Id)
  2471. {
  2472. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  2473. if (order != null)
  2474. {
  2475. //机具券逻辑
  2476. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  2477. if (pro != null)
  2478. {
  2479. //推荐下单奖励
  2480. if (pro.ProductId == 10 || pro.ProductId == 11)
  2481. {
  2482. int OrderId = order.Id;
  2483. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  2484. if (!checkPrize)
  2485. {
  2486. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2487. if (user != null)
  2488. {
  2489. bool directPrize = false; //直推奖标记
  2490. int ParentUserId = user.ParentUserId;
  2491. // List<int> proids = new List<int>();
  2492. // proids.Add(10);
  2493. // proids.Add(11);
  2494. while (ParentUserId > 0)
  2495. {
  2496. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2497. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  2498. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2499. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2500. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2501. {
  2502. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2503. directPrize = true;
  2504. db.SaveChanges();
  2505. return "发放成功";
  2506. }
  2507. ParentUserId = puser.ParentUserId;
  2508. }
  2509. }
  2510. }
  2511. return "已发放,请勿重复发放";
  2512. }
  2513. }
  2514. }
  2515. return "操作失败";
  2516. }
  2517. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2518. {
  2519. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2520. if (account == null)
  2521. {
  2522. account = db.UserAccount.Add(new UserAccount()
  2523. {
  2524. Id = UserId,
  2525. UserId = UserId,
  2526. }).Entity;
  2527. db.SaveChanges();
  2528. }
  2529. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2530. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2531. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2532. account.BalanceAmount += 100 * Count;
  2533. account.TotalAmount += 100 * Count;
  2534. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2535. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2536. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2537. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2538. {
  2539. CreateDate = DateTime.Now,
  2540. UpdateDate = DateTime.Now,
  2541. UserId = UserId, //创客
  2542. ChangeType = 112, //变动类型
  2543. ChangeAmount = 100 * Count, //变更金额
  2544. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2545. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2546. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2547. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2548. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2549. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2550. QueryCount = OrderId,
  2551. }).Entity;
  2552. db.SaveChanges();
  2553. }
  2554. #endregion
  2555. #region 查询机具开机奖
  2556. public IActionResult OpenPrize(string right)
  2557. {
  2558. ViewBag.RightInfo = RightInfo;
  2559. ViewBag.right = right;
  2560. return View();
  2561. }
  2562. [HttpPost]
  2563. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2564. {
  2565. Dictionary<string, string> dic = new Dictionary<string, string>();
  2566. string result = "";
  2567. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2568. if (pos == null)
  2569. {
  2570. result += "机具SN号不存在\n";
  2571. dic.Add("code", "1");
  2572. dic.Add("result", result);
  2573. return dic;
  2574. }
  2575. if (pos.BindingState == 0)
  2576. {
  2577. result += "机具未绑定\n";
  2578. dic.Add("code", "1");
  2579. dic.Add("result", result);
  2580. return dic;
  2581. }
  2582. if (pos.ActivationState == 0)
  2583. {
  2584. result += "机具未激活\n";
  2585. dic.Add("code", "1");
  2586. dic.Add("result", result);
  2587. return dic;
  2588. }
  2589. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2590. if (merchant == null)
  2591. {
  2592. result += "商户不存在\n";
  2593. dic.Add("code", "1");
  2594. dic.Add("result", result);
  2595. return dic;
  2596. }
  2597. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2598. result += "机具号:" + PosSn + "\n";
  2599. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2600. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2601. string OpenUser10 = "未领取";
  2602. string OpenUser20 = "未领取";
  2603. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2604. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2605. if (openreward.Id > 0)
  2606. {
  2607. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2608. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2609. }
  2610. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2611. if (openreward.Id > 0)
  2612. {
  2613. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2614. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2615. }
  2616. result += "开机奖20:" + OpenUser20 + "\n";
  2617. // result += "开机奖10:" + OpenUser10 + "\n";
  2618. dic.Add("id", pos.Id.ToString());
  2619. dic.Add("code", "0");
  2620. dic.Add("result", result);
  2621. return dic;
  2622. }
  2623. public string AddOpenPrize(int Id)
  2624. {
  2625. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2626. if (pos == null)
  2627. {
  2628. return "机具未激活";
  2629. }
  2630. if (pos.BindingTime <= pos.TransferTime)
  2631. {
  2632. return "补录机,不能补发开机奖";
  2633. }
  2634. // if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2635. // {
  2636. // return "绑定已超过30天";
  2637. // }
  2638. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2639. if (ActPrize == 0)
  2640. {
  2641. return "机具无押金";
  2642. }
  2643. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2644. if (merchant == null)
  2645. {
  2646. return "商户不存在";
  2647. }
  2648. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2649. if (check)
  2650. {
  2651. return "开机奖励已发放,请勿重复操作";
  2652. }
  2653. // 从机具所属人上级开始分开机奖励
  2654. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2655. if (user != null)
  2656. {
  2657. if (!string.IsNullOrEmpty(user.ParentNav))
  2658. {
  2659. decimal Prize = 20;
  2660. List<string> PrizeFlag = new List<string>();
  2661. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2662. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2663. {
  2664. int UserId = int.Parse(ParentNavs[i]);
  2665. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2666. if (puser != null && Prize > 0)
  2667. {
  2668. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2669. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2670. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2671. if (machineCount + ActiveCount + couponCount >= 3)
  2672. {
  2673. int pTopUserId = 0;
  2674. if (!string.IsNullOrEmpty(puser.ParentNav))
  2675. {
  2676. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2677. }
  2678. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2679. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2680. {
  2681. CreateDate = DateTime.Now,
  2682. UpdateDate = DateTime.Now,
  2683. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2684. TradeDate = pos.ActivationTime, //达标日期
  2685. UserId = puser.Id, //创客
  2686. BrandId = pos.BrandId, //品牌
  2687. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2688. MerchantId = pos.BindMerchantId, //商户
  2689. DirectUserId = merchant.UserId, //商户直属人
  2690. SnNo = pos.PosSn, //SN号
  2691. MerNo = merchant.KqMerNo, //渠道商户号
  2692. SnType = pos.PosSnType, //机具类型
  2693. StandardDate = pos.ActivationTime, //商户的激活日期
  2694. SnStoreId = pos.StoreId, //SN仓库
  2695. MerBuddyType = puser.MerchantType, //商户创客类型
  2696. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2697. RewardTips = "开机奖励", //奖励描述
  2698. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2699. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2700. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2701. RewardDesc = "开机奖励", //奖励描述
  2702. TopUserId = pTopUserId, //顶级创客
  2703. SeoTitle = machineUser.RealName,
  2704. }).Entity;
  2705. db.OpenReward.Add(new OpenReward()
  2706. {
  2707. CreateDate = DateTime.Now,
  2708. UpdateDate = DateTime.Now,
  2709. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2710. TradeDate = DateTime.Now, //达标日期
  2711. UserId = puser.Id, //创客
  2712. BrandId = pos.BrandId, //品牌
  2713. RewardType = 2, //奖励类型
  2714. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2715. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2716. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2717. RewardDesc = "开机奖励", //奖励描述
  2718. TopUserId = pTopUserId, //顶级创客
  2719. });
  2720. string IdBrand = puser.Id + "_" + pos.BrandId;
  2721. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2722. if (userData == null)
  2723. {
  2724. userData = db.UserMachineData.Add(new UserMachineData()
  2725. {
  2726. IdBrand = IdBrand,
  2727. }).Entity;
  2728. db.SaveChanges();
  2729. }
  2730. userData.OpenProfit += Prize;
  2731. db.SaveChanges();
  2732. //账户入库
  2733. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2734. if (account == null)
  2735. {
  2736. account = db.UserAccount.Add(new UserAccount()
  2737. {
  2738. Id = puser.Id,
  2739. UserId = puser.Id,
  2740. }).Entity;
  2741. db.SaveChanges();
  2742. }
  2743. //收支明细入库
  2744. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2745. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2746. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2747. account.BalanceAmount += Prize;
  2748. account.TotalAmount += Prize;
  2749. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2750. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2751. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2752. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2753. {
  2754. CreateDate = DateTime.Now,
  2755. UpdateDate = DateTime.Now,
  2756. UserId = puser.Id, //创客
  2757. ChangeType = 50, //变动类型
  2758. ProductType = pos.BrandId, //产品类型
  2759. ChangeAmount = Prize, //变更金额
  2760. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2761. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2762. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2763. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2764. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2765. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2766. }).Entity;
  2767. db.SaveChanges();
  2768. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  2769. string dateString = DateTime.Now.ToString("yyyyMMdd");
  2770. string monthString = DateTime.Now.ToString("yyyyMM");
  2771. // 开机奖励列表
  2772. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  2773. if (!dates.Contains(dateString))
  2774. {
  2775. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  2776. }
  2777. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  2778. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  2779. if (!months.Contains(monthString))
  2780. {
  2781. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  2782. }
  2783. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  2784. // 开机奖励详情
  2785. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  2786. //收支明细
  2787. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  2788. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  2789. Prize = 0;
  2790. PrizeFlag.Add(Prize.ToString("f0"));
  2791. }
  2792. }
  2793. }
  2794. string result = "";
  2795. // if (!PrizeFlag.Contains("20"))
  2796. // {
  2797. // result += "20元奖励未发,请检查上级是否满足条件\n";
  2798. // }
  2799. // if (!PrizeFlag.Contains("10"))
  2800. // {
  2801. // result += "10元奖励未发,请检查上级是否满足条件\n";
  2802. // }
  2803. if (string.IsNullOrEmpty(result))
  2804. {
  2805. return "发放成功";
  2806. }
  2807. return result;
  2808. }
  2809. }
  2810. db.Dispose();
  2811. return "操作失败";
  2812. }
  2813. #endregion
  2814. #region 查询机具流量费分佣
  2815. public IActionResult FluxPrize(string right)
  2816. {
  2817. ViewBag.RightInfo = RightInfo;
  2818. ViewBag.right = right;
  2819. return View();
  2820. }
  2821. [HttpPost]
  2822. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  2823. {
  2824. Dictionary<string, string> dic = new Dictionary<string, string>();
  2825. string result = "";
  2826. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2827. if (pos == null)
  2828. {
  2829. result += "机具SN号不存在\n";
  2830. dic.Add("code", "1");
  2831. dic.Add("result", result);
  2832. return dic;
  2833. }
  2834. if (pos.BindingState == 0)
  2835. {
  2836. result += "机具未绑定\n";
  2837. dic.Add("code", "1");
  2838. dic.Add("result", result);
  2839. return dic;
  2840. }
  2841. if (pos.ActivationState == 0)
  2842. {
  2843. result += "机具未激活\n";
  2844. dic.Add("code", "1");
  2845. dic.Add("result", result);
  2846. return dic;
  2847. }
  2848. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2849. if (merchant == null)
  2850. {
  2851. result += "商户不存在\n";
  2852. dic.Add("code", "1");
  2853. dic.Add("result", result);
  2854. return dic;
  2855. }
  2856. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2857. result += "机具号:" + PosSn + "\n";
  2858. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2859. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2860. string FluxGet6 = "未领取";
  2861. string FluxUser6 = "";
  2862. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  2863. if (flux.Id > 0)
  2864. {
  2865. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  2866. FluxGet6 = "已领取(金额:" + flux.FluxFeeAmt + ",领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2867. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2868. }
  2869. result += "流量费:" + FluxGet6 + "\n";
  2870. result += "流量费发放对象:" + FluxUser6 + "\n";
  2871. dic.Add("id", pos.Id.ToString());
  2872. dic.Add("code", "0");
  2873. dic.Add("result", result);
  2874. return dic;
  2875. }
  2876. public string AddFluxPrize(int Id)
  2877. {
  2878. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2879. if (pos == null)
  2880. {
  2881. return "机具未激活";
  2882. }
  2883. // if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2884. // {
  2885. // return "绑定已超过30天";
  2886. // }
  2887. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2888. if (ActPrize == 0)
  2889. {
  2890. return "机具无押金";
  2891. }
  2892. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2893. if (merchant == null)
  2894. {
  2895. return "商户不存在";
  2896. }
  2897. if (pos.BrandId == 6)
  2898. {
  2899. return "立刷不支持流量费分佣";
  2900. }
  2901. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  2902. {
  2903. return "无押金机,不支持流量费分佣";
  2904. }
  2905. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  2906. if (check)
  2907. {
  2908. return "开机奖励已发放,请勿重复操作";
  2909. }
  2910. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  2911. if (trade != null)
  2912. {
  2913. try
  2914. {
  2915. string OrderNo = trade.TradeSerialNo; //单号
  2916. DateTime TradeDate = trade.CreateDate.Value;
  2917. string TradeMonth = TradeDate.ToString("yyyyMM");
  2918. decimal FeeAmount = trade.FeeAmount; //流量费
  2919. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  2920. {
  2921. FeeAmount = FeeAmount / 100;
  2922. }
  2923. string TradeSnNo = trade.TradeSnNo; //机具SN
  2924. decimal FluxProfit = 0;
  2925. if (trade.ProductType == "1" && FeeAmount == 60)
  2926. {
  2927. FluxProfit = 24;
  2928. }
  2929. else if (trade.ProductType == "7" && FeeAmount == 46)
  2930. {
  2931. FluxProfit = 10;
  2932. }
  2933. else if (trade.ProductType != "1" && FeeAmount == 48)
  2934. {
  2935. FluxProfit = 12;
  2936. }
  2937. if (FluxProfit > 0)
  2938. {
  2939. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2940. int GetUserId = user.Id;
  2941. int TopUserId = 0;
  2942. string ParentNav = user.ParentNav;
  2943. if (!string.IsNullOrEmpty(ParentNav))
  2944. {
  2945. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2946. if (ParentNavList.Length > 1)
  2947. {
  2948. TopUserId = int.Parse(ParentNavList[1]);
  2949. }
  2950. else if (ParentNavList.Length == 1)
  2951. {
  2952. TopUserId = int.Parse(ParentNavList[0]);
  2953. }
  2954. }
  2955. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  2956. if (fluxProfit == null)
  2957. {
  2958. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  2959. {
  2960. CreateDate = DateTime.Now,
  2961. UpdateDate = DateTime.Now,
  2962. UserId = GetUserId, //创客
  2963. BrandId = pos.BrandId,
  2964. TopUserId = TopUserId, //顶级创客
  2965. TradeMonth = TradeMonth, //交易月
  2966. MerUserType = user.MerchantType, //商户创客类型
  2967. Remark = "流量卡分佣", //备注
  2968. }).Entity;
  2969. db.SaveChanges();
  2970. }
  2971. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  2972. db.FluxProfitDetail.Add(new FluxProfitDetail()
  2973. {
  2974. CreateDate = DateTime.Now,
  2975. UpdateDate = DateTime.Now,
  2976. RecordNo = OrderNo, //单号
  2977. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  2978. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  2979. TradeMonth = TradeMonth, //交易月
  2980. UserId = GetUserId, //创客
  2981. MerchantId = pos.BindMerchantId, //商户
  2982. MerchantUserId = pos.UserId, //商户直属人
  2983. MerNo = merchant.KqMerNo, //渠道商户编号
  2984. SnNo = pos.PosSn, //渠道SN号
  2985. FluxOrderNo = OrderNo, //流量扣费单号
  2986. TradeOrderNo = OrderNo, //交易流水号
  2987. TradeAmt = trade.TradeAmount, //商户交易额
  2988. FluxFeeAmt = FeeAmount, //流量费
  2989. FluxProfitAmt = FluxProfit, //流量分润总金额
  2990. PosType = pos.PosSnType.ToString(), //POS类型
  2991. Remark = "流量卡分佣", //备注
  2992. BrandId = pos.BrandId, //品牌
  2993. TopUserId = TopUserId, //顶级创客
  2994. MerUserType = user.MerchantType, //商户创客类型
  2995. });
  2996. string IdBrand = user.Id + "_" + pos.BrandId;
  2997. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2998. if (userData == null)
  2999. {
  3000. userData = db.UserMachineData.Add(new UserMachineData()
  3001. {
  3002. IdBrand = IdBrand,
  3003. }).Entity;
  3004. db.SaveChanges();
  3005. }
  3006. userData.FluxProfit += FluxProfit;
  3007. db.SaveChanges();
  3008. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  3009. if (account == null)
  3010. {
  3011. account = db.UserAccount.Add(new UserAccount()
  3012. {
  3013. Id = GetUserId,
  3014. UserId = GetUserId,
  3015. }).Entity;
  3016. db.SaveChanges();
  3017. }
  3018. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  3019. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  3020. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  3021. account.BalanceAmount += FluxProfit;
  3022. account.TotalAmount += FluxProfit;
  3023. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  3024. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  3025. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  3026. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  3027. {
  3028. CreateDate = DateTime.Now,
  3029. UpdateDate = DateTime.Now,
  3030. UserId = GetUserId, //创客
  3031. ChangeType = 60, //变动类型
  3032. ProductType = pos.BrandId, //产品类型
  3033. ChangeAmount = FluxProfit, //变更金额
  3034. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3035. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3036. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3037. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3038. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3039. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3040. }).Entity;
  3041. db.SaveChanges();
  3042. spdb.Dispose();
  3043. db.Dispose();
  3044. return "发放成功";
  3045. }
  3046. }
  3047. catch (Exception ex)
  3048. {
  3049. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  3050. }
  3051. }
  3052. spdb.Dispose();
  3053. db.Dispose();
  3054. return "操作失败";
  3055. }
  3056. #endregion
  3057. #region 设置立刷费率
  3058. public IActionResult LisFee(string right)
  3059. {
  3060. ViewBag.RightInfo = RightInfo;
  3061. ViewBag.right = right;
  3062. return View();
  3063. }
  3064. [HttpPost]
  3065. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  3066. {
  3067. if (string.IsNullOrEmpty(PosSns))
  3068. {
  3069. return "请输入机具号";
  3070. }
  3071. string result = SysUserName + "设置\n";
  3072. string[] PosSnList = PosSns.Split('\n');
  3073. int total = PosSnList.Length;
  3074. int index = 0;
  3075. foreach (string SubPosSn in PosSnList)
  3076. {
  3077. index += 1;
  3078. string PosSn = SubPosSn.Replace("\r", "");
  3079. result += PosSn + ":" + Fee + "\n";
  3080. if (Kind == "M5")
  3081. {
  3082. result += SetLiSFee(PosSn, Fee) + "\n";
  3083. }
  3084. else if (Kind == "N1")
  3085. {
  3086. result += SetLiSDeposit(PosSn, (int)Fee);
  3087. }
  3088. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  3089. }
  3090. result += "\n\n";
  3091. function.WriteLog(result, "设置立刷费率");
  3092. return result;
  3093. }
  3094. public string LisFeeProcess()
  3095. {
  3096. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  3097. }
  3098. #region 立刷
  3099. string LiSAgentId = "50814834";
  3100. 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=";
  3101. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  3102. public string LiSSign(string data)
  3103. {
  3104. var rsa = RSA.Create();
  3105. var key = Convert.FromBase64String(LiSPrivateKey);
  3106. var content = Encoding.UTF8.GetBytes(data);
  3107. rsa.ImportPkcs8PrivateKey(key, out _);
  3108. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  3109. return Convert.ToBase64String(result);
  3110. }
  3111. // 设置费率
  3112. public string SetLiSFee(string sn, decimal serviceFee)
  3113. {
  3114. Dictionary<string, object> dic = new Dictionary<string, object>();
  3115. dic.Add("agentId", LiSAgentId);
  3116. dic.Add("deviceSn", sn);
  3117. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3118. Dictionary<string, object> item = new Dictionary<string, object>();
  3119. item.Add("feeCalcType", "M5");
  3120. item.Add("fixed", "0");
  3121. item.Add("rate", serviceFee);
  3122. feeList.Add(item);
  3123. dic.Add("feeList", feeList);
  3124. dic.Add("signMethod", "02");
  3125. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  3126. string signstr = LiSSign(content);
  3127. dic.Add("signData", signstr);
  3128. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3129. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3130. return result;
  3131. }
  3132. // 设置押金
  3133. public string SetLiSDeposit(string sn, int serviceFee)
  3134. {
  3135. serviceFee = serviceFee * 100;
  3136. Dictionary<string, object> dic = new Dictionary<string, object>();
  3137. dic.Add("agentId", LiSAgentId);
  3138. dic.Add("deviceSn", sn);
  3139. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3140. Dictionary<string, object> item = new Dictionary<string, object>();
  3141. item.Add("feeCalcType", "N1");
  3142. item.Add("fixed", "1");
  3143. item.Add("rate", serviceFee);
  3144. feeList.Add(item);
  3145. dic.Add("feeList", feeList);
  3146. dic.Add("signMethod", "02");
  3147. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  3148. string signstr = LiSSign(content);
  3149. dic.Add("signData", signstr);
  3150. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3151. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3152. return result;
  3153. }
  3154. #endregion
  3155. #endregion
  3156. #region 查询商户型创客设置信息
  3157. public IActionResult SeeMerchantType(string right)
  3158. {
  3159. ViewBag.RightInfo = RightInfo;
  3160. ViewBag.right = right;
  3161. return View();
  3162. }
  3163. [HttpPost]
  3164. public string SeeMerchantTypeDo(string PosSn)
  3165. {
  3166. if (string.IsNullOrEmpty(PosSn))
  3167. {
  3168. return "请输入机具SN或者创客编号";
  3169. }
  3170. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3171. if (PosSn.StartsWith("K"))
  3172. {
  3173. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3174. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3175. if (check)
  3176. {
  3177. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3178. }
  3179. }
  3180. else
  3181. {
  3182. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3183. if (check)
  3184. {
  3185. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3186. }
  3187. }
  3188. if (pos.Id == 0)
  3189. {
  3190. return "查无信息";
  3191. }
  3192. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3193. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3194. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3195. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3196. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3197. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3198. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3199. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3200. string result = "";
  3201. result += "机具SN:" + pos.PosSn + "\n";
  3202. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3203. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3204. result += "商户编号:" + pos.MerNo + "\n";
  3205. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3206. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3207. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3208. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3209. result += "是否循环:" + RecycFlag + "\n";
  3210. return result;
  3211. }
  3212. #endregion
  3213. #region 三要素验证
  3214. public IActionResult CheckThreeElements(string right)
  3215. {
  3216. ViewBag.RightInfo = RightInfo;
  3217. ViewBag.right = right;
  3218. return View();
  3219. }
  3220. [HttpPost]
  3221. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3222. {
  3223. var host = "https://bankcard3c.shumaidata.com";
  3224. var path = "/bankcard3c";
  3225. var method = "GET";
  3226. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3227. if (string.IsNullOrEmpty(bankcard))
  3228. {
  3229. return "结算银行卡号";
  3230. }
  3231. if (string.IsNullOrEmpty(idcard))
  3232. {
  3233. return "身份证号";
  3234. }
  3235. if (string.IsNullOrEmpty(name))
  3236. {
  3237. return "真实姓名";
  3238. }
  3239. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3240. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3241. function.WriteLog(querys, "验证三要素日志");
  3242. String bodys = "";
  3243. String url = host + path;
  3244. HttpWebRequest httpRequest = null;
  3245. HttpWebResponse httpResponse = null;
  3246. if (0 < querys.Length)
  3247. {
  3248. url = url + "?" + querys;
  3249. }
  3250. if (host.Contains("https://"))
  3251. {
  3252. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3253. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3254. }
  3255. else
  3256. {
  3257. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3258. }
  3259. httpRequest.Method = method;
  3260. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3261. if (0 < bodys.Length)
  3262. {
  3263. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3264. using (Stream stream = httpRequest.GetRequestStream())
  3265. {
  3266. stream.Write(data, 0, data.Length);
  3267. }
  3268. }
  3269. try
  3270. {
  3271. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3272. }
  3273. catch (WebException ex)
  3274. {
  3275. httpResponse = (HttpWebResponse)ex.Response;
  3276. }
  3277. Stream st = httpResponse.GetResponseStream();
  3278. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3279. string result = reader.ReadToEnd();
  3280. JsonData jsonObj = JsonMapper.ToObject(result);
  3281. result = jsonObj["data"]["desc"].ToString();
  3282. function.WriteLog(result, "验证三要素日志");
  3283. function.WriteLog("\n\n", "验证三要素日志");
  3284. return result;
  3285. }
  3286. #endregion
  3287. #region 四要素验证
  3288. public IActionResult CheckFourElements(string right)
  3289. {
  3290. ViewBag.RightInfo = RightInfo;
  3291. ViewBag.right = right;
  3292. return View();
  3293. }
  3294. [HttpPost]
  3295. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3296. {
  3297. var host = "https://bankcard4c.shumaidata.com";
  3298. var path = "/bankcard4c";
  3299. var method = "GET";
  3300. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3301. if (string.IsNullOrEmpty(bankcard))
  3302. {
  3303. return "请输入结算银行卡号";
  3304. }
  3305. if (string.IsNullOrEmpty(idcard))
  3306. {
  3307. return "请输入身份证号";
  3308. }
  3309. if (string.IsNullOrEmpty(mobile))
  3310. {
  3311. return "请输入银行预留手机号";
  3312. }
  3313. if (string.IsNullOrEmpty(name))
  3314. {
  3315. return "请输入真实姓名";
  3316. }
  3317. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3318. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3319. function.WriteLog(querys, "验证四要素日志");
  3320. String bodys = "";
  3321. String url = host + path;
  3322. HttpWebRequest httpRequest = null;
  3323. HttpWebResponse httpResponse = null;
  3324. if (0 < querys.Length)
  3325. {
  3326. url = url + "?" + querys;
  3327. }
  3328. if (host.Contains("https://"))
  3329. {
  3330. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3331. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3332. }
  3333. else
  3334. {
  3335. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3336. }
  3337. httpRequest.Method = method;
  3338. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3339. if (0 < bodys.Length)
  3340. {
  3341. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3342. using (Stream stream = httpRequest.GetRequestStream())
  3343. {
  3344. stream.Write(data, 0, data.Length);
  3345. }
  3346. }
  3347. try
  3348. {
  3349. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3350. }
  3351. catch (WebException ex)
  3352. {
  3353. httpResponse = (HttpWebResponse)ex.Response;
  3354. }
  3355. Stream st = httpResponse.GetResponseStream();
  3356. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3357. string result = reader.ReadToEnd();
  3358. JsonData jsonObj = JsonMapper.ToObject(result);
  3359. result = jsonObj["data"]["desc"].ToString();
  3360. function.WriteLog(result, "验证四要素日志");
  3361. function.WriteLog("\n\n", "验证四要素日志");
  3362. return result;
  3363. }
  3364. #endregion
  3365. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3366. {
  3367. return true;
  3368. }
  3369. #region 根据机具号同步商户激活状态
  3370. public IActionResult SyncMerchantStatus(string right)
  3371. {
  3372. ViewBag.RightInfo = RightInfo;
  3373. ViewBag.right = right;
  3374. return View();
  3375. }
  3376. [HttpPost]
  3377. public string SyncMerchantStatusDo(string PosSn)
  3378. {
  3379. if (string.IsNullOrEmpty(PosSn))
  3380. {
  3381. return "请输入机具号";
  3382. }
  3383. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3384. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3385. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
  3386. if (posInfo.Id == 0)
  3387. {
  3388. return "机具" + PosSn + "不存在";
  3389. }
  3390. if (posMerchant.Id == 0)
  3391. {
  3392. return "机具绑定商户不存在";
  3393. }
  3394. else
  3395. {
  3396. posMerchant.ActiveStatus = 1;
  3397. posMerchant.UpdateDate = DateTime.Now;
  3398. posMerchant.MerStandardDate = posInfo.ActivationTime;
  3399. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
  3400. db.SaveChanges();
  3401. }
  3402. return "success";
  3403. }
  3404. #endregion
  3405. #region 根据机具号补发开机奖励
  3406. public IActionResult PosRewardReissued(string right)
  3407. {
  3408. ViewBag.RightInfo = RightInfo;
  3409. ViewBag.right = right;
  3410. return View();
  3411. }
  3412. [HttpPost]
  3413. public string PosRewardReissuedDo(string PosSn)
  3414. {
  3415. if (string.IsNullOrEmpty(PosSn))
  3416. {
  3417. return "请输入机具SN";
  3418. }
  3419. string[] PosSnList = PosSn.Split('\n');
  3420. var PosId = "";
  3421. var error = "";
  3422. foreach (var item in PosSnList)
  3423. {
  3424. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3425. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3426. bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
  3427. if (checkExist)
  3428. {
  3429. error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
  3430. }
  3431. else
  3432. {
  3433. if (posInfo.Id > 0)
  3434. {
  3435. PosId += posInfo.Id + ",";
  3436. }
  3437. }
  3438. }
  3439. if (!string.IsNullOrEmpty(error))
  3440. {
  3441. return "Warning|" + error;
  3442. }
  3443. PosId = PosId.TrimEnd(',');
  3444. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
  3445. RedisDbconn.Instance.AddList("OpenRewardQueue", PosId);
  3446. return "success";
  3447. }
  3448. #endregion
  3449. #region 根据机具号设置费率
  3450. public IActionResult SetPosFee(string right)
  3451. {
  3452. ViewBag.RightInfo = RightInfo;
  3453. ViewBag.right = right;
  3454. return View();
  3455. }
  3456. [HttpPost]
  3457. public string SetPosFeeDo(string PosSn, string FeeType)
  3458. {
  3459. if (string.IsNullOrEmpty(PosSn))
  3460. {
  3461. return "请输入机具SN";
  3462. }
  3463. if (string.IsNullOrEmpty(FeeType))
  3464. {
  3465. return "请输入选择费率";
  3466. }
  3467. if (FeeType == "0")
  3468. {
  3469. FeeType = "0.6";
  3470. }
  3471. if (FeeType == "1")
  3472. {
  3473. FeeType = "0.63";
  3474. }
  3475. string[] PosSnList = PosSn.Split('\n');
  3476. var PosId = "";
  3477. var RecordId = "";
  3478. var error = "";
  3479. foreach (var item in PosSnList)
  3480. {
  3481. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3482. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3483. if (posInfo.Id > 0)
  3484. {
  3485. var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  3486. {
  3487. Sort = posInfo.BrandId,
  3488. CreateDate = DateTime.Now,
  3489. PosId = posInfo.Id,
  3490. PosSn = posInfo.PosSn,
  3491. PosUserId = posInfo.UserId,
  3492. MerchantId = posInfo.BindMerchantId,
  3493. UserId = posInfo.UserId,
  3494. ChangeFee = decimal.Parse(FeeType),
  3495. }).Entity;
  3496. db.SaveChanges();
  3497. PosId += posInfo.Id + ",";
  3498. RecordId += query.Id + ",";
  3499. }
  3500. else
  3501. {
  3502. error += "机具" + PosSn + "不存在";
  3503. }
  3504. }
  3505. if (!string.IsNullOrEmpty(error))
  3506. {
  3507. return "Warning|" + error;
  3508. }
  3509. PosId = PosId.TrimEnd(',');
  3510. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
  3511. string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  3512. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  3513. return "success";
  3514. }
  3515. #endregion
  3516. #region 根据机具号、商户号、商户姓名关联商户和机具信息
  3517. public IActionResult RelationPosAndMerchant(string right)
  3518. {
  3519. ViewBag.RightInfo = RightInfo;
  3520. ViewBag.right = right;
  3521. return View();
  3522. }
  3523. [HttpPost]
  3524. public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
  3525. {
  3526. if (string.IsNullOrEmpty(PosSn))
  3527. {
  3528. return "请输入机具SN";
  3529. }
  3530. if (string.IsNullOrEmpty(MerchantNo))
  3531. {
  3532. return "请输入商户编号";
  3533. }
  3534. if (string.IsNullOrEmpty(MerchantName))
  3535. {
  3536. return "请输入商户姓名";
  3537. }
  3538. var query = PosSn + "," + MerchantNo + "," + MerchantName;
  3539. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
  3540. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
  3541. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3542. if (posMerchant.Id == 0)
  3543. {
  3544. return "商户" + MerchantNo + "不存在";
  3545. }
  3546. else if (pos.Id == 0)
  3547. {
  3548. return "机具" + PosSn + "不存在";
  3549. }
  3550. else
  3551. {
  3552. pos.BindMerchantId = posMerchant.Id;
  3553. db.SaveChanges();
  3554. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
  3555. }
  3556. return "success";
  3557. }
  3558. #endregion
  3559. #region 设置商户信息
  3560. public IActionResult SetMerchantInfo(string right)
  3561. {
  3562. ViewBag.RightInfo = RightInfo;
  3563. ViewBag.right = right;
  3564. return View();
  3565. }
  3566. [HttpPost]
  3567. public string SetMerchantInfoDo(string PosSn, string MerchantNo, string MerchantName, string MerIdcardNo, string MerchantMobile)
  3568. {
  3569. if (string.IsNullOrEmpty(PosSn))
  3570. {
  3571. return "请输入机具SN";
  3572. }
  3573. if (string.IsNullOrEmpty(MerchantNo))
  3574. {
  3575. return "请输入商户编号";
  3576. }
  3577. if (string.IsNullOrEmpty(MerchantName))
  3578. {
  3579. return "请输入商户姓名";
  3580. }
  3581. if (string.IsNullOrEmpty(MerIdcardNo))
  3582. {
  3583. return "请输入商户身份证号";
  3584. }
  3585. if (string.IsNullOrEmpty(MerchantMobile))
  3586. {
  3587. return "请输入商户手机号";
  3588. }
  3589. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo && m.KqSnNo == PosSn && m.MerchantName.StartsWith(MerchantName.Substring(0, 1))) ?? new PosMerchantInfo();
  3590. var query = "";
  3591. query += "修改前:" + posMerchant.KqSnNo + "," + posMerchant.MerchantNo + "," + posMerchant.MerchantName + "," + posMerchant.MerIdcardNo + "," + posMerchant.MerchantMobile;
  3592. query += "修改后:" + PosSn + "," + MerchantNo + "," + MerchantName + "," + MerIdcardNo + "," + MerchantMobile;
  3593. if (posMerchant.Id == 0)
  3594. {
  3595. return "商户" + MerchantNo + "不存在或不在" + MerchantName + "名下";
  3596. }
  3597. else
  3598. {
  3599. posMerchant.MerIdcardNo = MerIdcardNo;
  3600. posMerchant.MerchantName = MerchantName;
  3601. posMerchant.MerchantMobile = MerchantMobile;
  3602. db.SaveChanges();
  3603. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "设置商户信息");
  3604. }
  3605. return "success";
  3606. }
  3607. #endregion
  3608. #region 认证创客
  3609. public IActionResult AuthMaker(string right)
  3610. {
  3611. ViewBag.RightInfo = RightInfo;
  3612. ViewBag.right = right;
  3613. return View();
  3614. }
  3615. [HttpPost]
  3616. public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
  3617. {
  3618. if (string.IsNullOrEmpty(MakerCode))
  3619. {
  3620. return "请输入创客编号";
  3621. }
  3622. if (string.IsNullOrEmpty(RealName))
  3623. {
  3624. return "请输入真实姓名";
  3625. }
  3626. if (string.IsNullOrEmpty(CertId))
  3627. {
  3628. return "请输入身份证号";
  3629. }
  3630. if (string.IsNullOrEmpty(BackCard))
  3631. {
  3632. return "请输入银行卡号";
  3633. }
  3634. if (string.IsNullOrEmpty(BackName))
  3635. {
  3636. return "请输入银行名称";
  3637. }
  3638. var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
  3639. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3640. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3641. if (userInfo.AuthFlag == 1)
  3642. {
  3643. return "已认证";
  3644. }
  3645. else
  3646. {
  3647. userInfo.UpdateDate = DateTime.Now;
  3648. userInfo.RealName = RealName;
  3649. userInfo.AuthFlag = 1;
  3650. if (userInfo.AuthDate == null)
  3651. {
  3652. userInfo.AuthDate = DateTime.Now;
  3653. }
  3654. userInfo.CertId = CertId;
  3655. userInfo.SettleBankCardNo = BackCard;
  3656. userInfo.SettleBankCardName = BackName;
  3657. db.SaveChanges();
  3658. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
  3659. }
  3660. return "success";
  3661. }
  3662. #endregion
  3663. #region 划拨创客机具
  3664. public IActionResult TransferPos(string right)
  3665. {
  3666. ViewBag.RightInfo = RightInfo;
  3667. ViewBag.right = right;
  3668. return View();
  3669. }
  3670. [HttpPost]
  3671. public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  3672. {
  3673. if (string.IsNullOrEmpty(PosSn))
  3674. {
  3675. return "请输入机具SN";
  3676. }
  3677. if (string.IsNullOrEmpty(FromMakerCode))
  3678. {
  3679. return "请输入机具来源创客编号";
  3680. }
  3681. if (string.IsNullOrEmpty(ToMakerCode))
  3682. {
  3683. return "请输入划拨对象创客编号";
  3684. }
  3685. var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
  3686. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3687. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3688. if (posInfo.Id == 0)
  3689. {
  3690. return "机具" + PosSn + "不存在";
  3691. }
  3692. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3693. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3694. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3695. if (fUserId.Id == 0)
  3696. {
  3697. return "来源创客" + FromMakerCode + "不存在";
  3698. }
  3699. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3700. if (tUserId.Id == 0)
  3701. {
  3702. return "划拨创客" + ToMakerCode + "不存在";
  3703. }
  3704. if (posInfo.BindingState == 0)
  3705. {
  3706. if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  3707. {
  3708. posInfo.BuyUserId = tUserId.Id;
  3709. posInfo.UserId = tUserId.Id;
  3710. }
  3711. else
  3712. {
  3713. posInfo.BuyUserId = tUserId.Id;
  3714. }
  3715. var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3716. var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3717. fUserPos.TotalMachineCount -= 1;
  3718. fUserPos.UnBindCount -= 1;
  3719. tUserPos.TotalMachineCount += 1;
  3720. tUserPos.UnBindCount += 1;
  3721. db.SaveChanges();
  3722. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  3723. }
  3724. else
  3725. {
  3726. return "机具" + PosSn + "已使用";
  3727. }
  3728. return "success";
  3729. }
  3730. #endregion
  3731. #region 还原提现订单状态
  3732. public IActionResult RestoreStatus(string right)
  3733. {
  3734. ViewBag.RightInfo = RightInfo;
  3735. ViewBag.right = right;
  3736. return View();
  3737. }
  3738. [HttpPost]
  3739. public string RestoreStatusDo(string OrderNo)
  3740. {
  3741. if (string.IsNullOrEmpty(OrderNo))
  3742. {
  3743. return "请输入提现订单编号";
  3744. }
  3745. string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
  3746. var error = "";
  3747. foreach (var item in OrderNoList)
  3748. {
  3749. var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
  3750. if (cash.Id > 0)
  3751. {
  3752. cash.QueryCount = 0;
  3753. cash.Status = 0;
  3754. db.SaveChanges();
  3755. }
  3756. else
  3757. {
  3758. error += "订单" + item + "不存在" + '\n';
  3759. }
  3760. }
  3761. if (!string.IsNullOrEmpty(error))
  3762. {
  3763. return "Warning|" + error;
  3764. }
  3765. return "success";
  3766. }
  3767. #endregion
  3768. #region 查询创客循环资格
  3769. public IActionResult SeeUserLoop(string right)
  3770. {
  3771. ViewBag.RightInfo = RightInfo;
  3772. ViewBag.right = right;
  3773. return View();
  3774. }
  3775. [HttpPost]
  3776. public string SeeUserLoopDo(string MakerCode)
  3777. {
  3778. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3779. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3780. var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
  3781. var brandList = db.KqProducts.ToList();
  3782. var info = "";
  3783. foreach (var item in brandList)
  3784. {
  3785. var brand = item.Name;
  3786. //已过期
  3787. var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  3788. //可申请
  3789. var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  3790. //已使用
  3791. // var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id && m.PosSnType == 0);
  3792. // info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
  3793. info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + "\n";
  3794. }
  3795. return info;
  3796. }
  3797. #endregion
  3798. #region 提交到代付排除的创客名单
  3799. public IActionResult CashWithoutUser(string right)
  3800. {
  3801. ViewBag.RightInfo = RightInfo;
  3802. ViewBag.right = right;
  3803. return View();
  3804. }
  3805. public string CashWithoutUserDo(string Content)
  3806. {
  3807. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser");
  3808. if (set == null)
  3809. {
  3810. set = db.CustomTagSet.Add(new CustomTagSet()
  3811. {
  3812. Tags = "CashWithoutUser",
  3813. Title = "提交到代付排除的创客名单"
  3814. }).Entity;
  3815. db.SaveChanges();
  3816. }
  3817. set.Contents = Content;
  3818. db.SaveChanges();
  3819. db.Dispose();
  3820. return "success";
  3821. }
  3822. #endregion
  3823. #region 坏机回仓
  3824. public IActionResult BadPosToStore(string right)
  3825. {
  3826. ViewBag.RightInfo = RightInfo;
  3827. ViewBag.right = right;
  3828. return View();
  3829. }
  3830. [HttpPost]
  3831. public string BadPosToStoreDo(string OldSn)
  3832. {
  3833. string[] OldSnList;
  3834. OldSnList = OldSn.Replace("\r", "").Split('\n');
  3835. string error = "";
  3836. for (int i = 0; i < OldSnList.Length; i++)
  3837. {
  3838. string OldSnNum = OldSnList[i];
  3839. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  3840. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId) ?? new PosMachinesTwo();
  3841. var store = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId) ?? new StoreHouse();
  3842. if (store.UserId != 142237)//判断是否是属于坏机仓的机具
  3843. {
  3844. error += "以下操作失败" + OldSnNum + ',' + "该机具不在坏机仓或不存在" + '\n';
  3845. }
  3846. oldpos.Status = 1;
  3847. oldpos.QueryCount = 0;
  3848. oldpos.UpdateDate = null;
  3849. oldpos.ActivityList = null;
  3850. oldpos.SeoKeyword = null;
  3851. oldpos.SeoDescription = null;
  3852. oldpos.OrderId = 0;
  3853. oldpos.RecycEndDate = null;
  3854. oldpos.RecycBackCount = 0;
  3855. oldpos.PrizeParams = null;
  3856. oldpos.ScanQrTrade = 0;
  3857. oldpos.BindMerchantId = 0;
  3858. oldpos.CreditTrade = 0;
  3859. oldpos.DebitCardTrade = 0;
  3860. oldpos.IsVip = 0;
  3861. oldpos.UserNav = null;
  3862. oldpos.TransferTime = null;
  3863. oldpos.IsPurchase = 0;
  3864. oldpos.Detail = null;
  3865. oldpos.BindingTime = null;
  3866. oldpos.BindingState = 0;
  3867. oldpos.ActivationTime = null;
  3868. oldpos.ActivationState = 0;
  3869. oldpos.LeaderUserId = 0;
  3870. oldpos.PreUserId = 0;
  3871. oldpos.IsFirst = 0;
  3872. oldpos.DownFeeMan = null;
  3873. oldpos.DownFeeFlag = 0;
  3874. oldpos.DownFeeDate = null;
  3875. oldpos.UpFeeMan = null;
  3876. oldpos.UpFeeFlag = 0;
  3877. oldpos.UpFeeDate = null;
  3878. oldpos.OpReserve1 = 0;
  3879. oldpos.OpReserve2 = 0;
  3880. oldpos.OpReserve3 = 0;
  3881. oldpos.OpId = 0;
  3882. oldpos.RecycStartDate = null;
  3883. oldpos.SourcePosSn = null;
  3884. oldpos.BuyUserId = 0;
  3885. oldpos.UserId = 0;
  3886. }
  3887. if (!string.IsNullOrEmpty(error))
  3888. {
  3889. return "Warning|" + error;
  3890. }
  3891. db.SaveChanges();
  3892. return "success";
  3893. }
  3894. #endregion
  3895. #region 划拨创客机具券
  3896. public IActionResult TransferPosCoupon(string right)
  3897. {
  3898. ViewBag.RightInfo = RightInfo;
  3899. ViewBag.right = right;
  3900. return View();
  3901. }
  3902. public string TransferPosCouponDo(string PosCouponCodes, string FromMakerCode, string ToMakerCode, string LeaderMakerCode = "")
  3903. {
  3904. if (string.IsNullOrEmpty(PosCouponCodes))
  3905. {
  3906. return "请输入机具券码";
  3907. }
  3908. if (string.IsNullOrEmpty(FromMakerCode))
  3909. {
  3910. return "请输入机具来源创客编号";
  3911. }
  3912. if (string.IsNullOrEmpty(ToMakerCode))
  3913. {
  3914. return "请输入划拨对象创客编号";
  3915. }
  3916. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3917. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3918. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3919. if (fUserId.Id == 0)
  3920. {
  3921. return "来源创客" + FromMakerCode + "不存在";
  3922. }
  3923. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3924. if (tUserId.Id == 0)
  3925. {
  3926. return "划拨创客" + ToMakerCode + "不存在";
  3927. }
  3928. int LeaderUserId = 0;
  3929. if (!string.IsNullOrEmpty(LeaderMakerCode))
  3930. {
  3931. UserForMakerCode leaderuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LeaderMakerCode) ?? new UserForMakerCode();
  3932. Users LeaderUserItem = db.Users.FirstOrDefault(m => m.Id == leaderuser.UserId) ?? new Users();
  3933. if (LeaderUserItem.Id == 0)
  3934. {
  3935. return "大盟主创客编号" + LeaderMakerCode + "不存在";
  3936. }
  3937. LeaderUserId = leaderuser.UserId;
  3938. }
  3939. var query = PosCouponCodes + "\n" + FromMakerCode + "," + ToMakerCode;
  3940. string[] PosCouponList = PosCouponCodes.Replace("\r", "").Replace("\n", ",").Split(',');
  3941. foreach (string PosCouponCode in PosCouponList)
  3942. {
  3943. PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == PosCouponCode) ?? new PosCoupons();
  3944. if (item.UserId != fUserId.Id)
  3945. {
  3946. return "机具券" + PosCouponCode + "不在创客" + FromMakerCode + "名下";
  3947. }
  3948. if (item.Id == 0)
  3949. {
  3950. return "机具券" + PosCouponCode + "不存在";
  3951. }
  3952. if (item.IsUse == 1)
  3953. {
  3954. return "机具券" + PosCouponCode + "已使用";
  3955. }
  3956. item.UserId = tUserId.Id;
  3957. if (LeaderUserId > 0 && item.LeaderUserId == 0)
  3958. {
  3959. item.LeaderUserId = LeaderUserId;
  3960. }
  3961. }
  3962. db.SaveChanges();
  3963. db.Dispose();
  3964. return "success";
  3965. }
  3966. #endregion
  3967. #region 机具回仓退款
  3968. public IActionResult RefundPosFee(string right)
  3969. {
  3970. ViewBag.RightInfo = RightInfo;
  3971. ViewBag.right = right;
  3972. return View();
  3973. }
  3974. [HttpPost]
  3975. public string RefundPosFeeDo(string PosSn, string BackStoreNo, int IsBack = 0)
  3976. {
  3977. if (string.IsNullOrEmpty(PosSn))
  3978. {
  3979. return "请输入机具SN";
  3980. }
  3981. if (IsBack == 1)
  3982. {
  3983. if (string.IsNullOrEmpty(BackStoreNo))
  3984. {
  3985. return "请输入仓库编号";
  3986. }
  3987. }
  3988. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3989. WebCMSEntities db = new WebCMSEntities();
  3990. DateTime time = DateTime.Parse(DateTime.Now.ToString(("yyyy-MM-dd") + " 00:00:00"));
  3991. var endTime = time.AddDays(20 - time.Day).AddDays(-60);
  3992. StoreForCode storeForBack = new StoreForCode();
  3993. StoreHouse BackStore = new StoreHouse();
  3994. foreach (var item in PosSnList)
  3995. {
  3996. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3997. if (machineForSnNo.SnId == 0)
  3998. {
  3999. return "未找到机具" + item + "关联数据";
  4000. }
  4001. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.Status > -1 && m.RecycEndDate < endTime && m.BindingState == 0) ?? new PosMachinesTwo();
  4002. if (pos.Id == 0)
  4003. {
  4004. return "机具" + item + "不存在或者不满足条件";
  4005. }
  4006. if (IsBack == 1)
  4007. {
  4008. storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  4009. if (storeForBack.StoreId == 0)
  4010. {
  4011. return "未找到" + BackStoreNo + "关联数据";
  4012. }
  4013. BackStore = db.StoreHouse.FirstOrDefault(m => m.Status > -1 && m.Id == storeForBack.StoreId && m.BrandId == pos.BrandId.ToString()) ?? new StoreHouse();
  4014. if (BackStore.Id == 0)
  4015. {
  4016. return "仓库" + BackStoreNo + "不存在或与机具品牌不符";
  4017. }
  4018. }
  4019. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BackStore.UserId) ?? new UserAccount();
  4020. var refundUserAccount = db.UserAccount.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new UserAccount();
  4021. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  4022. var amount = 0;
  4023. if (brandInfo.Name.Contains("电签"))
  4024. {
  4025. amount = 200;
  4026. }
  4027. if (brandInfo.Name.Contains("大POS"))
  4028. {
  4029. amount = 300;
  4030. }
  4031. if (IsBack == 1)
  4032. {
  4033. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  4034. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  4035. {
  4036. CreateDate = DateTime.Now,
  4037. CreateMan = SysUserName,
  4038. StoreId = pos.StoreId, //出货仓库
  4039. BrandId = pos.BrandId, //产品类型
  4040. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  4041. TransType = 5, //交易类型
  4042. SnNo = item, //SN编号
  4043. StockOpDirect = 0, //库存操作方向
  4044. SnStatus = 1, //SN状态
  4045. DeviceVendor = pos.DeviceName, //设备厂商
  4046. DeviceModel = pos.DeviceKind, //设备型号
  4047. DeviceType = pos.DeviceType, //设备类型
  4048. FromUserId = pos.BuyUserId, //来源创客
  4049. ToRemark = "过期机具回仓退款", //入库备注
  4050. ToStoreId = BackStore.Id, //退货收货仓库
  4051. SourceStoreId = pos.SourceStoreId, //源仓库编号
  4052. BrandType = pos.DeviceType, //品牌类型
  4053. }).Entity;
  4054. string ChangeNo = "HCTK";
  4055. int StoreStockChangeId = stockchange.Id;
  4056. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  4057. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  4058. {
  4059. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  4060. }
  4061. ChangeNo += StoreStockChangeIdString;
  4062. stockchange.ChangeNo = ChangeNo; //交易流水编号
  4063. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4064. {
  4065. CreateDate = DateTime.Now,
  4066. BrandId = pos.BrandId, //产品类型
  4067. ChangeRecordNo = ChangeNo, //变更记录单号
  4068. TransType = 5, //交易类型
  4069. SnNo = item, //SN编号
  4070. SnType = pos.PosSnType, //SN机具类型
  4071. StockOpDirect = 0, //库存操作方向
  4072. DeviceVendor = pos.DeviceName, //设备厂商
  4073. DeviceModel = pos.DeviceKind, //设备型号
  4074. DeviceType = pos.DeviceType, //设备类型
  4075. FromUserId = pos.BuyUserId, //来源创客
  4076. ToRemark = "过期机具回仓退款", //入库备注
  4077. SourceStoreId = pos.SourceStoreId, //源仓库
  4078. StoreId = pos.StoreId, //出货仓库
  4079. });
  4080. db.MachineReturn.Add(new MachineReturn()
  4081. {
  4082. CreateDate = DateTime.Now,
  4083. Operator = SysUserName + "_" + SysRealName,//操作人
  4084. BrandId = pos.BrandId, //产品类型
  4085. DeviceSnNos = pos.PosSn,
  4086. ToStoreId = BackStore.Id,
  4087. ApplyNo = ChangeNo, //变更记录单号
  4088. UserId = pos.BuyUserId, //来源创客
  4089. Remark = "过期机具回仓退款", //入库备注
  4090. });
  4091. if (pos.ScanQrTrade > 0)
  4092. {
  4093. decimal ChangeAmount = 0;
  4094. decimal BeforeBalanceAmount = 0;
  4095. decimal AfterBalanceAmount = 0;
  4096. if (pos.ScanQrTrade == 999)
  4097. {
  4098. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4099. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4100. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4101. ChangeAmount = amount;
  4102. }
  4103. else
  4104. {
  4105. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4106. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4107. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4108. ChangeAmount = pos.ScanQrTrade;
  4109. }
  4110. db.UserAccountRecord.Add(new UserAccountRecord()
  4111. {
  4112. CreateDate = DateTime.Now,
  4113. UpdateDate = DateTime.Now,
  4114. UserId = pos.BuyUserId, //创客
  4115. ChangeType = 126, //变动类型(机具货款退还)
  4116. ProductType = 0, //产品类型
  4117. ChangeAmount = ChangeAmount, //变更金额
  4118. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4119. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4120. });
  4121. }
  4122. var bInfo = BackStore.UserId + "_" + pos.BrandId;
  4123. var userMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == bInfo) ?? new UserMachineData();
  4124. userMachineData.TotalMachineCount += 1;
  4125. userMachineData.UnBindCount += 1;
  4126. BackStore.LaveNum += 1;
  4127. BackStore.TotalNum += 1;
  4128. var fInfo = pos.BuyUserId + "_" + pos.BrandId;
  4129. var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
  4130. userMachineDatas.TotalMachineCount -= 1;
  4131. userMachineDatas.UnBindCount -= 1;
  4132. pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
  4133. pos.Status = 1;
  4134. pos.QueryCount = 0;
  4135. pos.UpdateDate = null;
  4136. pos.ActivityList = null;
  4137. pos.SeoKeyword = null;
  4138. pos.SeoDescription = null;
  4139. pos.OrderId = 0;
  4140. pos.RecycEndDate = null;
  4141. pos.RecycBackCount = 0;
  4142. pos.PrizeParams = null;
  4143. pos.ScanQrTrade = 0;
  4144. pos.BindMerchantId = 0;
  4145. pos.CreditTrade = 0;
  4146. pos.DebitCardTrade = 0;
  4147. pos.IsVip = 0;
  4148. pos.UserNav = null;
  4149. pos.TransferTime = null;
  4150. pos.IsPurchase = 0;
  4151. pos.Detail = null;
  4152. pos.BindingTime = null;
  4153. pos.BindingState = 0;
  4154. pos.ActivationTime = null;
  4155. pos.ActivationState = 0;
  4156. pos.LeaderUserId = 0;
  4157. pos.PreUserId = 0;
  4158. pos.IsFirst = 0;
  4159. pos.DownFeeMan = null;
  4160. pos.DownFeeFlag = 0;
  4161. pos.DownFeeDate = null;
  4162. pos.UpFeeMan = null;
  4163. pos.UpFeeFlag = 0;
  4164. pos.UpFeeDate = null;
  4165. pos.OpReserve1 = 0;
  4166. pos.OpReserve2 = 0;
  4167. pos.OpReserve3 = 0;
  4168. pos.OpId = 0;
  4169. pos.RecycStartDate = null;
  4170. pos.SourcePosSn = null;
  4171. pos.BuyUserId = 0;
  4172. pos.UserId = 0;
  4173. }
  4174. else
  4175. {
  4176. if (pos.ScanQrTrade > 0)
  4177. {
  4178. decimal ChangeAmount = 0;
  4179. decimal BeforeBalanceAmount = 0;
  4180. decimal AfterBalanceAmount = 0;
  4181. if (pos.ScanQrTrade == 999)
  4182. {
  4183. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4184. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4185. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4186. ChangeAmount = amount;
  4187. }
  4188. else
  4189. {
  4190. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4191. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4192. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4193. ChangeAmount = pos.ScanQrTrade;
  4194. }
  4195. pos.ScanQrTrade = 0;
  4196. db.UserAccountRecord.Add(new UserAccountRecord()
  4197. {
  4198. CreateDate = DateTime.Now,
  4199. UpdateDate = DateTime.Now,
  4200. UserId = pos.BuyUserId, //创客
  4201. ChangeType = 126, //变动类型(机具货款退还)
  4202. ProductType = 0, //产品类型
  4203. ChangeAmount = ChangeAmount, //变更金额
  4204. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4205. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4206. });
  4207. }
  4208. }
  4209. }
  4210. db.SaveChanges();
  4211. return "success";
  4212. }
  4213. #endregion
  4214. #region 添加商户信息
  4215. public IActionResult AddMerchantnfo(string right)
  4216. {
  4217. ViewBag.RightInfo = RightInfo;
  4218. ViewBag.right = right;
  4219. return View();
  4220. }
  4221. [HttpPost]
  4222. public string AddMerchantnfoDo(string PosSn, string MerSn)
  4223. {
  4224. if (string.IsNullOrEmpty(PosSn))
  4225. {
  4226. return "请输入机具号";
  4227. }
  4228. if (string.IsNullOrEmpty(MerSn))
  4229. {
  4230. return "请输入商户号";
  4231. }
  4232. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4233. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4234. var merchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4235. if (machineForSnNo.SnId == 0)
  4236. {
  4237. return "未找到机具" + PosSn + "关联数据";
  4238. }
  4239. if (pos.Id == 0)
  4240. {
  4241. return "未找到机具" + PosSn;
  4242. }
  4243. if (merchantInfo.Id > 0)
  4244. {
  4245. return "机具" + PosSn + "以经存在绑定商户";
  4246. }
  4247. var spInfo = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerSn && m.MerSnNo == PosSn) ?? new SpModels.BindRecord();
  4248. if (spInfo.Id > 0)
  4249. {
  4250. var MerUserType = 0;
  4251. var ActiveStatus = 0;
  4252. if (pos.BuyUserId != pos.UserId)
  4253. {
  4254. MerUserType = 1;
  4255. }
  4256. if (string.IsNullOrEmpty(pos.ActivationTime.ToString()))
  4257. {
  4258. ActiveStatus = 1;
  4259. }
  4260. PosMerchantInfo posMerchantInfo = db.PosMerchantInfo.Add(new PosMerchantInfo()
  4261. {
  4262. CreateDate = pos.BindingTime,
  4263. TopUserId = 1,
  4264. BrandId = pos.BrandId,
  4265. SnStoreId = pos.StoreId,
  4266. MerStandardDate = pos.ActivationTime,
  4267. SnType = pos.PosSnType,
  4268. MerUserType = MerUserType,
  4269. UserId = pos.UserId,
  4270. ActiveStatus = ActiveStatus,
  4271. MerStatus = 1,
  4272. KqSnNo = PosSn,
  4273. KqMerNo = MerSn,
  4274. MerIdcardNo = spInfo.SeoKeyword,
  4275. MerchantMobile = spInfo.MerNewSnNo,
  4276. MerchantName = spInfo.MerName,
  4277. MerchantNo = spInfo.MerNo,
  4278. }).Entity;
  4279. db.SaveChanges();
  4280. string text = string.Format("设置商户信息,机具Sn: " + PosSn + ",商户编号: " + MerSn + ",操作人:" + SysUserName + "_" + SysRealName + ",时间:" + DateTime.Now + "");
  4281. function.WriteLog(text, "设置商户信息");
  4282. }
  4283. return "success";
  4284. }
  4285. #endregion
  4286. }
  4287. }