SysToolsController.cs 271 KB

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