SysToolsController.cs 269 KB

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