SysToolsController.cs 216 KB

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