SysToolsController.cs 215 KB

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