SysToolsController.cs 265 KB

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