SysToolsController.cs 261 KB

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