SysToolsController.cs 265 KB

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