SysToolsController.cs 183 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815
  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 + ",手机号:" + user.Mobile;
  971. }
  972. string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  973. var storeInfo = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  974. string results = "该机具为故障机" + "\n";
  975. results += "所在仓库:" + storeInfo.StoreNo + "\n";
  976. results += "仓库名称:" + storeInfo.StoreName + "\n";
  977. results += "押金返现实际返现对象:" + DepositUsers + "\n";
  978. results += "押金:" + Deposits + "\n";
  979. results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
  980. return results;
  981. }
  982. string merInfo = "";
  983. string merName = "";
  984. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  985. if (mer != null)
  986. {
  987. merInfo = mer.KqMerNo;
  988. merName = mer.MerchantName;
  989. }
  990. else
  991. {
  992. merInfo = "未找到商户";
  993. }
  994. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  995. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  996. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  997. int TopUserId = 0;
  998. if (!string.IsNullOrEmpty(posUser.ParentNav))
  999. {
  1000. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1001. if (ParentNavs.Length > 1)
  1002. {
  1003. TopUserId = int.Parse(ParentNavs[1]);
  1004. }
  1005. if (ParentNavs.Length == 1)
  1006. {
  1007. TopUserId = int.Parse(ParentNavs[0]);
  1008. }
  1009. }
  1010. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1011. string bindResult = "", bindTime = "";
  1012. if (pos.BindingState == 0)
  1013. {
  1014. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  1015. if (bind != null)
  1016. {
  1017. if (bind.Status != 1)
  1018. {
  1019. bindResult = "执行中";
  1020. }
  1021. }
  1022. else
  1023. {
  1024. bindResult = "未绑定";
  1025. }
  1026. }
  1027. else
  1028. {
  1029. bindResult = "已绑定";
  1030. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1031. }
  1032. string activeResult = "", activeTime = "";
  1033. if (pos.ActivationState == 0)
  1034. {
  1035. if (pos.CreditTrade < 1000)
  1036. {
  1037. activeResult = "未刷满1000";
  1038. }
  1039. else if (pos.TransferTime == null)
  1040. {
  1041. activeResult = "未激活, 需补录";
  1042. }
  1043. }
  1044. else
  1045. {
  1046. activeResult = "已激活";
  1047. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1048. }
  1049. string tradeAmount = pos.CreditTrade.ToString();
  1050. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1051. if (pos.BrandId != 2 && pos.BrandId != 7)
  1052. {
  1053. Deposit = Deposit / 100;
  1054. }
  1055. string DepositGet = "未领取";
  1056. string DepositUser = "";
  1057. string DepositToUser = "";
  1058. decimal headAmount = 0;
  1059. decimal footAmount = 0;
  1060. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1061. if (reward.Id > 0)
  1062. {
  1063. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1064. DepositGet = "已领取";
  1065. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1066. var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
  1067. if (fAmount != null)
  1068. {
  1069. headAmount = fAmount.RewardAmount;
  1070. }
  1071. var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
  1072. if (lAmount != null)
  1073. {
  1074. footAmount = lAmount.RewardAmount;
  1075. }
  1076. }
  1077. string DepositGet6 = "未领取";
  1078. string DepositUser6 = "";
  1079. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  1080. if (lisreward.Id > 0)
  1081. {
  1082. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  1083. DepositGet6 = "已领取";
  1084. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1085. }
  1086. string FluxGet6 = "未领取";
  1087. string FluxUser6 = "";
  1088. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1089. if (flux.Id > 0)
  1090. {
  1091. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1092. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1093. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1094. }
  1095. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1096. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  1097. string OpenUser10 = "未领取";
  1098. string OpenUser20 = "未领取";
  1099. string Leader10 = "未领取";
  1100. string YYZX5 = "未领取";
  1101. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1102. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1103. if (openreward.Id > 0)
  1104. {
  1105. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1106. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1107. }
  1108. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1109. if (openreward.Id > 0)
  1110. {
  1111. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1112. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1113. }
  1114. var leader10 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 116) ?? new UserAccountRecord();
  1115. if (leader10.Id > 0)
  1116. {
  1117. Users user = db.Users.FirstOrDefault(m => m.Id == leader10.UserId) ?? new Users();
  1118. Leader10 = "金额:" + leader10.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1119. }
  1120. var yyzx5 = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == pos.Id && m.ChangeType == 121) ?? new UserAccountRecord();
  1121. if (yyzx5.Id > 0)
  1122. {
  1123. Users user = db.Users.FirstOrDefault(m => m.Id == yyzx5.UserId) ?? new Users();
  1124. YYZX5 = "金额:" + yyzx5.ChangeAmount + ",创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1125. }
  1126. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1127. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1128. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1129. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1130. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1131. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1132. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1133. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1134. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1135. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1136. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1137. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1138. string result = "";
  1139. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + "\n";
  1140. result += "\n";
  1141. result += "机具SN:" + pos.PosSn + "\n";
  1142. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1143. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  1144. if (change.Id > 0)
  1145. {
  1146. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1147. }
  1148. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  1149. // result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  1150. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1151. if (pos.PreUserId > 0)
  1152. {
  1153. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1154. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1155. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1156. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",手机号:" + smallStoreUser.Mobile + ",预发时间:" + preSendDate + "\n";
  1157. }
  1158. else
  1159. {
  1160. result += "机具所属小分仓:暂无小分仓\n";
  1161. }
  1162. result += "入库时间:" + CreateDate + "\n";
  1163. result += "循环到期时间:" + RecycEndDate + "\n";
  1164. result += "划拨时间:" + TransferTime + "\n";
  1165. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1166. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1167. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1168. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1169. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1170. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1171. result += "押金:" + Deposit + "\n";
  1172. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1173. result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";//TODO: 添加返现金额和额外奖励
  1174. result += "押金返现应返现对象:" + DepositToUser + "\n";
  1175. result += "押金返现实际返现对象:" + DepositUser + "\n";
  1176. if (pos.BrandId == 6)
  1177. {
  1178. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1179. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1180. }
  1181. result += "流量费:" + FluxGet6 + "\n";
  1182. result += "流量费发放对象:" + FluxUser6 + "\n";
  1183. result += "开机奖20:" + OpenUser20 + "\n";
  1184. result += "开机奖10:" + OpenUser10 + "\n";
  1185. result += "盟主奖" + Leader10 + "\n";
  1186. result += "运营中心奖" + YYZX5 + "\n";
  1187. return result;
  1188. }
  1189. //解析金控日志
  1190. // public decimal CheckLog(DateTime startDate, string PosSn)
  1191. // {
  1192. // bool op = true;
  1193. // decimal result = 0;
  1194. // DateTime today = DateTime.Now;
  1195. // int i = 0;
  1196. // while (op)
  1197. // {
  1198. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  1199. // if (check <= today)
  1200. // {
  1201. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  1202. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  1203. // foreach (Match sub in mc)
  1204. // {
  1205. // string content = sub.Value;
  1206. // JsonData jsonObj = JsonMapper.ToObject(content);
  1207. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  1208. // string posSnCheck = jsonObj["posSn"].ToString();
  1209. // if (posSnCheck == PosSn && serviceAmount > 0)
  1210. // {
  1211. // result = serviceAmount / 100;
  1212. // op = false;
  1213. // }
  1214. // }
  1215. // }
  1216. // else
  1217. // {
  1218. // op = false;
  1219. // }
  1220. // i += 1;
  1221. // }
  1222. // return result;
  1223. // }
  1224. #endregion
  1225. #region 生成机具兑换码
  1226. public IActionResult MakeCoupons(string right)
  1227. {
  1228. ViewBag.RightInfo = RightInfo;
  1229. ViewBag.right = right;
  1230. return View();
  1231. }
  1232. [HttpPost]
  1233. public string MakeCouponsDo(int Kind, int Number)
  1234. {
  1235. DateTime checkTime = DateTime.Parse("1900-01-01");
  1236. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1237. if (!string.IsNullOrEmpty(checkTimeString))
  1238. {
  1239. checkTime = DateTime.Parse(checkTimeString);
  1240. }
  1241. if (checkTime.AddHours(1) < DateTime.Now)
  1242. {
  1243. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1244. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1245. return "生成程序已执行";
  1246. }
  1247. return "请稍后再试";
  1248. }
  1249. #endregion
  1250. #region 导出没有刷满1000的机具
  1251. public IActionResult ExportPos(string right)
  1252. {
  1253. ViewBag.RightInfo = RightInfo;
  1254. ViewBag.right = right;
  1255. return View();
  1256. }
  1257. [HttpPost]
  1258. public JsonResult ExportPosDo()
  1259. {
  1260. WebCMSEntities db = new WebCMSEntities();
  1261. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1262. int total = poses.Count;
  1263. int index = 0;
  1264. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1265. foreach (PosMachinesTwo pos in poses)
  1266. {
  1267. index += 1;
  1268. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1269. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1270. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1271. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1272. Dictionary<string, object> item = new Dictionary<string, object>();
  1273. string TopRealName = "";
  1274. string TopMakerCode = "";
  1275. string TopMobile = "";
  1276. string ParentNav = user.ParentNav;
  1277. if (!string.IsNullOrEmpty(ParentNav))
  1278. {
  1279. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1280. if (navlist.Length > 1)
  1281. {
  1282. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1283. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1284. TopRealName = tuser.RealName;
  1285. TopMakerCode = tuser.MakerCode;
  1286. TopMobile = tuser.Mobile;
  1287. }
  1288. }
  1289. item.Add("TopRealName", TopRealName); //顶级姓名
  1290. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1291. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1292. item.Add("UpRealName", puser.RealName); //上级姓名
  1293. item.Add("RealName", user.RealName); //代理姓名
  1294. item.Add("MakerCode", user.MakerCode); //代理编号
  1295. item.Add("Mobile", user.Mobile); //代理手机号
  1296. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1297. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1298. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1299. item.Add("Sn", pos.PosSn); //SN
  1300. list.Add(item);
  1301. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1302. }
  1303. db.Dispose();
  1304. Dictionary<string, object> result = new Dictionary<string, object>();
  1305. result.Add("Status", "1");
  1306. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1307. result.Add("Obj", list);
  1308. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1309. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1310. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1311. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1312. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1313. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1314. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1315. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1316. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1317. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1318. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1319. ReturnFields.Add("Sn", "SN"); //SN
  1320. result.Add("Fields", ReturnFields);
  1321. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1322. return Json(result);
  1323. }
  1324. public string ExportPosCheck()
  1325. {
  1326. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1327. if (content == "finish")
  1328. {
  1329. RedisDbconn.Instance.Clear("ExportPosCheck");
  1330. }
  1331. return content;
  1332. }
  1333. #endregion
  1334. #region 更换机具
  1335. public IActionResult ChangePos(string right)
  1336. {
  1337. ViewBag.RightInfo = RightInfo;
  1338. ViewBag.right = right;
  1339. return View();
  1340. }
  1341. [HttpPost]
  1342. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1343. {
  1344. if (string.IsNullOrEmpty(OldSn))
  1345. {
  1346. return "请输入原机具SN";
  1347. }
  1348. if (string.IsNullOrEmpty(NewSn))
  1349. {
  1350. return "请输入新机具SN";
  1351. }
  1352. string[] OldSnList = OldSn.Split('\n');
  1353. string[] NewSnList = NewSn.Split('\n');
  1354. if (OldSnList.Length != NewSnList.Length)
  1355. {
  1356. return "原机具SN数量和新机具SN数量不一致";
  1357. }
  1358. WebCMSEntities db = new WebCMSEntities();
  1359. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1360. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1361. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1362. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1363. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1364. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1365. KqProducts oldPosBrand = new KqProducts();
  1366. KqProducts newPosBrand = new KqProducts();
  1367. MachineChange add = db.MachineChange.Add(new MachineChange()
  1368. {
  1369. CreateDate = DateTime.Now,
  1370. UpdateDate = DateTime.Now,
  1371. CreateMan = SysUserName + "-" + SysRealName,
  1372. ChangeNo = ChangeNo, //转换单号
  1373. UserId = 0, //创客
  1374. ChangeTime = DateTime.Now, //转换时间
  1375. BackStoreId = BackStore.Id, //退回仓库
  1376. BackStoreName = BackStore.StoreName, //退回仓库名称
  1377. Remark = "机具更换", //订单备注
  1378. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1379. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1380. OutProductName = OutStore.ProductName, //出库产品名称
  1381. OutStoreId = OutStore.Id, //出库仓库
  1382. OutStoreName = OutStore.StoreName, //出库仓库名称
  1383. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1384. OutStoreAddress = OutStore.Address, //出库仓库地址
  1385. OutStoreManager = "", //出库仓库联系人
  1386. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1387. }).Entity;
  1388. db.SaveChanges();
  1389. int BackProductType = 0;
  1390. string BackProductName = "";
  1391. string ChangeDeviceName = "";
  1392. string ChangeSnExpand = "";
  1393. for (int i = 0; i < OldSnList.Length; i++)
  1394. {
  1395. string OldSnNum = OldSnList[i];
  1396. string NewSnNum = NewSnList[i];
  1397. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1398. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1399. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1400. if (oldpos == null)
  1401. {
  1402. return "原机具SN不正确";
  1403. }
  1404. // if (oldpos.BindingState != 1)
  1405. // {
  1406. // return "原机具未绑定";
  1407. // }
  1408. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1409. if (newpos == null)
  1410. {
  1411. return "新机具SN不正确";
  1412. }
  1413. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1414. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1415. PosMerchantInfo merchant = new PosMerchantInfo();
  1416. if (!string.IsNullOrEmpty(MerNo))
  1417. {
  1418. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1419. }
  1420. else
  1421. {
  1422. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
  1423. }
  1424. newpos.BindMerchantId = merchant.Id;
  1425. newpos.BuyUserId = oldpos.BuyUserId;
  1426. newpos.UserId = oldpos.UserId;
  1427. newpos.RecycEndDate = oldpos.RecycEndDate;
  1428. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1429. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1430. newpos.CreditTrade = oldpos.CreditTrade;
  1431. newpos.PosSnType = oldpos.PosSnType;
  1432. newpos.TransferTime = oldpos.TransferTime;
  1433. newpos.IsPurchase = oldpos.IsPurchase;
  1434. newpos.BindingState = oldpos.BindingState;
  1435. newpos.ActivationState = oldpos.ActivationState;
  1436. newpos.BindingTime = oldpos.BindingTime;
  1437. newpos.ActivationTime = oldpos.ActivationTime;
  1438. newpos.IsFirst = oldpos.IsFirst;
  1439. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1440. // if (!checkActReward)
  1441. // {
  1442. newpos.SeoKeyword = oldpos.SeoKeyword;
  1443. newpos.PrizeParams = oldpos.PrizeParams;
  1444. newpos.LeaderUserId = oldpos.LeaderUserId;
  1445. // }
  1446. // oldpos.BuyUserId = 0;
  1447. // oldpos.UserId = 0;
  1448. oldpos.Status = -1;
  1449. //对应调整客小爽企业版数据
  1450. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
  1451. if (posInfo != null)
  1452. {
  1453. posInfo.PosSn = newpos.PosSn;
  1454. posInfo.PosId = newpos.Id;
  1455. db.SaveChanges();
  1456. }
  1457. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1458. if (forMerNo != null)
  1459. {
  1460. forMerNo.SnId = newpos.Id;
  1461. }
  1462. merchant.KqSnNo = NewSn;
  1463. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1464. {
  1465. CreateDate = DateTime.Now,
  1466. UpdateDate = DateTime.Now,
  1467. CreateMan = SysUserName + "-" + SysRealName,
  1468. ChangeNo = ChangeNo, //订单号
  1469. ChangeId = add.Id, //订单Id
  1470. BackProductType = oldpos.BrandId, //退回产品类型
  1471. BackProductName = oldPosBrand.Name, //退回产品名称
  1472. UserId = 0, //创客
  1473. BackSnNo = oldpos.PosSn, //设备SN编号
  1474. OutProductType = newpos.BrandId, //出库产品类型
  1475. OutProductName = newPosBrand.Name, //出库产品名称
  1476. OutSnNo = newpos.PosSn, //出库设备SN编号
  1477. OutSnType = newpos.PosSnType, //出库SN机具类型
  1478. Remark = "机具更换", //备注
  1479. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1480. });
  1481. db.SaveChanges();
  1482. BackProductType = oldpos.BrandId;
  1483. BackProductName = newPosBrand.Name;
  1484. ChangeDeviceName = oldpos.DeviceName;
  1485. ChangeSnExpand += oldpos.PosSn + "\n";
  1486. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1487. }
  1488. add.BackProductType = BackProductType; //退回产品类型
  1489. add.BackProductName = BackProductName; //退回产品名称
  1490. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1491. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1492. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1493. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1494. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1495. db.SaveChanges();
  1496. db.Dispose();
  1497. if (IsSend == 1)
  1498. {
  1499. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1500. {
  1501. UserId = pos.BuyUserId, //接收创客
  1502. MsgType = 2,
  1503. Title = "换绑成功通知", //标题
  1504. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1505. CreateDate = DateTime.Now,
  1506. }));
  1507. }
  1508. return "success";
  1509. }
  1510. #endregion
  1511. #region 坏机换新
  1512. public IActionResult ChangeBadPos(string right)
  1513. {
  1514. ViewBag.RightInfo = RightInfo;
  1515. ViewBag.right = right;
  1516. return View();
  1517. }
  1518. [HttpPost]
  1519. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1520. {
  1521. string[] OldSnList;
  1522. string[] NewSnList;
  1523. decimal amount = 0;
  1524. //创客坏机换新
  1525. if (ChangeType == "0")
  1526. {
  1527. if (string.IsNullOrEmpty(MakerCode))
  1528. {
  1529. return "请输入创客编号";
  1530. }
  1531. if (string.IsNullOrEmpty(OldSn))
  1532. {
  1533. return "请输入坏机SN";
  1534. }
  1535. if (string.IsNullOrEmpty(NewSn))
  1536. {
  1537. return "请输入新机SN";
  1538. }
  1539. if (string.IsNullOrEmpty(FromStoreNo))
  1540. {
  1541. return "请输入新机发货仓库编号";
  1542. }
  1543. if (string.IsNullOrEmpty(BackStoreNo))
  1544. {
  1545. return "请输入坏机退回仓库编号";
  1546. }
  1547. OldSnList = OldSn.Split('\n');
  1548. NewSnList = NewSn.Split('\n');
  1549. if (OldSnList.Length != NewSnList.Length)
  1550. {
  1551. return "原机具SN数量和新机具SN数量不一致";
  1552. }
  1553. for (int i = 0; i < OldSnList.Length; i++)
  1554. {
  1555. string OldSnNum = OldSnList[i];
  1556. string NewSnNum = NewSnList[i];
  1557. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1558. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1559. if (storeForCodeFrom.StoreId == 0)
  1560. {
  1561. return "您输入的新机发货仓库编号不存在";
  1562. }
  1563. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1564. if (storeForCodeBack.StoreId == 0)
  1565. {
  1566. return "您输入的坏机退回仓库编号不存在";
  1567. }
  1568. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1569. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1570. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1571. if (oldpos.Id == 0)
  1572. {
  1573. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1574. }
  1575. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0) ?? new PosMachinesTwo();
  1576. if (newpos.Id == 0)
  1577. {
  1578. return "您输入的新机SN不存在";
  1579. }
  1580. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1581. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(newpos.BrandId))
  1582. {
  1583. return "您输入的新机发货仓库不符新机机具对应品牌";
  1584. }
  1585. if (newpos.StoreId != storeFrom.Id)
  1586. {
  1587. return "您输入的新机SN不在新机发货仓库";
  1588. }
  1589. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1590. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1591. {
  1592. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1593. }
  1594. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(storeFrom.BrandId))
  1595. {
  1596. return "您输入的新机发货仓库和坏机退回仓库品牌类型不同";
  1597. }
  1598. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1599. if (brandInfo.Name.Contains("大POS"))
  1600. {
  1601. amount = 300;
  1602. }
  1603. if (brandInfo.Name.Contains("电签"))
  1604. {
  1605. amount = 200;
  1606. }
  1607. // var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1608. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1609. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1610. // storeUserAcount.ValidAmount += amount;
  1611. storeFromUserAcount.ValidAmount += amount;
  1612. storeBackUserAcount.ValidAmount -= amount;
  1613. newpos.BuyUserId = oldpos.BuyUserId;
  1614. newpos.UserId = oldpos.UserId;
  1615. newpos.RecycEndDate = oldpos.RecycEndDate;
  1616. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1617. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1618. newpos.CreditTrade = oldpos.CreditTrade;
  1619. newpos.PosSnType = oldpos.PosSnType;
  1620. newpos.TransferTime = oldpos.TransferTime;
  1621. newpos.IsPurchase = oldpos.IsPurchase;
  1622. newpos.BindingState = oldpos.BindingState;
  1623. newpos.ActivationState = oldpos.ActivationState;
  1624. newpos.BindingTime = oldpos.BindingTime;
  1625. newpos.ActivationTime = oldpos.ActivationTime;
  1626. newpos.IsFirst = oldpos.IsFirst;
  1627. newpos.SeoKeyword = oldpos.SeoKeyword;
  1628. newpos.PrizeParams = oldpos.PrizeParams;
  1629. newpos.LeaderUserId = oldpos.LeaderUserId;
  1630. newpos.BindMerchantId = oldpos.BindMerchantId;
  1631. newpos.StoreId = oldpos.StoreId;
  1632. newpos.UserId = oldpos.UserId;
  1633. newpos.PreUserId = oldpos.PreUserId;
  1634. oldpos.StoreId = storeBack.Id;
  1635. oldpos.BuyUserId = 0;
  1636. oldpos.UserId = 0;
  1637. oldpos.Status = -1;
  1638. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  1639. if (merchant != null)
  1640. {
  1641. merchant.KqSnNo = newpos.PosSn;
  1642. merchant.ActiveStatus = newpos.ActivationState;
  1643. }
  1644. db.SaveChanges();
  1645. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1646. {
  1647. CreateDate = DateTime.Now,
  1648. CreateMan = SysUserName + "-" + SysRealName,
  1649. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1650. OutStoreId = storeFrom.Id,
  1651. BackStoreId = storeBack.Id,
  1652. OutProductType = newpos.BrandId,
  1653. BackProductType = oldpos.BrandId,
  1654. UserId = userForMakerCode.UserId, //创客
  1655. }).Entity;
  1656. db.SaveChanges();
  1657. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1658. {
  1659. CreateDate = DateTime.Now,
  1660. CreateMan = SysUserName + "-" + SysRealName,
  1661. OutSnNo = OldSnNum,
  1662. BackSnNo = NewSnNum,
  1663. ChangeNo = add.ChangeNo, //转换单号
  1664. ChangeId = add.Id, //转换记录Id
  1665. UserId = add.UserId, //创客
  1666. }).Entity;
  1667. db.SaveChanges();
  1668. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1669. if (IsSend == 1)
  1670. {
  1671. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1672. {
  1673. UserId = userForMakerCode.UserId, //接收创客
  1674. MsgType = 2,
  1675. Title = "坏机换新成功通知", //标题
  1676. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1677. CreateDate = DateTime.Now,
  1678. }));
  1679. }
  1680. }
  1681. }
  1682. //仓库坏机换新
  1683. else
  1684. {
  1685. if (string.IsNullOrEmpty(StoreCode))
  1686. {
  1687. return "请输入仓库编号";
  1688. }
  1689. if (string.IsNullOrEmpty(OldSn))
  1690. {
  1691. return "请输入坏机SN";
  1692. }
  1693. if (string.IsNullOrEmpty(NewSn))
  1694. {
  1695. return "请输入新机SN";
  1696. }
  1697. if (string.IsNullOrEmpty(FromStoreNo))
  1698. {
  1699. return "请输入新机发货仓库编号";
  1700. }
  1701. if (string.IsNullOrEmpty(BackStoreNo))
  1702. {
  1703. return "请输入坏机退回仓库编号";
  1704. }
  1705. OldSnList = OldSn.Split('\n');
  1706. NewSnList = NewSn.Split('\n');
  1707. if (OldSnList.Length != NewSnList.Length)
  1708. {
  1709. return "原机具SN数量和新机具SN数量不一致";
  1710. }
  1711. for (int i = 0; i < OldSnList.Length; i++)
  1712. {
  1713. string OldSnNum = OldSnList[i];
  1714. string NewSnNum = NewSnList[i];
  1715. StoreHouse store = new StoreHouse();
  1716. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  1717. if (storeForBadCode.StoreId > 0)
  1718. {
  1719. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  1720. }
  1721. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1722. if (storeForCodeFrom.StoreId == 0)
  1723. {
  1724. return "您输入的新机发货仓库编号不存在";
  1725. }
  1726. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1727. if (storeForCodeBack.StoreId == 0)
  1728. {
  1729. return "您输入的坏机退回仓库编号不存在";
  1730. }
  1731. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1732. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1733. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  1734. if (oldpos.Id == 0)
  1735. {
  1736. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  1737. }
  1738. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0) ?? new PosMachinesTwo();
  1739. if (newpos.Id == 0)
  1740. {
  1741. return "您输入的新机SN不存在";
  1742. }
  1743. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1744. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1745. {
  1746. return "您输入的新机发货仓库不符新机机具对应品牌";
  1747. }
  1748. if (newpos.StoreId != storeFrom.Id)
  1749. {
  1750. return "您输入的新机SN不在新机发货仓库";
  1751. }
  1752. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1753. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1754. {
  1755. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1756. }
  1757. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1758. if (brandInfo.Name.Contains("大POS"))
  1759. {
  1760. amount = 300;
  1761. }
  1762. if (brandInfo.Name.Contains("电签"))
  1763. {
  1764. amount = 200;
  1765. }
  1766. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1767. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1768. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1769. // storeUserAcount.ValidAmount += amount;
  1770. storeFromUserAcount.ValidAmount += amount;
  1771. storeBackUserAcount.ValidAmount -= amount;
  1772. newpos.StoreId = oldpos.StoreId;
  1773. newpos.BuyUserId = oldpos.BuyUserId;
  1774. newpos.UserId = oldpos.UserId;
  1775. newpos.LeaderUserId = oldpos.LeaderUserId;
  1776. newpos.PreUserId = oldpos.PreUserId;
  1777. newpos.IsFirst = oldpos.IsFirst;
  1778. newpos.TransferTime = oldpos.TransferTime;
  1779. oldpos.StoreId = storeBack.Id;
  1780. oldpos.BuyUserId = 0;
  1781. oldpos.UserId = 0;
  1782. oldpos.Status = -1;
  1783. db.SaveChanges();
  1784. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1785. {
  1786. CreateDate = DateTime.Now,
  1787. CreateMan = SysUserName + "-" + SysRealName,
  1788. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1789. OutStoreId = storeFrom.Id,
  1790. BackStoreId = storeBack.Id,
  1791. OutProductType = newpos.BrandId,
  1792. BackProductType = oldpos.BrandId,
  1793. UserId = store.UserId, //创客
  1794. }).Entity;
  1795. db.SaveChanges();
  1796. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1797. {
  1798. CreateDate = DateTime.Now,
  1799. CreateMan = SysUserName + "-" + SysRealName,
  1800. OutSnNo = OldSnNum,
  1801. BackSnNo = NewSnNum,
  1802. ChangeNo = add.ChangeNo, //转换单号
  1803. ChangeId = add.Id, //转换记录Id
  1804. UserId = add.UserId, //创客
  1805. }).Entity;
  1806. db.SaveChanges();
  1807. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1808. if (IsSend == 1)
  1809. {
  1810. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1811. {
  1812. UserId = store.UserId, //接收创客
  1813. MsgType = 2,
  1814. Title = "坏机换新成功通知", //标题
  1815. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1816. CreateDate = DateTime.Now,
  1817. }));
  1818. }
  1819. }
  1820. }
  1821. // for (int i = 0; i < OldSnList.Length; i++)
  1822. // {
  1823. // string OldSnNum = OldSnList[i];
  1824. // string NewSnNum = NewSnList[i];
  1825. // StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1826. // MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1827. // MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1828. // StoreHouse oldStore = new StoreHouse();
  1829. // PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0);
  1830. // if (storeForCode.StoreId > 0)
  1831. // {
  1832. // StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId);
  1833. // if (Convert.ToInt32(store.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1834. // {
  1835. // return "您输入的仓库不符机具对应品牌";
  1836. // }
  1837. // oldStore = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId);
  1838. // oldpos.Status = -1;
  1839. // oldpos.StoreId = store.Id;
  1840. // }
  1841. // if (oldpos == null)
  1842. // {
  1843. // return "原机具SN不正确或者不符合换机条件";
  1844. // }
  1845. // PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BuyUserId == 0 && m.UserId == 0 && m.BindingState == 0);
  1846. // if (newpos == null)
  1847. // {
  1848. // return "新机具SN不正确或者不为仓库机";
  1849. // }
  1850. // if (oldpos.BrandId != newpos.BrandId)
  1851. // {
  1852. // return "新机具和旧机具品牌不相同";
  1853. // }
  1854. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1855. // if (brandInfo.Name.Contains("大POS"))
  1856. // {
  1857. // amount = 300;
  1858. // }
  1859. // if (brandInfo.Name.Contains("电签"))
  1860. // {
  1861. // amount = 200;
  1862. // }
  1863. // var storehouse = db.StoreHouse.FirstOrDefault(m => m.Id == newpos.StoreId) ?? new StoreHouse();
  1864. // storehouse.LaveNum -= 1;
  1865. // var userAcount = db.UserAccount.FirstOrDefault(m => m.Id == storehouse.UserId) ?? new UserAccount();
  1866. // if (oldpos.StoreId != newpos.StoreId)
  1867. // {
  1868. // userAcount.ValidAmount += amount;
  1869. // newpos.StoreId = oldpos.StoreId;
  1870. // newpos.BuyUserId = oldpos.BuyUserId;
  1871. // newpos.UserId = oldpos.UserId;
  1872. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1873. // newpos.PreUserId = oldpos.PreUserId;
  1874. // newpos.IsFirst = oldpos.IsFirst;
  1875. // newpos.TransferTime = oldpos.TransferTime;
  1876. // }
  1877. // else
  1878. // {
  1879. // newpos.BuyUserId = oldpos.BuyUserId;
  1880. // newpos.UserId = oldpos.UserId;
  1881. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1882. // newpos.PreUserId = oldpos.PreUserId;
  1883. // newpos.IsFirst = oldpos.IsFirst;
  1884. // newpos.TransferTime = oldpos.TransferTime;
  1885. // }
  1886. // db.SaveChanges();
  1887. // var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1888. // var newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1889. // var UserId = 0;
  1890. // if (oldpos.BuyUserId == 0)
  1891. // {
  1892. // UserId = oldStore.UserId;
  1893. // }
  1894. // else
  1895. // {
  1896. // UserId = oldpos.BuyUserId;
  1897. // }
  1898. // BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1899. // {
  1900. // CreateDate = DateTime.Now,
  1901. // CreateMan = SysUserName + "-" + SysRealName,
  1902. // ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1903. // UserId = UserId, //创客
  1904. // }).Entity;
  1905. // db.SaveChanges();
  1906. // BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1907. // {
  1908. // CreateDate = DateTime.Now,
  1909. // CreateMan = SysUserName + "-" + SysRealName,
  1910. // OutSnNo = OldSnNum,
  1911. // BackSnNo = NewSnNum,
  1912. // ChangeNo = add.ChangeNo, //转换单号
  1913. // ChangeId = add.Id, //转换记录Id
  1914. // UserId = add.UserId, //创客
  1915. // }).Entity;
  1916. // db.SaveChanges();
  1917. // if (IsSend == 1)
  1918. // {
  1919. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1920. // {
  1921. // UserId = UserId, //接收创客
  1922. // MsgType = 2,
  1923. // Title = "坏机换新成功通知", //标题
  1924. // Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为您换为" + newPosBrand.Name + "SN:" + NewSn + "。",
  1925. // CreateDate = DateTime.Now,
  1926. // }));
  1927. // }
  1928. // }
  1929. return "success";
  1930. }
  1931. #endregion
  1932. #region 机具解绑
  1933. public IActionResult Unbind(string right)
  1934. {
  1935. ViewBag.RightInfo = RightInfo;
  1936. ViewBag.right = right;
  1937. return View();
  1938. }
  1939. [HttpPost]
  1940. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  1941. {
  1942. if (string.IsNullOrEmpty(PosSn))
  1943. {
  1944. return "请输入机具SN";
  1945. }
  1946. if (string.IsNullOrEmpty(MakerCode))
  1947. {
  1948. return "请输入创客编号";
  1949. }
  1950. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1951. if (forSnNo == null)
  1952. {
  1953. return "机具SN不存在";
  1954. }
  1955. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  1956. if (pos == null)
  1957. {
  1958. return "机具SN不存在";
  1959. }
  1960. if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  1961. {
  1962. return "请输入商户编号";
  1963. }
  1964. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1965. if (forMakerCode == null)
  1966. {
  1967. return "创客不存在";
  1968. }
  1969. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1970. if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  1971. {
  1972. return "商户编号不存在";
  1973. }
  1974. if (pos.BuyUserId != forMakerCode.UserId)
  1975. {
  1976. return "机具SN和创客不匹配";
  1977. }
  1978. if (pos.ActivationState == 1)
  1979. {
  1980. return "机具已激活,不能解绑";
  1981. }
  1982. if (pos.BuyUserId == 0)
  1983. {
  1984. return "机具是仓库机,不支持解绑";
  1985. }
  1986. if (pos.BindingState == 0)
  1987. {
  1988. return "机具未绑定,不支持解绑";
  1989. }
  1990. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  1991. {
  1992. return "机具绑定已超过30天,不支持解绑";
  1993. }
  1994. if (forMerNo != null)
  1995. {
  1996. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  1997. if (merchant != null)
  1998. {
  1999. //机具解绑删除客小爽企业版对应数据
  2000. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  2001. if (merInfo != null)
  2002. {
  2003. db.BusinessPartnerMerchant.Remove(merInfo);
  2004. }
  2005. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  2006. if (posInfo != null)
  2007. {
  2008. db.BusinessPartnerPos.Remove(posInfo);
  2009. }
  2010. db.PosMerchantInfo.Remove(merchant);
  2011. }
  2012. db.MachineForMerNo.Remove(forMerNo);
  2013. db.SaveChanges();
  2014. }
  2015. db.MachineUnBind.Add(new MachineUnBind()
  2016. {
  2017. CreateDate = DateTime.Now,
  2018. SeoTitle = SysUserName + "-" + SysRealName,
  2019. MerchantId = pos.BindMerchantId,
  2020. AuditDate = DateTime.Now,
  2021. AuditDesc = "平台操作解绑",
  2022. AuditStatus = 1,
  2023. SnNo = pos.PosSn,
  2024. BrandId = pos.BrandId,
  2025. UserId = pos.BuyUserId,
  2026. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  2027. });
  2028. pos.BindMerchantId = 0;
  2029. pos.BindingState = 0;
  2030. pos.BindingTime = DateTime.Parse("1900-01-01");
  2031. pos.UserId = pos.BuyUserId;
  2032. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2033. db.SaveChanges();
  2034. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2035. if (IsSend == 1)
  2036. {
  2037. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2038. {
  2039. UserId = pos.BuyUserId, //接收创客
  2040. MsgType = 2,
  2041. Title = "解绑成功通知", //标题
  2042. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2043. CreateDate = DateTime.Now,
  2044. }));
  2045. }
  2046. return "success";
  2047. }
  2048. #endregion
  2049. #region 通过券码修改盟主标记
  2050. public IActionResult ChangeSignQuan(string right)
  2051. {
  2052. ViewBag.RightInfo = RightInfo;
  2053. ViewBag.right = right;
  2054. return View();
  2055. }
  2056. [HttpPost]
  2057. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2058. {
  2059. if (string.IsNullOrEmpty(Coupons))
  2060. {
  2061. return "请输入机具券码,多个券码用回车分隔";
  2062. }
  2063. if (string.IsNullOrEmpty(MakerCode))
  2064. {
  2065. return "请输入创客编号";
  2066. }
  2067. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2068. if (forMakerCode == null)
  2069. {
  2070. return "创客不存在";
  2071. }
  2072. string[] SnList = Coupons.Split('\n');
  2073. foreach (var item in SnList)
  2074. {
  2075. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2076. if (coupos == null)
  2077. {
  2078. return "机具券不存在";
  2079. }
  2080. else
  2081. {
  2082. coupos.LeaderUserId = forMakerCode.UserId;
  2083. }
  2084. }
  2085. db.SaveChanges();
  2086. return "success";
  2087. }
  2088. #endregion
  2089. #region 通过机具SN修改盟主标记
  2090. public IActionResult ChangeSignSn(string right)
  2091. {
  2092. ViewBag.RightInfo = RightInfo;
  2093. ViewBag.right = right;
  2094. return View();
  2095. }
  2096. [HttpPost]
  2097. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2098. {
  2099. if (string.IsNullOrEmpty(PosSn))
  2100. {
  2101. return "请输入机具SN,多个SN用回车分隔";
  2102. }
  2103. if (string.IsNullOrEmpty(MakerCode))
  2104. {
  2105. return "请输入创客编号";
  2106. }
  2107. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2108. if (forMakerCode == null)
  2109. {
  2110. return "创客不存在";
  2111. }
  2112. string[] SnList = PosSn.Split('\n');
  2113. foreach (var item in SnList)
  2114. {
  2115. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2116. if (pos == null)
  2117. {
  2118. return "该机具不存在";
  2119. }
  2120. else
  2121. {
  2122. pos.LeaderUserId = forMakerCode.UserId;
  2123. }
  2124. }
  2125. db.SaveChanges();
  2126. return "success";
  2127. }
  2128. #endregion
  2129. #region 机具循环列表
  2130. /// <summary>
  2131. /// 根据条件查询机具循环列表
  2132. /// </summary>
  2133. /// <returns></returns>
  2134. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2135. {
  2136. ViewBag.RightInfo = RightInfo;
  2137. ViewBag.right = right;
  2138. ViewBag.SwapSnExpand = SwapSnExpand;
  2139. ViewBag.SnNos = SnNos;
  2140. return View();
  2141. }
  2142. #endregion
  2143. #region 根据条件查询机具循环列表
  2144. /// <summary>
  2145. /// 机具循环列表
  2146. /// </summary>
  2147. /// <returns></returns>
  2148. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2149. {
  2150. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2151. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2152. Fields.Add("SnNos", "1"); //发货机具SN
  2153. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2154. if (!string.IsNullOrEmpty(SwapSnExpand))
  2155. {
  2156. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2157. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2158. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2159. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2160. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2161. for (int i = 0; i < SnNoList.Length; i++)
  2162. {
  2163. Dictionary<string, object> data = new Dictionary<string, object>();
  2164. data["ApplyNo"] = apply.ApplyNo;
  2165. data["OrderNo"] = order.OrderNo;
  2166. data["MakerCode"] = user.MakerCode;
  2167. data["RealName"] = user.RealName;
  2168. if (SnNoList.Length > i)
  2169. {
  2170. string SourceSn = SnNoList[i].Split(':')[0];
  2171. data["ComeSn"] = SnNoList[i];
  2172. data["ComeSnParam"] = SourceSn;
  2173. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2174. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2175. if (pos.LeaderUserId > 0)
  2176. {
  2177. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2178. data["ComeSnMakerCode"] = leader.MakerCode;
  2179. data["ComeSnRealName"] = leader.RealName;
  2180. }
  2181. }
  2182. if (OrderSnNo.Length > i)
  2183. {
  2184. string SendSn = OrderSnNo[i];
  2185. data["SendSn"] = OrderSnNo[i];
  2186. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2187. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2188. if (pos.LeaderUserId > 0)
  2189. {
  2190. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2191. data["SendSnMakerCode"] = leader.MakerCode;
  2192. data["SendSnRealName"] = leader.RealName;
  2193. }
  2194. }
  2195. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2196. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2197. dataList.Add(data);
  2198. }
  2199. }
  2200. else if (!string.IsNullOrEmpty(SnNos))
  2201. {
  2202. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2203. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2204. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2205. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2206. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2207. for (int i = 0; i < OrderSnNo.Length; i++)
  2208. {
  2209. Dictionary<string, object> data = new Dictionary<string, object>();
  2210. data["ApplyNo"] = apply.ApplyNo;
  2211. data["OrderNo"] = order.OrderNo;
  2212. data["MakerCode"] = user.MakerCode;
  2213. data["RealName"] = user.RealName;
  2214. if (SnNoList.Length > i)
  2215. {
  2216. string SourceSn = SnNoList[i].Split(':')[0];
  2217. data["ComeSn"] = SnNoList[i];
  2218. data["ComeSnParam"] = SourceSn;
  2219. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2220. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2221. if (pos.LeaderUserId > 0)
  2222. {
  2223. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2224. data["ComeSnMakerCode"] = leader.MakerCode;
  2225. data["ComeSnRealName"] = leader.RealName;
  2226. }
  2227. }
  2228. if (OrderSnNo.Length > i)
  2229. {
  2230. string SendSn = OrderSnNo[i];
  2231. data["SendSn"] = OrderSnNo[i];
  2232. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? new MachineForSnNo();
  2233. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2234. if (pos.LeaderUserId > 0)
  2235. {
  2236. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2237. data["SendSnMakerCode"] = leader.MakerCode;
  2238. data["SendSnRealName"] = leader.RealName;
  2239. }
  2240. }
  2241. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2242. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2243. dataList.Add(data);
  2244. }
  2245. }
  2246. Dictionary<string, object> obj = new Dictionary<string, object>();
  2247. obj.Add("code", 0);
  2248. obj.Add("msg", "");
  2249. obj.Add("count", dataList.Count);
  2250. obj.Add("data", dataList);
  2251. return Json(obj);
  2252. }
  2253. #endregion
  2254. #region 查询创客直推奖
  2255. public IActionResult Prize100(string right)
  2256. {
  2257. ViewBag.RightInfo = RightInfo;
  2258. ViewBag.right = right;
  2259. return View();
  2260. }
  2261. [HttpPost]
  2262. public Dictionary<string, string> Prize100Do(string MakerCode)
  2263. {
  2264. Dictionary<string, string> dic = new Dictionary<string, string>();
  2265. string result = "";
  2266. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2267. if (forMakerCode == null)
  2268. {
  2269. result += "创客编号不存在\n";
  2270. dic.Add("code", "1");
  2271. dic.Add("result", result);
  2272. return dic;
  2273. }
  2274. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2275. if (OrderCount == 0)
  2276. {
  2277. result += "该创客未下单\n";
  2278. dic.Add("code", "1");
  2279. dic.Add("result", result);
  2280. return dic;
  2281. }
  2282. if (OrderCount > 1)
  2283. {
  2284. result += "该创客已不是首笔下单\n";
  2285. dic.Add("code", "1");
  2286. dic.Add("result", result);
  2287. return dic;
  2288. }
  2289. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2290. if (order.PayStatus < 1)
  2291. {
  2292. result += "未付款\n";
  2293. dic.Add("code", "1");
  2294. dic.Add("result", result);
  2295. return dic;
  2296. }
  2297. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2298. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2299. result += "订单号:" + order.OrderNo + "\n";
  2300. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2301. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2302. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2303. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2304. if (machineCount + ActiveCount >= 3)
  2305. {
  2306. string IsGet = "未发放";
  2307. int ToUserId = 0;
  2308. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2309. if (item == null)
  2310. {
  2311. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2312. DateTime end = order.PayDate.Value.AddMinutes(2);
  2313. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2314. }
  2315. if (item != null)
  2316. {
  2317. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2318. ToUserId = item.UserId;
  2319. dic.Add("code", "1");
  2320. }
  2321. else
  2322. {
  2323. dic.Add("id", order.Id.ToString());
  2324. dic.Add("code", "0");
  2325. }
  2326. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  2327. result += "是否发放:" + IsGet + "\n";
  2328. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2329. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  2330. }
  2331. else
  2332. {
  2333. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  2334. dic.Add("code", "1");
  2335. }
  2336. dic.Add("result", result);
  2337. return dic;
  2338. }
  2339. public string AddPrize100(int Id)
  2340. {
  2341. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  2342. if (order != null)
  2343. {
  2344. //机具券逻辑
  2345. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  2346. if (pro != null)
  2347. {
  2348. //推荐下单奖励
  2349. if (pro.ProductId == 10 || pro.ProductId == 11)
  2350. {
  2351. int OrderId = order.Id;
  2352. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  2353. if (!checkPrize)
  2354. {
  2355. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2356. if (user != null)
  2357. {
  2358. bool directPrize = false; //直推奖标记
  2359. int ParentUserId = user.ParentUserId;
  2360. // List<int> proids = new List<int>();
  2361. // proids.Add(10);
  2362. // proids.Add(11);
  2363. while (ParentUserId > 0)
  2364. {
  2365. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2366. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  2367. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2368. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2369. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2370. {
  2371. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2372. directPrize = true;
  2373. db.SaveChanges();
  2374. return "发放成功";
  2375. }
  2376. ParentUserId = puser.ParentUserId;
  2377. }
  2378. }
  2379. }
  2380. return "已发放,请勿重复发放";
  2381. }
  2382. }
  2383. }
  2384. return "操作失败";
  2385. }
  2386. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2387. {
  2388. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2389. if (account == null)
  2390. {
  2391. account = db.UserAccount.Add(new UserAccount()
  2392. {
  2393. Id = UserId,
  2394. UserId = UserId,
  2395. }).Entity;
  2396. db.SaveChanges();
  2397. }
  2398. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2399. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2400. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2401. account.BalanceAmount += 100 * Count;
  2402. account.TotalAmount += 100 * Count;
  2403. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2404. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2405. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2406. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2407. {
  2408. CreateDate = DateTime.Now,
  2409. UpdateDate = DateTime.Now,
  2410. UserId = UserId, //创客
  2411. ChangeType = 112, //变动类型
  2412. ChangeAmount = 100 * Count, //变更金额
  2413. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2414. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2415. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2416. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2417. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2418. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2419. QueryCount = OrderId,
  2420. }).Entity;
  2421. db.SaveChanges();
  2422. }
  2423. #endregion
  2424. #region 查询机具开机奖
  2425. public IActionResult OpenPrize(string right)
  2426. {
  2427. ViewBag.RightInfo = RightInfo;
  2428. ViewBag.right = right;
  2429. return View();
  2430. }
  2431. [HttpPost]
  2432. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2433. {
  2434. Dictionary<string, string> dic = new Dictionary<string, string>();
  2435. string result = "";
  2436. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2437. if (pos == null)
  2438. {
  2439. result += "机具SN号不存在\n";
  2440. dic.Add("code", "1");
  2441. dic.Add("result", result);
  2442. return dic;
  2443. }
  2444. if (pos.BindingState == 0)
  2445. {
  2446. result += "机具未绑定\n";
  2447. dic.Add("code", "1");
  2448. dic.Add("result", result);
  2449. return dic;
  2450. }
  2451. if (pos.ActivationState == 0)
  2452. {
  2453. result += "机具未激活\n";
  2454. dic.Add("code", "1");
  2455. dic.Add("result", result);
  2456. return dic;
  2457. }
  2458. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2459. if (merchant == null)
  2460. {
  2461. result += "商户不存在\n";
  2462. dic.Add("code", "1");
  2463. dic.Add("result", result);
  2464. return dic;
  2465. }
  2466. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2467. result += "机具号:" + PosSn + "\n";
  2468. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2469. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2470. string OpenUser10 = "未领取";
  2471. string OpenUser20 = "未领取";
  2472. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2473. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2474. if (openreward.Id > 0)
  2475. {
  2476. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2477. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2478. }
  2479. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2480. if (openreward.Id > 0)
  2481. {
  2482. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2483. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2484. }
  2485. result += "开机奖20:" + OpenUser20 + "\n";
  2486. result += "开机奖10:" + OpenUser10 + "\n";
  2487. dic.Add("id", pos.Id.ToString());
  2488. dic.Add("code", "0");
  2489. dic.Add("result", result);
  2490. return dic;
  2491. }
  2492. public string AddOpenPrize(int Id)
  2493. {
  2494. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2495. if (pos == null)
  2496. {
  2497. return "机具未激活";
  2498. }
  2499. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2500. {
  2501. return "绑定已超过30天";
  2502. }
  2503. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2504. if (ActPrize == 0)
  2505. {
  2506. return "机具无押金";
  2507. }
  2508. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2509. if (merchant == null)
  2510. {
  2511. return "商户不存在";
  2512. }
  2513. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2514. if (check)
  2515. {
  2516. return "开机奖励已发放,请勿重复操作";
  2517. }
  2518. // 从机具所属人上级开始分开机奖励
  2519. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2520. if (user != null)
  2521. {
  2522. if (!string.IsNullOrEmpty(user.ParentNav))
  2523. {
  2524. decimal Prize = 20;
  2525. List<string> PrizeFlag = new List<string>();
  2526. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2527. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2528. {
  2529. int UserId = int.Parse(ParentNavs[i]);
  2530. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2531. if (puser != null && Prize > 0)
  2532. {
  2533. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2534. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2535. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2536. if (machineCount + ActiveCount + couponCount >= 3)
  2537. {
  2538. int pTopUserId = 0;
  2539. if (!string.IsNullOrEmpty(puser.ParentNav))
  2540. {
  2541. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2542. }
  2543. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2544. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2545. {
  2546. CreateDate = DateTime.Now,
  2547. UpdateDate = DateTime.Now,
  2548. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2549. TradeDate = pos.ActivationTime, //达标日期
  2550. UserId = puser.Id, //创客
  2551. BrandId = pos.BrandId, //品牌
  2552. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2553. MerchantId = pos.BindMerchantId, //商户
  2554. DirectUserId = merchant.UserId, //商户直属人
  2555. SnNo = pos.PosSn, //SN号
  2556. MerNo = merchant.KqMerNo, //渠道商户号
  2557. SnType = pos.PosSnType, //机具类型
  2558. StandardDate = pos.ActivationTime, //商户的激活日期
  2559. SnStoreId = pos.StoreId, //SN仓库
  2560. MerBuddyType = puser.MerchantType, //商户创客类型
  2561. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2562. RewardTips = "开机奖励", //奖励描述
  2563. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2564. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2565. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2566. RewardDesc = "开机奖励", //奖励描述
  2567. TopUserId = pTopUserId, //顶级创客
  2568. SeoTitle = machineUser.RealName,
  2569. }).Entity;
  2570. db.OpenReward.Add(new OpenReward()
  2571. {
  2572. CreateDate = DateTime.Now,
  2573. UpdateDate = DateTime.Now,
  2574. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2575. TradeDate = DateTime.Now, //达标日期
  2576. UserId = puser.Id, //创客
  2577. BrandId = pos.BrandId, //品牌
  2578. RewardType = 2, //奖励类型
  2579. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2580. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2581. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2582. RewardDesc = "开机奖励", //奖励描述
  2583. TopUserId = pTopUserId, //顶级创客
  2584. });
  2585. string IdBrand = puser.Id + "_" + pos.BrandId;
  2586. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2587. if (userData == null)
  2588. {
  2589. userData = db.UserMachineData.Add(new UserMachineData()
  2590. {
  2591. IdBrand = IdBrand,
  2592. }).Entity;
  2593. db.SaveChanges();
  2594. }
  2595. userData.OpenProfit += Prize;
  2596. db.SaveChanges();
  2597. //账户入库
  2598. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2599. if (account == null)
  2600. {
  2601. account = db.UserAccount.Add(new UserAccount()
  2602. {
  2603. Id = puser.Id,
  2604. UserId = puser.Id,
  2605. }).Entity;
  2606. db.SaveChanges();
  2607. }
  2608. //收支明细入库
  2609. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2610. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2611. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2612. account.BalanceAmount += Prize;
  2613. account.TotalAmount += Prize;
  2614. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2615. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2616. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2617. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2618. {
  2619. CreateDate = DateTime.Now,
  2620. UpdateDate = DateTime.Now,
  2621. UserId = puser.Id, //创客
  2622. ChangeType = 50, //变动类型
  2623. ProductType = pos.BrandId, //产品类型
  2624. ChangeAmount = Prize, //变更金额
  2625. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2626. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2627. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2628. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2629. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2630. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2631. }).Entity;
  2632. db.SaveChanges();
  2633. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  2634. string dateString = DateTime.Now.ToString("yyyyMMdd");
  2635. string monthString = DateTime.Now.ToString("yyyyMM");
  2636. // 开机奖励列表
  2637. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  2638. if (!dates.Contains(dateString))
  2639. {
  2640. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  2641. }
  2642. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  2643. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  2644. if (!months.Contains(monthString))
  2645. {
  2646. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  2647. }
  2648. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  2649. // 开机奖励详情
  2650. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  2651. //收支明细
  2652. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  2653. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  2654. Prize -= 10;
  2655. PrizeFlag.Add(Prize.ToString("f0"));
  2656. }
  2657. }
  2658. }
  2659. string result = "";
  2660. if (!PrizeFlag.Contains("20"))
  2661. {
  2662. result += "20元奖励未发,请检查上级是否满足条件\n";
  2663. }
  2664. if (!PrizeFlag.Contains("10"))
  2665. {
  2666. result += "10元奖励未发,请检查上级是否满足条件\n";
  2667. }
  2668. if (string.IsNullOrEmpty(result))
  2669. {
  2670. return "发放成功";
  2671. }
  2672. return result;
  2673. }
  2674. }
  2675. db.Dispose();
  2676. return "操作失败";
  2677. }
  2678. #endregion
  2679. #region 查询机具流量费分佣
  2680. public IActionResult FluxPrize(string right)
  2681. {
  2682. ViewBag.RightInfo = RightInfo;
  2683. ViewBag.right = right;
  2684. return View();
  2685. }
  2686. [HttpPost]
  2687. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  2688. {
  2689. Dictionary<string, string> dic = new Dictionary<string, string>();
  2690. string result = "";
  2691. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2692. if (pos == null)
  2693. {
  2694. result += "机具SN号不存在\n";
  2695. dic.Add("code", "1");
  2696. dic.Add("result", result);
  2697. return dic;
  2698. }
  2699. if (pos.BindingState == 0)
  2700. {
  2701. result += "机具未绑定\n";
  2702. dic.Add("code", "1");
  2703. dic.Add("result", result);
  2704. return dic;
  2705. }
  2706. if (pos.ActivationState == 0)
  2707. {
  2708. result += "机具未激活\n";
  2709. dic.Add("code", "1");
  2710. dic.Add("result", result);
  2711. return dic;
  2712. }
  2713. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2714. if (merchant == null)
  2715. {
  2716. result += "商户不存在\n";
  2717. dic.Add("code", "1");
  2718. dic.Add("result", result);
  2719. return dic;
  2720. }
  2721. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2722. result += "机具号:" + PosSn + "\n";
  2723. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2724. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2725. string FluxGet6 = "未领取";
  2726. string FluxUser6 = "";
  2727. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  2728. if (flux.Id > 0)
  2729. {
  2730. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  2731. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2732. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2733. }
  2734. result += "流量费:" + FluxGet6 + "\n";
  2735. result += "流量费发放对象:" + FluxUser6 + "\n";
  2736. dic.Add("id", pos.Id.ToString());
  2737. dic.Add("code", "0");
  2738. dic.Add("result", result);
  2739. return dic;
  2740. }
  2741. public string AddFluxPrize(int Id)
  2742. {
  2743. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2744. if (pos == null)
  2745. {
  2746. return "机具未激活";
  2747. }
  2748. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2749. {
  2750. return "绑定已超过30天";
  2751. }
  2752. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2753. if (ActPrize == 0)
  2754. {
  2755. return "机具无押金";
  2756. }
  2757. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2758. if (merchant == null)
  2759. {
  2760. return "商户不存在";
  2761. }
  2762. if (pos.BrandId == 6)
  2763. {
  2764. return "立刷不支持流量费分佣";
  2765. }
  2766. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  2767. {
  2768. return "无押金机,不支持流量费分佣";
  2769. }
  2770. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  2771. if (check)
  2772. {
  2773. return "开机奖励已发放,请勿重复操作";
  2774. }
  2775. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  2776. if (trade != null)
  2777. {
  2778. try
  2779. {
  2780. string OrderNo = trade.TradeSerialNo; //单号
  2781. DateTime TradeDate = trade.CreateDate.Value;
  2782. string TradeMonth = TradeDate.ToString("yyyyMM");
  2783. decimal FeeAmount = trade.FeeAmount; //流量费
  2784. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  2785. {
  2786. FeeAmount = FeeAmount / 100;
  2787. }
  2788. string TradeSnNo = trade.TradeSnNo; //机具SN
  2789. decimal FluxProfit = 0;
  2790. if (trade.ProductType == "1" && FeeAmount == 60)
  2791. {
  2792. FluxProfit = 24;
  2793. }
  2794. else if (trade.ProductType == "7" && FeeAmount == 46)
  2795. {
  2796. FluxProfit = 10;
  2797. }
  2798. else if (trade.ProductType != "1" && FeeAmount == 48)
  2799. {
  2800. FluxProfit = 12;
  2801. }
  2802. if (FluxProfit > 0)
  2803. {
  2804. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2805. int GetUserId = user.Id;
  2806. int TopUserId = 0;
  2807. string ParentNav = user.ParentNav;
  2808. if (!string.IsNullOrEmpty(ParentNav))
  2809. {
  2810. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2811. if (ParentNavList.Length > 1)
  2812. {
  2813. TopUserId = int.Parse(ParentNavList[1]);
  2814. }
  2815. else if (ParentNavList.Length == 1)
  2816. {
  2817. TopUserId = int.Parse(ParentNavList[0]);
  2818. }
  2819. }
  2820. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  2821. if (fluxProfit == null)
  2822. {
  2823. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  2824. {
  2825. CreateDate = DateTime.Now,
  2826. UpdateDate = DateTime.Now,
  2827. UserId = GetUserId, //创客
  2828. BrandId = pos.BrandId,
  2829. TopUserId = TopUserId, //顶级创客
  2830. TradeMonth = TradeMonth, //交易月
  2831. MerUserType = user.MerchantType, //商户创客类型
  2832. Remark = "流量卡分佣", //备注
  2833. }).Entity;
  2834. db.SaveChanges();
  2835. }
  2836. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  2837. db.FluxProfitDetail.Add(new FluxProfitDetail()
  2838. {
  2839. CreateDate = DateTime.Now,
  2840. UpdateDate = DateTime.Now,
  2841. RecordNo = OrderNo, //单号
  2842. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  2843. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  2844. TradeMonth = TradeMonth, //交易月
  2845. UserId = GetUserId, //创客
  2846. MerchantId = pos.BindMerchantId, //商户
  2847. MerchantUserId = pos.UserId, //商户直属人
  2848. MerNo = merchant.KqMerNo, //渠道商户编号
  2849. SnNo = pos.PosSn, //渠道SN号
  2850. FluxOrderNo = OrderNo, //流量扣费单号
  2851. TradeOrderNo = OrderNo, //交易流水号
  2852. TradeAmt = trade.TradeAmount, //商户交易额
  2853. FluxFeeAmt = FeeAmount, //流量费
  2854. FluxProfitAmt = FluxProfit, //流量分润总金额
  2855. PosType = pos.PosSnType.ToString(), //POS类型
  2856. Remark = "流量卡分佣", //备注
  2857. BrandId = pos.BrandId, //品牌
  2858. TopUserId = TopUserId, //顶级创客
  2859. MerUserType = user.MerchantType, //商户创客类型
  2860. });
  2861. string IdBrand = user.Id + "_" + pos.BrandId;
  2862. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2863. if (userData == null)
  2864. {
  2865. userData = db.UserMachineData.Add(new UserMachineData()
  2866. {
  2867. IdBrand = IdBrand,
  2868. }).Entity;
  2869. db.SaveChanges();
  2870. }
  2871. userData.FluxProfit += FluxProfit;
  2872. db.SaveChanges();
  2873. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  2874. if (account == null)
  2875. {
  2876. account = db.UserAccount.Add(new UserAccount()
  2877. {
  2878. Id = GetUserId,
  2879. UserId = GetUserId,
  2880. }).Entity;
  2881. db.SaveChanges();
  2882. }
  2883. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2884. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2885. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2886. account.BalanceAmount += FluxProfit;
  2887. account.TotalAmount += FluxProfit;
  2888. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2889. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2890. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2891. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2892. {
  2893. CreateDate = DateTime.Now,
  2894. UpdateDate = DateTime.Now,
  2895. UserId = GetUserId, //创客
  2896. ChangeType = 60, //变动类型
  2897. ProductType = pos.BrandId, //产品类型
  2898. ChangeAmount = FluxProfit, //变更金额
  2899. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2900. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2901. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2902. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2903. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2904. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2905. }).Entity;
  2906. db.SaveChanges();
  2907. spdb.Dispose();
  2908. db.Dispose();
  2909. return "发放成功";
  2910. }
  2911. }
  2912. catch (Exception ex)
  2913. {
  2914. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  2915. }
  2916. }
  2917. spdb.Dispose();
  2918. db.Dispose();
  2919. return "操作失败";
  2920. }
  2921. #endregion
  2922. #region 设置立刷费率
  2923. public IActionResult LisFee(string right)
  2924. {
  2925. ViewBag.RightInfo = RightInfo;
  2926. ViewBag.right = right;
  2927. return View();
  2928. }
  2929. [HttpPost]
  2930. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  2931. {
  2932. if (string.IsNullOrEmpty(PosSns))
  2933. {
  2934. return "请输入机具号";
  2935. }
  2936. string result = SysUserName + "设置\n";
  2937. string[] PosSnList = PosSns.Split('\n');
  2938. int total = PosSnList.Length;
  2939. int index = 0;
  2940. foreach (string SubPosSn in PosSnList)
  2941. {
  2942. index += 1;
  2943. string PosSn = SubPosSn.Replace("\r", "");
  2944. result += PosSn + ":" + Fee + "\n";
  2945. if (Kind == "M5")
  2946. {
  2947. result += SetLiSFee(PosSn, Fee) + "\n";
  2948. }
  2949. else if (Kind == "N1")
  2950. {
  2951. result += SetLiSDeposit(PosSn, (int)Fee);
  2952. }
  2953. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  2954. }
  2955. result += "\n\n";
  2956. function.WriteLog(result, "设置立刷费率");
  2957. return result;
  2958. }
  2959. public string LisFeeProcess()
  2960. {
  2961. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  2962. }
  2963. #region 立刷
  2964. string LiSAgentId = "50814834";
  2965. 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=";
  2966. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  2967. public string LiSSign(string data)
  2968. {
  2969. var rsa = RSA.Create();
  2970. var key = Convert.FromBase64String(LiSPrivateKey);
  2971. var content = Encoding.UTF8.GetBytes(data);
  2972. rsa.ImportPkcs8PrivateKey(key, out _);
  2973. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  2974. return Convert.ToBase64String(result);
  2975. }
  2976. // 设置费率
  2977. public string SetLiSFee(string sn, decimal serviceFee)
  2978. {
  2979. Dictionary<string, object> dic = new Dictionary<string, object>();
  2980. dic.Add("agentId", LiSAgentId);
  2981. dic.Add("deviceSn", sn);
  2982. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2983. Dictionary<string, object> item = new Dictionary<string, object>();
  2984. item.Add("feeCalcType", "M5");
  2985. item.Add("fixed", "0");
  2986. item.Add("rate", serviceFee);
  2987. feeList.Add(item);
  2988. dic.Add("feeList", feeList);
  2989. dic.Add("signMethod", "02");
  2990. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  2991. string signstr = LiSSign(content);
  2992. dic.Add("signData", signstr);
  2993. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2994. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2995. return result;
  2996. }
  2997. // 设置押金
  2998. public string SetLiSDeposit(string sn, int serviceFee)
  2999. {
  3000. serviceFee = serviceFee * 100;
  3001. Dictionary<string, object> dic = new Dictionary<string, object>();
  3002. dic.Add("agentId", LiSAgentId);
  3003. dic.Add("deviceSn", sn);
  3004. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  3005. Dictionary<string, object> item = new Dictionary<string, object>();
  3006. item.Add("feeCalcType", "N1");
  3007. item.Add("fixed", "1");
  3008. item.Add("rate", serviceFee);
  3009. feeList.Add(item);
  3010. dic.Add("feeList", feeList);
  3011. dic.Add("signMethod", "02");
  3012. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  3013. string signstr = LiSSign(content);
  3014. dic.Add("signData", signstr);
  3015. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  3016. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  3017. return result;
  3018. }
  3019. #endregion
  3020. #endregion
  3021. #region 查询商户型创客设置信息
  3022. public IActionResult SeeMerchantType(string right)
  3023. {
  3024. ViewBag.RightInfo = RightInfo;
  3025. ViewBag.right = right;
  3026. return View();
  3027. }
  3028. [HttpPost]
  3029. public string SeeMerchantTypeDo(string PosSn)
  3030. {
  3031. if (string.IsNullOrEmpty(PosSn))
  3032. {
  3033. return "请输入机具SN或者创客编号";
  3034. }
  3035. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3036. if (PosSn.StartsWith("K"))
  3037. {
  3038. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3039. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3040. if (check)
  3041. {
  3042. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3043. }
  3044. }
  3045. else
  3046. {
  3047. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3048. if (check)
  3049. {
  3050. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3051. }
  3052. }
  3053. if (pos.Id == 0)
  3054. {
  3055. return "查无信息";
  3056. }
  3057. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3058. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3059. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3060. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3061. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3062. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3063. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3064. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3065. string result = "";
  3066. result += "机具SN:" + pos.PosSn + "\n";
  3067. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3068. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3069. result += "商户编号:" + pos.MerNo + "\n";
  3070. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3071. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3072. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3073. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3074. result += "是否循环:" + RecycFlag + "\n";
  3075. return result;
  3076. }
  3077. #endregion
  3078. #region 三要素验证
  3079. public IActionResult CheckThreeElements(string right)
  3080. {
  3081. ViewBag.RightInfo = RightInfo;
  3082. ViewBag.right = right;
  3083. return View();
  3084. }
  3085. [HttpPost]
  3086. public string CheckThreeElementsDo(string bankcard, string idcard, string name)
  3087. {
  3088. var host = "https://bankcard3c.shumaidata.com";
  3089. var path = "/bankcard3c";
  3090. var method = "GET";
  3091. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3092. if (string.IsNullOrEmpty(bankcard))
  3093. {
  3094. return "结算银行卡号";
  3095. }
  3096. if (string.IsNullOrEmpty(idcard))
  3097. {
  3098. return "身份证号";
  3099. }
  3100. if (string.IsNullOrEmpty(name))
  3101. {
  3102. return "真实姓名";
  3103. }
  3104. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&name=" + name;
  3105. function.WriteLog(DateTime.Now.ToString(), "验证三要素日志");
  3106. function.WriteLog(querys, "验证三要素日志");
  3107. String bodys = "";
  3108. String url = host + path;
  3109. HttpWebRequest httpRequest = null;
  3110. HttpWebResponse httpResponse = null;
  3111. if (0 < querys.Length)
  3112. {
  3113. url = url + "?" + querys;
  3114. }
  3115. if (host.Contains("https://"))
  3116. {
  3117. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3118. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3119. }
  3120. else
  3121. {
  3122. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3123. }
  3124. httpRequest.Method = method;
  3125. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3126. if (0 < bodys.Length)
  3127. {
  3128. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3129. using (Stream stream = httpRequest.GetRequestStream())
  3130. {
  3131. stream.Write(data, 0, data.Length);
  3132. }
  3133. }
  3134. try
  3135. {
  3136. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3137. }
  3138. catch (WebException ex)
  3139. {
  3140. httpResponse = (HttpWebResponse)ex.Response;
  3141. }
  3142. Stream st = httpResponse.GetResponseStream();
  3143. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3144. string result = reader.ReadToEnd();
  3145. JsonData jsonObj = JsonMapper.ToObject(result);
  3146. result = jsonObj["data"]["desc"].ToString();
  3147. function.WriteLog(result, "验证三要素日志");
  3148. function.WriteLog("\n\n", "验证三要素日志");
  3149. return result;
  3150. }
  3151. #endregion
  3152. #region 四要素验证
  3153. public IActionResult CheckFourElements(string right)
  3154. {
  3155. ViewBag.RightInfo = RightInfo;
  3156. ViewBag.right = right;
  3157. return View();
  3158. }
  3159. [HttpPost]
  3160. public string CheckFourElementsDo(string bankcard, string idcard, string mobile, string name)
  3161. {
  3162. var host = "https://bankcard4c.shumaidata.com";
  3163. var path = "/bankcard4c";
  3164. var method = "GET";
  3165. var appcode = "8e5704921ca3422f80f0deb935a7ddc6";
  3166. if (string.IsNullOrEmpty(bankcard))
  3167. {
  3168. return "请输入结算银行卡号";
  3169. }
  3170. if (string.IsNullOrEmpty(idcard))
  3171. {
  3172. return "请输入身份证号";
  3173. }
  3174. if (string.IsNullOrEmpty(mobile))
  3175. {
  3176. return "请输入银行预留手机号";
  3177. }
  3178. if (string.IsNullOrEmpty(name))
  3179. {
  3180. return "请输入真实姓名";
  3181. }
  3182. String querys = "bankcard=" + bankcard + "&idcard=" + idcard + "&mobile=" + mobile + "&name=" + name;
  3183. function.WriteLog(DateTime.Now.ToString(), "验证四要素日志");
  3184. function.WriteLog(querys, "验证四要素日志");
  3185. String bodys = "";
  3186. String url = host + path;
  3187. HttpWebRequest httpRequest = null;
  3188. HttpWebResponse httpResponse = null;
  3189. if (0 < querys.Length)
  3190. {
  3191. url = url + "?" + querys;
  3192. }
  3193. if (host.Contains("https://"))
  3194. {
  3195. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  3196. httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
  3197. }
  3198. else
  3199. {
  3200. httpRequest = (HttpWebRequest)WebRequest.Create(url);
  3201. }
  3202. httpRequest.Method = method;
  3203. httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
  3204. if (0 < bodys.Length)
  3205. {
  3206. byte[] data = Encoding.UTF8.GetBytes(bodys);
  3207. using (Stream stream = httpRequest.GetRequestStream())
  3208. {
  3209. stream.Write(data, 0, data.Length);
  3210. }
  3211. }
  3212. try
  3213. {
  3214. httpResponse = (HttpWebResponse)httpRequest.GetResponse();
  3215. }
  3216. catch (WebException ex)
  3217. {
  3218. httpResponse = (HttpWebResponse)ex.Response;
  3219. }
  3220. Stream st = httpResponse.GetResponseStream();
  3221. StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
  3222. string result = reader.ReadToEnd();
  3223. JsonData jsonObj = JsonMapper.ToObject(result);
  3224. result = jsonObj["data"]["desc"].ToString();
  3225. function.WriteLog(result, "验证四要素日志");
  3226. function.WriteLog("\n\n", "验证四要素日志");
  3227. return result;
  3228. }
  3229. #endregion
  3230. public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  3231. {
  3232. return true;
  3233. }
  3234. #region 根据机具号同步商户激活状态
  3235. public IActionResult SyncMerchantStatus(string right)
  3236. {
  3237. ViewBag.RightInfo = RightInfo;
  3238. ViewBag.right = right;
  3239. return View();
  3240. }
  3241. [HttpPost]
  3242. public string SyncMerchantStatusDo(string PosSn)
  3243. {
  3244. if (string.IsNullOrEmpty(PosSn))
  3245. {
  3246. return "请输入机具号";
  3247. }
  3248. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3249. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3250. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == posInfo.BindMerchantId) ?? new PosMerchantInfo();
  3251. if (posInfo.Id == 0)
  3252. {
  3253. return "机具" + PosSn + "不存在";
  3254. }
  3255. if (posMerchant.Id == 0)
  3256. {
  3257. return "机具绑定商户不存在";
  3258. }
  3259. else
  3260. {
  3261. posMerchant.ActiveStatus = 1;
  3262. posMerchant.UpdateDate = DateTime.Now;
  3263. posMerchant.MerStandardDate = posInfo.ActivationTime;
  3264. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosSn + ":" + SysUserName + "-" + SysRealName, "根据机具号同步商户激活状态");
  3265. db.SaveChanges();
  3266. }
  3267. return "success";
  3268. }
  3269. #endregion
  3270. #region 根据机具号补发开机奖励
  3271. public IActionResult PosRewardReissued(string right)
  3272. {
  3273. ViewBag.RightInfo = RightInfo;
  3274. ViewBag.right = right;
  3275. return View();
  3276. }
  3277. [HttpPost]
  3278. public string PosRewardReissuedDo(string PosSn)
  3279. {
  3280. if (string.IsNullOrEmpty(PosSn))
  3281. {
  3282. return "请输入机具SN";
  3283. }
  3284. string[] PosSnList = PosSn.Split('\n');
  3285. var PosId = "";
  3286. var error = "";
  3287. foreach (var item in PosSnList)
  3288. {
  3289. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3290. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3291. bool checkExist = db.OpenRewardDetail.Any(m => m.SnNo == item);
  3292. if (checkExist)
  3293. {
  3294. error += "以下操作失败" + item + ',' + "该机具开机奖励已发,请勿再次操作" + '\n';
  3295. }
  3296. else
  3297. {
  3298. if (posInfo.Id > 0)
  3299. {
  3300. PosId += posInfo.Id + ",";
  3301. }
  3302. }
  3303. }
  3304. if (!string.IsNullOrEmpty(error))
  3305. {
  3306. return "Warning|" + error;
  3307. }
  3308. PosId = PosId.TrimEnd(',');
  3309. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号补发开机奖励");
  3310. RedisDbconn.Instance.AddList("OpenRewardQueue", PosId);
  3311. return "success";
  3312. }
  3313. #endregion
  3314. #region 根据机具号设置费率
  3315. public IActionResult SetPosFee(string right)
  3316. {
  3317. ViewBag.RightInfo = RightInfo;
  3318. ViewBag.right = right;
  3319. return View();
  3320. }
  3321. [HttpPost]
  3322. public string SetPosFeeDo(string PosSn, string FeeType)
  3323. {
  3324. if (string.IsNullOrEmpty(PosSn))
  3325. {
  3326. return "请输入机具SN";
  3327. }
  3328. if (string.IsNullOrEmpty(FeeType))
  3329. {
  3330. return "请输入选择费率";
  3331. }
  3332. if (FeeType == "0")
  3333. {
  3334. FeeType = "0.6";
  3335. }
  3336. if (FeeType == "1")
  3337. {
  3338. FeeType = "0.63";
  3339. }
  3340. string[] PosSnList = PosSn.Split('\n');
  3341. var PosId = "";
  3342. var RecordId = "";
  3343. var error = "";
  3344. foreach (var item in PosSnList)
  3345. {
  3346. var pos = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == item) ?? new MachineForSnNo();
  3347. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == pos.SnId) ?? new PosMachinesTwo();
  3348. if (posInfo.Id > 0)
  3349. {
  3350. var query = db.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
  3351. {
  3352. Sort = posInfo.BrandId,
  3353. CreateDate = DateTime.Now,
  3354. PosId = posInfo.Id,
  3355. PosSn = posInfo.PosSn,
  3356. PosUserId = posInfo.UserId,
  3357. MerchantId = posInfo.BindMerchantId,
  3358. UserId = posInfo.UserId,
  3359. ChangeFee = decimal.Parse(FeeType),
  3360. }).Entity;
  3361. db.SaveChanges();
  3362. PosId += posInfo.Id + ",";
  3363. RecordId += query.Id + ",";
  3364. }
  3365. else
  3366. {
  3367. error += "机具" + PosSn + "不存在";
  3368. }
  3369. }
  3370. if (!string.IsNullOrEmpty(error))
  3371. {
  3372. return "Warning|" + error;
  3373. }
  3374. PosId = PosId.TrimEnd(',');
  3375. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + PosId + ":" + SysUserName + "-" + SysRealName, "根据机具号设置费率");
  3376. string data = "{\"RecordId\":\"" + RecordId + "\",\"PosId\":\"" + PosId + "\",\"Fee\": \"" + FeeType + "\",\"Kind\": \"2\",\"OpMan\": \"系统\"}";
  3377. RedisDbconn.Instance.AddList("SetDepositPostQueue", data);
  3378. return "success";
  3379. }
  3380. #endregion
  3381. #region 根据机具号、商户号、商户姓名关联商户和机具信息
  3382. public IActionResult RelationPosAndMerchant(string right)
  3383. {
  3384. ViewBag.RightInfo = RightInfo;
  3385. ViewBag.right = right;
  3386. return View();
  3387. }
  3388. [HttpPost]
  3389. public string RelationPosAndMerchantDo(string PosSn, string MerchantNo, string MerchantName)
  3390. {
  3391. if (string.IsNullOrEmpty(PosSn))
  3392. {
  3393. return "请输入机具SN";
  3394. }
  3395. if (string.IsNullOrEmpty(MerchantNo))
  3396. {
  3397. return "请输入商户编号";
  3398. }
  3399. if (string.IsNullOrEmpty(MerchantName))
  3400. {
  3401. return "请输入商户姓名";
  3402. }
  3403. var query = PosSn + "," + MerchantNo + "," + MerchantName;
  3404. var posMerchant = db.PosMerchantInfo.FirstOrDefault(m => m.MerchantNo == MerchantNo && m.MerchantName == MerchantName) ?? new PosMerchantInfo();
  3405. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == posMerchant.KqSnNo) ?? new MachineForSnNo();
  3406. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3407. if (posMerchant.Id == 0)
  3408. {
  3409. return "商户" + MerchantNo + "不存在";
  3410. }
  3411. if (pos.Id == 0)
  3412. {
  3413. return "机具" + PosSn + "不存在";
  3414. }
  3415. else
  3416. {
  3417. pos.BindMerchantId = posMerchant.Id;
  3418. db.SaveChanges();
  3419. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "根据机具号、商户号、商户姓名关联");
  3420. }
  3421. return "success";
  3422. }
  3423. #endregion
  3424. #region 认证创客
  3425. public IActionResult AuthMaker(string right)
  3426. {
  3427. ViewBag.RightInfo = RightInfo;
  3428. ViewBag.right = right;
  3429. return View();
  3430. }
  3431. [HttpPost]
  3432. public string AuthMakerDo(string MakerCode, string RealName, string CertId, string BackCard, string BackName)
  3433. {
  3434. if (string.IsNullOrEmpty(MakerCode))
  3435. {
  3436. return "请输入创客编号";
  3437. }
  3438. if (string.IsNullOrEmpty(RealName))
  3439. {
  3440. return "请输入真实姓名";
  3441. }
  3442. if (string.IsNullOrEmpty(CertId))
  3443. {
  3444. return "请输入身份证号";
  3445. }
  3446. if (string.IsNullOrEmpty(BackCard))
  3447. {
  3448. return "请输入银行卡号";
  3449. }
  3450. if (string.IsNullOrEmpty(BackName))
  3451. {
  3452. return "请输入银行名称";
  3453. }
  3454. var query = MakerCode + "," + RealName + "," + CertId + "," + BackCard + "," + BackName;
  3455. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3456. var userInfo = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3457. if (userInfo.AuthFlag == 1)
  3458. {
  3459. return "已认证";
  3460. }
  3461. else
  3462. {
  3463. userInfo.UpdateDate = DateTime.Now;
  3464. userInfo.RealName = RealName;
  3465. userInfo.CertId = CertId;
  3466. userInfo.SettleBankCardNo = BackCard;
  3467. userInfo.SettleBankCardName = BackName;
  3468. db.SaveChanges();
  3469. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "认证创客");
  3470. }
  3471. return "success";
  3472. }
  3473. #endregion
  3474. #region 划拨创客机具
  3475. public IActionResult TransferPos(string right)
  3476. {
  3477. ViewBag.RightInfo = RightInfo;
  3478. ViewBag.right = right;
  3479. return View();
  3480. }
  3481. [HttpPost]
  3482. public string TransferPosDo(string PosSn, string FromMakerCode, string ToMakerCode)
  3483. {
  3484. if (string.IsNullOrEmpty(PosSn))
  3485. {
  3486. return "请输入机具SN";
  3487. }
  3488. if (string.IsNullOrEmpty(FromMakerCode))
  3489. {
  3490. return "请输入机具来源创客编号";
  3491. }
  3492. if (string.IsNullOrEmpty(ToMakerCode))
  3493. {
  3494. return "请输入划拨对象创客编号";
  3495. }
  3496. var query = PosSn + "," + FromMakerCode + "," + ToMakerCode;
  3497. var machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  3498. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId) ?? new PosMachinesTwo();
  3499. if (posInfo.Id == 0)
  3500. {
  3501. return "机具" + PosSn + "不存在";
  3502. }
  3503. var user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == FromMakerCode) ?? new UserForMakerCode();
  3504. var tuser = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ToMakerCode) ?? new UserForMakerCode();
  3505. var fUserId = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
  3506. if (fUserId.Id == 0)
  3507. {
  3508. return "来源创客" + FromMakerCode + "不存在";
  3509. }
  3510. var tUserId = db.Users.FirstOrDefault(m => m.Id == tuser.UserId) ?? new Users();
  3511. if (tUserId.Id == 0)
  3512. {
  3513. return "划拨创客" + ToMakerCode + "不存在";
  3514. }
  3515. if (posInfo.BindingState == 0)
  3516. {
  3517. posInfo.BuyUserId = tUserId.Id;
  3518. posInfo.UserId = tUserId.Id;
  3519. db.SaveChanges();
  3520. function.WriteLog(DateTime.Now.ToString() + ":请求参数," + query + ":" + SysUserName + "-" + SysRealName, "划拨创客机具");
  3521. }
  3522. else
  3523. {
  3524. return "机具" + PosSn + "已使用";
  3525. }
  3526. return "success";
  3527. }
  3528. #endregion
  3529. #region 还原提现订单状态
  3530. public IActionResult RestoreStatus(string right)
  3531. {
  3532. ViewBag.RightInfo = RightInfo;
  3533. ViewBag.right = right;
  3534. return View();
  3535. }
  3536. [HttpPost]
  3537. public string RestoreStatusDo(string OrderNo)
  3538. {
  3539. if (string.IsNullOrEmpty(OrderNo))
  3540. {
  3541. return "请输入提现订单编号";
  3542. }
  3543. string[] OrderNoList = OrderNo.Replace("\r", "").Split('\n');
  3544. var error = "";
  3545. foreach (var item in OrderNoList)
  3546. {
  3547. var cash = db.UserCashRecord.FirstOrDefault(m => m.CashOrderNo == item) ?? new UserCashRecord();
  3548. if (cash.Id > 0)
  3549. {
  3550. cash.QueryCount = 0;
  3551. cash.Status = 0;
  3552. db.SaveChanges();
  3553. }
  3554. else
  3555. {
  3556. error += "订单" + item + "不存在" + '\n';
  3557. }
  3558. }
  3559. if (!string.IsNullOrEmpty(error))
  3560. {
  3561. return "Warning|" + error;
  3562. }
  3563. return "success";
  3564. }
  3565. #endregion
  3566. #region 查询机具信息
  3567. public IActionResult SeeUserLoop(string right)
  3568. {
  3569. ViewBag.RightInfo = RightInfo;
  3570. ViewBag.right = right;
  3571. return View();
  3572. }
  3573. [HttpPost]
  3574. public string SeeUserLoopDo(string MakerCode)
  3575. {
  3576. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  3577. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  3578. var pos = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == user.Id).ToList();
  3579. var brandList = db.KqProducts.ToList();
  3580. var info = "";
  3581. foreach (var item in brandList)
  3582. {
  3583. var brand = item.Name;
  3584. //已过期
  3585. var overdue = pos.Count(m => m.RecycEndDate < DateTime.Now && m.BrandId == item.Id);
  3586. //可申请
  3587. var use = pos.Count(m => m.IsPurchase == 0 && m.RecycEndDate > DateTime.Now && m.BrandId == item.Id);
  3588. //已使用
  3589. var used = pos.Count(m => m.IsPurchase == 1 && m.BrandId == item.Id);
  3590. info += "品牌:" + brand + ",已过期:" + overdue + ",可申请:" + use + ",已使用:" + used + "\n";
  3591. }
  3592. return info;
  3593. }
  3594. #endregion
  3595. }
  3596. }