| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009 |
- /*
- * 机具激活限制信息
- */
- using System;
- using System.Web;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.Models;
- using System.Data;
- using Library;
- using LitJson;
- using MySystemLib;
- using System.Text.RegularExpressions;
- using System.Security.Cryptography;
- using System.Security.Cryptography.X509Certificates;
- using System.Text;
- using System.Net;
- using System.Net.Security;
- using System.IO;
- namespace MySystem.Areas.Admin.Controllers
- {
- [Area("Admin")]
- [Route("Admin/[controller]/[action]")]
- public class SysToolsController : BaseController
- {
- public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 关联上下级
- public IActionResult RelationForUser(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(ParentMakerCode))
- {
- return "请输入上级创客编号";
- }
- MakerCode = MakerCode.ToUpper();
- ParentMakerCode = ParentMakerCode.ToUpper();
- Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
- if (puser != null)
- {
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user != null)
- {
- user.ParentUserId = puser.Id;
- user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
- if (IsTeam == 1)
- {
- RelationForUserSub(db, user.Id, user);
- }
- db.SaveChanges();
- function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
- return "success";
- }
- return "创客编号不存在";
- }
- return "上级创客编号不存在";
- }
- private void RelationForUserSub(WebCMSEntities dbnew, int ParentUserId, Users puser)
- {
- var subusers = dbnew.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
- foreach (var subuser in subusers)
- {
- Users user = dbnew.Users.FirstOrDefault(m => m.Id == subuser.Id);
- if (user != null)
- {
- user.ParentUserId = puser.Id;
- user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
- RelationForUserSub(dbnew, user.Id, user);
- }
- }
- }
- #endregion
- #region 机具补录
- public IActionResult CheckMachine(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string CheckMachineDo(string MakerCode, string PosSn, int AddActPrize = 0, int IsSend = 0)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- var MerNo = "";
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "创客编号不存在";
- }
- if (pos.PreUserId > 0)
- {
- if (pos.BuyUserId == 0)
- {
- pos.BuyUserId = user.Id;
- }
- if (pos.UserId == 0)
- {
- pos.UserId = user.Id;
- }
- }
- if (pos.BindingState == 0)
- {
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
- if (bind != null)
- {
- pos.BindingState = 1;
- pos.BindingTime = bind.CreateTime;
- db.SaveChanges();
- MerNo = bind.MerNo;
- }
- }
- decimal CreditTrade = 0;
- string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
- string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
- int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
- bool check = spdb.TradeRecord.Any(m => m.Id > StartId && m.TradeSnNo == pos.PosSn);
- if (check)
- {
- if (pos.BrandId == 1)
- {
- 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;
- }
- else if (pos.BrandId == 2)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
- }
- else if (pos.BrandId == 3)
- {
- 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;
- }
- else if (pos.BrandId == 4 || pos.BrandId == 5)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 6)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 7)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 8)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 9)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 10 || pos.BrandId == 11)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
- }
- else if (pos.BrandId == 12)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "12").Sum(m => m.TradeAmount);
- }
- pos.CreditTrade = CreditTrade;
- db.SaveChanges();
- }
- if (AddActPrize == 1)
- {
- if (pos.BuyUserId == 0)
- {
- return "机具未划拨,无法补录激活奖励";
- }
- if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
- {
- bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
- if (has)
- {
- SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
- pos.SeoKeyword = chkAct.SeoTitle;
- db.SaveChanges();
- }
- }
- if (pos.BindingTime != null && pos.ActivationTime != null)
- {
- TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
- if (ts.TotalDays <= 30 || SysUserName == "admin")
- {
- AddAct(pos.Id);
- }
- }
- }
- decimal CheckMoney = 1000;
- if (pos.BrandId == 6)
- {
- CheckMoney = 5000;
- }
- if (pos.BuyUserId > 0)
- {
- if (pos.CreditTrade < CheckMoney)
- {
- return "该机具贷记卡累计交易不足" + CheckMoney;
- }
- if (pos.BindingTime != null && pos.ActivationTime != null)
- {
- TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
- if (ts.TotalDays > 30 && SysUserName != "admin")
- {
- return "机具划拨后已超过30天";
- }
- }
- if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
- {
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (pos.ActivationState == 1 && mer != null)
- {
- mer.ActiveStatus = 1;
- mer.MerStandardDate = DateTime.Now;
- }
- }
- else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
- {
- if (AddActPrize == 1)
- {
- if (IsSend == 1)
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = pos.BuyUserId, //接收创客
- MsgType = 2,
- Title = "补录成功通知", //标题
- Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
- CreateDate = DateTime.Now,
- }));
- }
- return "激活奖励已补录";
- }
- else
- {
- return "数据正常,无需补录";
- }
- }
- db.SaveChanges();
- return "success";
- }
- pos.UserId = user.Id;
- pos.BuyUserId = user.Id;
- if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
- {
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- }
- PosMerchantInfo merchant = new PosMerchantInfo();
- if (!string.IsNullOrEmpty(MerNo))
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
- if (merchant == null)
- {
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
- if (bind == null)
- {
- return "该机具尚未绑定";
- }
- SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
- if (Mer == null)
- {
- return "该机具尚未绑定";
- }
- PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
- {
- CreateDate = Mer.CreateTime,
- UpdateDate = Mer.UpdateTime,
- TopUserId = TopUserId,
- MerUserType = user.MerchantType,
- BrandId = int.Parse(Mer.ProductType),
- SnStoreId = pos.StoreId,
- SnType = pos.PosSnType,
- UserId = user.Id,
- MgrName = Mer.AgentName,
- MerStatus = 1,
- KqSnNo = Mer.SnNo,
- KqMerNo = Mer.MerNo,
- MerIdcardNo = Mer.MerIdcardNo,
- MerRealName = Mer.MerRealName,
- MerchantMobile = Mer.MerMobile,
- MerchantName = Mer.MerName,
- MerchantNo = Mer.MerNo,
- }).Entity;
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
- if (forMerNo == null)
- {
- forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
- {
- MerNo = Mer.MerNo,
- SnId = pos.Id,
- }).Entity;
- }
- else
- {
- forMerNo.SnId = pos.Id;
- }
- }
- }
- else
- {
- if (pos.BindMerchantId > 0)
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- }
- else
- {
- return "找不到机具所属商户";
- }
- }
- merchant.UserId = user.Id;
- if (pos.ActivationState == 1)
- {
- merchant.ActiveStatus = 1;
- merchant.MerStandardDate = DateTime.Now;
- }
- if (pos.BindMerchantId == 0)
- {
- pos.BindMerchantId = merchant.Id;
- }
- db.SaveChanges();
- function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize, "机具补录日志");
- return "success";
- }
- public IActionResult CheckMachine2(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "创客编号不存在";
- }
- if (pos.BindingState == 0)
- {
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
- if (bind != null)
- {
- pos.BindingState = 1;
- pos.BindingTime = bind.CreateTime;
- db.SaveChanges();
- MerNo = bind.MerNo;
- }
- }
- decimal CreditTrade = 0;
- bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
- if (check)
- {
- string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
- string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
- int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
- if (pos.BrandId == 1)
- {
- 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;
- }
- else if (pos.BrandId == 2)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
- }
- else if (pos.BrandId == 3)
- {
- 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;
- }
- else if (pos.BrandId == 4 || pos.BrandId == 5)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 6)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 8)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 9)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
- }
- else if (pos.BrandId == 10 || pos.BrandId == 11)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "10").Sum(m => m.TradeAmount);
- }
- else if (pos.BrandId == 12)
- {
- CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "12").Sum(m => m.TradeAmount);
- }
- pos.CreditTrade = CreditTrade;
- db.SaveChanges();
- }
- if (AddActPrize == 1)
- {
- if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
- {
- bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
- if (has)
- {
- SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
- pos.SeoKeyword = chkAct.SeoTitle;
- db.SaveChanges();
- }
- }
- AddAct(pos.Id);
- }
- if (pos.BuyUserId > 0)
- {
- if (pos.CreditTrade < 1000)
- {
- db.SaveChanges();
- return "该机具贷记卡累计交易不足1000";
- }
- if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
- {
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (pos.ActivationState == 1 && mer != null)
- {
- mer.ActiveStatus = 1;
- mer.MerStandardDate = DateTime.Now;
- }
- }
- else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
- {
- if (AddActPrize == 1)
- {
- return "激活奖励已补录";
- }
- else
- {
- return "数据正常,无需补录";
- }
- }
- db.SaveChanges();
- return "success";
- }
- pos.UserId = user.Id;
- pos.BuyUserId = user.Id;
- if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
- {
- pos.ActivationState = 1;
- pos.ActivationTime = DateTime.Now;
- }
- PosMerchantInfo merchant = new PosMerchantInfo();
- if (!string.IsNullOrEmpty(MerNo))
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
- if (merchant == null)
- {
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
- if (bind == null)
- {
- return "该机具尚未绑定";
- }
- SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
- if (Mer == null)
- {
- return "该机具尚未绑定";
- }
- PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
- {
- CreateDate = Mer.CreateTime,
- UpdateDate = Mer.UpdateTime,
- TopUserId = TopUserId,
- MerUserType = user.MerchantType,
- BrandId = int.Parse(Mer.ProductType),
- SnStoreId = pos.StoreId,
- SnType = pos.PosSnType,
- UserId = user.Id,
- MgrName = Mer.AgentName,
- MerStatus = 1,
- KqSnNo = Mer.SnNo,
- KqMerNo = Mer.MerNo,
- MerIdcardNo = Mer.MerIdcardNo,
- MerRealName = Mer.MerRealName,
- MerchantMobile = Mer.MerMobile,
- MerchantName = Mer.MerName,
- MerchantNo = Mer.MerNo,
- }).Entity;
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
- if (forMerNo == null)
- {
- forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
- {
- MerNo = Mer.MerNo,
- SnId = pos.Id,
- }).Entity;
- }
- else
- {
- forMerNo.SnId = pos.Id;
- }
- }
- }
- else
- {
- if (pos.BindMerchantId > 0)
- {
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- }
- else
- {
- return "找不到机具所属商户";
- }
- }
- merchant.UserId = user.Id;
- if (pos.ActivationState == 1)
- {
- merchant.ActiveStatus = 1;
- merchant.MerStandardDate = DateTime.Now;
- }
- if (pos.BindMerchantId == 0)
- {
- pos.BindMerchantId = merchant.Id;
- }
- db.SaveChanges();
- return "success";
- }
- public void AddAct(int posid = 0)
- {
- WebCMSEntities db = new WebCMSEntities();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && m.Id == posid);
- if (pos != null)
- {
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant != null)
- {
- string ParentNav = "";
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
- if (user != null)
- {
- int GetUserId = user.Id;
- ParentNav = user.ParentNav;
- int TopUserId = 1;
- if (!string.IsNullOrEmpty(ParentNav))
- {
- string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- if (ParentNavList.Length > 1)
- {
- TopUserId = int.Parse(ParentNavList[1]);
- }
- else if (ParentNavList.Length == 1)
- {
- TopUserId = int.Parse(ParentNavList[0]);
- }
- }
- List<decimal> prizes = new List<decimal>();
- decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
- {
- ActPrize = ActPrize / 100;
- }
- if (ActPrize > 0)
- {
- if (ActPrize == 99)
- {
- ActPrize = 100;
- }
- else if (ActPrize == 199)
- {
- ActPrize = 200;
- }
- else if (ActPrize == 299)
- {
- ActPrize = 300;
- }
- else if (ActPrize == 249)
- {
- ActPrize = 260;
- }
- prizes.Add(ActPrize);
- if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
- {
- prizes.Add(40);
- }
- }
- else if (pos.BrandId == 6 && ActPrize == 0) //立刷首台无押金机返50
- {
- prizes.Add(50);
- }
- 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
- {
- prizes.Add(50);
- }
- else if (pos.BrandId == 12 && pos.IsFirst == 1 && ActPrize == 0) //盒易付首台无押金机返50
- {
- prizes.Add(50);
- }
- foreach (decimal prize in prizes)
- {
- int ChangeType = prize == 40 ? 12 : 0;
- bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
- if (!check)
- {
- Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- db.ActiveReward.Add(new ActiveReward()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = GetUserId, //创客
- MerchantId = pos.BindMerchantId, //商户
- StandardDate = pos.ActivationTime, //达标日期
- RewardAmount = prize, //奖励金额
- BrandId = pos.BrandId, //品牌
- UserNav = ParentNav, //创客父级
- DirectBuddyNo = merchant.UserId, //商户直属创客
- KqMerNo = merchant.KqMerNo, //渠道商户编号
- KqSnNo = pos.PosSn, //渠道SN号
- SnType = pos.PosSnType, //机具类型
- SnApplyUserId = pos.BuyUserId, //机具申请创客
- ActType = 0, //激活类型
- SnStoreId = pos.StoreId, //SN仓库
- RewardTips = "激活奖励", //奖励描述
- Remark = "激活奖励", //备注
- ActDate = pos.ActivationTime, //激活时间
- TopUserId = TopUserId, //顶级创客
- SeoTitle = machineUser.RealName,
- });
- db.SaveChanges();
- string IdBrand = GetUserId + "_" + pos.BrandId;
- UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
- if (userData == null)
- {
- userData = db.UserMachineData.Add(new UserMachineData()
- {
- IdBrand = IdBrand,
- }).Entity;
- db.SaveChanges();
- }
- userData.ActProfit += prize;
- db.SaveChanges();
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = GetUserId,
- UserId = GetUserId,
- }).Entity;
- db.SaveChanges();
- }
- decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
- decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
- decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
- account.BalanceAmount += prize;
- account.TotalAmount += prize;
- decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
- decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
- decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
- UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = GetUserId, //创客
- ChangeType = ChangeType, //变动类型
- ProductType = pos.BrandId, //产品类型
- ChangeAmount = prize, //变更金额
- BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
- AfterTotalAmount = AfterTotalAmount, //变更后总金额
- BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
- AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- }).Entity;
- db.SaveChanges();
- RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
- string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
- string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
- // 激活奖励列表
- List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
- if (!dates.Contains(dateString))
- {
- RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
- }
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
- List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
- if (!months.Contains(monthString))
- {
- RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
- }
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
- // 激活奖励详情
- List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
- if (!actPrizeList.Contains(pos.BindMerchantId))
- {
- RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
- }
- RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
- //收支明细
- RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
- RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
- }
- }
- }
- // }
- }
- }
- db.Dispose();
- }
- #endregion
- #region 设置商户代理
- public IActionResult SetMerAgent(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- if (string.IsNullOrEmpty(MerNo))
- {
- return "请输入商户编号";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "创客编号不存在";
- }
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
- if (merchant == null)
- {
- return "商户编号不存在";
- }
- pos.SeoTitle = user.Id.ToString();
- pos.UserId = user.Id;
- if (pos.BindMerchantId == 0)
- {
- pos.BindMerchantId = merchant.Id;
- if (IsSend == 1)
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = pos.BuyUserId, //接收创客
- MsgType = 2,
- Title = "商户型代理设置成功", //标题
- Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
- CreateDate = DateTime.Now,
- }));
- }
- }
- user.MerchantType = 1;
- merchant.UserId = user.Id;
- merchant.MerUserType = 1;
- db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
- {
- CreateDate = DateTime.Now,
- IsRecyc = (ulong)pos.IsPurchase,
- CreditAmount = pos.CreditTrade,
- PosSnType = pos.PosSnType,
- ActDate = pos.ActivationTime,
- BindDate = pos.BindingTime,
- ActStatus = (ulong)pos.ActivationState,
- BindStatus = (ulong)pos.BindingState,
- MerNo = MerNo,
- PosSn = pos.PosSn,
- Note = "后台设置商户型创客",
- ToUserId = user.Id,
- FromUserId = pos.BuyUserId,
- });
- db.SaveChanges();
- string text = string.Format("设置商户代理,创客编号: " + MakerCode + ",机具SN:" + PosSn + ",商户:" + MerNo + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
- function.WriteLog(text, "SetMerAgent-设置商户代理");//设置商户型代理日志
- return "success";
- }
- #endregion
- #region 取消商户代理
- public IActionResult CancelMerAgent(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string CancelMerAgentDo(string MakerCode, string PosSn, int IsSend = 0)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "创客编号不存在";
- }
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == PosSn);
- pos.UserId = pos.BuyUserId;
- merchant.UserId = pos.BuyUserId;
- merchant.MerUserType = 0;
- user.MerchantType = 0;
- db.SaveChanges();
- if (pos.BindMerchantId == 0)
- {
- pos.BindMerchantId = merchant.Id;
- if (IsSend == 1)
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = pos.BuyUserId, //接收创客
- MsgType = 2,
- Title = "商户型代理取消成功", //标题
- Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已给下级代理" + user.RealName + "" + MakerCode + "取消成功",
- CreateDate = DateTime.Now,
- }));
- }
- }
- string text = string.Format("取消商户代理,创客编号: " + user.MakerCode + ",机具SN:" + pos.PosSn + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
- function.WriteLog(text, "CancelMerAgent");//取消商户型代理日志
- return "success";
- }
- #endregion
- #region 查看SP原始数据日志
- public IActionResult SeeSpLog(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 查询机具信息
- public IActionResult SeeSnDetail(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SeeSnDetailDo(string PosSn)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- if (pos.Status == -1)
- {
- Users posUsers = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- decimal Deposits = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11 && pos.BrandId != 12)
- {
- Deposits = Deposits / 100;
- }
- string DepositGets = "未领取";
- string DepositUsers = "";
- ActiveReward rewards = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
- if (rewards.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == rewards.UserId) ?? new Users();
- DepositGets = "已领取";
- DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
- }
- string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- var storeInfo = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
- string results = "该机具为故障机" + "\n";
- results += "所在仓库:" + storeInfo.StoreNo + "\n";
- results += "仓库名称:" + storeInfo.StoreName + "\n";
- results += "服务费返现实际返现对象:" + DepositUsers + "\n";
- results += "服务费:" + Deposits + "\n";
- results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
- return results;
- }
- string merInfo = "";
- string merName = "";
- PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (mer != null)
- {
- merInfo = mer.KqMerNo;
- merName = mer.MerchantName;
- }
- else
- {
- merInfo = "未找到商户";
- }
- StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
- Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
- int TopUserId = 0;
- if (!string.IsNullOrEmpty(posUser.ParentNav))
- {
- string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
- if (ParentNavs.Length > 1)
- {
- TopUserId = int.Parse(ParentNavs[1]);
- }
- if (ParentNavs.Length == 1)
- {
- TopUserId = int.Parse(ParentNavs[0]);
- }
- }
- Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
- string bindResult = "", bindTime = "";
- if (pos.BindingState == 0)
- {
- bindResult = "未绑定";
- }
- else
- {
- bindResult = "已绑定";
- bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
- }
- string activeResult = "", activeTime = "";
- if (pos.ActivationState == 0)
- {
- if (pos.CreditTrade < 1000)
- {
- activeResult = "未刷满1000";
- }
- else if (pos.TransferTime == null)
- {
- activeResult = "未激活, 需补录";
- }
- }
- else
- {
- activeResult = "已激活";
- activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
- }
- string tradeAmount = pos.CreditTrade.ToString();
- decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11 && pos.BrandId != 12)
- {
- Deposit = Deposit / 100;
- }
- string DepositGet = "未领取";
- string DepositUser = "";
- string DepositToUser = "";
- decimal headAmount = 0;
- decimal footAmount = 0;
- ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
- if (reward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
- DepositGet = "已领取";
- DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
- var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
- if (fAmount != null)
- {
- headAmount = fAmount.RewardAmount;
- }
- var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
- if (lAmount != null)
- {
- footAmount = lAmount.RewardAmount;
- }
- }
- string DepositGet6 = "未领取";
- string DepositUser6 = "";
- ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
- if (lisreward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
- DepositGet6 = "已领取";
- DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
- }
- string FluxGet6 = "未领取";
- string FluxUser6 = "";
- FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
- if (flux.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
- FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
- FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
- }
- Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName;
- string OpenUser10 = "未领取";
- string OpenUser20 = "未领取";
- string Leader10 = "未领取";
- string YYZX5 = "未领取";
- var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
- OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
- if (openreward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
- OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + "发放时间:" + openreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- }
- openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
- if (openreward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
- OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName;
- }
- var leader10 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 116) ?? new UserAccountRecord();
- if (leader10.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == leader10.UserId) ?? new Users();
- Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + leader10.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- }
- var yyzx5 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 121) ?? new UserAccountRecord();
- if (yyzx5.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == yyzx5.UserId) ?? new Users();
- YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",发奖时间:" + yyzx5.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- }
- MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
- Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
- MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
- string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
- string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
- string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string result = "";
- result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + "\n";
- result += "\n";
- result += "机具SN:" + pos.PosSn + "\n";
- string PosSnType = pos.PosSnType == 0 ? "兑换机" : "循环机";
- result += "机具类型:" + PosSnType + "\n";
- result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
- result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + "\n";
- if (change.Id > 0)
- {
- result += "换机来源机具SN:" + change.BackSnNo + "\n";
- }
- result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + "\n";
- result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
- if (pos.PreUserId > 0)
- {
- Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
- PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
- string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",预发时间:" + preSendDate + "\n";
- }
- else
- {
- result += "机具所属小分仓:暂无小分仓\n";
- }
- result += "入库时间:" + CreateDate + "\n";
- result += "循环到期时间:" + RecycEndDate + "\n";
- result += "划拨时间:" + TransferTime + "\n";
- result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
- result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
- result += "贷记卡(总)交易额:" + tradeAmount + "\n";
- result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
- result += "申请循环后的SN:" + applyorder.SnNos + "\n";
- result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
- result += "服务费:" + Deposit + "\n";
- result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
- result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";
- result += "服务费返现应返现对象:" + DepositToUser + "\n";
- result += "服务费返现实际返现对象:" + DepositUser + "\n";
- if (pos.BrandId == 6)
- {
- result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
- result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
- }
- result += "流量费:" + FluxGet6 + "\n";
- result += "流量费发放对象:" + FluxUser6 + "\n";
- result += "开机奖20:" + OpenUser20 + "\n";
- result += "盟主奖:" + Leader10 + "\n";
- result += "运营中心奖:" + YYZX5 + "\n";
- return result;
- }
- #endregion
- #region 生成机具兑换码
- public IActionResult MakeCoupons(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string MakeCouponsDo(int Kind, int Number)
- {
- DateTime checkTime = DateTime.Parse("1900-01-01");
- string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
- if (!string.IsNullOrEmpty(checkTimeString))
- {
- checkTime = DateTime.Parse(checkTimeString);
- }
- if (checkTime.AddHours(1) < DateTime.Now)
- {
- RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
- return "生成程序已执行";
- }
- return "请稍后再试";
- }
- #endregion
- #region 导出没有刷满1000的机具
- public IActionResult ExportPos(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public JsonResult ExportPosDo()
- {
- WebCMSEntities db = new WebCMSEntities();
- List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
- int total = poses.Count;
- int index = 0;
- List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
- foreach (PosMachinesTwo pos in poses)
- {
- index += 1;
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
- Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
- Dictionary<string, object> item = new Dictionary<string, object>();
- string TopRealName = "";
- string TopMakerCode = "";
- string TopMobile = "";
- string ParentNav = user.ParentNav;
- if (!string.IsNullOrEmpty(ParentNav))
- {
- string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- if (navlist.Length > 1)
- {
- int TopId = int.Parse(function.CheckInt(navlist[1]));
- Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
- TopRealName = tuser.RealName;
- TopMakerCode = tuser.MakerCode;
- TopMobile = tuser.Mobile;
- }
- }
- item.Add("TopRealName", TopRealName); //顶级姓名
- item.Add("TopMakerCode", TopMakerCode); //顶级编号
- item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
- item.Add("UpRealName", puser.RealName); //上级姓名
- item.Add("RealName", user.RealName); //代理姓名
- item.Add("MakerCode", user.MakerCode); //代理编号
- item.Add("Mobile", user.Mobile); //代理手机号
- item.Add("MerchantName", merchant.MerchantName); //客户姓名
- item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
- item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
- item.Add("Sn", pos.PosSn); //SN
- list.Add(item);
- RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
- }
- db.Dispose();
- Dictionary<string, object> result = new Dictionary<string, object>();
- result.Add("Status", "1");
- result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
- result.Add("Obj", list);
- Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
- ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
- ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
- ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
- ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
- ReturnFields.Add("RealName", "代理姓名"); //代理姓名
- ReturnFields.Add("MakerCode", "代理编号"); //代理编号
- ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
- ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
- ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
- ReturnFields.Add("OpenTime", "开机日期"); //开机日期
- ReturnFields.Add("Sn", "SN"); //SN
- result.Add("Fields", ReturnFields);
- RedisDbconn.Instance.Set("ExportPosCheck", "finish");
- return Json(result);
- }
- public string ExportPosCheck()
- {
- string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
- if (content == "finish")
- {
- RedisDbconn.Instance.Clear("ExportPosCheck");
- }
- return content;
- }
- #endregion
- #region 更换机具
- public IActionResult ChangePos(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
- {
- if (string.IsNullOrEmpty(OldSn))
- {
- return "请输入原机具SN";
- }
- if (string.IsNullOrEmpty(NewSn))
- {
- return "请输入新机具SN";
- }
- if (string.IsNullOrEmpty(MerNo))
- {
- return "请输入商户编号";
- }
- string[] OldSnList = OldSn.Split('\n');
- string[] NewSnList = NewSn.Split('\n');
- if (OldSnList.Length != NewSnList.Length)
- {
- return "原机具SN数量和新机具SN数量不一致";
- }
- WebCMSEntities db = new WebCMSEntities();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
- StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
- StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
- StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
- StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
- string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
- KqProducts oldPosBrand = new KqProducts();
- KqProducts newPosBrand = new KqProducts();
- MachineChange add = db.MachineChange.Add(new MachineChange()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- CreateMan = SysUserName + "-" + SysRealName,
- ChangeNo = ChangeNo, //转换单号
- UserId = 0, //创客
- ChangeTime = DateTime.Now, //转换时间
- BackStoreId = BackStore.Id, //退回仓库
- BackStoreName = BackStore.StoreName, //退回仓库名称
- Remark = "机具更换", //订单备注
- BackStoreUserId = BackStore.UserId, //退回仓库归属人
- OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
- OutProductName = OutStore.ProductName, //出库产品名称
- OutStoreId = OutStore.Id, //出库仓库
- OutStoreName = OutStore.StoreName, //出库仓库名称
- OutStoreAreas = OutStore.Areas, //出库仓库所在地区
- OutStoreAddress = OutStore.Address, //出库仓库地址
- OutStoreManager = "", //出库仓库联系人
- OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
- }).Entity;
- db.SaveChanges();
- int BackProductType = 0;
- string BackProductName = "";
- string ChangeDeviceName = "";
- string ChangeSnExpand = "";
- for (int i = 0; i < OldSnList.Length; i++)
- {
- string OldSnNum = OldSnList[i];
- string NewSnNum = NewSnList[i];
- MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
- MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
- PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
- if (oldpos == null)
- {
- return "原机具SN不正确";
- }
- PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.PreUserId == 0);//添加新机是否为预发机判断
- if (newpos == null)
- {
- return "新机具SN不正确或不满足条件";
- }
- oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
- newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
- if (merchant == null)
- {
- CustomerSqlConn.op("insert into PosMerchantInfo select * from PosMerchantInfoBak where KqMerNo='" + MerNo + "'", MysqlConn.connstr);
- }
- if (oldpos.OpId > 0)
- {
- if (oldpos.ActivationState == 0)
- {
- var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
- decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
- opUserAccount.ValidAmount += oldpos.OpReserve3;
- opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
- opUserAccount.TotalAmt += oldpos.OpReserve1;
- var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
- {
- CreateDate = DateTime.Now,
- UserId = oldpos.OpId,
- SeoDescription = "机具换绑",
- OperateType = 1,
- UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
- BeforeAmount = TotalAmount,
- AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
- }).Entity;
- oldpos.OpReserve1 = 0;
- oldpos.OpReserve2 = 0;
- oldpos.OpReserve3 = 0;
- }
- else
- {
- if (newpos.OpId > 0)
- {
- var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == newpos.OpId && m.UserId == newpos.OpId) ?? new OpModels.UserAccount();
- decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
- opUserAccount.ValidAmount += newpos.OpReserve3;
- opUserAccount.ValidForGetAmount += newpos.OpReserve2;
- opUserAccount.TotalAmt += newpos.OpReserve1;
- var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
- {
- CreateDate = DateTime.Now,
- UserId = newpos.OpId,
- SeoDescription = "机具换绑",
- OperateType = 1,
- UseAmount = newpos.OpReserve3 + newpos.OpReserve2 + newpos.OpReserve1,
- BeforeAmount = TotalAmount,
- AfterAmount = TotalAmount + newpos.OpReserve3 + newpos.OpReserve2 + newpos.OpReserve1,
- }).Entity;
- newpos.OpReserve1 = 0;
- newpos.OpReserve2 = 0;
- newpos.OpReserve3 = 0;
- }
- }
- }
- opdb.SaveChanges();
- merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
- newpos.BindMerchantId = merchant.Id;
- newpos.BuyUserId = oldpos.BuyUserId;
- newpos.UserId = oldpos.UserId;
- newpos.RecycEndDate = oldpos.RecycEndDate;
- newpos.ScanQrTrade = oldpos.ScanQrTrade;
- newpos.DebitCardTrade = oldpos.DebitCardTrade;
- newpos.CreditTrade = oldpos.CreditTrade;
- newpos.PosSnType = oldpos.PosSnType;
- newpos.TransferTime = oldpos.TransferTime;
- newpos.IsPurchase = oldpos.IsPurchase;
- newpos.BindingState = oldpos.BindingState;
- newpos.ActivationState = oldpos.ActivationState;
- newpos.BindingTime = oldpos.BindingTime;
- newpos.ActivationTime = oldpos.ActivationTime;
- newpos.IsFirst = oldpos.IsFirst;
- newpos.SeoKeyword = oldpos.SeoKeyword;
- newpos.PrizeParams = oldpos.PrizeParams;
- newpos.LeaderUserId = oldpos.LeaderUserId;
- oldpos.Status = -1;
- //对应调整客小爽企业版数据
- var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
- if (posInfo != null)
- {
- posInfo.PosSn = newpos.PosSn;
- posInfo.PosId = newpos.Id;
- db.SaveChanges();
- }
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
- if (forMerNo != null)
- {
- forMerNo.SnId = newpos.Id;
- }
- merchant.KqSnNo = NewSn;
- merchant.ActiveStatus = newpos.ActivationState;
- merchant.MerStandardDate = newpos.ActivationTime;
- db.MachineChangeDetail.Add(new MachineChangeDetail()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- CreateMan = SysUserName + "-" + SysRealName,
- ChangeNo = ChangeNo, //订单号
- ChangeId = add.Id, //订单Id
- BackProductType = oldpos.BrandId, //退回产品类型
- BackProductName = oldPosBrand.Name, //退回产品名称
- UserId = 0, //创客
- BackSnNo = oldpos.PosSn, //设备SN编号
- OutProductType = newpos.BrandId, //出库产品类型
- OutProductName = newPosBrand.Name, //出库产品名称
- OutSnNo = newpos.PosSn, //出库设备SN编号
- OutSnType = newpos.PosSnType, //出库SN机具类型
- Remark = "机具更换", //备注
- BackSnType = oldpos.PosSnType, //退回SN机具类型
- });
- db.SaveChanges();
- BackProductType = oldpos.BrandId;
- BackProductName = newPosBrand.Name;
- ChangeDeviceName = oldpos.DeviceName;
- ChangeSnExpand += oldpos.PosSn + "\n";
- PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
- }
- add.BackProductType = BackProductType; //退回产品类型
- add.BackProductName = BackProductName; //退回产品名称
- add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
- add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
- add.ChangeSnExpand = ChangeSnExpand; //机具SN
- BackStore.LaveNum += OldSnList.Length; //退回仓库库存
- OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
- db.SaveChanges();
- db.Dispose();
- if (IsSend == 1)
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = pos.BuyUserId, //接收创客
- MsgType = 2,
- Title = "换绑成功通知", //标题
- Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
- CreateDate = DateTime.Now,
- }));
- }
- if (BackStore.UserId != OutStore.UserId)
- {
- RedisDbconn.Instance.AddList("ResetStoreReserveQueue", BackStore.UserId);
- RedisDbconn.Instance.AddList("ResetStoreReserveQueue", OutStore.UserId);
- }
- return "success";
- }
- #endregion
- #region 坏机换新
- public IActionResult ChangeBadPos(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
- {
- string[] OldSnList;
- string[] NewSnList;
- decimal amount = 0;
- List<string> opData = new List<string>();
- //创客坏机换新
- if (ChangeType == "0")
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(OldSn))
- {
- return "请输入坏机SN";
- }
- if (string.IsNullOrEmpty(NewSn))
- {
- return "请输入新机SN";
- }
- if (string.IsNullOrEmpty(FromStoreNo))
- {
- return "请输入新机发货仓库编号";
- }
- if (string.IsNullOrEmpty(BackStoreNo))
- {
- return "请输入坏机退回仓库编号";
- }
- OldSnList = OldSn.Split('\n');
- NewSnList = NewSn.Split('\n');
- if (OldSnList.Length != NewSnList.Length)
- {
- return "原机具SN数量和新机具SN数量不一致";
- }
- for (int i = 0; i < OldSnList.Length; i++)
- {
- string OldSnNum = OldSnList[i];
- string NewSnNum = NewSnList[i];
- UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
- StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
- if (storeForCodeFrom.StoreId == 0)
- {
- return "您输入的新机发货仓库编号不存在";
- }
- StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
- if (storeForCodeBack.StoreId == 0)
- {
- return "您输入的坏机退回仓库编号不存在";
- }
- MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
- MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
- PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
- if (oldpos.Id == 0)
- {
- return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
- }
- PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
- if (newpos.Id == 0)
- {
- return "您输入的新机SN不存在或不满足条件";
- }
- StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
- if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
- {
- return "您输入的新机发货仓库不符新机机具对应品牌";
- }
- if (newpos.StoreId != storeFrom.Id)
- {
- return "您输入的新机SN不在新机发货仓库";
- }
- StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
- if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
- {
- return "您输入的坏机退回仓库不符坏机机具对应品牌";
- }
- if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
- {
- return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
- }
- var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
- if (brandInfo.Name.Contains("大POS"))
- {
- amount = 300;
- }
- if (brandInfo.Name.Contains("电签"))
- {
- amount = 200;
- }
- var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
- var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
- storeFromUserAcount.ValidAmount += amount;
- storeBackUserAcount.ValidAmount -= amount;
- if (oldpos.OpId > 0)
- {
- if (newpos.OpId > 0)
- {
- var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
- decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
- opUserAccount.ValidAmount += oldpos.OpReserve3;
- opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
- opUserAccount.TotalAmt += oldpos.OpReserve1;
- var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
- {
- CreateDate = DateTime.Now,
- UserId = oldpos.OpId,
- SeoDescription = "坏机换新",
- OperateType = 1,
- UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
- BeforeAmount = TotalAmount,
- AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
- }).Entity;
- }
- if (newpos.OpId == 0)
- {
- newpos.OpReserve1 = oldpos.OpReserve1;
- newpos.OpReserve2 = oldpos.OpReserve3;
- newpos.OpReserve3 = oldpos.OpReserve1;
- newpos.OpId = oldpos.OpId;
- }
- }
- newpos.BuyUserId = oldpos.BuyUserId;
- newpos.UserId = oldpos.UserId;
- newpos.RecycEndDate = oldpos.RecycEndDate;
- newpos.ScanQrTrade = oldpos.ScanQrTrade;
- newpos.DebitCardTrade = oldpos.DebitCardTrade;
- newpos.CreditTrade = oldpos.CreditTrade;
- newpos.PosSnType = oldpos.PosSnType;
- newpos.TransferTime = oldpos.TransferTime;
- newpos.IsPurchase = oldpos.IsPurchase;
- newpos.BindingState = oldpos.BindingState;
- newpos.ActivationState = oldpos.ActivationState;
- newpos.BindingTime = oldpos.BindingTime;
- newpos.ActivationTime = oldpos.ActivationTime;
- newpos.IsFirst = oldpos.IsFirst;
- newpos.SeoKeyword = oldpos.SeoKeyword;
- newpos.PrizeParams = oldpos.PrizeParams;
- newpos.LeaderUserId = oldpos.LeaderUserId;
- newpos.BindMerchantId = oldpos.BindMerchantId;
- newpos.StoreId = oldpos.StoreId;
- newpos.UserId = oldpos.UserId;
- newpos.PreUserId = oldpos.PreUserId;
- if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
- {
- opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
- }
- oldpos.StoreId = storeBack.Id;
- oldpos.QueryCount = 0;
- oldpos.UpdateDate = null;
- oldpos.ActivityList = null;
- oldpos.SeoKeyword = null;
- oldpos.SeoDescription = null;
- oldpos.OrderId = 0;
- oldpos.RecycEndDate = null;
- oldpos.RecycBackCount = 0;
- oldpos.PrizeParams = null;
- oldpos.ScanQrTrade = 0;
- oldpos.BindMerchantId = 0;
- oldpos.CreditTrade = 0;
- oldpos.DebitCardTrade = 0;
- oldpos.IsVip = 0;
- oldpos.UserNav = null;
- oldpos.TransferTime = null;
- oldpos.IsPurchase = 0;
- oldpos.Detail = null;
- oldpos.BindingTime = null;
- oldpos.BindingState = 0;
- oldpos.ActivationTime = null;
- oldpos.ActivationState = 0;
- oldpos.LeaderUserId = 0;
- oldpos.PreUserId = 0;
- oldpos.IsFirst = 0;
- oldpos.DownFeeMan = null;
- oldpos.DownFeeFlag = 0;
- oldpos.DownFeeDate = null;
- oldpos.UpFeeMan = null;
- oldpos.UpFeeFlag = 0;
- oldpos.UpFeeDate = null;
- oldpos.OpReserve1 = 0;
- oldpos.OpReserve2 = 0;
- oldpos.OpReserve3 = 0;
- oldpos.OpId = 0;
- oldpos.RecycStartDate = null;
- oldpos.SourcePosSn = null;
- oldpos.BuyUserId = 0;
- oldpos.UserId = 0;
- oldpos.Status = -1;
- PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
- db.SaveChanges();
- opdb.SaveChanges();
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
- if (merchant != null)
- {
- merchant.KqSnNo = newpos.PosSn;
- merchant.ActiveStatus = newpos.ActivationState;
- }
- db.SaveChanges();
- BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
- {
- CreateDate = DateTime.Now,
- CreateMan = SysUserName + "-" + SysRealName,
- ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
- OutStoreId = storeFrom.Id,
- BackStoreId = storeBack.Id,
- OutProductType = newpos.BrandId,
- BackProductType = oldpos.BrandId,
- UserId = userForMakerCode.UserId, //创客
- }).Entity;
- db.SaveChanges();
- BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
- {
- CreateDate = DateTime.Now,
- CreateMan = SysUserName + "-" + SysRealName,
- OutSnNo = OldSnNum,
- BackSnNo = NewSnNum,
- ChangeNo = add.ChangeNo, //转换单号
- ChangeId = add.Id, //转换记录Id
- UserId = add.UserId, //创客
- }).Entity;
- db.SaveChanges();
- var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
- if (IsSend == 1)
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = userForMakerCode.UserId, //接收创客
- MsgType = 2,
- Title = "坏机换新成功通知", //标题
- Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
- CreateDate = DateTime.Now,
- }));
- }
- }
- }
- //仓库坏机换新
- else
- {
- if (string.IsNullOrEmpty(StoreCode))
- {
- return "请输入仓库编号";
- }
- if (string.IsNullOrEmpty(OldSn))
- {
- return "请输入坏机SN";
- }
- if (string.IsNullOrEmpty(NewSn))
- {
- return "请输入新机SN";
- }
- if (string.IsNullOrEmpty(FromStoreNo))
- {
- return "请输入新机发货仓库编号";
- }
- if (string.IsNullOrEmpty(BackStoreNo))
- {
- return "请输入坏机退回仓库编号";
- }
- OldSnList = OldSn.Split('\n');
- NewSnList = NewSn.Split('\n');
- if (OldSnList.Length != NewSnList.Length)
- {
- return "原机具SN数量和新机具SN数量不一致";
- }
- for (int i = 0; i < OldSnList.Length; i++)
- {
- string OldSnNum = OldSnList[i];
- string NewSnNum = NewSnList[i];
- StoreHouse store = new StoreHouse();
- StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
- if (storeForBadCode.StoreId > 0)
- {
- store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
- }
- StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
- if (storeForCodeFrom.StoreId == 0)
- {
- return "您输入的新机发货仓库编号不存在";
- }
- StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
- if (storeForCodeBack.StoreId == 0)
- {
- return "您输入的坏机退回仓库编号不存在";
- }
- MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
- MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
- PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
- if (oldpos.Id == 0)
- {
- return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
- }
- PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0 && m.PreUserId == 0) ?? new PosMachinesTwo();
- if (newpos.Id == 0)
- {
- return "您输入的新机SN不存在或不满足条件";
- }
- StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
- if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
- {
- return "您输入的新机发货仓库不符新机机具对应品牌";
- }
- if (newpos.StoreId != storeFrom.Id)
- {
- return "您输入的新机SN不在新机发货仓库";
- }
- StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
- if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
- {
- return "您输入的坏机退回仓库不符坏机机具对应品牌";
- }
- var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
- if (brandInfo.Name.Contains("大POS"))
- {
- amount = 300;
- }
- if (brandInfo.Name.Contains("电签"))
- {
- amount = 200;
- }
- var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
- var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
- var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
- storeFromUserAcount.ValidAmount += amount;
- storeBackUserAcount.ValidAmount -= amount;
- newpos.StoreId = oldpos.StoreId;
- newpos.BuyUserId = oldpos.BuyUserId;
- newpos.UserId = oldpos.UserId;
- newpos.LeaderUserId = oldpos.LeaderUserId;
- newpos.PreUserId = oldpos.PreUserId;
- newpos.IsFirst = oldpos.IsFirst;
- newpos.TransferTime = oldpos.TransferTime;
- if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
- {
- opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
- }
- if (oldpos.OpId > 0)
- {
- if (newpos.OpId > 0)
- {
- var opUserAccount = opdb.UserAccount.FirstOrDefault(m => m.Sort > 0 && m.Id == oldpos.OpId && m.UserId == oldpos.OpId) ?? new OpModels.UserAccount();
- decimal TotalAmount = opUserAccount.ValidAmount + opUserAccount.TotalAmt + opUserAccount.ValidForGetAmount;//旧的总金额
- opUserAccount.ValidAmount += oldpos.OpReserve3;
- opUserAccount.ValidForGetAmount += oldpos.OpReserve2;
- opUserAccount.TotalAmt += oldpos.OpReserve1;
- var amoutRecord = opdb.AmountRecord.Add(new OpModels.AmountRecord
- {
- CreateDate = DateTime.Now,
- UserId = oldpos.OpId,
- SeoDescription = "坏机换新",
- OperateType = 1,
- UseAmount = oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
- BeforeAmount = TotalAmount,
- AfterAmount = TotalAmount + oldpos.OpReserve3 + oldpos.OpReserve2 + oldpos.OpReserve1,
- }).Entity;
- }
- if (newpos.OpId == 0)
- {
- newpos.OpReserve1 = oldpos.OpReserve1;
- newpos.OpReserve2 = oldpos.OpReserve3;
- newpos.OpReserve3 = oldpos.OpReserve1;
- newpos.OpId = oldpos.OpId;
- }
- }
- oldpos.StoreId = storeBack.Id;
- oldpos.QueryCount = 0;
- oldpos.UpdateDate = null;
- oldpos.ActivityList = null;
- oldpos.SeoKeyword = null;
- oldpos.SeoDescription = null;
- oldpos.OrderId = 0;
- oldpos.RecycEndDate = null;
- oldpos.RecycBackCount = 0;
- oldpos.PrizeParams = null;
- oldpos.ScanQrTrade = 0;
- oldpos.BindMerchantId = 0;
- oldpos.CreditTrade = 0;
- oldpos.DebitCardTrade = 0;
- oldpos.IsVip = 0;
- oldpos.UserNav = null;
- oldpos.TransferTime = null;
- oldpos.IsPurchase = 0;
- oldpos.Detail = null;
- oldpos.BindingTime = null;
- oldpos.BindingState = 0;
- oldpos.ActivationTime = null;
- oldpos.ActivationState = 0;
- oldpos.LeaderUserId = 0;
- oldpos.PreUserId = 0;
- oldpos.IsFirst = 0;
- oldpos.DownFeeMan = null;
- oldpos.DownFeeFlag = 0;
- oldpos.DownFeeDate = null;
- oldpos.UpFeeMan = null;
- oldpos.UpFeeFlag = 0;
- oldpos.UpFeeDate = null;
- oldpos.OpReserve1 = 0;
- oldpos.OpReserve2 = 0;
- oldpos.OpReserve3 = 0;
- oldpos.OpId = 0;
- oldpos.RecycStartDate = null;
- oldpos.SourcePosSn = null;
- oldpos.BuyUserId = 0;
- oldpos.UserId = 0;
- oldpos.Status = -1;
- PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
- db.SaveChanges();
- opdb.SaveChanges();
- BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
- {
- CreateDate = DateTime.Now,
- CreateMan = SysUserName + "-" + SysRealName,
- ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
- OutStoreId = storeFrom.Id,
- BackStoreId = storeBack.Id,
- OutProductType = newpos.BrandId,
- BackProductType = oldpos.BrandId,
- UserId = store.UserId, //创客
- }).Entity;
- db.SaveChanges();
- BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
- {
- CreateDate = DateTime.Now,
- CreateMan = SysUserName + "-" + SysRealName,
- OutSnNo = OldSnNum,
- BackSnNo = NewSnNum,
- ChangeNo = add.ChangeNo, //转换单号
- ChangeId = add.Id, //转换记录Id
- UserId = add.UserId, //创客
- }).Entity;
- db.SaveChanges();
- var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
- if (IsSend == 1)
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = store.UserId, //接收创客
- MsgType = 2,
- Title = "坏机换新成功通知", //标题
- Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
- CreateDate = DateTime.Now,
- }));
- }
- }
- }
- foreach (string sub in opData)
- {
- string[] datalist = sub.Split(":");
- PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
- }
- return "success";
- }
- #endregion
- #region 机具解绑
- public IActionResult Unbind(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
- if (forSnNo == null)
- {
- return "机具SN不存在";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
- if (pos == null)
- {
- return "机具SN不存在";
- }
- if (pos.ActivationState == 1)
- {
- return "机具已激活,不能解绑";
- }
- if (pos.BuyUserId == 0)
- {
- return "机具是仓库机,不支持解绑";
- }
- if (pos.BindingState == 0)
- {
- return "机具未绑定,不支持解绑";
- }
- if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
- {
- return "机具绑定已超过30天,不支持解绑";
- }
- if (pos.CreditTrade > 0 || !string.IsNullOrEmpty(pos.SeoKeyword))
- {
- return "该机具已交易,无法解绑";
- }
- if (pos.BrandId != 10 || pos.BrandId != 11)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(MerNo))
- {
- return "请输入商户编号";
- }
- UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (forMakerCode == null)
- {
- return "创客不存在";
- }
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
- if (forMerNo == null)
- {
- return "商户编号不存在";
- }
- if (pos.BuyUserId != forMakerCode.UserId)
- {
- return "机具SN和创客不匹配";
- }
- if (forMerNo != null)
- {
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant != null)
- {
- //机具解绑删除客小爽企业版对应数据
- var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
- if (merInfo != null)
- {
- db.BusinessPartnerMerchant.Remove(merInfo);
- }
- var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
- if (posInfo != null)
- {
- db.BusinessPartnerPos.Remove(posInfo);
- }
- db.PosMerchantInfo.Remove(merchant);
- }
- db.MachineForMerNo.Remove(forMerNo);
- db.SaveChanges();
- }
- }
- else
- {
- var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
- MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
- if (forMerNo != null && posMerchantInfo != null)
- {
- //机具解绑删除客小爽企业版对应数据
- var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == posMerchantInfo.Id);
- if (merInfo != null)
- {
- db.BusinessPartnerMerchant.Remove(merInfo);
- }
- var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
- if (posInfo != null)
- {
- db.BusinessPartnerPos.Remove(posInfo);
- }
- db.PosMerchantInfo.Remove(posMerchantInfo);
- db.MachineForMerNo.Remove(forMerNo);
- db.SaveChanges();
- }
- }
- db.MachineUnBind.Add(new MachineUnBind()
- {
- CreateDate = DateTime.Now,
- SeoTitle = SysUserName + "-" + SysRealName,
- MerchantId = pos.BindMerchantId,
- AuditDate = DateTime.Now,
- AuditDesc = "平台操作解绑",
- AuditStatus = 1,
- SnNo = pos.PosSn,
- BrandId = pos.BrandId,
- UserId = pos.BuyUserId,
- ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
- });
- pos.BindMerchantId = 0;
- pos.BindingState = 0;
- pos.BindingTime = DateTime.Parse("1900-01-01");
- pos.UserId = pos.BuyUserId;
- string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
- db.SaveChanges();
- PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
- if (IsSend == 1)
- {
- RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
- {
- UserId = pos.BuyUserId, //接收创客
- MsgType = 2,
- Title = "解绑成功通知", //标题
- Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
- CreateDate = DateTime.Now,
- }));
- }
- return "success";
- }
- #endregion
- #region 通过券码修改盟主标记
- public IActionResult ChangeSignQuan(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string ChangeSignQuanDo(string Coupons, string MakerCode)
- {
- if (string.IsNullOrEmpty(Coupons))
- {
- return "请输入机具券码,多个券码用回车分隔";
- }
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (forMakerCode == null)
- {
- return "创客不存在";
- }
- string[] SnList = Coupons.Split('\n');
- foreach (var item in SnList)
- {
- var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
- if (coupos == null)
- {
- return "机具券不存在";
- }
- else
- {
- coupos.LeaderUserId = forMakerCode.UserId;
- }
- }
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 通过机具SN修改盟主标记
- public IActionResult ChangeSignSn(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string ChangeSignSnDo(string PosSn, string MakerCode)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN,多个SN用回车分隔";
- }
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (forMakerCode == null)
- {
- return "创客不存在";
- }
- string[] SnList = PosSn.Split('\n');
- foreach (var item in SnList)
- {
- var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
- if (pos == null)
- {
- return "该机具不存在";
- }
- else
- {
- pos.LeaderUserId = forMakerCode.UserId;
- }
- }
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 机具循环列表
- /// <summary>
- /// 根据条件查询机具循环列表
- /// </summary>
- /// <returns></returns>
- public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- ViewBag.SwapSnExpand = SwapSnExpand;
- ViewBag.SnNos = SnNos;
- return View();
- }
- #endregion
- #region 根据条件查询机具循环列表
- /// <summary>
- /// 机具循环列表
- /// </summary>
- /// <returns></returns>
- public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("SwapSnExpand", "1"); //申请机具SN
- Fields.Add("SnNos", "1"); //发货机具SN
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- if (!string.IsNullOrEmpty(SwapSnExpand))
- {
- var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
- var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
- var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
- string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
- string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
- for (int i = 0; i < SnNoList.Length; i++)
- {
- Dictionary<string, object> data = new Dictionary<string, object>();
- data["ApplyNo"] = apply.ApplyNo;
- data["OrderNo"] = order.OrderNo;
- data["MakerCode"] = user.MakerCode;
- data["RealName"] = user.RealName;
- if (SnNoList.Length > i)
- {
- string SourceSn = SnNoList[i].Split(':')[0];
- data["ComeSn"] = SnNoList[i];
- data["ComeSnParam"] = SourceSn;
- MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
- if (pos.LeaderUserId > 0)
- {
- Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
- data["ComeSnMakerCode"] = leader.MakerCode;
- data["ComeSnRealName"] = leader.RealName;
- }
- }
- if (OrderSnNo.Length > i)
- {
- string SendSn = OrderSnNo[i];
- data["SendSn"] = OrderSnNo[i];
- MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
- if (pos.LeaderUserId > 0)
- {
- Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
- data["SendSnMakerCode"] = leader.MakerCode;
- data["SendSnRealName"] = leader.RealName;
- }
- }
- data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- data["Status"] = order.Status == 2 ? "已发货" : "未发货";
- dataList.Add(data);
- }
- }
- else if (!string.IsNullOrEmpty(SnNos))
- {
- var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
- var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
- var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
- string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
- string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
- for (int i = 0; i < OrderSnNo.Length; i++)
- {
- Dictionary<string, object> data = new Dictionary<string, object>();
- data["ApplyNo"] = apply.ApplyNo;
- data["OrderNo"] = order.OrderNo;
- data["MakerCode"] = user.MakerCode;
- data["RealName"] = user.RealName;
- if (SnNoList.Length > i)
- {
- string SourceSn = SnNoList[i].Split(':')[0];
- data["ComeSn"] = SnNoList[i];
- data["ComeSnParam"] = SourceSn;
- MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
- if (pos.LeaderUserId > 0)
- {
- Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
- data["ComeSnMakerCode"] = leader.MakerCode;
- data["ComeSnRealName"] = leader.RealName;
- }
- }
- if (OrderSnNo.Length > i)
- {
- string SendSn = OrderSnNo[i];
- data["SendSn"] = OrderSnNo[i];
- MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
- if (pos.LeaderUserId > 0)
- {
- Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
- data["SendSnMakerCode"] = leader.MakerCode;
- data["SendSnRealName"] = leader.RealName;
- }
- }
- data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- data["Status"] = order.Status == 2 ? "已发货" : "未发货";
- dataList.Add(data);
- }
- }
- Dictionary<string, object> obj = new Dictionary<string, object>();
- obj.Add("code", 0);
- obj.Add("msg", "");
- obj.Add("count", dataList.Count);
- obj.Add("data", dataList);
- return Json(obj);
- }
- #endregion
- #region 查询机具循环
- /// <summary>
- /// 根据条件查询机具来源机具和券码
- /// </summary>
- /// <returns></returns>
- public IActionResult SourceLoop(string right, string SnNos)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- ViewBag.SnNos = SnNos;
- return View();
- }
- #endregion
- #region 根据条件查询机具来源机具和券码
- /// <summary>
- /// 机具循环列表
- /// </summary>
- /// <returns></returns>
- public string SourceLoopData(string SnNo, int page = 1, int limit = 30)
- {
- var result = "";
- var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new MachineForSnNo();
- var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
- if (pos.Id == 0)
- {
- return "机具:" + SnNo + "不存在";
- }
- else
- {
- var stattime = pos.RecycStartDate == null ? "" : pos.RecycStartDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- var endtime = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- result += "循环开始时间:" + stattime + "\n";
- result += "循环结束时间:" + endtime + "\n";
- result += "来源机具/券:" + pos.SourcePosSn + "\n";
- }
- return result;
- }
- #endregion
- #region 查询创客直推奖
- public IActionResult Prize100(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public Dictionary<string, string> Prize100Do(string MakerCode)
- {
- Dictionary<string, string> dic = new Dictionary<string, string>();
- string result = "";
- UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (forMakerCode == null)
- {
- result += "创客编号不存在\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
- if (OrderCount == 0)
- {
- result += "该创客未下单\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- if (OrderCount > 1)
- {
- result += "该创客已不是首笔下单\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
- if (order.PayStatus < 1)
- {
- result += "未付款\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
- Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
- result += "订单号:" + order.OrderNo + "\n";
- result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
- result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
- int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
- int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
- if (machineCount + ActiveCount >= 3)
- {
- string IsGet = "未发放";
- int ToUserId = 0;
- UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
- if (item == null)
- {
- DateTime start = order.PayDate.Value.AddMinutes(-2);
- DateTime end = order.PayDate.Value.AddMinutes(2);
- item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
- }
- if (item != null)
- {
- IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
- ToUserId = item.UserId;
- dic.Add("code", "1");
- }
- else
- {
- dic.Add("id", order.Id.ToString());
- dic.Add("code", "0");
- }
- Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
- result += "是否发放:" + IsGet + "\n";
- result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
- result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
- }
- else
- {
- result += "上级创客未满足条件\n兑换机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
- dic.Add("code", "1");
- }
- dic.Add("result", result);
- return dic;
- }
- public string AddPrize100(int Id)
- {
- Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
- if (order != null)
- {
- //机具券逻辑
- OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
- if (pro != null)
- {
- //推荐下单奖励
- if (pro.ProductId == 10 || pro.ProductId == 11)
- {
- int OrderId = order.Id;
- bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
- if (!checkPrize)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
- if (user != null)
- {
- bool directPrize = false; //直推奖标记
- int ParentUserId = user.ParentUserId;
- while (ParentUserId > 0)
- {
- Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
- int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台兑换机
- int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
- int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
- if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
- {
- DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
- directPrize = true;
- db.SaveChanges();
- return "发放成功";
- }
- ParentUserId = puser.ParentUserId;
- }
- }
- }
- return "已发放,请勿重复发放";
- }
- }
- }
- return "操作失败";
- }
- public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
- {
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = UserId,
- UserId = UserId,
- }).Entity;
- db.SaveChanges();
- }
- decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
- decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
- decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
- account.BalanceAmount += 100 * Count;
- account.TotalAmount += 100 * Count;
- decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
- decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
- decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
- UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = UserId, //创客
- ChangeType = 112, //变动类型
- ChangeAmount = 100 * Count, //变更金额
- BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
- AfterTotalAmount = AfterTotalAmount, //变更后总金额
- BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
- AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- QueryCount = OrderId,
- }).Entity;
- db.SaveChanges();
- }
- #endregion
- #region 查询机具开机奖
- public IActionResult OpenPrize(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public Dictionary<string, string> OpenPrizeDo(string PosSn)
- {
- Dictionary<string, string> dic = new Dictionary<string, string>();
- string result = "";
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- result += "机具SN号不存在\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- if (pos.BindingState == 0)
- {
- result += "机具未绑定\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- if (pos.ActivationState == 0)
- {
- result += "机具未激活\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant == null)
- {
- result += "商户不存在\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- result += "机具号:" + PosSn + "\n";
- result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
- result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
- string OpenUser10 = "未领取";
- string OpenUser20 = "未领取";
- var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
- OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
- if (openreward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
- OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
- }
- openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
- if (openreward.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
- OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
- }
- result += "开机奖20:" + OpenUser20 + "\n";
- dic.Add("id", pos.Id.ToString());
- dic.Add("code", "0");
- dic.Add("result", result);
- return dic;
- }
- public string AddOpenPrize(int Id)
- {
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
- if (pos == null)
- {
- return "机具未激活";
- }
- if (pos.BindingTime <= pos.TransferTime)
- {
- return "补录机,不能补发开机奖";
- }
- decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (ActPrize == 0)
- {
- return "机具无押金";
- }
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant == null)
- {
- return "商户不存在";
- }
- bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
- if (check)
- {
- return "开机奖励已发放,请勿重复操作";
- }
- // 从机具所属人上级开始分开机奖励
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
- if (user != null)
- {
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- decimal Prize = 20;
- List<string> PrizeFlag = new List<string>();
- string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
- for (int i = ParentNavs.Length - 1; i >= 0; i--)
- {
- int UserId = int.Parse(ParentNavs[i]);
- Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
- if (puser != null && Prize > 0)
- {
- int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台兑换机
- int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
- int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
- if (machineCount + ActiveCount + couponCount >= 3)
- {
- int pTopUserId = 0;
- if (!string.IsNullOrEmpty(puser.ParentNav))
- {
- pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
- }
- Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
- TradeDate = pos.ActivationTime, //达标日期
- UserId = puser.Id, //创客
- BrandId = pos.BrandId, //品牌
- ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
- MerchantId = pos.BindMerchantId, //商户
- DirectUserId = merchant.UserId, //商户直属人
- SnNo = pos.PosSn, //SN号
- MerNo = merchant.KqMerNo, //渠道商户号
- SnType = pos.PosSnType, //机具类型
- StandardDate = pos.ActivationTime, //商户的激活日期
- SnStoreId = pos.StoreId, //SN仓库
- MerBuddyType = puser.MerchantType, //商户创客类型
- RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
- RewardTips = "开机奖励", //奖励描述
- CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
- DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
- CreditRewardAmount = Prize, //贷记卡交易奖励金额
- RewardDesc = "开机奖励", //奖励描述
- TopUserId = pTopUserId, //顶级创客
- SeoTitle = machineUser.RealName,
- }).Entity;
- db.OpenReward.Add(new OpenReward()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
- TradeDate = DateTime.Now, //达标日期
- UserId = puser.Id, //创客
- BrandId = pos.BrandId, //品牌
- RewardType = 2, //奖励类型
- CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
- DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
- CreditRewardAmount = Prize, //贷记卡交易奖励金额
- RewardDesc = "开机奖励", //奖励描述
- TopUserId = pTopUserId, //顶级创客
- });
- string IdBrand = puser.Id + "_" + pos.BrandId;
- UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
- if (userData == null)
- {
- userData = db.UserMachineData.Add(new UserMachineData()
- {
- IdBrand = IdBrand,
- }).Entity;
- db.SaveChanges();
- }
- userData.OpenProfit += Prize;
- db.SaveChanges();
- //账户入库
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = puser.Id,
- UserId = puser.Id,
- }).Entity;
- db.SaveChanges();
- }
- //收支明细入库
- decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
- decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
- decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
- account.BalanceAmount += Prize;
- account.TotalAmount += Prize;
- decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
- decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
- decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
- UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = puser.Id, //创客
- ChangeType = 50, //变动类型
- ProductType = pos.BrandId, //产品类型
- ChangeAmount = Prize, //变更金额
- BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
- AfterTotalAmount = AfterTotalAmount, //变更后总金额
- BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
- AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- }).Entity;
- db.SaveChanges();
- RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
- string dateString = DateTime.Now.ToString("yyyyMMdd");
- string monthString = DateTime.Now.ToString("yyyyMM");
- // 开机奖励列表
- List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
- if (!dates.Contains(dateString))
- {
- RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
- }
- RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
- List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
- if (!months.Contains(monthString))
- {
- RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
- }
- RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
- // 开机奖励详情
- RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
- //收支明细
- RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
- RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
- Prize = 0;
- PrizeFlag.Add(Prize.ToString("f0"));
- }
- }
- }
- string result = "";
- if (string.IsNullOrEmpty(result))
- {
- return "发放成功";
- }
- return result;
- }
- }
- db.Dispose();
- return "操作失败";
- }
- #endregion
- #region 查询机具流量费分佣
- public IActionResult FluxPrize(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public Dictionary<string, string> FluxPrizeDo(string PosSn)
- {
- Dictionary<string, string> dic = new Dictionary<string, string>();
- string result = "";
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if (pos == null)
- {
- result += "机具SN号不存在\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- if (pos.BindingState == 0)
- {
- result += "机具未绑定\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- if (pos.ActivationState == 0)
- {
- result += "机具未激活\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant == null)
- {
- result += "商户不存在\n";
- dic.Add("code", "1");
- dic.Add("result", result);
- return dic;
- }
- Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- result += "机具号:" + PosSn + "\n";
- result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
- result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
- string FluxGet6 = "未领取";
- string FluxUser6 = "";
- FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
- if (flux.Id > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
- FluxGet6 = "已领取(金额:" + flux.FluxFeeAmt + ",领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
- FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
- }
- result += "流量费:" + FluxGet6 + "\n";
- result += "流量费发放对象:" + FluxUser6 + "\n";
- dic.Add("id", pos.Id.ToString());
- dic.Add("code", "0");
- dic.Add("result", result);
- return dic;
- }
- public string AddFluxPrize(int Id)
- {
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
- if (pos == null)
- {
- return "机具未激活";
- }
- decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (ActPrize == 0)
- {
- return "机具无押金";
- }
- PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant == null)
- {
- return "商户不存在";
- }
- if (pos.BrandId == 6)
- {
- return "立刷不支持流量费分佣";
- }
- if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
- {
- return "无押金机,不支持流量费分佣";
- }
- bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
- if (check)
- {
- return "流量费奖励已发放,请勿重复操作";
- }
- SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
- if (trade != null)
- {
- try
- {
- string OrderNo = trade.TradeSerialNo; //单号
- DateTime TradeDate = trade.CreateDate.Value;
- string TradeMonth = TradeDate.ToString("yyyyMM");
- decimal FeeAmount = trade.FeeAmount; //流量费
- if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
- {
- FeeAmount = FeeAmount / 100;
- }
- string TradeSnNo = trade.TradeSnNo; //机具SN
- decimal FluxProfit = 0;
- if (trade.ProductType == "1" && FeeAmount == 60)
- {
- FluxProfit = 24;
- }
- else if (trade.ProductType == "7" && FeeAmount == 46)
- {
- FluxProfit = 10;
- }
- else if (trade.ProductType != "1" && FeeAmount == 48)
- {
- FluxProfit = 12;
- }
- if (FluxProfit > 0)
- {
- Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
- int GetUserId = user.Id;
- int TopUserId = 0;
- string ParentNav = user.ParentNav;
- if (!string.IsNullOrEmpty(ParentNav))
- {
- string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- if (ParentNavList.Length > 1)
- {
- TopUserId = int.Parse(ParentNavList[1]);
- }
- else if (ParentNavList.Length == 1)
- {
- TopUserId = int.Parse(ParentNavList[0]);
- }
- }
- FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
- if (fluxProfit == null)
- {
- fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = GetUserId, //创客
- BrandId = pos.BrandId,
- TopUserId = TopUserId, //顶级创客
- TradeMonth = TradeMonth, //交易月
- MerUserType = user.MerchantType, //商户创客类型
- Remark = "流量卡分佣", //备注
- }).Entity;
- db.SaveChanges();
- }
- fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
- db.FluxProfitDetail.Add(new FluxProfitDetail()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- RecordNo = OrderNo, //单号
- TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
- TradeTime = TradeDate.ToString("HHmmss"), //交易时间
- TradeMonth = TradeMonth, //交易月
- UserId = GetUserId, //创客
- MerchantId = pos.BindMerchantId, //商户
- MerchantUserId = pos.UserId, //商户直属人
- MerNo = merchant.KqMerNo, //渠道商户编号
- SnNo = pos.PosSn, //渠道SN号
- FluxOrderNo = OrderNo, //流量扣费单号
- TradeOrderNo = OrderNo, //交易流水号
- TradeAmt = trade.TradeAmount, //商户交易额
- FluxFeeAmt = FeeAmount, //流量费
- FluxProfitAmt = FluxProfit, //流量分润总金额
- PosType = pos.PosSnType.ToString(), //POS类型
- Remark = "流量卡分佣", //备注
- BrandId = pos.BrandId, //品牌
- TopUserId = TopUserId, //顶级创客
- MerUserType = user.MerchantType, //商户创客类型
- });
- string IdBrand = user.Id + "_" + pos.BrandId;
- UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
- if (userData == null)
- {
- userData = db.UserMachineData.Add(new UserMachineData()
- {
- IdBrand = IdBrand,
- }).Entity;
- db.SaveChanges();
- }
- userData.FluxProfit += FluxProfit;
- db.SaveChanges();
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = GetUserId,
- UserId = GetUserId,
- }).Entity;
- db.SaveChanges();
- }
- decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
- decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
- decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
- account.BalanceAmount += FluxProfit;
- account.TotalAmount += FluxProfit;
- decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
- decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
- decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
- UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = GetUserId, //创客
- ChangeType = 60, //变动类型
- ProductType = pos.BrandId, //产品类型
- ChangeAmount = FluxProfit, //变更金额
- BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
- AfterTotalAmount = AfterTotalAmount, //变更后总金额
- BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
- AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- }).Entity;
- db.SaveChanges();
- spdb.Dispose();
- db.Dispose();
- return "发放成功";
- }
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
- }
- }
- spdb.Dispose();
- db.Dispose();
- return "操作失败";
- }
- #endregion
- #region 设置立刷费率
- public IActionResult LisFee(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
- {
- if (string.IsNullOrEmpty(PosSns))
- {
- return "请输入机具号";
- }
- string result = SysUserName + "设置\n";
- string[] PosSnList = PosSns.Split('\n');
- int total = PosSnList.Length;
- int index = 0;
- foreach (string SubPosSn in PosSnList)
- {
- index += 1;
- string PosSn = SubPosSn.Replace("\r", "");
- result += PosSn + ":" + Fee + "\n";
- if (Kind == "M5")
- {
- result += SetLiSFee(PosSn, Fee) + "\n";
- }
- else if (Kind == "N1")
- {
- result += SetLiSDeposit(PosSn, (int)Fee);
- }
- RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
- }
- result += "\n\n";
- function.WriteLog(result, "设置立刷费率");
- return result;
- }
- public string LisFeeProcess()
- {
- return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
- }
- #region 立刷
- string LiSAgentId = "50814834";
- 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=";
- string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
- public string LiSSign(string data)
- {
- var rsa = RSA.Create();
- var key = Convert.FromBase64String(LiSPrivateKey);
- var content = Encoding.UTF8.GetBytes(data);
- rsa.ImportPkcs8PrivateKey(key, out _);
- var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
- return Convert.ToBase64String(result);
- }
- // 设置费率
- public string SetLiSFee(string sn, decimal serviceFee)
- {
- Dictionary<string, object> dic = new Dictionary<string, object>();
- dic.Add("agentId", LiSAgentId);
- dic.Add("deviceSn", sn);
- List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
- Dictionary<string, object> item = new Dictionary<string, object>();
- item.Add("feeCalcType", "M5");
- item.Add("fixed", "0");
- item.Add("rate", serviceFee);
- feeList.Add(item);
- dic.Add("feeList", feeList);
- dic.Add("signMethod", "02");
- string content = LiSAgentId + sn + "M50" + serviceFee + "02";
- string signstr = LiSSign(content);
- dic.Add("signData", signstr);
- string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
- string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
- return result;
- }
- // 设置押金
- public string SetLiSDeposit(string sn, int serviceFee)
- {
- serviceFee = serviceFee * 100;
- Dictionary<string, object> dic = new Dictionary<string, object>();
- dic.Add("agentId", LiSAgentId);
- dic.Add("deviceSn", sn);
- List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
- Dictionary<string, object> item = new Dictionary<string, object>();
- item.Add("feeCalcType", "N1");
- item.Add("fixed", "1");
- item.Add("rate", serviceFee);
- feeList.Add(item);
- dic.Add("feeList", feeList);
- dic.Add("signMethod", "02");
- string content = LiSAgentId + sn + "N11" + serviceFee + "02";
- string signstr = LiSSign(content);
- dic.Add("signData", signstr);
- string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
- string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
- return result;
- }
- #endregion
- #endregion
- #region 查询商户型创客设置信息
- public IActionResult SeeMerchantType(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SeeMerchantTypeDo(string PosSn)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN或者创客编号";
- }
- SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
- if (PosSn.StartsWith("K"))
- {
- UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
- bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
- if (check)
- {
- pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
- }
- }
- else
- {
- bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
- if (check)
- {
- pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
- }
- }
- if (pos.Id == 0)
- {
- return "查无信息";
- }
- Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
- Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
- string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
- string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
- string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
- string result = "";
- result += "机具SN:" + pos.PosSn + "\n";
- result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
- result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
- result += "商户编号:" + pos.MerNo + "\n";
- result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
- result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
- result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
- result += "贷记卡交易额:" + pos.CreditAmount + "\n";
- result += "是否循环:" + RecycFlag + "\n";
- return result;
- }
- #endregion
- #region 三要素验证
- public IActionResult CheckThreeElements(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string CheckThreeElementsDo(string bankcard, string idcard, string name)
- {
- var host = "https://bankcard3c.shumaidata.com";
- var path = "/bankcard3c";
- var method = "GET";
- var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
- if (string.IsNullOrEmpty(bankcard))
- {
- return "结算银行卡号";
- }
- if (string.IsNullOrEmpty(idcard))
- {
- return "身份证号";
- }
- if (string.IsNullOrEmpty(name))
- {
- return "真实姓名";
- }
- String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
- function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
- function.WriteLog(querys, "验证三要素日志");
- String bodys = "";
- String url = host + path;
- HttpWebRequest httpRequest = null;
- HttpWebResponse httpResponse = null;
- if (0 < querys.Length)
- {
- url = url + "?" + querys;
- }
- if (host.Contains("https://"))
- {
- ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
- httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
- }
- else
- {
- httpRequest = (HttpWebRequest)WebRequest.Create(url);
- }
- httpRequest.Method = method;
- httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
- if (0 < bodys.Length)
- {
- byte[] data = Encoding.UTF8.GetBytes(bodys);
- using (Stream stream = httpRequest.GetRequestStream())
- {
- stream.Write(data, 0, data.Length);
- }
- }
- try
- {
- httpResponse = (HttpWebResponse)httpRequest.GetResponse();
- }
- catch (WebException ex)
- {
- httpResponse = (HttpWebResponse)ex.Response;
- }
- Stream st = httpResponse.GetResponseStream();
- StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
- string result = reader.ReadToEnd();
- JsonData jsonObj = JsonMapper.ToObject(result);
- result = jsonObj["data"]["desc"].ToString();
- function.WriteLog(result, "验证三要素日志");
- function.WriteLog("\n\n", "验证三要素日志");
- return result;
- }
- #endregion
- #region 四要素验证
- public IActionResult CheckFourElements(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
- {
- var host = "https://bankcard4c.shumaidata.com";
- var path = "/bankcard4c";
- var method = "GET";
- var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
- if (string.IsNullOrEmpty(bankcard))
- {
- return "请输入结算银行卡号";
- }
- if (string.IsNullOrEmpty(idcard))
- {
- return "请输入身份证号";
- }
- if (string.IsNullOrEmpty(mobile))
- {
- return "请输入银行预留手机号";
- }
- if (string.IsNullOrEmpty(name))
- {
- return "请输入真实姓名";
- }
- String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
- function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
- function.WriteLog(querys, "验证四要素日志");
- String bodys = "";
- String url = host + path;
- HttpWebRequest httpRequest = null;
- HttpWebResponse httpResponse = null;
- if (0 < querys.Length)
- {
- url = url + "?" + querys;
- }
- if (host.Contains("https://"))
- {
- ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
- httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
- }
- else
- {
- httpRequest = (HttpWebRequest)WebRequest.Create(url);
- }
- httpRequest.Method = method;
- httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
- if (0 < bodys.Length)
- {
- byte[] data = Encoding.UTF8.GetBytes(bodys);
- using (Stream stream = httpRequest.GetRequestStream())
- {
- stream.Write(data, 0, data.Length);
- }
- }
- try
- {
- httpResponse = (HttpWebResponse)httpRequest.GetResponse();
- }
- catch (WebException ex)
- {
- httpResponse = (HttpWebResponse)ex.Response;
- }
- Stream st = httpResponse.GetResponseStream();
- StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
- string result = reader.ReadToEnd();
- JsonData jsonObj = JsonMapper.ToObject(result);
- result = jsonObj["data"]["desc"].ToString();
- function.WriteLog(result, "验证四要素日志");
- function.WriteLog("\n\n", "验证四要素日志");
- return result;
- }
- #endregion
- public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
- {
- return true;
- }
- #region 根据机具号同步商户激活状态
- public IActionResult SyncMerchantStatus(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SyncMerchantStatusDo(string PosSn)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具号";
- }
- var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
- var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
- var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
- if (posInfo.Id == 0)
- {
- return "机具" + PosSn + "不存在";
- }
- if (posMerchant.Id == 0)
- {
- return "机具绑定商户不存在";
- }
- else
- {
- posMerchant.ActiveStatus = 1;
- posMerchant.UpdateDate = DateTime.Now;
- posMerchant.MerStandardDate = posInfo.ActivationTime;
- function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
- db.SaveChanges();
- }
- return "success";
- }
- #endregion
- #region 根据机具号补发开机奖励
- public IActionResult PosRewardReissued(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string PosRewardReissuedDo(string PosSn)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
- var PosId = "";
- var error = "";
- foreach (var item in PosSnList)
- {
- var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
- var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
- bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
- if (checkExist)
- {
- error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
- }
- else
- {
- if (posInfo.Id > 0)
- {
- RedisDbconn.Instance.AddList("OpenRewardQueue", posInfo.Id.ToString());
- }
- }
- }
- if (!string.IsNullOrEmpty(error))
- {
- return "Warning|" + error;
- }
- PosId = PosId.TrimEnd(',');
- function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
- return "success";
- }
- #endregion
- #region 根据机具号设置费率
- public IActionResult SetPosFee(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SetPosFeeDo(string PosSn, string FeeType)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- if (string.IsNullOrEmpty(FeeType))
- {
- return "请输入选择费率";
- }
- if (FeeType == "0")
- {
- FeeType = "0.6";
- }
- if (FeeType == "1")
- {
- FeeType = "0.63";
- }
- string[] PosSnList = PosSn.Split('\n');
- var PosId = "";
- var RecordId = "";
- var error = "";
- foreach (var item in PosSnList)
- {
- var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
- var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
- if (posInfo.Id > 0)
- {
- var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
- {
- Sort = posInfo.BrandId,
- CreateDate = DateTime.Now,
- PosId = posInfo.Id,
- PosSn = posInfo.PosSn,
- PosUserId = posInfo.UserId,
- MerchantId = posInfo.BindMerchantId,
- UserId = posInfo.UserId,
- ChangeFee = decimal.Parse(FeeType),
- }).Entity;
- db.SaveChanges();
- PosId += posInfo.Id + ",";
- RecordId += query.Id + ",";
- }
- else
- {
- error += "机具" + PosSn + "不存在";
- }
- }
- if (!string.IsNullOrEmpty(error))
- {
- return "Warning|" + error;
- }
- PosId = PosId.TrimEnd(',');
- function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
- string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
- RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
- return "success";
- }
- #endregion
- #region 根据机具号、商户号、商户姓名关联商户和机具信息
- public IActionResult RelationPosAndMerchant(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- if (string.IsNullOrEmpty(MerchantNo))
- {
- return "请输入商户编号";
- }
- if (string.IsNullOrEmpty(MerchantName))
- {
- return "请输入商户姓名";
- }
- var query = PosSn + "," + MerchantNo + "," + MerchantName;
- var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
- var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
- var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
- if (posMerchant.Id == 0)
- {
- return "商户" + MerchantNo + "不存在";
- }
- else if (pos.Id == 0)
- {
- return "机具" + PosSn + "不存在";
- }
- else
- {
- pos.BindMerchantId = posMerchant.Id;
- db.SaveChanges();
- function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
- }
- return "success";
- }
- #endregion
- #region 设置商户信息
- public IActionResult SetMerchantInfo(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SetMerchantInfoDo(string PosSn, string MerchantNo, string MerchantName, string MerIdcardNo, string MerchantMobile)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- if (string.IsNullOrEmpty(MerchantNo))
- {
- return "请输入商户编号";
- }
- if (string.IsNullOrEmpty(MerchantName))
- {
- return "请输入商户姓名";
- }
- if (string.IsNullOrEmpty(MerIdcardNo))
- {
- return "请输入商户身份证号";
- }
- if (string.IsNullOrEmpty(MerchantMobile))
- {
- return "请输入商户手机号";
- }
- var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo && m.KqSnNo == PosSn && m.MerchantName.StartsWith(MerchantName.Substring(0, 1))) ?? new PosMerchantInfo();
- var query = "";
- query += "修改前:" + posMerchant.KqSnNo + "," + posMerchant.MerchantNo + "," + posMerchant.MerchantName + "," + posMerchant.MerIdcardNo + "," + posMerchant.MerchantMobile;
- query += "修改后:" + PosSn + "," + MerchantNo + "," + MerchantName + "," + MerIdcardNo + "," + MerchantMobile;
- if (posMerchant.Id == 0)
- {
- return "商户" + MerchantNo + "不存在或不在" + MerchantName + "名下";
- }
- else
- {
- posMerchant.MerIdcardNo = MerIdcardNo;
- posMerchant.MerchantName = MerchantName;
- posMerchant.MerRealName = MerchantName;
- posMerchant.MerchantMobile = MerchantMobile;
- db.SaveChanges();
- function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "设置商户信息");
- }
- return "success";
- }
- #endregion
- #region 认证创客
- public IActionResult AuthMaker(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
- {
- if (string.IsNullOrEmpty(MakerCode))
- {
- return "请输入创客编号";
- }
- if (string.IsNullOrEmpty(RealName))
- {
- return "请输入真实姓名";
- }
- if (string.IsNullOrEmpty(CertId))
- {
- return "请输入身份证号";
- }
- if (string.IsNullOrEmpty(BackCard))
- {
- return "请输入银行卡号";
- }
- if (string.IsNullOrEmpty(BackName))
- {
- return "请输入银行名称";
- }
- var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
- var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
- var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
- if (userInfo.AuthFlag == 1)
- {
- return "已认证";
- }
- else
- {
- userInfo.UpdateDate = DateTime.Now;
- userInfo.RealName = RealName;
- userInfo.AuthFlag = 1;
- if (userInfo.AuthDate == null)
- {
- userInfo.AuthDate = DateTime.Now;
- }
- userInfo.CertId = CertId;
- userInfo.SettleBankCardNo = BackCard;
- userInfo.SettleBankName = BackName;
- db.SaveChanges();
- function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
- }
- return "success";
- }
- #endregion
- #region 划拨创客机具
- public IActionResult TransferPos(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- // public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
- // {
- // if (string.IsNullOrEmpty(PosSn))
- // {
- // return "请输入机具SN";
- // }
- // if (string.IsNullOrEmpty(FromMakerCode))
- // {
- // return "请输入机具来源创客编号";
- // }
- // if (string.IsNullOrEmpty(ToMakerCode))
- // {
- // return "请输入划拨对象创客编号";
- // }
- // var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
- // var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
- // var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
- // if (posInfo.Id == 0)
- // {
- // return "机具" + PosSn + "不存在";
- // }
- // var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
- // var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
- // var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
- // if (fUserId.Id == 0)
- // {
- // return "来源创客" + FromMakerCode + "不存在";
- // }
- // var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
- // if (tUserId.Id == 0)
- // {
- // return "划拨创客" + ToMakerCode + "不存在";
- // }
- // if (posInfo.BindingState == 0)
- // {
- // if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
- // {
- // posInfo.BuyUserId = tUserId.Id;
- // posInfo.UserId = tUserId.Id;
- // }
- // else
- // {
- // posInfo.BuyUserId = tUserId.Id;
- // }
- // var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
- // var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
- // fUserPos.TotalMachineCount -= 1;
- // fUserPos.UnBindCount -= 1;
- // tUserPos.TotalMachineCount += 1;
- // tUserPos.UnBindCount += 1;
- // db.SaveChanges();
- // function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
- // }
- // else
- // {
- // return "机具" + PosSn + "已使用";
- // }
- // return "success";
- // }
- // #endregion
- public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- if (string.IsNullOrEmpty(FromMakerCode))
- {
- return "请输入机具来源创客编号";
- }
- if (string.IsNullOrEmpty(ToMakerCode))
- {
- return "请输入划拨对象创客编号";
- }
- var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
- var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
- var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
- if (fUserId.Id == 0)
- {
- return "来源创客" + FromMakerCode + "不存在";
- }
- var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
- if (tUserId.Id == 0)
- {
- return "划拨创客" + ToMakerCode + "不存在";
- }
- List<int> SnIds = new List<int>();
- string[] PosSnList = PosSn.Replace("\r", "").Replace("\n", ",").Split(',');
- string error = "";
- foreach (string Sn in PosSnList)
- {
- 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();
- if (posInfo.Id == 0)
- {
- error += "以下操作失败" + Sn + ',' + "不存在或者不符合条件" + '\n';
- }
- else
- {
- SnIds.Add(posInfo.Id);
- }
- }
- if (!string.IsNullOrEmpty(error))
- {
- return "Warning|" + error;
- }
- else
- {
- var ChangeRecordNo = "HBJJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8); //变更记录单号
- foreach (int SnId in SnIds)
- {
- var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
- if (posInfo.UserId == 0 || posInfo.BuyUserId == posInfo.UserId)
- {
- posInfo.BuyUserId = tUserId.Id;
- posInfo.UserId = tUserId.Id;
- }
- else
- {
- posInfo.BuyUserId = tUserId.Id;
- }
- var fUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
- var tUserPos = db.UserMachineData.FirstOrDefault(m => m.IdBrand == tUserId.Id + "_" + posInfo.BrandId) ?? new UserMachineData();
- fUserPos.TotalMachineCount -= 1;
- fUserPos.UnBindCount -= 1;
- tUserPos.TotalMachineCount += 1;
- tUserPos.UnBindCount += 1;
- db.StoreChangeHistory.Add(new StoreChangeHistory()
- {
- CreateDate = DateTime.Now,
- UserId = fUserId.Id, //创客
- BrandId = posInfo.BrandId,//产品类型
- // ChangeRecordNo = "HBJJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
- ChangeRecordNo = ChangeRecordNo, //变更记录单号
- TransType = 1, //交易类型
- SnNo = posInfo.PosSn, //SN编号
- SnType = posInfo.PosSnType, //SN机具类型
- StockOpDirect = 1, //库存操作方向
- DeviceVendor = posInfo.DeviceName, //设备厂商
- DeviceModel = posInfo.DeviceKind, //设备型号
- DeviceType = posInfo.DeviceType, //设备类型
- FromUserId = fUserId.Id, //出货创客
- FromDate = DateTime.Now, //出库时间
- FromRemark = "划拨创客机具", //出库备注
- SourceStoreId = posInfo.SourceStoreId, //源仓库
- ToUserId = tUserId.Id,//收货创客
- });
- // UserStoreChange userstore = db.UserStoreChange.Add(new UserStoreChange()
- // {
- // CreateDate = DateTime.Now,
- // UserId = fUserId.Id, //创客
- // BrandId = posInfo.BrandId, //产品类型
- // ChangeRecordNo = ChangeRecordNo, //变更记录单号
- // TransType = 0, //交易类型
- // SnNo = posInfo.PosSn, //SN编号
- // SnType = posInfo.PosSnType, //SN机具类型
- // StockOpDirect = 0, //库存操作方向
- // DeviceVendor = posInfo.DeviceName, //设备厂商
- // DeviceType = posInfo.DeviceKind, //设备类型
- // DeviceModel = posInfo.DeviceType, //设备型号
- // ToUserId = tUserId.Id, //收货创客
- // ToDate = DateTime.Now, //入库时间
- // SourceStoreId = posInfo.SourceStoreId, //源仓库
- // SnStatus = 1, //SN状态
- // BindStatus = (int)posInfo.BindingState, //绑定状态
- // BindMerchantId = posInfo.BindMerchantId, //绑定商户
- // ActiveStatus = (int)posInfo.ActivationState, //激活状态
- // ActRewardUserId = posInfo.BuyUserId, //激活奖励创客
- // BrandType = posInfo.DeviceType, //品牌类型
- // }).Entity;
- }
- var query = SnIds + ";" + FromMakerCode + ";" + ToMakerCode;
- function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
- db.SaveChanges();
- db.Dispose();
- }
- return "success";
- }
- #endregion
- #region 还原提现订单状态
- public IActionResult RestoreStatus(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string RestoreStatusDo(string OrderNo)
- {
- if (string.IsNullOrEmpty(OrderNo))
- {
- return "请输入提现订单编号";
- }
- string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
- var error = "";
- foreach (var item in OrderNoList)
- {
- var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
- if (cash.Id > 0)
- {
- cash.QueryCount = 0;
- cash.Status = 0;
- db.SaveChanges();
- }
- else
- {
- error += "订单" + item + "不存在" + '\n';
- }
- }
- if (!string.IsNullOrEmpty(error))
- {
- return "Warning|" + error;
- }
- return "success";
- }
- #endregion
- #region 查询创客循环资格
- public IActionResult SeeUserLoop(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SeeUserLoopDo(string MakerCode)
- {
- var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
- var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
- var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
- var brandList = db.KqProducts.ToList();
- var info = "";
- foreach (var item in brandList)
- {
- var brand = item.Name;
- //已过期
- var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
- //可申请
- var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id && m.PosSnType == 0);
- //已使用
- // var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id && m.PosSnType == 0);
- // info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
- info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + "\n";
- }
- return info;
- }
- #endregion
- #region 提交到代付排除的创客名单
- public IActionResult CashWithoutUser(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser") ?? new CustomTagSet();
- ViewBag.set = set;
- return View();
- }
- public string CashWithoutUserDo(string Content)
- {
- CustomTagSet set = db.CustomTagSet.FirstOrDefault(m => m.Tags == "CashWithoutUser");
- if (set == null)
- {
- set = db.CustomTagSet.Add(new CustomTagSet()
- {
- Tags = "CashWithoutUser",
- Title = "提交到代付排除的创客名单"
- }).Entity;
- db.SaveChanges();
- }
- set.Contents = Content;
- db.SaveChanges();
- db.Dispose();
- return "success";
- }
- #endregion
- #region 坏机回仓
- public IActionResult BadPosToStore(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string BadPosToStoreDo(string OldSn)
- {
- string[] OldSnList;
- OldSnList = OldSn.Replace("\r", "").Split('\n');
- string error = "";
- List<string> opData = new List<string>();
- for (int i = 0; i < OldSnList.Length; i++)
- {
- string OldSnNum = OldSnList[i];
- MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
- PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId) ?? new PosMachinesTwo();
- if (!opData.Contains(oldpos.BuyUserId + ":" + oldpos.BrandId))
- {
- opData.Add(oldpos.BuyUserId + ":" + oldpos.BrandId);
- }
- oldpos.Status = 1;
- oldpos.PosSnType = 0;
- oldpos.QueryCount = 0;
- oldpos.UpdateDate = null;
- oldpos.ActivityList = null;
- oldpos.SeoKeyword = null;
- oldpos.SeoDescription = null;
- oldpos.OrderId = 0;
- oldpos.RecycEndDate = null;
- oldpos.RecycBackCount = 0;
- oldpos.PrizeParams = null;
- oldpos.ScanQrTrade = 0;
- oldpos.BindMerchantId = 0;
- oldpos.CreditTrade = 0;
- oldpos.DebitCardTrade = 0;
- oldpos.IsVip = 0;
- oldpos.UserNav = null;
- oldpos.TransferTime = null;
- oldpos.IsPurchase = 0;
- oldpos.Detail = null;
- oldpos.BindingTime = null;
- oldpos.BindingState = 0;
- oldpos.ActivationTime = null;
- oldpos.ActivationState = 0;
- oldpos.LeaderUserId = 0;
- oldpos.PreUserId = 0;
- oldpos.IsFirst = 0;
- oldpos.DownFeeMan = null;
- oldpos.DownFeeFlag = 0;
- oldpos.DownFeeDate = null;
- oldpos.UpFeeMan = null;
- oldpos.UpFeeFlag = 0;
- oldpos.UpFeeDate = null;
- oldpos.OpReserve1 = 0;
- oldpos.OpReserve2 = 0;
- oldpos.OpReserve3 = 0;
- oldpos.OpId = 0;
- oldpos.RecycStartDate = null;
- oldpos.SourcePosSn = null;
- oldpos.BuyUserId = 0;
- oldpos.UserId = 0;
- PublicFunction.ClearPosHistory(db, oldpos.PosSn); //清除机具历史记录
- }
- if (!string.IsNullOrEmpty(error))
- {
- return "Warning|" + error;
- }
- db.SaveChanges();
- foreach (string sub in opData)
- {
- string[] datalist = sub.Split(":");
- PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
- }
- return "success";
- }
- #endregion
- #region 划拨创客机具券
- public IActionResult TransferPosCoupon(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- public string TransferPosCouponDo(string Kind, string PosCouponCodes, string FromMakerCode, string ToMakerCode, string LeaderMakerCode = "")
- {
- if (string.IsNullOrEmpty(Kind))
- {
- return "请选择划拨的券类型";
- }
- if (string.IsNullOrEmpty(PosCouponCodes))
- {
- return "请输入机具券码";
- }
- if (string.IsNullOrEmpty(FromMakerCode))
- {
- return "请输入机具来源创客编号";
- }
- if (string.IsNullOrEmpty(ToMakerCode))
- {
- return "请输入划拨对象创客编号";
- }
- var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
- var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
- var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
- if (fUserId.Id == 0)
- {
- return "来源创客" + FromMakerCode + "不存在";
- }
- var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
- if (tUserId.Id == 0)
- {
- return "划拨创客" + ToMakerCode + "不存在";
- }
- int LeaderUserId = 0;
- if (!string.IsNullOrEmpty(LeaderMakerCode))
- {
- UserForMakerCode leaderuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == LeaderMakerCode) ?? new UserForMakerCode();
- Users LeaderUserItem = db.Users.FirstOrDefault(m => m.Id == leaderuser.UserId) ?? new Users();
- if (LeaderUserItem.Id == 0)
- {
- return "大盟主创客编号" + LeaderMakerCode + "不存在";
- }
- LeaderUserId = leaderuser.UserId;
- }
- string ChangeRecordNo = "SC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- var query = PosCouponCodes + "\n" + FromMakerCode + "," + ToMakerCode;
- string[] PosCouponList = PosCouponCodes.Replace("\r", "").Replace("\n", ",").Split(',');
- foreach (string PosCouponCode in PosCouponList)
- {
- PosCoupons item = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == PosCouponCode) ?? new PosCoupons();
- if (item.UserId != fUserId.Id)
- {
- return "机具券" + PosCouponCode + "不在创客" + FromMakerCode + "名下";
- }
- if (item.Id == 0)
- {
- return "机具券" + PosCouponCode + "不存在";
- }
- if (item.IsUse == 1)
- {
- return "机具券" + PosCouponCode + "已使用";
- }
- item.UserId = tUserId.Id;
- if (LeaderUserId > 0 && item.LeaderUserId == 0)
- {
- item.LeaderUserId = LeaderUserId;
- }
- // PosCouponRecord posCouponRecord = db.PosCouponRecord.Add(new PosCouponRecord()
- // {
- // QueryCount = item.QueryCount,//券类型(1 电签 2 大POS)
- // CreateDate = DateTime.Now,
- // ChangeKind = 1,//类型(0购买,1划拨,2使⽤,3申请机具循环驳回)
- // OrderNo = ChangeRecordNo,
- // ToUserId = tUserId.Id,
- // FromUserId = fUserId.Id,
- // PosCouponId = item.Id,
- // }).Entity;
- }
- // int CouponCount = PosCouponList.Length;
- // PosCouponOrders stat = db.PosCouponOrders.Add(new PosCouponOrders()
- // {
- // QueryCount = 2,
- // CreateDate = DateTime.Now,
- // ChangeKind = 2,
- // ChangeCount = CouponCount,
- // // AfterOut = AfterOut,
- // // AfterTotal = AfterTotal,
- // // AfterStock = AfterStock,
- // // BeforeOut = BeforeOut,
- // // BeforeTotal = BeforeTotal,
- // // BeforeStock = BeforeStock,
- // OrderNo = ChangeRecordNo,
- // ToUserId = tUserId.Id,
- // FromUserId = fUserId.Id,
- // }).Entity;
- db.SaveChanges();
- db.Dispose();
- return "success";
- }
- #endregion
- #region 机具回仓退款
- public IActionResult RefundPosFee(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string RefundPosFeeDo(string PosSn, string BackStoreNo, int IsBack = 0)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- if (IsBack == 1)
- {
- if (string.IsNullOrEmpty(BackStoreNo))
- {
- return "请输入仓库编号";
- }
- }
- string[] PosSnList = PosSn.Replace("\r", "").Split('\n');
- WebCMSEntities db = new WebCMSEntities();
- DateTime time = DateTime.Parse(DateTime.Now.ToString(("yyyy-MM-dd") + " 00:00:00"));
- var endTime = time.AddDays(20 - time.Day).AddDays(-60);
- StoreForCode storeForBack = new StoreForCode();
- StoreHouse BackStore = new StoreHouse();
- List<string> opData = new List<string>();
- foreach (var item in PosSnList)
- {
- MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
- if (machineForSnNo.SnId == 0)
- {
- return "未找到机具" + item + "关联数据";
- }
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.Status > -1 && m.RecycEndDate < endTime && m.BindingState == 0) ?? new PosMachinesTwo();
- if (pos.Id == 0)
- {
- return "机具" + item + "不存在或者不满足条件";
- }
- if (IsBack == 1)
- {
- storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
- if (storeForBack.StoreId == 0)
- {
- return "未找到" + BackStoreNo + "关联数据";
- }
- BackStore = db.StoreHouse.FirstOrDefault(m => m.Status > -1 && m.Id == storeForBack.StoreId && m.BrandId == pos.BrandId.ToString()) ?? new StoreHouse();
- if (BackStore.Id == 0)
- {
- return "仓库" + BackStoreNo + "不存在或与机具品牌不符";
- }
- }
- var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == BackStore.UserId) ?? new UserAccount();
- var refundUserAccount = db.UserAccount.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new UserAccount();
- var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
- var amount = 0;
- if (brandInfo.Name.Contains("电签"))
- {
- amount = 200;
- }
- if (brandInfo.Name.Contains("大POS"))
- {
- amount = 300;
- }
- if (IsBack == 1)
- {
- userAccount.ValidAmount -= amount;//扣减分仓可用额度
- StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
- {
- CreateDate = DateTime.Now,
- CreateMan = SysUserName,
- StoreId = pos.StoreId, //出货仓库
- BrandId = pos.BrandId, //产品类型
- ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
- TransType = 5, //交易类型
- SnNo = item, //SN编号
- StockOpDirect = 0, //库存操作方向
- SnStatus = 1, //SN状态
- DeviceVendor = pos.DeviceName, //设备厂商
- DeviceModel = pos.DeviceKind, //设备型号
- DeviceType = pos.DeviceType, //设备类型
- FromUserId = pos.BuyUserId, //来源创客
- ToRemark = "过期机具回仓退款", //入库备注
- ToStoreId = BackStore.Id, //退货收货仓库
- SourceStoreId = pos.SourceStoreId, //源仓库编号
- BrandType = pos.DeviceType, //品牌类型
- }).Entity;
- string ChangeNo = "HCTK";
- int StoreStockChangeId = stockchange.Id;
- string StoreStockChangeIdString = StoreStockChangeId.ToString();
- for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
- {
- StoreStockChangeIdString = "0" + StoreStockChangeIdString;
- }
- ChangeNo += StoreStockChangeIdString;
- stockchange.ChangeNo = ChangeNo; //交易流水编号
- db.StoreChangeHistory.Add(new StoreChangeHistory()
- {
- CreateDate = DateTime.Now,
- BrandId = pos.BrandId, //产品类型
- ChangeRecordNo = ChangeNo, //变更记录单号
- TransType = 5, //交易类型
- SnNo = item, //SN编号
- SnType = pos.PosSnType, //SN机具类型
- StockOpDirect = 0, //库存操作方向
- DeviceVendor = pos.DeviceName, //设备厂商
- DeviceModel = pos.DeviceKind, //设备型号
- DeviceType = pos.DeviceType, //设备类型
- FromUserId = pos.BuyUserId, //来源创客
- ToRemark = "过期机具回仓退款", //入库备注
- SourceStoreId = pos.SourceStoreId, //源仓库
- StoreId = pos.StoreId, //出货仓库
- });
- db.MachineReturn.Add(new MachineReturn()
- {
- CreateDate = DateTime.Now,
- Operator = SysUserName + "_" + SysRealName,//操作人
- BrandId = pos.BrandId, //产品类型
- DeviceSnNos = pos.PosSn,
- ToStoreId = BackStore.Id,
- ApplyNo = ChangeNo, //变更记录单号
- UserId = pos.BuyUserId, //来源创客
- Remark = "过期机具回仓退款", //入库备注
- });
- if (pos.ScanQrTrade > 0)
- {
- decimal ChangeAmount = 0;
- decimal BeforeBalanceAmount = 0;
- decimal AfterBalanceAmount = 0;
- if (pos.ScanQrTrade == 999)
- {
- refundUserAccount.BalanceAmount += amount;//退还创客机具货款
- BeforeBalanceAmount = refundUserAccount.BalanceAmount;
- AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
- ChangeAmount = amount;
- }
- else
- {
- refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
- BeforeBalanceAmount = refundUserAccount.BalanceAmount;
- AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
- ChangeAmount = pos.ScanQrTrade;
- }
- db.UserAccountRecord.Add(new UserAccountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = pos.BuyUserId, //创客
- ChangeType = 126, //变动类型(机具货款退还)
- ProductType = 0, //产品类型
- ChangeAmount = ChangeAmount, //变更金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- });
- }
- var bInfo = BackStore.UserId + "_" + pos.BrandId;
- var userMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == bInfo) ?? new UserMachineData();
- userMachineData.TotalMachineCount += 1;
- userMachineData.UnBindCount += 1;
- BackStore.LaveNum += 1;
- BackStore.TotalNum += 1;
- var fInfo = pos.BuyUserId + "_" + pos.BrandId;
- var userMachineDatas = db.UserMachineData.FirstOrDefault(m => m.IdBrand == fInfo) ?? new UserMachineData();
- userMachineDatas.TotalMachineCount -= 1;
- userMachineDatas.UnBindCount -= 1;
- if (!opData.Contains(pos.BuyUserId + ":" + pos.BrandId))
- {
- opData.Add(pos.BuyUserId + ":" + pos.BrandId);
- }
- pos.StoreId = BackStore.Id;//变更机具所属仓库,重置为仓库机
- pos.Status = 1;
- pos.QueryCount = 0;
- pos.UpdateDate = null;
- pos.ActivityList = null;
- pos.SeoKeyword = null;
- pos.SeoDescription = null;
- pos.OrderId = 0;
- pos.RecycEndDate = null;
- pos.RecycBackCount = 0;
- pos.PrizeParams = null;
- pos.ScanQrTrade = 0;
- pos.BindMerchantId = 0;
- pos.CreditTrade = 0;
- pos.DebitCardTrade = 0;
- pos.IsVip = 0;
- pos.UserNav = null;
- pos.TransferTime = null;
- pos.IsPurchase = 0;
- pos.Detail = null;
- pos.BindingTime = null;
- pos.BindingState = 0;
- pos.ActivationTime = null;
- pos.ActivationState = 0;
- pos.LeaderUserId = 0;
- pos.PreUserId = 0;
- pos.IsFirst = 0;
- pos.DownFeeMan = null;
- pos.DownFeeFlag = 0;
- pos.DownFeeDate = null;
- pos.UpFeeMan = null;
- pos.UpFeeFlag = 0;
- pos.UpFeeDate = null;
- pos.OpReserve1 = 0;
- pos.OpReserve2 = 0;
- pos.OpReserve3 = 0;
- pos.OpId = 0;
- pos.RecycStartDate = null;
- pos.SourcePosSn = null;
- pos.BuyUserId = 0;
- pos.UserId = 0;
- PublicFunction.ClearPosHistory(db, pos.PosSn); //清除机具历史记录
- }
- else
- {
- if (pos.ScanQrTrade > 0)
- {
- decimal ChangeAmount = 0;
- decimal BeforeBalanceAmount = 0;
- decimal AfterBalanceAmount = 0;
- if (pos.ScanQrTrade == 999)
- {
- refundUserAccount.BalanceAmount += amount;//退还创客机具货款
- BeforeBalanceAmount = refundUserAccount.BalanceAmount;
- AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
- ChangeAmount = amount;
- }
- else
- {
- refundUserAccount.BalanceAmount += pos.ScanQrTrade;//退还创客机具货款
- BeforeBalanceAmount = refundUserAccount.BalanceAmount;
- AfterBalanceAmount = refundUserAccount.BalanceAmount + pos.ScanQrTrade;
- ChangeAmount = pos.ScanQrTrade;
- }
- pos.ScanQrTrade = 0;
- db.UserAccountRecord.Add(new UserAccountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = pos.BuyUserId, //创客
- ChangeType = 126, //变动类型(机具货款退还)
- ProductType = 0, //产品类型
- ChangeAmount = ChangeAmount, //变更金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- });
- }
- }
- }
- db.SaveChanges();
- foreach (string sub in opData)
- {
- string[] datalist = sub.Split(":");
- PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
- }
- return "success";
- }
- #endregion
- #region 添加商户信息
- public IActionResult AddMerchantnfo(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string AddMerchantnfoDo(string PosSn, string MerSn)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具号";
- }
- if (string.IsNullOrEmpty(MerSn))
- {
- return "请输入商户号";
- }
- var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
- var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
- var merchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
- if (machineForSnNo.SnId == 0)
- {
- return "未找到机具" + PosSn + "关联数据";
- }
- if (pos.Id == 0)
- {
- return "未找到机具" + PosSn;
- }
- if (merchantInfo.Id > 0)
- {
- return "机具" + PosSn + "以经存在绑定商户";
- }
- var spInfo = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerSn && m.MerSnNo == PosSn) ?? new SpModels.BindRecord();
- if (spInfo.Id > 0)
- {
- var MerUserType = 0;
- var ActiveStatus = 0;
- if (pos.BuyUserId != pos.UserId)
- {
- MerUserType = 1;
- }
- if (string.IsNullOrEmpty(pos.ActivationTime.ToString()))
- {
- ActiveStatus = 1;
- }
- PosMerchantInfo posMerchantInfo = db.PosMerchantInfo.Add(new PosMerchantInfo()
- {
- CreateDate = pos.BindingTime,
- TopUserId = 1,
- BrandId = pos.BrandId,
- SnStoreId = pos.StoreId,
- MerStandardDate = pos.ActivationTime,
- SnType = pos.PosSnType,
- MerUserType = MerUserType,
- UserId = pos.UserId,
- ActiveStatus = ActiveStatus,
- MerStatus = 1,
- KqSnNo = PosSn,
- KqMerNo = MerSn,
- MerIdcardNo = spInfo.SeoKeyword,
- MerchantMobile = spInfo.MerNewSnNo,
- MerchantName = spInfo.MerName,
- MerchantNo = spInfo.MerNo,
- }).Entity;
- db.SaveChanges();
- string text = string.Format("设置商户信息,机具Sn: " + PosSn + ",商户编号: " + MerSn + ",操作人:" + SysUserName + "_" + SysRealName + ",时间:" + DateTime.Now + "");
- function.WriteLog(text, "设置商户信息");
- }
- return "success";
- }
- #endregion
- #region 查询商户达标明细
- public IActionResult SeeMerchantTradeDetail(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string SeeMerchantTradeDetailDo(string PosSn)
- {
- if (string.IsNullOrEmpty(PosSn))
- {
- return "请输入机具SN";
- }
- var result = "";
- var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
- if (pos.Id > 0)
- {
- var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
- if (mer.Id > 0)
- {
- var IsOk = "";//是否达标
- var timeInfo = "";
- if (mer.StandardMonths == 10)
- {
- IsOk = "已达标";
- }
- else
- {
- IsOk = "未达标";
- }
- result += IsOk + "\n";
- result += "开机时间:" + DateTime.Parse(pos.BindingTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss") + "\n";
- result += "激活时间:" + DateTime.Parse(pos.ActivationTime.ToString()).ToString("yyyy-MM-dd HH:mm:ss") + "\n";
- result += "商户姓名:" + mer.MerRealName + "\n";
- result += "明细:\n";
- for (int i = 0; i < 12; i++)
- {
- var time = DateTime.Parse(pos.ActivationTime.ToString()).AddMonths(i + 1).ToString("yyyyMM");//达标计算开始时间
- timeInfo += "," + time;
- }
- timeInfo = timeInfo + ",";
- var merTradeInfo = db.PosMerchantTradeSummay.Where(m => m.MerchantId == mer.Id && timeInfo.Contains("," + m.TradeMonth + ",")).ToList();
- string[] month = timeInfo.TrimStart(',').TrimEnd(',').Split(',');
- foreach (var item in month)
- {
- var tradeAmount = merTradeInfo.Where(m => m.TradeMonth == item).Sum(m => m.TradeAmount);
- result += item + "交易额:" + tradeAmount + "\n";
- }
- }
- else
- {
- return "未找到机具" + PosSn + "所对应的商户";
- }
- }
- else
- {
- return "未找到机具" + PosSn;
- }
- return result;
- }
- #endregion
- #region 指定文件Excel导出
- public IActionResult ExportExcel(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string ExportExcelDo(string FileName, string Operator, string Sql, int Number = 0)
- {
- if (string.IsNullOrEmpty(FileName))
- {
- return "请输入文件名";
- }
- if (string.IsNullOrEmpty(Operator))
- {
- return "请输入后台操作人";
- }
- if (string.IsNullOrEmpty(Sql))
- {
- return "请输入SQL语句";
- }
- var SqlString = "";
- if (Number == 0)
- {
- SqlString = Sql;
- }
- if (Number > 0)
- {
- SqlString = Sql + " LIMIT " + Number;
- }
- string[] Operators = Operator.Replace("\r", "").Replace("\n", ",").Split(',');
- foreach (var item in Operators)
- {
- var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == item && m.Status > -1);
- string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + SqlString + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"" + Number + "\"}";
- RedisDbconn.Instance.AddList("ExportQueue", SendData);
- }
- return "success";
- }
- #endregion
- #region 服务费返现注册查询
- public IActionResult SeeMerchantAuthInfo(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 服务费返现注册查询
- public JsonResult SeeMerchantAuthInfoDo(string RealName, string Mobile, string CertId, int page = 1, int limit = 30)
- {
- var query = db.UserFamilyMember.Where(m => m.Status > -1);
- if (string.IsNullOrEmpty(RealName) && string.IsNullOrEmpty(Mobile) && string.IsNullOrEmpty(CertId))
- {
- Dictionary<string, object> objs = new Dictionary<string, object>();
- return Json(objs);
- }
- else
- {
- if (!string.IsNullOrEmpty(RealName))
- {
- query = query.Where(m => m.Name == RealName);
- }
- if (!string.IsNullOrEmpty(Mobile))
- {
- query = query.Where(m => m.Mobile == Mobile);
- }
- if (!string.IsNullOrEmpty(CertId))
- {
- query = query.Where(m => m.IdCardNo.ToUpper() == CertId.ToUpper());
- }
- }
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- foreach (var subdata in query.ToList())
- {
- Dictionary<string, object> data = new Dictionary<string, object>();
- if (subdata.Id > 0)
- {
- data["IsRegist"] = "已注册";
- if (subdata.Status == 1)
- {
- data["IsAuth"] = "已认证";
- data["Name"] = subdata.Name;
- data["Mobile"] = subdata.Mobile;
- data["IdcardNo"] = subdata.IdCardNo;
- var linkCount = db.PosMerchantInfo.Count(m => m.MerRealName == subdata.Name && m.MerchantMobile == subdata.Mobile && m.MerIdcardNo.ToUpper() == subdata.IdCardNo.ToUpper());
- data["Count"] = linkCount;
- }
- else
- {
- data["IsAuth"] = "未认证";
- data["Name"] = "";
- data["Mobile"] = subdata.Mobile;
- data["IdcardNo"] = "";
- data["Count"] = "";
- }
- }
- else
- {
- data["IsRegist"] = "未注册";
- data["IsAuth"] = "未认证";
- data["Name"] = "";
- data["Mobile"] = "";
- data["IdcardNo"] = "";
- data["Count"] = "";
- }
- dataList.Add(data);
- }
- Dictionary<string, object> obj = new Dictionary<string, object>();
- obj.Add("code", 0);
- obj.Add("msg", "");
- obj.Add("count", dataList.Count);
- obj.Add("data", dataList);
- return Json(obj);
- }
- #endregion
- #region 直营团队数据
- public IActionResult Team1Info(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 直营团队数据
- public JsonResult Team1InfoDo(string MakerCode, string BindingTime, string ActivationTime, string PosFeeSelect, string BrandId, int page = 1, int limit = 30)
- {
- string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- string condition = " where 1=1";
- var UserId = 0;
- var bstart = "";
- var bend = "";
- var astart = "";
- var aend = "";
- if (!string.IsNullOrEmpty(MakerCode))
- {
- var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
- UserId = user.Id;
- }
- if (!string.IsNullOrEmpty(BindingTime))
- {
- string[] datelist = BindingTime.Split(new string[] { " - " }, StringSplitOptions.None);
- bstart = datelist[0] + " 00:00:00";
- bend = datelist[1] + " 23:59:59";
- condition += " and tb.BindingTime>='" + bstart + "' and tb.BindingTime<='" + bend + "'";
- }
- if (!string.IsNullOrEmpty(ActivationTime))
- {
- string[] datelist = ActivationTime.Split(new string[] { " - " }, StringSplitOptions.None);
- astart = datelist[0] + " 00:00:00";
- aend = datelist[1] + " 23:59:59";
- condition += " and tb.ActivationTime>='" + astart + "' and tb.ActivationTime<='" + aend + "'";
- }
- if (!string.IsNullOrEmpty(PosFeeSelect))
- {
- if (PosFeeSelect == "0")
- {
- condition += " and tb.SeoKeyword is null";
- }
- else
- {
- condition += " and tb.SeoKeyword=" + PosFeeSelect;
- }
- }
- if (!string.IsNullOrEmpty(BrandId))
- {
- condition += " and tb.BrandId=" + BrandId;
- }
- 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);
- foreach (DataRow item in dt.Rows)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("wname", item["wname"].ToString()); //伙伴名称
- curData.Add("Name", item["Name"].ToString()); //机具品牌
- curData.Add("PosSn", item["PosSn"].ToString()); //机具Sn
- curData.Add("SeoKeyword", item["SeoKeyword"].ToString()); //服务费
- curData.Add("BindingTime", string.IsNullOrEmpty(item["BindingTime"].ToString()) ? "" : Convert.ToDateTime(item["BindingTime"]).ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
- curData.Add("ActivationTime", string.IsNullOrEmpty(item["ActivationTime"].ToString()) ? "" : Convert.ToDateTime(item["ActivationTime"]).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
- dataList.Add(curData);
- }
- Dictionary<string, object> obj = new Dictionary<string, object>();
- obj.Add("code", 0);
- obj.Add("msg", "");
- obj.Add("count", dataList.Count);
- obj.Add("data", dataList);
- return Json(obj);
- }
- #endregion
- #region 直营团队数据导出
- public IActionResult ExportTeam1InfoExcel(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- [HttpPost]
- public string ExportTeam1InfoExcelDo(string MakerCode, string BindingTime, string ActivationTime, string PosFeeSelect, string BrandId)
- {
- string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- var RealName = "";
- string condition = " where 1=1";
- var UserId = 0;
- var bstart = "";
- var bend = "";
- var astart = "";
- var aend = "";
- if (!string.IsNullOrEmpty(MakerCode))
- {
- var user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new Users();
- UserId = user.Id;
- RealName = user.RealName;
- }
- if (!string.IsNullOrEmpty(BindingTime))
- {
- string[] datelist = BindingTime.Split(new string[] { " - " }, StringSplitOptions.None);
- bstart = datelist[0] + " 00:00:00";
- bend = datelist[1] + " 23:59:59";
- condition += " and tb.BindingTime>='" + bstart + "' and tb.BindingTime<='" + bend + "'";
- }
- if (!string.IsNullOrEmpty(ActivationTime))
- {
- string[] datelist = ActivationTime.Split(new string[] { " - " }, StringSplitOptions.None);
- astart = datelist[0] + " 00:00:00";
- aend = datelist[1] + " 23:59:59";
- condition += " and tb.ActivationTime>='" + astart + "' and tb.ActivationTime<='" + aend + "'";
- }
- if (!string.IsNullOrEmpty(PosFeeSelect))
- {
- if (PosFeeSelect == "0")
- {
- condition += " and tb.SeoKeyword is null";
- }
- else
- {
- condition += " and tb.SeoKeyword=" + PosFeeSelect;
- }
- }
- if (!string.IsNullOrEmpty(BrandId))
- {
- condition += " and tb.BrandId=" + BrandId;
- }
- 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;
- var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
- var FileName = MakerCode + RealName + "直营团队数据记录" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + Sql + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
- RedisDbconn.Instance.AddList("ExportQueue", SendData);
- return "success";
- }
- #endregion
- }
- }
|