SysToolsController.cs 264 KB

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