SysToolsController.cs 249 KB

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