SysToolsController.cs 266 KB

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