SysToolsController.cs 255 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335
  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.Replace("\r", "").Split('\n');
  1277. string[] NewSnList = NewSn.Replace("\r", "").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.Replace("\r", "").Split('\n');
  1516. NewSnList = NewSn.Replace("\r", "").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.Replace("\r", "").Split('\n');
  1743. NewSnList = NewSn.Replace("\r", "").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.Replace("\r", "").Split('\n');
  1971. NewSnList = NewSn.Replace("\r", "").Split('\n');
  1972. if (OldSnList.Length != NewSnList.Length)
  1973. {
  1974. return "原机具SN数量和新机具SN数量不一致";
  1975. }
  1976. var ChangeRecordNo = "KPHJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //变更记录单号
  1977. for (int i = 0; i < OldSnList.Length; i++)
  1978. {
  1979. string OldSnNum = OldSnList[i];
  1980. string NewSnNum = NewSnList[i];
  1981. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1982. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  1983. if (userInfo.Id == 0)
  1984. {
  1985. return MakerCode + "不存在或关联信息缺失";
  1986. }
  1987. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1988. if (storeForCodeFrom.StoreId == 0)
  1989. {
  1990. return "您输入的新机发货仓库编号不存在";
  1991. }
  1992. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1993. if (storeForCodeBack.StoreId == 0)
  1994. {
  1995. return "您输入的旧机退回仓库编号不存在";
  1996. }
  1997. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1998. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1999. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.ActivationState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  2000. if (oldpos.Id == 0)
  2001. {
  2002. return "您输入的旧机SN不存在或者不在" + MakerCode + "名下";
  2003. }
  2004. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.ActivationState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
  2005. if (newpos.Id == 0)
  2006. {
  2007. return "您输入的新机SN不存在或不满足条件";
  2008. }
  2009. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  2010. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  2011. {
  2012. return "您输入的新机发货仓库不符新机机具对应品牌";
  2013. }
  2014. if (newpos.StoreId != storeFrom.Id)
  2015. {
  2016. return "您输入的新机SN不在新机发货仓库";
  2017. }
  2018. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  2019. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  2020. {
  2021. return "您输入的旧机退回仓库不符旧机机具对应品牌";
  2022. }
  2023. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  2024. var brandNew = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  2025. if (brandInfo.Kind != brandNew.Kind)
  2026. {
  2027. return "原机具和新机具不是同种机型(电签或大POS)";
  2028. }
  2029. if (brandInfo.Name.Contains("大POS"))
  2030. {
  2031. amount = 300;
  2032. }
  2033. if (brandInfo.Name.Contains("电签"))
  2034. {
  2035. amount = 200;
  2036. }
  2037. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  2038. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  2039. storeFromUserAcount.ValidAmount += amount;
  2040. storeBackUserAcount.ValidAmount -= amount;
  2041. if (oldpos.OpId > 0)
  2042. {
  2043. if (newpos.OpId > 0)
  2044. {
  2045. var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
  2046. decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
  2047. opUserAccount.ValidAmount += oldpos.OpReserve3;
  2048. opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
  2049. opUserAccount.TotalAmt += oldpos.OpReserve1;
  2050. var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
  2051. {
  2052. CreateDate = DateTime.Now,
  2053. UserId = oldpos.OpId,
  2054. SeoDescription = "创客跨品牌换机",
  2055. OperateType = 1,
  2056. UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2057. BeforeAmount = TotalAmount,
  2058. AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
  2059. }).Entity;
  2060. }
  2061. if (newpos.OpId == 0)
  2062. {
  2063. newpos.OpReserve1 = oldpos.OpReserve1;
  2064. newpos.OpReserve2 = oldpos.OpReserve3;
  2065. newpos.OpReserve3 = oldpos.OpReserve1;
  2066. newpos.OpId = oldpos.OpId;
  2067. }
  2068. }
  2069. newpos.BuyUserId = oldpos.BuyUserId;
  2070. newpos.UserId = oldpos.UserId;
  2071. newpos.RecycEndDate = oldpos.RecycEndDate;
  2072. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  2073. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  2074. newpos.CreditTrade = oldpos.CreditTrade;
  2075. newpos.PosSnType = oldpos.PosSnType;
  2076. newpos.TransferTime = oldpos.TransferTime;
  2077. newpos.IsPurchase = oldpos.IsPurchase;
  2078. newpos.BindingState = oldpos.BindingState;
  2079. newpos.ActivationState = oldpos.ActivationState;
  2080. newpos.BindingTime = oldpos.BindingTime;
  2081. newpos.ActivationTime = oldpos.ActivationTime;
  2082. newpos.IsFirst = oldpos.IsFirst;
  2083. newpos.SeoKeyword = oldpos.SeoKeyword;
  2084. newpos.PrizeParams = oldpos.PrizeParams;
  2085. newpos.LeaderUserId = oldpos.LeaderUserId;
  2086. newpos.BindMerchantId = oldpos.BindMerchantId;
  2087. newpos.StoreId = oldpos.StoreId;
  2088. newpos.PreUserId = oldpos.PreUserId;
  2089. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  2090. {
  2091. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  2092. }
  2093. oldpos.StoreId = storeBack.Id;
  2094. oldpos.QueryCount = 0;
  2095. oldpos.UpdateDate = null;
  2096. oldpos.ActivityList = null;
  2097. oldpos.SeoKeyword = null;
  2098. oldpos.SeoDescription = null;
  2099. oldpos.OrderId = 0;
  2100. oldpos.RecycEndDate = null;
  2101. oldpos.RecycBackCount = 0;
  2102. oldpos.PrizeParams = null;
  2103. oldpos.ScanQrTrade = 0;
  2104. oldpos.BindMerchantId = 0;
  2105. oldpos.CreditTrade = 0;
  2106. oldpos.DebitCardTrade = 0;
  2107. oldpos.IsVip = 0;
  2108. oldpos.UserNav = null;
  2109. oldpos.TransferTime = null;
  2110. oldpos.IsPurchase = 0;
  2111. oldpos.Detail = null;
  2112. oldpos.BindingTime = null;
  2113. oldpos.BindingState = 0;
  2114. oldpos.ActivationTime = null;
  2115. oldpos.ActivationState = 0;
  2116. oldpos.LeaderUserId = 0;
  2117. oldpos.PreUserId = 0;
  2118. oldpos.IsFirst = 0;
  2119. oldpos.DownFeeMan = null;
  2120. oldpos.DownFeeFlag = 0;
  2121. oldpos.DownFeeDate = null;
  2122. oldpos.UpFeeMan = null;
  2123. oldpos.UpFeeFlag = 0;
  2124. oldpos.UpFeeDate = null;
  2125. oldpos.OpReserve1 = 0;
  2126. oldpos.OpReserve2 = 0;
  2127. oldpos.OpReserve3 = 0;
  2128. oldpos.OpId = 0;
  2129. oldpos.RecycStartDate = null;
  2130. oldpos.SourcePosSn = null;
  2131. oldpos.BuyUserId = 0;
  2132. oldpos.UserId = 0;
  2133. //发出方
  2134. db.StoreChangeHistory.Add(new StoreChangeHistory()
  2135. {
  2136. CreateDate = DateTime.Now,
  2137. UserId = userInfo.Id, //创客
  2138. BrandId = oldpos.BrandId,//产品类型
  2139. // ChangeRecordNo = "KPHJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  2140. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  2141. TransType = 6, //交易类型(0 采购 1 调拨 2 出货 3 退货 4 驳回 5 回仓退款 6 换机出库 7 换机入库)
  2142. SnNo = oldpos.PosSn, //SN编号
  2143. SnType = oldpos.PosSnType, //SN机具类型
  2144. StockOpDirect = 1, //库存操作方向(0 入库 1 出库)
  2145. DeviceVendor = oldpos.DeviceName, //设备厂商
  2146. DeviceModel = oldpos.DeviceKind, //设备型号
  2147. DeviceType = oldpos.DeviceType, //设备类型
  2148. // FromUserId = storeFrom.UserId, //出货创客
  2149. StoreId = storeFrom.Id,//出货仓库
  2150. FromDate = DateTime.Now, //出库时间
  2151. FromRemark = "跨品牌换机,出库", //出库备注
  2152. SourceStoreId = oldpos.SourceStoreId, //源仓库
  2153. // ToUserId = storeBack.UserId,//收货创客
  2154. ToStoreId = storeBack.Id,//收货仓库
  2155. });
  2156. //接收方
  2157. db.StoreChangeHistory.Add(new StoreChangeHistory()
  2158. {
  2159. CreateDate = DateTime.Now,
  2160. UserId = userInfo.Id, //创客
  2161. BrandId = oldpos.BrandId,//产品类型
  2162. // ChangeRecordNo = "KPHJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  2163. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  2164. TransType = 7, //交易类型(0 采购 1 调拨 2 出货 3 退货 4 驳回 5 回仓退款 6 换机出库 7 换机入库)
  2165. SnNo = oldpos.PosSn, //SN编号
  2166. SnType = oldpos.PosSnType, //SN机具类型
  2167. StockOpDirect = 0, //库存操作方向(0 入库 1 出库)
  2168. DeviceVendor = oldpos.DeviceName, //设备厂商
  2169. DeviceModel = oldpos.DeviceKind, //设备型号
  2170. DeviceType = oldpos.DeviceType, //设备类型
  2171. // FromUserId = storeFrom.UserId, //出货创客
  2172. StoreId = storeFrom.Id,//出货仓库
  2173. FromDate = DateTime.Now, //出库时间
  2174. FromRemark = "跨品牌换机,入库", //出库备注
  2175. SourceStoreId = oldpos.SourceStoreId, //源仓库
  2176. // ToUserId = storeBack.UserId,//收货创客
  2177. ToStoreId = storeBack.Id,//收货仓库
  2178. });
  2179. //发出方
  2180. db.StoreChangeHistory.Add(new StoreChangeHistory()
  2181. {
  2182. CreateDate = DateTime.Now,
  2183. UserId = userInfo.Id, //创客
  2184. BrandId = newpos.BrandId,//产品类型
  2185. // ChangeRecordNo = "KPHJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  2186. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  2187. TransType = 6, //交易类型(0 采购 1 调拨 2 出货 3 退货 4 驳回 5 回仓退款 6 换机出库 7 换机入库)
  2188. SnNo = newpos.PosSn, //SN编号
  2189. SnType = newpos.PosSnType, //SN机具类型
  2190. StockOpDirect = 1, //库存操作方向(0 入库 1 出库)
  2191. DeviceVendor = newpos.DeviceName, //设备厂商
  2192. DeviceModel = newpos.DeviceKind, //设备型号
  2193. DeviceType = newpos.DeviceType, //设备类型
  2194. // FromUserId = storeFrom.UserId, //出货创客
  2195. StoreId = storeFrom.Id,//出货仓库
  2196. FromDate = DateTime.Now, //出库时间
  2197. FromRemark = "跨品牌换机,出库", //出库备注
  2198. SourceStoreId = newpos.SourceStoreId, //源仓库
  2199. // ToUserId = storeBack.UserId,//收货创客
  2200. ToStoreId = storeBack.Id,//收货仓库
  2201. });
  2202. //接收方
  2203. db.StoreChangeHistory.Add(new StoreChangeHistory()
  2204. {
  2205. CreateDate = DateTime.Now,
  2206. UserId = userInfo.Id, //创客
  2207. BrandId = newpos.BrandId,//产品类型
  2208. // ChangeRecordNo = "KPHJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  2209. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  2210. TransType = 7, //交易类型(0 采购 1 调拨 2 出货 3 退货 4 驳回 5 回仓退款 6 换机出库 7 换机入库)
  2211. SnNo = newpos.PosSn, //SN编号
  2212. SnType = newpos.PosSnType, //SN机具类型
  2213. StockOpDirect = 0, //库存操作方向(0 入库 1 出库)
  2214. DeviceVendor = newpos.DeviceName, //设备厂商
  2215. DeviceModel = newpos.DeviceKind, //设备型号
  2216. DeviceType = newpos.DeviceType, //设备类型
  2217. // FromUserId = storeFrom.UserId, //出货创客
  2218. StoreId = storeFrom.Id,//出货仓库
  2219. FromDate = DateTime.Now, //出库时间
  2220. FromRemark = "跨品牌换机,入库", //出库备注
  2221. SourceStoreId = newpos.SourceStoreId, //源仓库
  2222. // ToUserId = storeBack.UserId,//收货创客
  2223. ToStoreId = storeBack.Id,//收货仓库
  2224. });
  2225. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  2226. db.SaveChanges();
  2227. opdb.SaveChanges();
  2228. if (IsSend == 1)
  2229. {
  2230. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2231. {
  2232. UserId = userForMakerCode.UserId, //接收创客
  2233. MsgType = 2,
  2234. Title = "创客跨品牌换机", //标题
  2235. Summary = "您的旧机 " + brandInfo.Name + " SN:" + OldSnNum + "已经成功为您换为" + brandNew.Name + "SN:" + NewSnNum + "。",
  2236. CreateDate = DateTime.Now,
  2237. }));
  2238. }
  2239. }
  2240. foreach (string sub in opData)
  2241. {
  2242. string[] datalist = sub.Split(":");
  2243. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  2244. }
  2245. return "success";
  2246. }
  2247. #endregion
  2248. #region 机具解绑
  2249. public IActionResult Unbind(string right)
  2250. {
  2251. ViewBag.RightInfo = RightInfo;
  2252. ViewBag.right = right;
  2253. return View();
  2254. }
  2255. [HttpPost]
  2256. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  2257. {
  2258. if (string.IsNullOrEmpty(PosSn))
  2259. {
  2260. return "请输入机具SN";
  2261. }
  2262. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  2263. if (forSnNo == null)
  2264. {
  2265. return "机具SN不存在";
  2266. }
  2267. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  2268. if (pos == null)
  2269. {
  2270. return "机具SN不存在";
  2271. }
  2272. if (pos.ActivationState == 1)
  2273. {
  2274. return "机具已激活,不能解绑";
  2275. }
  2276. if (pos.BuyUserId == 0)
  2277. {
  2278. return "机具是仓库机,不支持解绑";
  2279. }
  2280. if (pos.BindingState == 0)
  2281. {
  2282. return "机具未绑定,不支持解绑";
  2283. }
  2284. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  2285. {
  2286. return "机具绑定已超过30天,不支持解绑";
  2287. }
  2288. if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
  2289. {
  2290. return "该机具已交易,无法解绑";
  2291. }
  2292. if (pos.BrandId != 10 || pos.BrandId != 11)
  2293. {
  2294. if (string.IsNullOrEmpty(MakerCode))
  2295. {
  2296. return "请输入创客编号";
  2297. }
  2298. if (string.IsNullOrEmpty(MerNo))
  2299. {
  2300. return "请输入商户编号";
  2301. }
  2302. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2303. if (forMakerCode == null)
  2304. {
  2305. return "创客不存在";
  2306. }
  2307. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2308. if (forMerNo == null)
  2309. {
  2310. return "商户编号不存在";
  2311. }
  2312. if (pos.BuyUserId != forMakerCode.UserId)
  2313. {
  2314. return "机具SN和创客不匹配";
  2315. }
  2316. if (forMerNo != null)
  2317. {
  2318. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2319. if (merchant != null)
  2320. {
  2321. //机具解绑删除客小爽企业版对应数据
  2322. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2323. if (merInfo != null)
  2324. {
  2325. db.BusinessPartnerMerchant.Remove(merInfo);
  2326. }
  2327. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2328. if (posInfo != null)
  2329. {
  2330. db.BusinessPartnerPos.Remove(posInfo);
  2331. }
  2332. db.PosMerchantInfo.Remove(merchant);
  2333. }
  2334. db.MachineForMerNo.Remove(forMerNo);
  2335. db.SaveChanges();
  2336. }
  2337. }
  2338. else
  2339. {
  2340. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  2341. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  2342. if (forMerNo != null && posMerchantInfo != null)
  2343. {
  2344. //机具解绑删除客小爽企业版对应数据
  2345. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == posMerchantInfo.Id);
  2346. if (merInfo != null)
  2347. {
  2348. db.BusinessPartnerMerchant.Remove(merInfo);
  2349. }
  2350. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2351. if (posInfo != null)
  2352. {
  2353. db.BusinessPartnerPos.Remove(posInfo);
  2354. }
  2355. db.PosMerchantInfo.Remove(posMerchantInfo);
  2356. db.MachineForMerNo.Remove(forMerNo);
  2357. db.SaveChanges();
  2358. }
  2359. }
  2360. db.MachineUnBind.Add(new MachineUnBind()
  2361. {
  2362. CreateDate = DateTime.Now,
  2363. SeoTitle = SysUserName + "-" + SysRealName,
  2364. MerchantId = pos.BindMerchantId,
  2365. AuditDate = DateTime.Now,
  2366. AuditDesc = "平台操作解绑",
  2367. AuditStatus = 1,
  2368. SnNo = pos.PosSn,
  2369. BrandId = pos.BrandId,
  2370. UserId = pos.BuyUserId,
  2371. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2372. });
  2373. pos.BindMerchantId = 0;
  2374. pos.BindingState = 0;
  2375. pos.BindingTime = DateTime.Parse("1900-01-01");
  2376. pos.UserId = pos.BuyUserId;
  2377. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2378. db.SaveChanges();
  2379. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2380. if (IsSend == 1)
  2381. {
  2382. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2383. {
  2384. UserId = pos.BuyUserId, //接收创客
  2385. MsgType = 2,
  2386. Title = "解绑成功通知", //标题
  2387. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2388. CreateDate = DateTime.Now,
  2389. }));
  2390. }
  2391. return "success";
  2392. }
  2393. #endregion
  2394. #region 通过券码修改盟主标记
  2395. public IActionResult ChangeSignQuan(string right)
  2396. {
  2397. ViewBag.RightInfo = RightInfo;
  2398. ViewBag.right = right;
  2399. return View();
  2400. }
  2401. [HttpPost]
  2402. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2403. {
  2404. if (string.IsNullOrEmpty(Coupons))
  2405. {
  2406. return "请输入机具券码,多个券码用回车分隔";
  2407. }
  2408. if (string.IsNullOrEmpty(MakerCode))
  2409. {
  2410. return "请输入创客编号";
  2411. }
  2412. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2413. if (forMakerCode == null)
  2414. {
  2415. return "创客不存在";
  2416. }
  2417. string[] SnList = Coupons.Replace("\r", "").Split('\n');
  2418. foreach (var item in SnList)
  2419. {
  2420. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2421. if (coupos == null)
  2422. {
  2423. return "机具券不存在";
  2424. }
  2425. else
  2426. {
  2427. coupos.LeaderUserId = forMakerCode.UserId;
  2428. }
  2429. }
  2430. db.SaveChanges();
  2431. return "success";
  2432. }
  2433. #endregion
  2434. #region 通过机具SN修改盟主标记
  2435. public IActionResult ChangeSignSn(string right)
  2436. {
  2437. ViewBag.RightInfo = RightInfo;
  2438. ViewBag.right = right;
  2439. return View();
  2440. }
  2441. [HttpPost]
  2442. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2443. {
  2444. if (string.IsNullOrEmpty(PosSn))
  2445. {
  2446. return "请输入机具SN,多个SN用回车分隔";
  2447. }
  2448. if (string.IsNullOrEmpty(MakerCode))
  2449. {
  2450. return "请输入创客编号";
  2451. }
  2452. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2453. if (forMakerCode == null)
  2454. {
  2455. return "创客不存在";
  2456. }
  2457. string[] SnList = PosSn.Replace("\r", "").Split('\n');
  2458. foreach (var item in SnList)
  2459. {
  2460. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2461. if (pos == null)
  2462. {
  2463. return "该机具不存在";
  2464. }
  2465. else
  2466. {
  2467. pos.LeaderUserId = forMakerCode.UserId;
  2468. }
  2469. }
  2470. db.SaveChanges();
  2471. return "success";
  2472. }
  2473. #endregion
  2474. #region 机具循环列表
  2475. /// <summary>
  2476. /// 根据条件查询机具循环列表
  2477. /// </summary>
  2478. /// <returns></returns>
  2479. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2480. {
  2481. ViewBag.RightInfo = RightInfo;
  2482. ViewBag.right = right;
  2483. ViewBag.SwapSnExpand = SwapSnExpand;
  2484. ViewBag.SnNos = SnNos;
  2485. return View();
  2486. }
  2487. #endregion
  2488. #region 根据条件查询机具循环列表
  2489. /// <summary>
  2490. /// 机具循环列表
  2491. /// </summary>
  2492. /// <returns></returns>
  2493. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2494. {
  2495. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2496. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2497. Fields.Add("SnNos", "1"); //发货机具SN
  2498. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2499. if (!string.IsNullOrEmpty(SwapSnExpand))
  2500. {
  2501. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2502. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2503. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2504. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2505. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2506. for (int i = 0; i < SnNoList.Length; i++)
  2507. {
  2508. Dictionary<string, object> data = new Dictionary<string, object>();
  2509. data["ApplyNo"] = apply.ApplyNo;
  2510. data["OrderNo"] = order.OrderNo;
  2511. data["MakerCode"] = user.MakerCode;
  2512. data["RealName"] = user.RealName;
  2513. if (SnNoList.Length > i)
  2514. {
  2515. string SourceSn = SnNoList[i].Split(':')[0];
  2516. data["ComeSn"] = SnNoList[i];
  2517. data["ComeSnParam"] = SourceSn;
  2518. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2519. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2520. if (pos.LeaderUserId > 0)
  2521. {
  2522. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2523. data["ComeSnMakerCode"] = leader.MakerCode;
  2524. data["ComeSnRealName"] = leader.RealName;
  2525. }
  2526. }
  2527. if (OrderSnNo.Length > i)
  2528. {
  2529. string SendSn = OrderSnNo[i];
  2530. data["SendSn"] = OrderSnNo[i];
  2531. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2532. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2533. if (pos.LeaderUserId > 0)
  2534. {
  2535. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2536. data["SendSnMakerCode"] = leader.MakerCode;
  2537. data["SendSnRealName"] = leader.RealName;
  2538. }
  2539. }
  2540. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2541. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2542. dataList.Add(data);
  2543. }
  2544. }
  2545. else if (!string.IsNullOrEmpty(SnNos))
  2546. {
  2547. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2548. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2549. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2550. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2551. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2552. for (int i = 0; i < OrderSnNo.Length; i++)
  2553. {
  2554. Dictionary<string, object> data = new Dictionary<string, object>();
  2555. data["ApplyNo"] = apply.ApplyNo;
  2556. data["OrderNo"] = order.OrderNo;
  2557. data["MakerCode"] = user.MakerCode;
  2558. data["RealName"] = user.RealName;
  2559. if (SnNoList.Length > i)
  2560. {
  2561. string SourceSn = SnNoList[i].Split(':')[0];
  2562. data["ComeSn"] = SnNoList[i];
  2563. data["ComeSnParam"] = SourceSn;
  2564. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2565. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2566. if (pos.LeaderUserId > 0)
  2567. {
  2568. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2569. data["ComeSnMakerCode"] = leader.MakerCode;
  2570. data["ComeSnRealName"] = leader.RealName;
  2571. }
  2572. }
  2573. if (OrderSnNo.Length > i)
  2574. {
  2575. string SendSn = OrderSnNo[i];
  2576. data["SendSn"] = OrderSnNo[i];
  2577. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2578. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2579. if (pos.LeaderUserId > 0)
  2580. {
  2581. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2582. data["SendSnMakerCode"] = leader.MakerCode;
  2583. data["SendSnRealName"] = leader.RealName;
  2584. }
  2585. }
  2586. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2587. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2588. dataList.Add(data);
  2589. }
  2590. }
  2591. Dictionary<string, object> obj = new Dictionary<string, object>();
  2592. obj.Add("code", 0);
  2593. obj.Add("msg", "");
  2594. obj.Add("count", dataList.Count);
  2595. obj.Add("data", dataList);
  2596. return Json(obj);
  2597. }
  2598. #endregion
  2599. #region 查询机具循环
  2600. /// <summary>
  2601. /// 根据条件查询机具来源机具和券码
  2602. /// </summary>
  2603. /// <returns></returns>
  2604. public IActionResult SourceLoop(string right, string SnNos)
  2605. {
  2606. ViewBag.RightInfo = RightInfo;
  2607. ViewBag.right = right;
  2608. ViewBag.SnNos = SnNos;
  2609. return View();
  2610. }
  2611. #endregion
  2612. #region 根据条件查询机具来源机具和券码
  2613. /// <summary>
  2614. /// 机具循环列表
  2615. /// </summary>
  2616. /// <returns></returns>
  2617. public string SourceLoopData(string SnNo, int page = 1, int limit = 30)
  2618. {
  2619. var result = "";
  2620. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
  2621. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  2622. if (pos.Id == 0)
  2623. {
  2624. return "机具:" + SnNo + "不存在";
  2625. }
  2626. else
  2627. {
  2628. var stattime = pos.RecycStartDate == null ? "" : pos.RecycStartDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2629. var endtime = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2630. result += "循环开始时间:" + stattime + "\n";
  2631. result += "循环结束时间:" + endtime + "\n";
  2632. result += "来源机具/券:" + pos.SourcePosSn + "\n";
  2633. }
  2634. return result;
  2635. }
  2636. #endregion
  2637. #region 查询创客直推奖
  2638. public IActionResult Prize100(string right)
  2639. {
  2640. ViewBag.RightInfo = RightInfo;
  2641. ViewBag.right = right;
  2642. return View();
  2643. }
  2644. [HttpPost]
  2645. public Dictionary<string, string> Prize100Do(string MakerCode)
  2646. {
  2647. Dictionary<string, string> dic = new Dictionary<string, string>();
  2648. string result = "";
  2649. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2650. if (forMakerCode == null)
  2651. {
  2652. result += "创客编号不存在\n";
  2653. dic.Add("code", "1");
  2654. dic.Add("result", result);
  2655. return dic;
  2656. }
  2657. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2658. if (OrderCount == 0)
  2659. {
  2660. result += "该创客未下单\n";
  2661. dic.Add("code", "1");
  2662. dic.Add("result", result);
  2663. return dic;
  2664. }
  2665. if (OrderCount > 1)
  2666. {
  2667. result += "该创客已不是首笔下单\n";
  2668. dic.Add("code", "1");
  2669. dic.Add("result", result);
  2670. return dic;
  2671. }
  2672. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2673. if (order.PayStatus < 1)
  2674. {
  2675. result += "未付款\n";
  2676. dic.Add("code", "1");
  2677. dic.Add("result", result);
  2678. return dic;
  2679. }
  2680. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2681. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2682. result += "订单号:" + order.OrderNo + "\n";
  2683. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2684. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2685. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  2686. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2687. if (machineCount + ActiveCount >= 3)
  2688. {
  2689. string IsGet = "未发放";
  2690. int ToUserId = 0;
  2691. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2692. if (item == null)
  2693. {
  2694. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2695. DateTime end = order.PayDate.Value.AddMinutes(2);
  2696. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2697. }
  2698. if (item != null)
  2699. {
  2700. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2701. ToUserId = item.UserId;
  2702. dic.Add("code", "1");
  2703. }
  2704. else
  2705. {
  2706. dic.Add("id", order.Id.ToString());
  2707. dic.Add("code", "0");
  2708. }
  2709. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  2710. result += "是否发放:" + IsGet + "\n";
  2711. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2712. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  2713. }
  2714. else
  2715. {
  2716. result += "上级创客未满足条件\n兑换机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  2717. dic.Add("code", "1");
  2718. }
  2719. dic.Add("result", result);
  2720. return dic;
  2721. }
  2722. public string AddPrize100(int Id)
  2723. {
  2724. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  2725. if (order != null)
  2726. {
  2727. //机具券逻辑
  2728. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  2729. if (pro != null)
  2730. {
  2731. //推荐下单奖励
  2732. if (pro.ProductId == 10 || pro.ProductId == 11)
  2733. {
  2734. int OrderId = order.Id;
  2735. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  2736. if (!checkPrize)
  2737. {
  2738. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2739. if (user != null)
  2740. {
  2741. bool directPrize = false; //直推奖标记
  2742. int ParentUserId = user.ParentUserId;
  2743. while (ParentUserId > 0)
  2744. {
  2745. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2746. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台兑换机
  2747. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2748. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2749. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2750. {
  2751. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2752. directPrize = true;
  2753. db.SaveChanges();
  2754. return "发放成功";
  2755. }
  2756. ParentUserId = puser.ParentUserId;
  2757. }
  2758. }
  2759. }
  2760. return "已发放,请勿重复发放";
  2761. }
  2762. }
  2763. }
  2764. return "操作失败";
  2765. }
  2766. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2767. {
  2768. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2769. if (account == null)
  2770. {
  2771. account = db.UserAccount.Add(new UserAccount()
  2772. {
  2773. Id = UserId,
  2774. UserId = UserId,
  2775. }).Entity;
  2776. db.SaveChanges();
  2777. }
  2778. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2779. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2780. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2781. account.BalanceAmount += 100 * Count;
  2782. account.TotalAmount += 100 * Count;
  2783. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2784. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2785. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2786. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2787. {
  2788. CreateDate = DateTime.Now,
  2789. UpdateDate = DateTime.Now,
  2790. UserId = UserId, //创客
  2791. ChangeType = 112, //变动类型
  2792. ChangeAmount = 100 * Count, //变更金额
  2793. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2794. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2795. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2796. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2797. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2798. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2799. QueryCount = OrderId,
  2800. }).Entity;
  2801. db.SaveChanges();
  2802. }
  2803. #endregion
  2804. #region 查询机具开机奖
  2805. public IActionResult OpenPrize(string right)
  2806. {
  2807. ViewBag.RightInfo = RightInfo;
  2808. ViewBag.right = right;
  2809. return View();
  2810. }
  2811. [HttpPost]
  2812. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2813. {
  2814. Dictionary<string, string> dic = new Dictionary<string, string>();
  2815. string result = "";
  2816. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2817. if (pos == null)
  2818. {
  2819. result += "机具SN号不存在\n";
  2820. dic.Add("code", "1");
  2821. dic.Add("result", result);
  2822. return dic;
  2823. }
  2824. if (pos.BindingState == 0)
  2825. {
  2826. result += "机具未绑定\n";
  2827. dic.Add("code", "1");
  2828. dic.Add("result", result);
  2829. return dic;
  2830. }
  2831. if (pos.ActivationState == 0)
  2832. {
  2833. result += "机具未激活\n";
  2834. dic.Add("code", "1");
  2835. dic.Add("result", result);
  2836. return dic;
  2837. }
  2838. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2839. if (merchant == null)
  2840. {
  2841. result += "商户不存在\n";
  2842. dic.Add("code", "1");
  2843. dic.Add("result", result);
  2844. return dic;
  2845. }
  2846. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2847. result += "机具号:" + PosSn + "\n";
  2848. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2849. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2850. string OpenUser10 = "未领取";
  2851. string OpenUser20 = "未领取";
  2852. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2853. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2854. if (openreward.Id > 0)
  2855. {
  2856. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2857. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2858. }
  2859. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2860. if (openreward.Id > 0)
  2861. {
  2862. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2863. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2864. }
  2865. result += "开机奖20:" + OpenUser20 + "\n";
  2866. dic.Add("id", pos.Id.ToString());
  2867. dic.Add("code", "0");
  2868. dic.Add("result", result);
  2869. return dic;
  2870. }
  2871. public string AddOpenPrize(int Id)
  2872. {
  2873. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2874. if (pos == null)
  2875. {
  2876. return "机具未激活";
  2877. }
  2878. if (pos.BindingTime <= pos.TransferTime)
  2879. {
  2880. return "补录机,不能补发开机奖";
  2881. }
  2882. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2883. if (ActPrize == 0)
  2884. {
  2885. return "机具无押金";
  2886. }
  2887. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2888. if (merchant == null)
  2889. {
  2890. return "商户不存在";
  2891. }
  2892. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2893. if (check)
  2894. {
  2895. return "开机奖励已发放,请勿重复操作";
  2896. }
  2897. // 从机具所属人上级开始分开机奖励
  2898. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2899. if (user != null)
  2900. {
  2901. if (!string.IsNullOrEmpty(user.ParentNav))
  2902. {
  2903. decimal Prize = 20;
  2904. List<string> PrizeFlag = new List<string>();
  2905. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2906. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2907. {
  2908. int UserId = int.Parse(ParentNavs[i]);
  2909. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2910. if (puser != null && Prize > 0)
  2911. {
  2912. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
  2913. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2914. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2915. if (machineCount + ActiveCount + couponCount >= 3)
  2916. {
  2917. int pTopUserId = 0;
  2918. if (!string.IsNullOrEmpty(puser.ParentNav))
  2919. {
  2920. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2921. }
  2922. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2923. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2924. {
  2925. CreateDate = DateTime.Now,
  2926. UpdateDate = DateTime.Now,
  2927. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2928. TradeDate = pos.ActivationTime, //达标日期
  2929. UserId = puser.Id, //创客
  2930. BrandId = pos.BrandId, //品牌
  2931. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2932. MerchantId = pos.BindMerchantId, //商户
  2933. DirectUserId = merchant.UserId, //商户直属人
  2934. SnNo = pos.PosSn, //SN号
  2935. MerNo = merchant.KqMerNo, //渠道商户号
  2936. SnType = pos.PosSnType, //机具类型
  2937. StandardDate = pos.ActivationTime, //商户的激活日期
  2938. SnStoreId = pos.StoreId, //SN仓库
  2939. MerBuddyType = puser.MerchantType, //商户创客类型
  2940. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2941. RewardTips = "开机奖励", //奖励描述
  2942. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2943. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2944. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2945. RewardDesc = "开机奖励", //奖励描述
  2946. TopUserId = pTopUserId, //顶级创客
  2947. SeoTitle = machineUser.RealName,
  2948. }).Entity;
  2949. db.OpenReward.Add(new OpenReward()
  2950. {
  2951. CreateDate = DateTime.Now,
  2952. UpdateDate = DateTime.Now,
  2953. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2954. TradeDate = DateTime.Now, //达标日期
  2955. UserId = puser.Id, //创客
  2956. BrandId = pos.BrandId, //品牌
  2957. RewardType = 2, //奖励类型
  2958. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2959. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2960. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2961. RewardDesc = "开机奖励", //奖励描述
  2962. TopUserId = pTopUserId, //顶级创客
  2963. });
  2964. string IdBrand = puser.Id + "_" + pos.BrandId;
  2965. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2966. if (userData == null)
  2967. {
  2968. userData = db.UserMachineData.Add(new UserMachineData()
  2969. {
  2970. IdBrand = IdBrand,
  2971. }).Entity;
  2972. db.SaveChanges();
  2973. }
  2974. userData.OpenProfit += Prize;
  2975. db.SaveChanges();
  2976. //账户入库
  2977. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2978. if (account == null)
  2979. {
  2980. account = db.UserAccount.Add(new UserAccount()
  2981. {
  2982. Id = puser.Id,
  2983. UserId = puser.Id,
  2984. }).Entity;
  2985. db.SaveChanges();
  2986. }
  2987. //收支明细入库
  2988. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2989. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2990. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2991. account.BalanceAmount += Prize;
  2992. account.TotalAmount += Prize;
  2993. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2994. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2995. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2996. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2997. {
  2998. CreateDate = DateTime.Now,
  2999. UpdateDate = DateTime.Now,
  3000. UserId = puser.Id, //创客
  3001. ChangeType = 50, //变动类型
  3002. ProductType = pos.BrandId, //产品类型
  3003. ChangeAmount = Prize, //变更金额
  3004. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3005. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3006. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3007. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3008. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3009. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3010. }).Entity;
  3011. db.SaveChanges();
  3012. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  3013. string dateString = DateTime.Now.ToString("yyyyMMdd");
  3014. string monthString = DateTime.Now.ToString("yyyyMM");
  3015. // 开机奖励列表
  3016. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  3017. if (!dates.Contains(dateString))
  3018. {
  3019. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  3020. }
  3021. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  3022. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  3023. if (!months.Contains(monthString))
  3024. {
  3025. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  3026. }
  3027. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  3028. // 开机奖励详情
  3029. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  3030. //收支明细
  3031. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  3032. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  3033. Prize = 0;
  3034. PrizeFlag.Add(Prize.ToString("f0"));
  3035. }
  3036. }
  3037. }
  3038. string result = "";
  3039. if (string.IsNullOrEmpty(result))
  3040. {
  3041. return "发放成功";
  3042. }
  3043. return result;
  3044. }
  3045. }
  3046. db.Dispose();
  3047. return "操作失败";
  3048. }
  3049. #endregion
  3050. #region 查询机具流量费分佣
  3051. public IActionResult FluxPrize(string right)
  3052. {
  3053. ViewBag.RightInfo = RightInfo;
  3054. ViewBag.right = right;
  3055. return View();
  3056. }
  3057. [HttpPost]
  3058. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  3059. {
  3060. Dictionary<string, string> dic = new Dictionary<string, string>();
  3061. string result = "";
  3062. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  3063. if (pos == null)
  3064. {
  3065. result += "机具SN号不存在\n";
  3066. dic.Add("code", "1");
  3067. dic.Add("result", result);
  3068. return dic;
  3069. }
  3070. if (pos.BindingState == 0)
  3071. {
  3072. result += "机具未绑定\n";
  3073. dic.Add("code", "1");
  3074. dic.Add("result", result);
  3075. return dic;
  3076. }
  3077. if (pos.ActivationState == 0)
  3078. {
  3079. result += "机具未激活\n";
  3080. dic.Add("code", "1");
  3081. dic.Add("result", result);
  3082. return dic;
  3083. }
  3084. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3085. if (merchant == null)
  3086. {
  3087. result += "商户不存在\n";
  3088. dic.Add("code", "1");
  3089. dic.Add("result", result);
  3090. return dic;
  3091. }
  3092. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3093. result += "机具号:" + PosSn + "\n";
  3094. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  3095. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  3096. string FluxGet6 = "未领取";
  3097. string FluxUser6 = "";
  3098. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  3099. if (flux.Id > 0)
  3100. {
  3101. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  3102. FluxGet6 = "已领取(金额:" + flux.FluxFeeAmt + ",领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  3103. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  3104. }
  3105. result += "流量费:" + FluxGet6 + "\n";
  3106. result += "流量费发放对象:" + FluxUser6 + "\n";
  3107. dic.Add("id", pos.Id.ToString());
  3108. dic.Add("code", "0");
  3109. dic.Add("result", result);
  3110. return dic;
  3111. }
  3112. public string AddFluxPrize(int Id)
  3113. {
  3114. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  3115. if (pos == null)
  3116. {
  3117. return "机具未激活";
  3118. }
  3119. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  3120. if (ActPrize == 0)
  3121. {
  3122. return "机具无押金";
  3123. }
  3124. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  3125. if (merchant == null)
  3126. {
  3127. return "商户不存在";
  3128. }
  3129. if (pos.BrandId == 6)
  3130. {
  3131. return "立刷不支持流量费分佣";
  3132. }
  3133. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  3134. {
  3135. return "无押金机,不支持流量费分佣";
  3136. }
  3137. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  3138. if (check)
  3139. {
  3140. return "流量费奖励已发放,请勿重复操作";
  3141. }
  3142. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  3143. if (trade != null)
  3144. {
  3145. try
  3146. {
  3147. string OrderNo = trade.TradeSerialNo; //单号
  3148. DateTime TradeDate = trade.CreateDate.Value;
  3149. string TradeMonth = TradeDate.ToString("yyyyMM");
  3150. decimal FeeAmount = trade.FeeAmount; //流量费
  3151. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  3152. {
  3153. FeeAmount = FeeAmount / 100;
  3154. }
  3155. string TradeSnNo = trade.TradeSnNo; //机具SN
  3156. decimal FluxProfit = 0;
  3157. if (trade.ProductType == "1" && FeeAmount == 60)
  3158. {
  3159. FluxProfit = 24;
  3160. }
  3161. else if (trade.ProductType == "7" && FeeAmount == 46)
  3162. {
  3163. FluxProfit = 10;
  3164. }
  3165. else if (trade.ProductType != "1" && FeeAmount == 48)
  3166. {
  3167. FluxProfit = 12;
  3168. }
  3169. if (FluxProfit > 0)
  3170. {
  3171. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  3172. int GetUserId = user.Id;
  3173. int TopUserId = 0;
  3174. string ParentNav = user.ParentNav;
  3175. if (!string.IsNullOrEmpty(ParentNav))
  3176. {
  3177. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  3178. if (ParentNavList.Length > 1)
  3179. {
  3180. TopUserId = int.Parse(ParentNavList[1]);
  3181. }
  3182. else if (ParentNavList.Length == 1)
  3183. {
  3184. TopUserId = int.Parse(ParentNavList[0]);
  3185. }
  3186. }
  3187. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  3188. if (fluxProfit == null)
  3189. {
  3190. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  3191. {
  3192. CreateDate = DateTime.Now,
  3193. UpdateDate = DateTime.Now,
  3194. UserId = GetUserId, //创客
  3195. BrandId = pos.BrandId,
  3196. TopUserId = TopUserId, //顶级创客
  3197. TradeMonth = TradeMonth, //交易月
  3198. MerUserType = user.MerchantType, //商户创客类型
  3199. Remark = "流量卡分佣", //备注
  3200. }).Entity;
  3201. db.SaveChanges();
  3202. }
  3203. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  3204. db.FluxProfitDetail.Add(new FluxProfitDetail()
  3205. {
  3206. CreateDate = DateTime.Now,
  3207. UpdateDate = DateTime.Now,
  3208. RecordNo = OrderNo, //单号
  3209. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  3210. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  3211. TradeMonth = TradeMonth, //交易月
  3212. UserId = GetUserId, //创客
  3213. MerchantId = pos.BindMerchantId, //商户
  3214. MerchantUserId = pos.UserId, //商户直属人
  3215. MerNo = merchant.KqMerNo, //渠道商户编号
  3216. SnNo = pos.PosSn, //渠道SN号
  3217. FluxOrderNo = OrderNo, //流量扣费单号
  3218. TradeOrderNo = OrderNo, //交易流水号
  3219. TradeAmt = trade.TradeAmount, //商户交易额
  3220. FluxFeeAmt = FeeAmount, //流量费
  3221. FluxProfitAmt = FluxProfit, //流量分润总金额
  3222. PosType = pos.PosSnType.ToString(), //POS类型
  3223. Remark = "流量卡分佣", //备注
  3224. BrandId = pos.BrandId, //品牌
  3225. TopUserId = TopUserId, //顶级创客
  3226. MerUserType = user.MerchantType, //商户创客类型
  3227. });
  3228. string IdBrand = user.Id + "_" + pos.BrandId;
  3229. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  3230. if (userData == null)
  3231. {
  3232. userData = db.UserMachineData.Add(new UserMachineData()
  3233. {
  3234. IdBrand = IdBrand,
  3235. }).Entity;
  3236. db.SaveChanges();
  3237. }
  3238. userData.FluxProfit += FluxProfit;
  3239. db.SaveChanges();
  3240. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  3241. if (account == null)
  3242. {
  3243. account = db.UserAccount.Add(new UserAccount()
  3244. {
  3245. Id = GetUserId,
  3246. UserId = GetUserId,
  3247. }).Entity;
  3248. db.SaveChanges();
  3249. }
  3250. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  3251. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  3252. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  3253. account.BalanceAmount += FluxProfit;
  3254. account.TotalAmount += FluxProfit;
  3255. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  3256. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  3257. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  3258. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  3259. {
  3260. CreateDate = DateTime.Now,
  3261. UpdateDate = DateTime.Now,
  3262. UserId = GetUserId, //创客
  3263. ChangeType = 60, //变动类型
  3264. ProductType = pos.BrandId, //产品类型
  3265. ChangeAmount = FluxProfit, //变更金额
  3266. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  3267. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  3268. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  3269. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  3270. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  3271. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  3272. }).Entity;
  3273. db.SaveChanges();
  3274. spdb.Dispose();
  3275. db.Dispose();
  3276. return "发放成功";
  3277. }
  3278. }
  3279. catch (Exception ex)
  3280. {
  3281. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  3282. }
  3283. }
  3284. spdb.Dispose();
  3285. db.Dispose();
  3286. return "操作失败";
  3287. }
  3288. #endregion
  3289. #region 设置立刷费率
  3290. public IActionResult LisFee(string right)
  3291. {
  3292. ViewBag.RightInfo = RightInfo;
  3293. ViewBag.right = right;
  3294. return View();
  3295. }
  3296. [HttpPost]
  3297. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  3298. {
  3299. if (string.IsNullOrEmpty(PosSns))
  3300. {
  3301. return "请输入机具号";
  3302. }
  3303. string result = SysUserName + "设置\n";
  3304. string[] PosSnList = PosSns.Replace("\r", "").Split('\n');
  3305. int total = PosSnList.Length;
  3306. int index = 0;
  3307. foreach (string SubPosSn in PosSnList)
  3308. {
  3309. index += 1;
  3310. string PosSn = SubPosSn.Replace("\r", "");
  3311. result += PosSn + ":" + Fee + "\n";
  3312. if (Kind == "M5")
  3313. {
  3314. result += SetLiSFee(PosSn, Fee) + "\n";
  3315. }
  3316. else if (Kind == "N1")
  3317. {
  3318. result += SetLiSDeposit(PosSn, (int)Fee);
  3319. }
  3320. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  3321. }
  3322. result += "\n\n";
  3323. function.WriteLog(result, "设置立刷费率");
  3324. return result;
  3325. }
  3326. public string LisFeeProcess()
  3327. {
  3328. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  3329. }
  3330. #region 立刷
  3331. string LiSAgentId = "50814834";
  3332. 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=";
  3333. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  3334. public string LiSSign(string data)
  3335. {
  3336. var rsa = RSA.Create();
  3337. var key = Convert.FromBase64String(LiSPrivateKey);
  3338. var content = Encoding.UTF8.GetBytes(data);
  3339. rsa.ImportPkcs8PrivateKey(key, out _);
  3340. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  3341. return Convert.ToBase64String(result);
  3342. }
  3343. // 设置费率
  3344. public string SetLiSFee(string sn, decimal serviceFee)
  3345. {
  3346. Dictionary<string, object> dic = new Dictionary<string, object>();
  3347. dic.Add("agentId", LiSAgentId);
  3348. dic.Add("deviceSn", sn);
  3349. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3350. Dictionary<string, object> item = new Dictionary<string, object>();
  3351. item.Add("feeCalcType", "M5");
  3352. item.Add("fixed", "0");
  3353. item.Add("rate", serviceFee);
  3354. feeList.Add(item);
  3355. dic.Add("feeList", feeList);
  3356. dic.Add("signMethod", "02");
  3357. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  3358. string signstr = LiSSign(content);
  3359. dic.Add("signData", signstr);
  3360. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3361. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3362. return result;
  3363. }
  3364. // 设置押金
  3365. public string SetLiSDeposit(string sn, int serviceFee)
  3366. {
  3367. serviceFee = serviceFee * 100;
  3368. Dictionary<string, object> dic = new Dictionary<string, object>();
  3369. dic.Add("agentId", LiSAgentId);
  3370. dic.Add("deviceSn", sn);
  3371. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3372. Dictionary<string, object> item = new Dictionary<string, object>();
  3373. item.Add("feeCalcType", "N1");
  3374. item.Add("fixed", "1");
  3375. item.Add("rate", serviceFee);
  3376. feeList.Add(item);
  3377. dic.Add("feeList", feeList);
  3378. dic.Add("signMethod", "02");
  3379. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  3380. string signstr = LiSSign(content);
  3381. dic.Add("signData", signstr);
  3382. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3383. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3384. return result;
  3385. }
  3386. #endregion
  3387. #endregion
  3388. #region 查询商户型创客设置信息
  3389. public IActionResult SeeMerchantType(string right)
  3390. {
  3391. ViewBag.RightInfo = RightInfo;
  3392. ViewBag.right = right;
  3393. return View();
  3394. }
  3395. [HttpPost]
  3396. public string SeeMerchantTypeDo(string PosSn)
  3397. {
  3398. if (string.IsNullOrEmpty(PosSn))
  3399. {
  3400. return "请输入机具SN或者创客编号";
  3401. }
  3402. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3403. if (PosSn.StartsWith("K"))
  3404. {
  3405. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3406. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3407. if (check)
  3408. {
  3409. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3410. }
  3411. }
  3412. else
  3413. {
  3414. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3415. if (check)
  3416. {
  3417. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3418. }
  3419. }
  3420. if (pos.Id == 0)
  3421. {
  3422. return "查无信息";
  3423. }
  3424. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3425. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3426. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3427. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3428. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3429. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3430. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3431. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3432. string result = "";
  3433. result += "机具SN:" + pos.PosSn + "\n";
  3434. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3435. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3436. result += "商户编号:" + pos.MerNo + "\n";
  3437. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3438. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3439. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3440. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3441. result += "是否循环:" + RecycFlag + "\n";
  3442. return result;
  3443. }
  3444. #endregion
  3445. #region 三要素验证
  3446. public IActionResult CheckThreeElements(string right)
  3447. {
  3448. ViewBag.RightInfo = RightInfo;
  3449. ViewBag.right = right;
  3450. return View();
  3451. }
  3452. [HttpPost]
  3453. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3454. {
  3455. var host = "https://bankcard3c.shumaidata.com";
  3456. var path = "/bankcard3c";
  3457. var method = "GET";
  3458. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3459. if (string.IsNullOrEmpty(bankcard))
  3460. {
  3461. return "结算银行卡号";
  3462. }
  3463. if (string.IsNullOrEmpty(idcard))
  3464. {
  3465. return "身份证号";
  3466. }
  3467. if (string.IsNullOrEmpty(name))
  3468. {
  3469. return "真实姓名";
  3470. }
  3471. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3472. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3473. function.WriteLog(querys, "验证三要素日志");
  3474. String bodys = "";
  3475. String url = host + path;
  3476. HttpWebRequest httpRequest = null;
  3477. HttpWebResponse httpResponse = null;
  3478. if (0 < querys.Length)
  3479. {
  3480. url = url + "?" + querys;
  3481. }
  3482. if (host.Contains("https://"))
  3483. {
  3484. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3485. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3486. }
  3487. else
  3488. {
  3489. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3490. }
  3491. httpRequest.Method = method;
  3492. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3493. if (0 < bodys.Length)
  3494. {
  3495. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3496. using (Stream stream = httpRequest.GetRequestStream())
  3497. {
  3498. stream.Write(data, 0, data.Length);
  3499. }
  3500. }
  3501. try
  3502. {
  3503. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3504. }
  3505. catch (WebException ex)
  3506. {
  3507. httpResponse = (HttpWebResponse)ex.Response;
  3508. }
  3509. Stream st = httpResponse.GetResponseStream();
  3510. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3511. string result = reader.ReadToEnd();
  3512. JsonData jsonObj = JsonMapper.ToObject(result);
  3513. result = jsonObj["data"]["desc"].ToString();
  3514. function.WriteLog(result, "验证三要素日志");
  3515. function.WriteLog("\n\n", "验证三要素日志");
  3516. return result;
  3517. }
  3518. #endregion
  3519. #region 四要素验证
  3520. public IActionResult CheckFourElements(string right)
  3521. {
  3522. ViewBag.RightInfo = RightInfo;
  3523. ViewBag.right = right;
  3524. return View();
  3525. }
  3526. [HttpPost]
  3527. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3528. {
  3529. var host = "https://bankcard4c.shumaidata.com";
  3530. var path = "/bankcard4c";
  3531. var method = "GET";
  3532. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3533. if (string.IsNullOrEmpty(bankcard))
  3534. {
  3535. return "请输入结算银行卡号";
  3536. }
  3537. if (string.IsNullOrEmpty(idcard))
  3538. {
  3539. return "请输入身份证号";
  3540. }
  3541. if (string.IsNullOrEmpty(mobile))
  3542. {
  3543. return "请输入银行预留手机号";
  3544. }
  3545. if (string.IsNullOrEmpty(name))
  3546. {
  3547. return "请输入真实姓名";
  3548. }
  3549. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3550. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3551. function.WriteLog(querys, "验证四要素日志");
  3552. String bodys = "";
  3553. String url = host + path;
  3554. HttpWebRequest httpRequest = null;
  3555. HttpWebResponse httpResponse = null;
  3556. if (0 < querys.Length)
  3557. {
  3558. url = url + "?" + querys;
  3559. }
  3560. if (host.Contains("https://"))
  3561. {
  3562. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3563. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3564. }
  3565. else
  3566. {
  3567. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3568. }
  3569. httpRequest.Method = method;
  3570. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3571. if (0 < bodys.Length)
  3572. {
  3573. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3574. using (Stream stream = httpRequest.GetRequestStream())
  3575. {
  3576. stream.Write(data, 0, data.Length);
  3577. }
  3578. }
  3579. try
  3580. {
  3581. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3582. }
  3583. catch (WebException ex)
  3584. {
  3585. httpResponse = (HttpWebResponse)ex.Response;
  3586. }
  3587. Stream st = httpResponse.GetResponseStream();
  3588. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3589. string result = reader.ReadToEnd();
  3590. JsonData jsonObj = JsonMapper.ToObject(result);
  3591. result = jsonObj["data"]["desc"].ToString();
  3592. function.WriteLog(result, "验证四要素日志");
  3593. function.WriteLog("\n\n", "验证四要素日志");
  3594. return result;
  3595. }
  3596. #endregion
  3597. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3598. {
  3599. return true;
  3600. }
  3601. #region 根据机具号同步商户激活状态
  3602. public IActionResult SyncMerchantStatus(string right)
  3603. {
  3604. ViewBag.RightInfo = RightInfo;
  3605. ViewBag.right = right;
  3606. return View();
  3607. }
  3608. [HttpPost]
  3609. public string SyncMerchantStatusDo(string PosSn)
  3610. {
  3611. if (string.IsNullOrEmpty(PosSn))
  3612. {
  3613. return "请输入机具号";
  3614. }
  3615. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3616. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3617. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
  3618. if (posInfo.Id == 0)
  3619. {
  3620. return "机具" + PosSn + "不存在";
  3621. }
  3622. if (posMerchant.Id == 0)
  3623. {
  3624. return "机具绑定商户不存在";
  3625. }
  3626. else
  3627. {
  3628. posMerchant.ActiveStatus = 1;
  3629. posMerchant.UpdateDate = DateTime.Now;
  3630. posMerchant.MerStandardDate = posInfo.ActivationTime;
  3631. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
  3632. db.SaveChanges();
  3633. }
  3634. return "success";
  3635. }
  3636. #endregion
  3637. #region 根据机具号补发开机奖励
  3638. public IActionResult PosRewardReissued(string right)
  3639. {
  3640. ViewBag.RightInfo = RightInfo;
  3641. ViewBag.right = right;
  3642. return View();
  3643. }
  3644. [HttpPost]
  3645. public string PosRewardReissuedDo(string PosSn)
  3646. {
  3647. if (string.IsNullOrEmpty(PosSn))
  3648. {
  3649. return "请输入机具SN";
  3650. }
  3651. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3652. var PosId = "";
  3653. var error = "";
  3654. foreach (var item in PosSnList)
  3655. {
  3656. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3657. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3658. bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
  3659. if (checkExist)
  3660. {
  3661. error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
  3662. }
  3663. else
  3664. {
  3665. if (posInfo.Id > 0)
  3666. {
  3667. RedisDbconn.Instance.AddList("OpenRewardQueue", posInfo.Id.ToString());
  3668. }
  3669. }
  3670. }
  3671. if (!string.IsNullOrEmpty(error))
  3672. {
  3673. return "Warning|" + error;
  3674. }
  3675. PosId = PosId.TrimEnd(',');
  3676. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
  3677. return "success";
  3678. }
  3679. #endregion
  3680. #region 根据机具号设置费率
  3681. public IActionResult SetPosFee(string right)
  3682. {
  3683. ViewBag.RightInfo = RightInfo;
  3684. ViewBag.right = right;
  3685. return View();
  3686. }
  3687. [HttpPost]
  3688. public string SetPosFeeDo(string PosSn, string FeeType)
  3689. {
  3690. if (string.IsNullOrEmpty(PosSn))
  3691. {
  3692. return "请输入机具SN";
  3693. }
  3694. if (string.IsNullOrEmpty(FeeType))
  3695. {
  3696. return "请输入选择费率";
  3697. }
  3698. if (FeeType == "0")
  3699. {
  3700. FeeType = "0.6";
  3701. }
  3702. if (FeeType == "1")
  3703. {
  3704. FeeType = "0.63";
  3705. }
  3706. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  3707. var PosId = "";
  3708. var RecordId = "";
  3709. var error = "";
  3710. foreach (var item in PosSnList)
  3711. {
  3712. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3713. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3714. if (posInfo.Id > 0)
  3715. {
  3716. var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  3717. {
  3718. Sort = posInfo.BrandId,
  3719. CreateDate = DateTime.Now,
  3720. PosId = posInfo.Id,
  3721. PosSn = posInfo.PosSn,
  3722. PosUserId = posInfo.UserId,
  3723. MerchantId = posInfo.BindMerchantId,
  3724. UserId = posInfo.UserId,
  3725. ChangeFee = decimal.Parse(FeeType),
  3726. }).Entity;
  3727. db.SaveChanges();
  3728. PosId += posInfo.Id + ",";
  3729. RecordId += query.Id + ",";
  3730. }
  3731. else
  3732. {
  3733. error += "机具" + PosSn + "不存在";
  3734. }
  3735. }
  3736. if (!string.IsNullOrEmpty(error))
  3737. {
  3738. return "Warning|" + error;
  3739. }
  3740. PosId = PosId.TrimEnd(',');
  3741. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
  3742. string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  3743. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  3744. return "success";
  3745. }
  3746. #endregion
  3747. #region 根据机具号、商户号、商户姓名关联商户和机具信息
  3748. public IActionResult RelationPosAndMerchant(string right)
  3749. {
  3750. ViewBag.RightInfo = RightInfo;
  3751. ViewBag.right = right;
  3752. return View();
  3753. }
  3754. [HttpPost]
  3755. public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
  3756. {
  3757. if (string.IsNullOrEmpty(PosSn))
  3758. {
  3759. return "请输入机具SN";
  3760. }
  3761. if (string.IsNullOrEmpty(MerchantNo))
  3762. {
  3763. return "请输入商户编号";
  3764. }
  3765. if (string.IsNullOrEmpty(MerchantName))
  3766. {
  3767. return "请输入商户姓名";
  3768. }
  3769. var query = PosSn + "," + MerchantNo + "," + MerchantName;
  3770. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
  3771. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
  3772. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3773. if (posMerchant.Id == 0)
  3774. {
  3775. return "商户" + MerchantNo + "不存在";
  3776. }
  3777. else if (pos.Id == 0)
  3778. {
  3779. return "机具" + PosSn + "不存在";
  3780. }
  3781. else
  3782. {
  3783. pos.BindMerchantId = posMerchant.Id;
  3784. db.SaveChanges();
  3785. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
  3786. }
  3787. return "success";
  3788. }
  3789. #endregion
  3790. #region 设置商户信息
  3791. public IActionResult SetMerchantInfo(string right)
  3792. {
  3793. ViewBag.RightInfo = RightInfo;
  3794. ViewBag.right = right;
  3795. return View();
  3796. }
  3797. [HttpPost]
  3798. public string SetMerchantInfoDo(string PosSn, string MerchantNo, string MerchantName, string MerIdcardNo, string MerchantMobile)
  3799. {
  3800. if (string.IsNullOrEmpty(PosSn))
  3801. {
  3802. return "请输入机具SN";
  3803. }
  3804. if (string.IsNullOrEmpty(MerchantNo))
  3805. {
  3806. return "请输入商户编号";
  3807. }
  3808. if (string.IsNullOrEmpty(MerchantName))
  3809. {
  3810. return "请输入商户姓名";
  3811. }
  3812. if (string.IsNullOrEmpty(MerIdcardNo))
  3813. {
  3814. return "请输入商户身份证号";
  3815. }
  3816. if (string.IsNullOrEmpty(MerchantMobile))
  3817. {
  3818. return "请输入商户手机号";
  3819. }
  3820. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo && m.KqSnNo == PosSn && m.MerchantName.StartsWith(MerchantName.Substring(0, 1))) ?? new PosMerchantInfo();
  3821. var query = "";
  3822. query += "修改前:" + posMerchant.KqSnNo + "," + posMerchant.MerchantNo + "," + posMerchant.MerchantName + "," + posMerchant.MerIdcardNo + "," + posMerchant.MerchantMobile;
  3823. query += "修改后:" + PosSn + "," + MerchantNo + "," + MerchantName + "," + MerIdcardNo + "," + MerchantMobile;
  3824. if (posMerchant.Id == 0)
  3825. {
  3826. return "商户" + MerchantNo + "不存在或不在" + MerchantName + "名下";
  3827. }
  3828. else
  3829. {
  3830. posMerchant.MerIdcardNo = MerIdcardNo;
  3831. posMerchant.MerchantName = MerchantName;
  3832. posMerchant.MerRealName = MerchantName;
  3833. posMerchant.MerchantMobile = MerchantMobile;
  3834. db.SaveChanges();
  3835. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "设置商户信息");
  3836. }
  3837. return "success";
  3838. }
  3839. #endregion
  3840. #region 认证创客
  3841. public IActionResult AuthMaker(string right)
  3842. {
  3843. ViewBag.RightInfo = RightInfo;
  3844. ViewBag.right = right;
  3845. return View();
  3846. }
  3847. [HttpPost]
  3848. public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
  3849. {
  3850. if (string.IsNullOrEmpty(MakerCode))
  3851. {
  3852. return "请输入创客编号";
  3853. }
  3854. if (string.IsNullOrEmpty(RealName))
  3855. {
  3856. return "请输入真实姓名";
  3857. }
  3858. if (string.IsNullOrEmpty(CertId))
  3859. {
  3860. return "请输入身份证号";
  3861. }
  3862. if (string.IsNullOrEmpty(BackCard))
  3863. {
  3864. return "请输入银行卡号";
  3865. }
  3866. if (string.IsNullOrEmpty(BackName))
  3867. {
  3868. return "请输入银行名称";
  3869. }
  3870. var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
  3871. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3872. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3873. if (userInfo.AuthFlag == 1)
  3874. {
  3875. return "已认证";
  3876. }
  3877. else
  3878. {
  3879. userInfo.UpdateDate = DateTime.Now;
  3880. userInfo.RealName = RealName;
  3881. userInfo.AuthFlag = 1;
  3882. if (userInfo.AuthDate == null)
  3883. {
  3884. userInfo.AuthDate = DateTime.Now;
  3885. }
  3886. userInfo.CertId = CertId;
  3887. userInfo.SettleBankCardNo = BackCard;
  3888. userInfo.SettleBankName = BackName;
  3889. db.SaveChanges();
  3890. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
  3891. }
  3892. return "success";
  3893. }
  3894. #endregion
  3895. #region 划拨创客机具
  3896. public IActionResult TransferPos(string right)
  3897. {
  3898. ViewBag.RightInfo = RightInfo;
  3899. ViewBag.right = right;
  3900. return View();
  3901. }
  3902. [HttpPost]
  3903. // public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  3904. // {
  3905. // if (string.IsNullOrEmpty(PosSn))
  3906. // {
  3907. // return "请输入机具SN";
  3908. // }
  3909. // if (string.IsNullOrEmpty(FromMakerCode))
  3910. // {
  3911. // return "请输入机具来源创客编号";
  3912. // }
  3913. // if (string.IsNullOrEmpty(ToMakerCode))
  3914. // {
  3915. // return "请输入划拨对象创客编号";
  3916. // }
  3917. // var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
  3918. // var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3919. // var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3920. // if (posInfo.Id == 0)
  3921. // {
  3922. // return "机具" + PosSn + "不存在";
  3923. // }
  3924. // var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3925. // var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3926. // var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3927. // if (fUserId.Id == 0)
  3928. // {
  3929. // return "来源创客" + FromMakerCode + "不存在";
  3930. // }
  3931. // var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3932. // if (tUserId.Id == 0)
  3933. // {
  3934. // return "划拨创客" + ToMakerCode + "不存在";
  3935. // }
  3936. // if (posInfo.BindingState == 0)
  3937. // {
  3938. // if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  3939. // {
  3940. // posInfo.BuyUserId = tUserId.Id;
  3941. // posInfo.UserId = tUserId.Id;
  3942. // }
  3943. // else
  3944. // {
  3945. // posInfo.BuyUserId = tUserId.Id;
  3946. // }
  3947. // var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3948. // var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  3949. // fUserPos.TotalMachineCount -= 1;
  3950. // fUserPos.UnBindCount -= 1;
  3951. // tUserPos.TotalMachineCount += 1;
  3952. // tUserPos.UnBindCount += 1;
  3953. // db.SaveChanges();
  3954. // function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  3955. // }
  3956. // else
  3957. // {
  3958. // return "机具" + PosSn + "已使用";
  3959. // }
  3960. // return "success";
  3961. // }
  3962. // #endregion
  3963. public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  3964. {
  3965. if (string.IsNullOrEmpty(PosSn))
  3966. {
  3967. return "请输入机具SN";
  3968. }
  3969. if (string.IsNullOrEmpty(FromMakerCode))
  3970. {
  3971. return "请输入机具来源创客编号";
  3972. }
  3973. if (string.IsNullOrEmpty(ToMakerCode))
  3974. {
  3975. return "请输入划拨对象创客编号";
  3976. }
  3977. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3978. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3979. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3980. if (fUserId.Id == 0)
  3981. {
  3982. return "来源创客" + FromMakerCode + "不存在";
  3983. }
  3984. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3985. if (tUserId.Id == 0)
  3986. {
  3987. return "划拨创客" + ToMakerCode + "不存在";
  3988. }
  3989. List<int> SnIds = new List<int>();
  3990. string[] PosSnList = PosSn.Replace("\r", "").Replace("\n", ",").Split(',');
  3991. string error = "";
  3992. foreach (string Sn in PosSnList)
  3993. {
  3994. 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();
  3995. if (posInfo.Id == 0)
  3996. {
  3997. error += "以下操作失败" + Sn + ',' + "不存在或者不符合条件" + '\n';
  3998. }
  3999. else
  4000. {
  4001. SnIds.Add(posInfo.Id);
  4002. }
  4003. }
  4004. if (!string.IsNullOrEmpty(error))
  4005. {
  4006. return "Warning|" + error;
  4007. }
  4008. else
  4009. {
  4010. var ChangeRecordNo = "HBJJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //变更记录单号
  4011. foreach (int SnId in SnIds)
  4012. {
  4013. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
  4014. if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
  4015. {
  4016. posInfo.BuyUserId = tUserId.Id;
  4017. posInfo.UserId = tUserId.Id;
  4018. }
  4019. else
  4020. {
  4021. posInfo.BuyUserId = tUserId.Id;
  4022. }
  4023. var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4024. var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
  4025. fUserPos.TotalMachineCount -= 1;
  4026. fUserPos.UnBindCount -= 1;
  4027. tUserPos.TotalMachineCount += 1;
  4028. tUserPos.UnBindCount += 1;
  4029. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4030. {
  4031. CreateDate = DateTime.Now,
  4032. UserId = fUserId.Id, //创客
  4033. BrandId = posInfo.BrandId,//产品类型
  4034. // ChangeRecordNo = "HBJJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  4035. ChangeRecordNo = ChangeRecordNo, //变更记录单号
  4036. TransType = 1, //交易类型
  4037. SnNo = posInfo.PosSn, //SN编号
  4038. SnType = posInfo.PosSnType, //SN机具类型
  4039. StockOpDirect = 1, //库存操作方向
  4040. DeviceVendor = posInfo.DeviceName, //设备厂商
  4041. DeviceModel = posInfo.DeviceKind, //设备型号
  4042. DeviceType = posInfo.DeviceType, //设备类型
  4043. FromUserId = fUserId.Id, //出货创客
  4044. FromDate = DateTime.Now, //出库时间
  4045. FromRemark = "划拨创客机具", //出库备注
  4046. SourceStoreId = posInfo.SourceStoreId, //源仓库
  4047. ToUserId = tUserId.Id,//收货创客
  4048. });
  4049. // UserStoreChange userstore = db.UserStoreChange.Add(new UserStoreChange()
  4050. // {
  4051. // CreateDate = DateTime.Now,
  4052. // UserId = fUserId.Id, //创客
  4053. // BrandId = posInfo.BrandId, //产品类型
  4054. // ChangeRecordNo = ChangeRecordNo, //变更记录单号
  4055. // TransType = 0, //交易类型
  4056. // SnNo = posInfo.PosSn, //SN编号
  4057. // SnType = posInfo.PosSnType, //SN机具类型
  4058. // StockOpDirect = 0, //库存操作方向
  4059. // DeviceVendor = posInfo.DeviceName, //设备厂商
  4060. // DeviceType = posInfo.DeviceKind, //设备类型
  4061. // DeviceModel = posInfo.DeviceType, //设备型号
  4062. // ToUserId = tUserId.Id, //收货创客
  4063. // ToDate = DateTime.Now, //入库时间
  4064. // SourceStoreId = posInfo.SourceStoreId, //源仓库
  4065. // SnStatus = 1, //SN状态
  4066. // BindStatus = (int)posInfo.BindingState, //绑定状态
  4067. // BindMerchantId = posInfo.BindMerchantId, //绑定商户
  4068. // ActiveStatus = (int)posInfo.ActivationState, //激活状态
  4069. // ActRewardUserId = posInfo.BuyUserId, //激活奖励创客
  4070. // BrandType = posInfo.DeviceType, //品牌类型
  4071. // }).Entity;
  4072. }
  4073. var query = SnIds + ";" + FromMakerCode + ";" + ToMakerCode;
  4074. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  4075. db.SaveChanges();
  4076. db.Dispose();
  4077. }
  4078. return "success";
  4079. }
  4080. #endregion
  4081. #region 还原提现订单状态
  4082. public IActionResult RestoreStatus(string right)
  4083. {
  4084. ViewBag.RightInfo = RightInfo;
  4085. ViewBag.right = right;
  4086. return View();
  4087. }
  4088. [HttpPost]
  4089. public string RestoreStatusDo(string OrderNo)
  4090. {
  4091. if (string.IsNullOrEmpty(OrderNo))
  4092. {
  4093. return "请输入提现订单编号";
  4094. }
  4095. string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
  4096. var error = "";
  4097. foreach (var item in OrderNoList)
  4098. {
  4099. var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
  4100. if (cash.Id > 0)
  4101. {
  4102. cash.QueryCount = 0;
  4103. cash.Status = 0;
  4104. db.SaveChanges();
  4105. }
  4106. else
  4107. {
  4108. error += "订单" + item + "不存在" + '\n';
  4109. }
  4110. }
  4111. if (!string.IsNullOrEmpty(error))
  4112. {
  4113. return "Warning|" + error;
  4114. }
  4115. return "success";
  4116. }
  4117. #endregion
  4118. #region 查询创客循环资格
  4119. public IActionResult SeeUserLoop(string right)
  4120. {
  4121. ViewBag.RightInfo = RightInfo;
  4122. ViewBag.right = right;
  4123. return View();
  4124. }
  4125. [HttpPost]
  4126. public string SeeUserLoopDo(string MakerCode)
  4127. {
  4128. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  4129. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  4130. var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
  4131. var brandList = db.KqProducts.ToList();
  4132. var info = "";
  4133. foreach (var item in brandList)
  4134. {
  4135. var brand = item.Name;
  4136. //已过期
  4137. var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  4138. //可申请
  4139. var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
  4140. //已使用
  4141. // var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id && m.PosSnType == 0);
  4142. // info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
  4143. info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + "\n";
  4144. }
  4145. return info;
  4146. }
  4147. #endregion
  4148. #region 提交到代付排除的创客名单
  4149. public IActionResult CashWithoutUser(string right)
  4150. {
  4151. ViewBag.RightInfo = RightInfo;
  4152. ViewBag.right = right;
  4153. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser") ?? new CustomTagSet();
  4154. ViewBag.set = set;
  4155. return View();
  4156. }
  4157. public string CashWithoutUserDo(string Content)
  4158. {
  4159. CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser");
  4160. if (set == null)
  4161. {
  4162. set = db.CustomTagSet.Add(new CustomTagSet()
  4163. {
  4164. Tags = "CashWithoutUser",
  4165. Title = "提交到代付排除的创客名单"
  4166. }).Entity;
  4167. db.SaveChanges();
  4168. }
  4169. set.Contents = Content;
  4170. db.SaveChanges();
  4171. db.Dispose();
  4172. return "success";
  4173. }
  4174. #endregion
  4175. #region 坏机回仓
  4176. public IActionResult BadPosToStore(string right)
  4177. {
  4178. ViewBag.RightInfo = RightInfo;
  4179. ViewBag.right = right;
  4180. return View();
  4181. }
  4182. [HttpPost]
  4183. public string BadPosToStoreDo(string OldSn)
  4184. {
  4185. string[] OldSnList;
  4186. OldSnList = OldSn.Replace("\r", "").Split('\n');
  4187. string error = "";
  4188. List<string> opData = new List<string>();
  4189. for (int i = 0; i < OldSnList.Length; i++)
  4190. {
  4191. string OldSnNum = OldSnList[i];
  4192. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  4193. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId) ?? new PosMachinesTwo();
  4194. if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
  4195. {
  4196. opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
  4197. }
  4198. oldpos.Status = 1;
  4199. oldpos.PosSnType = 0;
  4200. oldpos.QueryCount = 0;
  4201. oldpos.UpdateDate = null;
  4202. oldpos.ActivityList = null;
  4203. oldpos.SeoKeyword = null;
  4204. oldpos.SeoDescription = null;
  4205. oldpos.OrderId = 0;
  4206. oldpos.RecycEndDate = null;
  4207. oldpos.RecycBackCount = 0;
  4208. oldpos.PrizeParams = null;
  4209. oldpos.ScanQrTrade = 0;
  4210. oldpos.BindMerchantId = 0;
  4211. oldpos.CreditTrade = 0;
  4212. oldpos.DebitCardTrade = 0;
  4213. oldpos.IsVip = 0;
  4214. oldpos.UserNav = null;
  4215. oldpos.TransferTime = null;
  4216. oldpos.IsPurchase = 0;
  4217. oldpos.Detail = null;
  4218. oldpos.BindingTime = null;
  4219. oldpos.BindingState = 0;
  4220. oldpos.ActivationTime = null;
  4221. oldpos.ActivationState = 0;
  4222. oldpos.LeaderUserId = 0;
  4223. oldpos.PreUserId = 0;
  4224. oldpos.IsFirst = 0;
  4225. oldpos.DownFeeMan = null;
  4226. oldpos.DownFeeFlag = 0;
  4227. oldpos.DownFeeDate = null;
  4228. oldpos.UpFeeMan = null;
  4229. oldpos.UpFeeFlag = 0;
  4230. oldpos.UpFeeDate = null;
  4231. oldpos.OpReserve1 = 0;
  4232. oldpos.OpReserve2 = 0;
  4233. oldpos.OpReserve3 = 0;
  4234. oldpos.OpId = 0;
  4235. oldpos.RecycStartDate = null;
  4236. oldpos.SourcePosSn = null;
  4237. oldpos.BuyUserId = 0;
  4238. oldpos.UserId = 0;
  4239. PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
  4240. }
  4241. if (!string.IsNullOrEmpty(error))
  4242. {
  4243. return "Warning|" + error;
  4244. }
  4245. db.SaveChanges();
  4246. foreach (string sub in opData)
  4247. {
  4248. string[] datalist = sub.Split(":");
  4249. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4250. }
  4251. return "success";
  4252. }
  4253. #endregion
  4254. #region 划拨创客机具券
  4255. public IActionResult TransferPosCoupon(string right)
  4256. {
  4257. ViewBag.RightInfo = RightInfo;
  4258. ViewBag.right = right;
  4259. return View();
  4260. }
  4261. public string TransferPosCouponDo(string Kind, string PosCouponCodes, string FromMakerCode, string ToMakerCode, string LeaderMakerCode = "")
  4262. {
  4263. if (string.IsNullOrEmpty(PosCouponCodes))
  4264. {
  4265. return "请输入机具券码";
  4266. }
  4267. if (string.IsNullOrEmpty(PosCouponCodes))
  4268. {
  4269. return "请输入机具券码";
  4270. }
  4271. if (string.IsNullOrEmpty(FromMakerCode))
  4272. {
  4273. return "请输入机具来源创客编号";
  4274. }
  4275. if (string.IsNullOrEmpty(ToMakerCode))
  4276. {
  4277. return "请输入划拨对象创客编号";
  4278. }
  4279. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  4280. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  4281. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  4282. if (fUserId.Id == 0)
  4283. {
  4284. return "来源创客" + FromMakerCode + "不存在";
  4285. }
  4286. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  4287. if (tUserId.Id == 0)
  4288. {
  4289. return "划拨创客" + ToMakerCode + "不存在";
  4290. }
  4291. int LeaderUserId = 0;
  4292. if (!string.IsNullOrEmpty(LeaderMakerCode))
  4293. {
  4294. UserForMakerCode leaderuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LeaderMakerCode) ?? new UserForMakerCode();
  4295. Users LeaderUserItem = db.Users.FirstOrDefault(m => m.Id == leaderuser.UserId) ?? new Users();
  4296. if (LeaderUserItem.Id == 0)
  4297. {
  4298. return "大盟主创客编号" + LeaderMakerCode + "不存在";
  4299. }
  4300. LeaderUserId = leaderuser.UserId;
  4301. }
  4302. string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  4303. var query = PosCouponCodes + "\n" + FromMakerCode + "," + ToMakerCode;
  4304. string[] PosCouponList = PosCouponCodes.Replace("\r", "").Replace("\n", ",").Split(',');
  4305. foreach (string PosCouponCode in PosCouponList)
  4306. {
  4307. PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == PosCouponCode) ?? new PosCoupons();
  4308. if (item.UserId != fUserId.Id)
  4309. {
  4310. return "机具券" + PosCouponCode + "不在创客" + FromMakerCode + "名下";
  4311. }
  4312. if (item.Id == 0)
  4313. {
  4314. return "机具券" + PosCouponCode + "不存在";
  4315. }
  4316. if (item.IsUse == 1)
  4317. {
  4318. return "机具券" + PosCouponCode + "已使用";
  4319. }
  4320. item.UserId = tUserId.Id;
  4321. if (LeaderUserId > 0 && item.LeaderUserId == 0)
  4322. {
  4323. item.LeaderUserId = LeaderUserId;
  4324. }
  4325. // PosCouponRecord posCouponRecord = db.PosCouponRecord.Add(new PosCouponRecord()
  4326. // {
  4327. // QueryCount = item.QueryCount,//券类型(1 电签 2 大POS)
  4328. // CreateDate = DateTime.Now,
  4329. // ChangeKind = 1,//类型(0购买,1划拨,2使⽤,3申请机具循环驳回)
  4330. // OrderNo = ChangeRecordNo,
  4331. // ToUserId = tUserId.Id,
  4332. // FromUserId = fUserId.Id,
  4333. // PosCouponId = item.Id,
  4334. // }).Entity;
  4335. }
  4336. // int CouponCount = PosCouponList.Length;
  4337. // PosCouponOrders stat = db.PosCouponOrders.Add(new PosCouponOrders()
  4338. // {
  4339. // QueryCount = 2,
  4340. // CreateDate = DateTime.Now,
  4341. // ChangeKind = 2,
  4342. // ChangeCount = CouponCount,
  4343. // // AfterOut = AfterOut,
  4344. // // AfterTotal = AfterTotal,
  4345. // // AfterStock = AfterStock,
  4346. // // BeforeOut = BeforeOut,
  4347. // // BeforeTotal = BeforeTotal,
  4348. // // BeforeStock = BeforeStock,
  4349. // OrderNo = ChangeRecordNo,
  4350. // ToUserId = tUserId.Id,
  4351. // FromUserId = fUserId.Id,
  4352. // }).Entity;
  4353. db.SaveChanges();
  4354. db.Dispose();
  4355. return "success";
  4356. }
  4357. #endregion
  4358. #region 机具回仓退款
  4359. public IActionResult RefundPosFee(string right)
  4360. {
  4361. ViewBag.RightInfo = RightInfo;
  4362. ViewBag.right = right;
  4363. return View();
  4364. }
  4365. [HttpPost]
  4366. public string RefundPosFeeDo(string PosSn, string BackStoreNo, int IsBack = 0)
  4367. {
  4368. if (string.IsNullOrEmpty(PosSn))
  4369. {
  4370. return "请输入机具SN";
  4371. }
  4372. if (IsBack == 1)
  4373. {
  4374. if (string.IsNullOrEmpty(BackStoreNo))
  4375. {
  4376. return "请输入仓库编号";
  4377. }
  4378. }
  4379. string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
  4380. WebCMSEntities db = new WebCMSEntities();
  4381. DateTime time = DateTime.Parse(DateTime.Now.ToString(("yyyy-MM-dd") + " 00:00:00"));
  4382. var endTime = time.AddDays(20 - time.Day).AddDays(-60);
  4383. StoreForCode storeForBack = new StoreForCode();
  4384. StoreHouse BackStore = new StoreHouse();
  4385. List<string> opData = new List<string>();
  4386. foreach (var item in PosSnList)
  4387. {
  4388. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  4389. if (machineForSnNo.SnId == 0)
  4390. {
  4391. return "未找到机具" + item + "关联数据";
  4392. }
  4393. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.Status > -1 && m.RecycEndDate < endTime && m.BindingState == 0) ?? new PosMachinesTwo();
  4394. if (pos.Id == 0)
  4395. {
  4396. return "机具" + item + "不存在或者不满足条件";
  4397. }
  4398. if (IsBack == 1)
  4399. {
  4400. storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  4401. if (storeForBack.StoreId == 0)
  4402. {
  4403. return "未找到" + BackStoreNo + "关联数据";
  4404. }
  4405. BackStore = db.StoreHouse.FirstOrDefault(m => m.Status > -1 && m.Id == storeForBack.StoreId && m.BrandId == pos.BrandId.ToString()) ?? new StoreHouse();
  4406. if (BackStore.Id == 0)
  4407. {
  4408. return "仓库" + BackStoreNo + "不存在或与机具品牌不符";
  4409. }
  4410. }
  4411. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BackStore.UserId) ?? new UserAccount();
  4412. var refundUserAccount = db.UserAccount.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new UserAccount();
  4413. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  4414. var amount = 0;
  4415. if (brandInfo.Name.Contains("电签"))
  4416. {
  4417. amount = 200;
  4418. }
  4419. if (brandInfo.Name.Contains("大POS"))
  4420. {
  4421. amount = 300;
  4422. }
  4423. if (IsBack == 1)
  4424. {
  4425. userAccount.ValidAmount -= amount;//扣减分仓可用额度
  4426. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  4427. {
  4428. CreateDate = DateTime.Now,
  4429. CreateMan = SysUserName,
  4430. StoreId = pos.StoreId, //出货仓库
  4431. BrandId = pos.BrandId, //产品类型
  4432. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  4433. TransType = 5, //交易类型
  4434. SnNo = item, //SN编号
  4435. StockOpDirect = 0, //库存操作方向
  4436. SnStatus = 1, //SN状态
  4437. DeviceVendor = pos.DeviceName, //设备厂商
  4438. DeviceModel = pos.DeviceKind, //设备型号
  4439. DeviceType = pos.DeviceType, //设备类型
  4440. FromUserId = pos.BuyUserId, //来源创客
  4441. ToRemark = "过期机具回仓退款", //入库备注
  4442. ToStoreId = BackStore.Id, //退货收货仓库
  4443. SourceStoreId = pos.SourceStoreId, //源仓库编号
  4444. BrandType = pos.DeviceType, //品牌类型
  4445. }).Entity;
  4446. string ChangeNo = "HCTK";
  4447. int StoreStockChangeId = stockchange.Id;
  4448. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  4449. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  4450. {
  4451. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  4452. }
  4453. ChangeNo += StoreStockChangeIdString;
  4454. stockchange.ChangeNo = ChangeNo; //交易流水编号
  4455. db.StoreChangeHistory.Add(new StoreChangeHistory()
  4456. {
  4457. CreateDate = DateTime.Now,
  4458. BrandId = pos.BrandId, //产品类型
  4459. ChangeRecordNo = ChangeNo, //变更记录单号
  4460. TransType = 5, //交易类型
  4461. SnNo = item, //SN编号
  4462. SnType = pos.PosSnType, //SN机具类型
  4463. StockOpDirect = 0, //库存操作方向
  4464. DeviceVendor = pos.DeviceName, //设备厂商
  4465. DeviceModel = pos.DeviceKind, //设备型号
  4466. DeviceType = pos.DeviceType, //设备类型
  4467. FromUserId = pos.BuyUserId, //来源创客
  4468. ToRemark = "过期机具回仓退款", //入库备注
  4469. SourceStoreId = pos.SourceStoreId, //源仓库
  4470. StoreId = pos.StoreId, //出货仓库
  4471. });
  4472. db.MachineReturn.Add(new MachineReturn()
  4473. {
  4474. CreateDate = DateTime.Now,
  4475. Operator = SysUserName + "_" + SysRealName,//操作人
  4476. BrandId = pos.BrandId, //产品类型
  4477. DeviceSnNos = pos.PosSn,
  4478. ToStoreId = BackStore.Id,
  4479. ApplyNo = ChangeNo, //变更记录单号
  4480. UserId = pos.BuyUserId, //来源创客
  4481. Remark = "过期机具回仓退款", //入库备注
  4482. });
  4483. if (pos.ScanQrTrade > 0)
  4484. {
  4485. decimal ChangeAmount = 0;
  4486. decimal BeforeBalanceAmount = 0;
  4487. decimal AfterBalanceAmount = 0;
  4488. if (pos.ScanQrTrade == 999)
  4489. {
  4490. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4491. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4492. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4493. ChangeAmount = amount;
  4494. }
  4495. else
  4496. {
  4497. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4498. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4499. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4500. ChangeAmount = pos.ScanQrTrade;
  4501. }
  4502. db.UserAccountRecord.Add(new UserAccountRecord()
  4503. {
  4504. CreateDate = DateTime.Now,
  4505. UpdateDate = DateTime.Now,
  4506. UserId = pos.BuyUserId, //创客
  4507. ChangeType = 126, //变动类型(机具货款退还)
  4508. ProductType = 0, //产品类型
  4509. ChangeAmount = ChangeAmount, //变更金额
  4510. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4511. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4512. });
  4513. }
  4514. var bInfo = BackStore.UserId + "_" + pos.BrandId;
  4515. var userMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == bInfo) ?? new UserMachineData();
  4516. userMachineData.TotalMachineCount += 1;
  4517. userMachineData.UnBindCount += 1;
  4518. BackStore.LaveNum += 1;
  4519. BackStore.TotalNum += 1;
  4520. var fInfo = pos.BuyUserId + "_" + pos.BrandId;
  4521. var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
  4522. userMachineDatas.TotalMachineCount -= 1;
  4523. userMachineDatas.UnBindCount -= 1;
  4524. if (!opData.Contains(pos.BuyUserId + ":" + pos.BrandId))
  4525. {
  4526. opData.Add(pos.BuyUserId + ":" + pos.BrandId);
  4527. }
  4528. pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
  4529. pos.Status = 1;
  4530. pos.QueryCount = 0;
  4531. pos.UpdateDate = null;
  4532. pos.ActivityList = null;
  4533. pos.SeoKeyword = null;
  4534. pos.SeoDescription = null;
  4535. pos.OrderId = 0;
  4536. pos.RecycEndDate = null;
  4537. pos.RecycBackCount = 0;
  4538. pos.PrizeParams = null;
  4539. pos.ScanQrTrade = 0;
  4540. pos.BindMerchantId = 0;
  4541. pos.CreditTrade = 0;
  4542. pos.DebitCardTrade = 0;
  4543. pos.IsVip = 0;
  4544. pos.UserNav = null;
  4545. pos.TransferTime = null;
  4546. pos.IsPurchase = 0;
  4547. pos.Detail = null;
  4548. pos.BindingTime = null;
  4549. pos.BindingState = 0;
  4550. pos.ActivationTime = null;
  4551. pos.ActivationState = 0;
  4552. pos.LeaderUserId = 0;
  4553. pos.PreUserId = 0;
  4554. pos.IsFirst = 0;
  4555. pos.DownFeeMan = null;
  4556. pos.DownFeeFlag = 0;
  4557. pos.DownFeeDate = null;
  4558. pos.UpFeeMan = null;
  4559. pos.UpFeeFlag = 0;
  4560. pos.UpFeeDate = null;
  4561. pos.OpReserve1 = 0;
  4562. pos.OpReserve2 = 0;
  4563. pos.OpReserve3 = 0;
  4564. pos.OpId = 0;
  4565. pos.RecycStartDate = null;
  4566. pos.SourcePosSn = null;
  4567. pos.BuyUserId = 0;
  4568. pos.UserId = 0;
  4569. PublicFunction.ClearPosHistory(db, pos.PosSn); //清除机具历史记录
  4570. }
  4571. else
  4572. {
  4573. if (pos.ScanQrTrade > 0)
  4574. {
  4575. decimal ChangeAmount = 0;
  4576. decimal BeforeBalanceAmount = 0;
  4577. decimal AfterBalanceAmount = 0;
  4578. if (pos.ScanQrTrade == 999)
  4579. {
  4580. refundUserAccount.BalanceAmount += amount;//退还创客机具货款
  4581. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4582. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4583. ChangeAmount = amount;
  4584. }
  4585. else
  4586. {
  4587. refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
  4588. BeforeBalanceAmount = refundUserAccount.BalanceAmount;
  4589. AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
  4590. ChangeAmount = pos.ScanQrTrade;
  4591. }
  4592. pos.ScanQrTrade = 0;
  4593. db.UserAccountRecord.Add(new UserAccountRecord()
  4594. {
  4595. CreateDate = DateTime.Now,
  4596. UpdateDate = DateTime.Now,
  4597. UserId = pos.BuyUserId, //创客
  4598. ChangeType = 126, //变动类型(机具货款退还)
  4599. ProductType = 0, //产品类型
  4600. ChangeAmount = ChangeAmount, //变更金额
  4601. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  4602. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  4603. });
  4604. }
  4605. }
  4606. }
  4607. db.SaveChanges();
  4608. foreach (string sub in opData)
  4609. {
  4610. string[] datalist = sub.Split(":");
  4611. PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
  4612. }
  4613. return "success";
  4614. }
  4615. #endregion
  4616. #region 添加商户信息
  4617. public IActionResult AddMerchantnfo(string right)
  4618. {
  4619. ViewBag.RightInfo = RightInfo;
  4620. ViewBag.right = right;
  4621. return View();
  4622. }
  4623. [HttpPost]
  4624. public string AddMerchantnfoDo(string PosSn, string MerSn)
  4625. {
  4626. if (string.IsNullOrEmpty(PosSn))
  4627. {
  4628. return "请输入机具号";
  4629. }
  4630. if (string.IsNullOrEmpty(MerSn))
  4631. {
  4632. return "请输入商户号";
  4633. }
  4634. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  4635. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  4636. var merchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4637. if (machineForSnNo.SnId == 0)
  4638. {
  4639. return "未找到机具" + PosSn + "关联数据";
  4640. }
  4641. if (pos.Id == 0)
  4642. {
  4643. return "未找到机具" + PosSn;
  4644. }
  4645. if (merchantInfo.Id > 0)
  4646. {
  4647. return "机具" + PosSn + "以经存在绑定商户";
  4648. }
  4649. var spInfo = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerSn && m.MerSnNo == PosSn) ?? new SpModels.BindRecord();
  4650. if (spInfo.Id > 0)
  4651. {
  4652. var MerUserType = 0;
  4653. var ActiveStatus = 0;
  4654. if (pos.BuyUserId != pos.UserId)
  4655. {
  4656. MerUserType = 1;
  4657. }
  4658. if (string.IsNullOrEmpty(pos.ActivationTime.ToString()))
  4659. {
  4660. ActiveStatus = 1;
  4661. }
  4662. PosMerchantInfo posMerchantInfo = db.PosMerchantInfo.Add(new PosMerchantInfo()
  4663. {
  4664. CreateDate = pos.BindingTime,
  4665. TopUserId = 1,
  4666. BrandId = pos.BrandId,
  4667. SnStoreId = pos.StoreId,
  4668. MerStandardDate = pos.ActivationTime,
  4669. SnType = pos.PosSnType,
  4670. MerUserType = MerUserType,
  4671. UserId = pos.UserId,
  4672. ActiveStatus = ActiveStatus,
  4673. MerStatus = 1,
  4674. KqSnNo = PosSn,
  4675. KqMerNo = MerSn,
  4676. MerIdcardNo = spInfo.SeoKeyword,
  4677. MerchantMobile = spInfo.MerNewSnNo,
  4678. MerchantName = spInfo.MerName,
  4679. MerchantNo = spInfo.MerNo,
  4680. }).Entity;
  4681. db.SaveChanges();
  4682. string text = string.Format("设置商户信息,机具Sn: " + PosSn + ",商户编号: " + MerSn + ",操作人:" + SysUserName + "_" + SysRealName + ",时间:" + DateTime.Now + "");
  4683. function.WriteLog(text, "设置商户信息");
  4684. }
  4685. return "success";
  4686. }
  4687. #endregion
  4688. #region 查询商户达标明细
  4689. public IActionResult SeeMerchantTradeDetail(string right)
  4690. {
  4691. ViewBag.RightInfo = RightInfo;
  4692. ViewBag.right = right;
  4693. return View();
  4694. }
  4695. [HttpPost]
  4696. public string SeeMerchantTradeDetailDo(string PosSn)
  4697. {
  4698. if (string.IsNullOrEmpty(PosSn))
  4699. {
  4700. return "请输入机具SN";
  4701. }
  4702. var result = "";
  4703. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  4704. if (pos.Id > 0)
  4705. {
  4706. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  4707. if (mer.Id > 0)
  4708. {
  4709. var IsOk = "";//是否达标
  4710. var timeInfo = "";
  4711. if (mer.StandardMonths == 10)
  4712. {
  4713. IsOk = "已达标";
  4714. }
  4715. else
  4716. {
  4717. IsOk = "未达标";
  4718. }
  4719. result += IsOk + "\n";
  4720. result += "开机时间:" + DateTime.Parse(pos.BindingTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  4721. result += "激活时间:" + DateTime.Parse(pos.ActivationTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  4722. result += "商户姓名:" + mer.MerRealName + "\n";
  4723. result += "明细:\n";
  4724. for (int i = 0; i < 12; i++)
  4725. {
  4726. var time = DateTime.Parse(pos.ActivationTime.ToString()).AddMonths(i + 1).ToString("yyyyMM");//达标计算开始时间
  4727. timeInfo += "," + time;
  4728. }
  4729. timeInfo = timeInfo + ",";
  4730. var merTradeInfo = db.PosMerchantTradeSummay.Where(m => m.MerchantId == mer.Id && timeInfo.Contains("," + m.TradeMonth + ",")).ToList();
  4731. string[] month = timeInfo.TrimStart(',').TrimEnd(',').Split(',');
  4732. foreach (var item in month)
  4733. {
  4734. var tradeAmount = merTradeInfo.Where(m => m.TradeMonth == item).Sum(m => m.TradeAmount);
  4735. result += item + "交易额:" + tradeAmount + "\n";
  4736. }
  4737. }
  4738. else
  4739. {
  4740. return "未找到机具" + PosSn + "所对应的商户";
  4741. }
  4742. }
  4743. else
  4744. {
  4745. return "未找到机具" + PosSn;
  4746. }
  4747. return result;
  4748. }
  4749. #endregion
  4750. #region 指定文件Excel导出
  4751. public IActionResult ExportExcel(string right)
  4752. {
  4753. ViewBag.RightInfo = RightInfo;
  4754. ViewBag.right = right;
  4755. return View();
  4756. }
  4757. [HttpPost]
  4758. public string ExportExcelDo(string FileName, string Operator, string Sql, int Number = 0)
  4759. {
  4760. if (string.IsNullOrEmpty(FileName))
  4761. {
  4762. return "请输入文件名";
  4763. }
  4764. if (string.IsNullOrEmpty(Operator))
  4765. {
  4766. return "请输入后台操作人";
  4767. }
  4768. if (string.IsNullOrEmpty(Sql))
  4769. {
  4770. return "请输入SQL语句";
  4771. }
  4772. var SqlString = "";
  4773. if (Number == 0)
  4774. {
  4775. SqlString = Sql;
  4776. }
  4777. if (Number > 0)
  4778. {
  4779. SqlString = Sql + " LIMIT " + Number;
  4780. }
  4781. string[] Operators = Operator.Replace("\r", "").Replace("\n", ",").Split(',');
  4782. foreach (var item in Operators)
  4783. {
  4784. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == item && m.Status > -1);
  4785. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + SqlString + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"" + Number + "\"}";
  4786. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  4787. }
  4788. return "success";
  4789. }
  4790. #endregion
  4791. #region 服务费返现注册查询
  4792. public IActionResult SeeMerchantAuthInfo(string right)
  4793. {
  4794. ViewBag.RightInfo = RightInfo;
  4795. ViewBag.right = right;
  4796. return View();
  4797. }
  4798. #endregion
  4799. #region 服务费返现注册查询
  4800. public JsonResult SeeMerchantAuthInfoDo(string RealName, string Mobile, string CertId, int page = 1, int limit = 30)
  4801. {
  4802. var query = db.UserFamilyMember.Where(m => m.Status > -1);
  4803. if (string.IsNullOrEmpty(RealName) && string.IsNullOrEmpty(Mobile) && string.IsNullOrEmpty(CertId))
  4804. {
  4805. Dictionary<string, object> objs = new Dictionary<string, object>();
  4806. return Json(objs);
  4807. }
  4808. else
  4809. {
  4810. if (!string.IsNullOrEmpty(RealName))
  4811. {
  4812. query = query.Where(m => m.Name == RealName);
  4813. }
  4814. if (!string.IsNullOrEmpty(Mobile))
  4815. {
  4816. query = query.Where(m => m.Mobile == Mobile);
  4817. }
  4818. if (!string.IsNullOrEmpty(CertId))
  4819. {
  4820. query = query.Where(m => m.IdCardNo.ToUpper() == CertId.ToUpper());
  4821. }
  4822. }
  4823. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  4824. foreach (var subdata in query.ToList())
  4825. {
  4826. Dictionary<string, object> data = new Dictionary<string, object>();
  4827. if (subdata.Id > 0)
  4828. {
  4829. data["IsRegist"] = "已注册";
  4830. if (subdata.Status == 1)
  4831. {
  4832. data["IsAuth"] = "已认证";
  4833. data["Name"] = subdata.Name;
  4834. data["Mobile"] = subdata.Mobile;
  4835. data["IdcardNo"] = subdata.IdCardNo;
  4836. var linkCount = db.PosMerchantInfo.Count(m => m.MerRealName == subdata.Name && m.MerchantMobile == subdata.Mobile && m.MerIdcardNo.ToUpper() == subdata.IdCardNo.ToUpper());
  4837. data["Count"] = linkCount;
  4838. }
  4839. else
  4840. {
  4841. data["IsAuth"] = "未认证";
  4842. data["Name"] = "";
  4843. data["Mobile"] = subdata.Mobile;
  4844. data["IdcardNo"] = "";
  4845. data["Count"] = "";
  4846. }
  4847. }
  4848. else
  4849. {
  4850. data["IsRegist"] = "未注册";
  4851. data["IsAuth"] = "未认证";
  4852. data["Name"] = "";
  4853. data["Mobile"] = "";
  4854. data["IdcardNo"] = "";
  4855. data["Count"] = "";
  4856. }
  4857. dataList.Add(data);
  4858. }
  4859. Dictionary<string, object> obj = new Dictionary<string, object>();
  4860. obj.Add("code", 0);
  4861. obj.Add("msg", "");
  4862. obj.Add("count", dataList.Count);
  4863. obj.Add("data", dataList);
  4864. return Json(obj);
  4865. }
  4866. #endregion
  4867. #region 直营团队数据
  4868. public IActionResult Team1Info(string right)
  4869. {
  4870. ViewBag.RightInfo = RightInfo;
  4871. ViewBag.right = right;
  4872. return View();
  4873. }
  4874. #endregion
  4875. #region 直营团队数据
  4876. public JsonResult Team1InfoDo(string MakerCode, string BindingTime, string ActivationTime, string PosFeeSelect, string BrandId, int page = 1, int limit = 30)
  4877. {
  4878. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  4879. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  4880. string condition = " where 1=1";
  4881. var UserId = 0;
  4882. var bstart = "";
  4883. var bend = "";
  4884. var astart = "";
  4885. var aend = "";
  4886. if (!string.IsNullOrEmpty(MakerCode))
  4887. {
  4888. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
  4889. UserId = user.Id;
  4890. }
  4891. if (!string.IsNullOrEmpty(BindingTime))
  4892. {
  4893. string[] datelist = BindingTime.Split(new string[] { " - " }, StringSplitOptions.None);
  4894. bstart = datelist[0] + " 00:00:00";
  4895. bend = datelist[1] + " 23:59:59";
  4896. condition += " and tb.BindingTime>='" + bstart + "' and tb.BindingTime<'" + bend + "'";
  4897. }
  4898. if (!string.IsNullOrEmpty(ActivationTime))
  4899. {
  4900. string[] datelist = ActivationTime.Split(new string[] { " - " }, StringSplitOptions.None);
  4901. astart = datelist[0] + " 00:00:00";
  4902. aend = datelist[1] + " 23:59:59";
  4903. condition += " and tb.ActivationTime>='" + astart + "' and tb.ActivationTime<'" + aend + "'";
  4904. }
  4905. if (!string.IsNullOrEmpty(PosFeeSelect))
  4906. {
  4907. if (PosFeeSelect == "0")
  4908. {
  4909. condition += " and tb.SeoKeyword is null";
  4910. }
  4911. else
  4912. {
  4913. condition += " and tb.SeoKeyword=" + PosFeeSelect;
  4914. }
  4915. }
  4916. if (!string.IsNullOrEmpty(BrandId))
  4917. {
  4918. condition += " and tb.BrandId=" + BrandId;
  4919. }
  4920. 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);
  4921. foreach (DataRow item in dt.Rows)
  4922. {
  4923. Dictionary<string, object> curData = new Dictionary<string, object>();
  4924. curData.Add("wname", item["wname"].ToString()); //伙伴名称
  4925. curData.Add("Name", item["Name"].ToString()); //机具品牌
  4926. curData.Add("PosSn", item["PosSn"].ToString()); //机具Sn
  4927. curData.Add("SeoKeyword", item["SeoKeyword"].ToString()); //服务费
  4928. curData.Add("BindingTime", string.IsNullOrEmpty(item["BindingTime"].ToString()) ? "" : Convert.ToDateTime(item["BindingTime"]).ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  4929. curData.Add("ActivationTime", string.IsNullOrEmpty(item["ActivationTime"].ToString()) ? "" : Convert.ToDateTime(item["ActivationTime"]).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  4930. dataList.Add(curData);
  4931. }
  4932. Dictionary<string, object> obj = new Dictionary<string, object>();
  4933. obj.Add("code", 0);
  4934. obj.Add("msg", "");
  4935. obj.Add("count", dataList.Count);
  4936. obj.Add("data", dataList);
  4937. return Json(obj);
  4938. }
  4939. #endregion
  4940. #region 直营团队数据导出
  4941. public IActionResult ExportTeam1InfoExcel(string right)
  4942. {
  4943. ViewBag.RightInfo = RightInfo;
  4944. ViewBag.right = right;
  4945. return View();
  4946. }
  4947. [HttpPost]
  4948. public string ExportTeam1InfoExcelDo(string MakerCode, string BindingTime, string ActivationTime, string PosFeeSelect, string BrandId)
  4949. {
  4950. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  4951. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  4952. var RealName = "";
  4953. string condition = " where 1=1";
  4954. var UserId = 0;
  4955. var bstart = "";
  4956. var bend = "";
  4957. var astart = "";
  4958. var aend = "";
  4959. if (!string.IsNullOrEmpty(MakerCode))
  4960. {
  4961. var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
  4962. UserId = user.Id;
  4963. RealName = user.RealName;
  4964. }
  4965. if (!string.IsNullOrEmpty(BindingTime))
  4966. {
  4967. string[] datelist = BindingTime.Split(new string[] { " - " }, StringSplitOptions.None);
  4968. bstart = datelist[0] + " 00:00:00";
  4969. bend = datelist[1] + " 23:59:59";
  4970. condition += " and tb.BindingTime>='" + bstart + "' and tb.BindingTime<'" + bend + "'";
  4971. }
  4972. if (!string.IsNullOrEmpty(ActivationTime))
  4973. {
  4974. string[] datelist = ActivationTime.Split(new string[] { " - " }, StringSplitOptions.None);
  4975. astart = datelist[0] + " 00:00:00";
  4976. aend = datelist[1] + " 23:59:59";
  4977. condition += " and tb.ActivationTime>='" + astart + "' and tb.ActivationTime<'" + aend + "'";
  4978. }
  4979. if (!string.IsNullOrEmpty(PosFeeSelect))
  4980. {
  4981. if (PosFeeSelect == "0")
  4982. {
  4983. condition += " and tb.SeoKeyword is null";
  4984. }
  4985. else
  4986. {
  4987. condition += " and tb.SeoKeyword=" + PosFeeSelect;
  4988. }
  4989. }
  4990. if (!string.IsNullOrEmpty(BrandId))
  4991. {
  4992. condition += " and tb.BrandId=" + BrandId;
  4993. }
  4994. 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;
  4995. var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
  4996. var FileName = MakerCode + RealName + "直营团队数据记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  4997. string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
  4998. RedisDbconn.Instance.AddList("ExportQueue", SendData);
  4999. return "success";
  5000. }
  5001. #endregion
  5002. }
  5003. }