SysToolsController.cs 181 KB

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