SysToolsController.cs 271 KB

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