SysToolsController.cs 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194
  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.Text;
  21. namespace MySystem.Areas.Admin.Controllers
  22. {
  23. [Area("Admin")]
  24. [Route("Admin/[controller]/[action]")]
  25. public class SysToolsController : BaseController
  26. {
  27. public SysToolsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  28. {
  29. }
  30. #region 关联上下级
  31. public IActionResult RelationForUser(string right)
  32. {
  33. ViewBag.RightInfo = RightInfo;
  34. ViewBag.right = right;
  35. return View();
  36. }
  37. [HttpPost]
  38. public string RelationForUserDo(string MakerCode, string ParentMakerCode, int IsTeam = 1)
  39. {
  40. if (string.IsNullOrEmpty(MakerCode))
  41. {
  42. return "请输入创客编号";
  43. }
  44. if (string.IsNullOrEmpty(ParentMakerCode))
  45. {
  46. return "请输入上级创客编号";
  47. }
  48. MakerCode = MakerCode.ToUpper();
  49. ParentMakerCode = ParentMakerCode.ToUpper();
  50. Users puser = db.Users.FirstOrDefault(m => m.MakerCode == ParentMakerCode);
  51. if (puser != null)
  52. {
  53. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  54. if (user != null)
  55. {
  56. if (IsTeam == 1)
  57. {
  58. RelationForUserSub(user.Id, user);
  59. }
  60. user.ParentUserId = puser.Id;
  61. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  62. db.SaveChanges();
  63. function.WriteLog(DateTime.Now.ToString() + ":下级:" + MakerCode + ", 上级:" + ParentMakerCode, "换线日志");
  64. return "success";
  65. }
  66. return "创客编号不存在";
  67. }
  68. return "上级创客编号不存在";
  69. }
  70. private void RelationForUserSub(int ParentUserId, Users puser)
  71. {
  72. var subusers = db.Users.Select(m => new { m.Id, m.ParentUserId, m.ParentNav }).Where(m => m.ParentUserId == ParentUserId).ToList();
  73. foreach (var subuser in subusers)
  74. {
  75. Users user = db.Users.FirstOrDefault(m => m.Id == subuser.Id);
  76. if (user != null)
  77. {
  78. user.ParentUserId = puser.Id;
  79. user.ParentNav = puser.ParentNav + "," + puser.Id + ",";
  80. db.SaveChanges();
  81. RelationForUserSub(user.Id, user);
  82. }
  83. }
  84. }
  85. #endregion
  86. #region 机具补录
  87. public IActionResult CheckMachine(string right)
  88. {
  89. ViewBag.RightInfo = RightInfo;
  90. ViewBag.right = right;
  91. return View();
  92. }
  93. [HttpPost]
  94. public string CheckMachineDo(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0, int IsPre = 0, int IsSend = 0)
  95. {
  96. if (string.IsNullOrEmpty(MakerCode))
  97. {
  98. return "请输入创客编号";
  99. }
  100. if (string.IsNullOrEmpty(PosSn))
  101. {
  102. return "请输入机具SN";
  103. }
  104. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  105. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  106. if (pos == null)
  107. {
  108. return "机具SN不存在";
  109. }
  110. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  111. if (user == null)
  112. {
  113. return "创客编号不存在";
  114. }
  115. if (IsPre == 1)
  116. {
  117. if (pos.BuyUserId == 0)
  118. {
  119. pos.BuyUserId = user.Id;
  120. }
  121. if (pos.UserId == 0)
  122. {
  123. pos.UserId = user.Id;
  124. }
  125. }
  126. if (pos.BindingState == 0)
  127. {
  128. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  129. if (bind != null)
  130. {
  131. pos.BindingState = 1;
  132. pos.BindingTime = bind.CreateTime;
  133. db.SaveChanges();
  134. MerNo = bind.MerNo;
  135. }
  136. }
  137. decimal CreditTrade = 0;
  138. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  139. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  140. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  141. bool check = spdb.TradeRecord.Any(m => m.Id > StartId && m.TradeSnNo == pos.PosSn);
  142. if (check)
  143. {
  144. if (pos.BrandId == 1)
  145. {
  146. 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;
  147. }
  148. else if (pos.BrandId == 2)
  149. {
  150. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  151. }
  152. else if (pos.BrandId == 3)
  153. {
  154. 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;
  155. }
  156. else if (pos.BrandId == 4 || pos.BrandId == 5)
  157. {
  158. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  159. }
  160. else if (pos.BrandId == 6)
  161. {
  162. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  163. }
  164. else if (pos.BrandId == 7)
  165. {
  166. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "7" && m.TradeStatus == "00").Sum(m => m.TradeAmount) / 100;
  167. }
  168. else if (pos.BrandId == 8)
  169. {
  170. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  171. }
  172. else if (pos.BrandId == 9)
  173. {
  174. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  175. }
  176. pos.CreditTrade = CreditTrade;
  177. db.SaveChanges();
  178. StatTradeAmount(pos.PosSn, StartId);
  179. }
  180. if (AddActPrize == 1)
  181. {
  182. if (pos.BuyUserId == 0)
  183. {
  184. return "机具未划拨,无法补录激活奖励";
  185. }
  186. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  187. {
  188. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  189. if (has)
  190. {
  191. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  192. pos.SeoKeyword = chkAct.SeoTitle;
  193. db.SaveChanges();
  194. }
  195. }
  196. if (pos.BindingTime != null && pos.ActivationTime != null)
  197. {
  198. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  199. if (ts.TotalDays <= 30 || SysUserName == "admin")
  200. {
  201. AddAct(pos.Id);
  202. }
  203. }
  204. }
  205. decimal CheckMoney = 1000;
  206. if (pos.BrandId == 6)
  207. {
  208. CheckMoney = 5000;
  209. }
  210. if (pos.BuyUserId > 0)
  211. {
  212. if (pos.CreditTrade < CheckMoney)
  213. {
  214. return "该机具贷记卡累计交易不足" + CheckMoney;
  215. }
  216. if (pos.BindingTime != null && pos.ActivationTime != null)
  217. {
  218. TimeSpan ts = pos.ActivationTime.Value - pos.BindingTime.Value;
  219. if (ts.TotalDays > 30 && SysUserName != "admin")
  220. {
  221. return "机具划拨后已超过30天";
  222. }
  223. }
  224. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0)
  225. {
  226. pos.ActivationState = 1;
  227. pos.ActivationTime = DateTime.Now;
  228. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  229. if (pos.ActivationState == 1 && mer != null)
  230. {
  231. mer.ActiveStatus = 1;
  232. mer.MerStandardDate = DateTime.Now;
  233. }
  234. }
  235. else if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 1)
  236. {
  237. if (AddActPrize == 1)
  238. {
  239. if (IsSend == 1)
  240. {
  241. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  242. {
  243. UserId = pos.BuyUserId, //接收创客
  244. MsgType = 2,
  245. Title = "补录成功通知", //标题
  246. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功补录,请查收。",
  247. CreateDate = DateTime.Now,
  248. }));
  249. }
  250. return "激活奖励已补录";
  251. }
  252. else
  253. {
  254. return "数据正常,无需补录";
  255. }
  256. }
  257. db.SaveChanges();
  258. return "success";
  259. }
  260. pos.UserId = user.Id;
  261. pos.BuyUserId = user.Id;
  262. if (pos.CreditTrade >= CheckMoney && pos.ActivationState == 0 && (pos.BindingTime > DateTime.Now.AddDays(-30) || SysUserName == "admin"))
  263. {
  264. // pos.IsPurchase = 0;
  265. pos.ActivationState = 1;
  266. pos.ActivationTime = DateTime.Now;
  267. }
  268. PosMerchantInfo merchant = new PosMerchantInfo();
  269. if (!string.IsNullOrEmpty(MerNo))
  270. {
  271. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  272. if (merchant == null)
  273. {
  274. int TopUserId = 0;
  275. if (!string.IsNullOrEmpty(user.ParentNav))
  276. {
  277. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  278. }
  279. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  280. if (bind == null)
  281. {
  282. return "该机具尚未绑定";
  283. }
  284. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  285. if (Mer == null)
  286. {
  287. return "该机具尚未绑定";
  288. }
  289. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  290. {
  291. CreateDate = Mer.CreateTime,
  292. UpdateDate = Mer.UpdateTime,
  293. TopUserId = TopUserId,
  294. MerUserType = user.MerchantType,
  295. BrandId = int.Parse(Mer.ProductType),
  296. SnStoreId = pos.StoreId,
  297. SnType = pos.PosSnType,
  298. UserId = user.Id,
  299. MgrName = Mer.AgentName,
  300. MerStatus = 1,
  301. KqSnNo = Mer.SnNo,
  302. KqMerNo = Mer.MerNo,
  303. MerIdcardNo = Mer.MerIdcardNo,
  304. MerRealName = Mer.MerRealName,
  305. MerchantMobile = Mer.MerMobile,
  306. MerchantName = Mer.MerName,
  307. MerchantNo = Mer.MerNo,
  308. }).Entity;
  309. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  310. if (forMerNo == null)
  311. {
  312. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  313. {
  314. MerNo = Mer.MerNo,
  315. SnId = pos.Id,
  316. }).Entity;
  317. }
  318. else
  319. {
  320. forMerNo.SnId = pos.Id;
  321. }
  322. }
  323. }
  324. else
  325. {
  326. if (pos.BindMerchantId > 0)
  327. {
  328. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  329. }
  330. else
  331. {
  332. return "找不到机具所属商户";
  333. }
  334. }
  335. merchant.UserId = user.Id;
  336. if (pos.ActivationState == 1)
  337. {
  338. merchant.ActiveStatus = 1;
  339. merchant.MerStandardDate = DateTime.Now;
  340. }
  341. if (pos.BindMerchantId == 0)
  342. {
  343. pos.BindMerchantId = merchant.Id;
  344. }
  345. // var makerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  346. // 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();
  347. // if (makerCode.UserId > 0 && prePos.Id > 0)
  348. // {
  349. // if (prePos.CreateDate <= DateTime.Now.AddDays(-30))
  350. // {
  351. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == prePos.BrandId);
  352. // var amount = 0;
  353. // if (brandInfo.Name.Contains("电签"))
  354. // {
  355. // amount = 200;
  356. // }
  357. // if (brandInfo.Name.Contains("大POS"))
  358. // {
  359. // amount = 300;
  360. // }
  361. // var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == makerCode.UserId) ?? new UserAccount();
  362. // if (userAccount.Id > 0)
  363. // {
  364. // userAccount.SmallStoreDeposit -= amount;
  365. // var add = db.UserAccountRecord.Add(new UserAccountRecord()
  366. // {
  367. // CreateDate = DateTime.Now,
  368. // Remark = "小分仓押金退还",
  369. // ChangeType = 65,
  370. // BeforeBalanceAmount = userAccount.SmallStoreDeposit + amount, //变更前小分仓押金
  371. // AfterBalanceAmount = userAccount.SmallStoreDeposit, //变更后小分仓押金
  372. // ChangeAmount = amount,//变动金额
  373. // UserId = userAccount.Id,
  374. // }).Entity;
  375. // db.SaveChanges();
  376. // }
  377. // }
  378. // }
  379. db.SaveChanges();
  380. function.WriteLog(DateTime.Now.ToString() + "\n" + SysUserName + "\nMakerCode:" + MakerCode + ", PosSn:" + PosSn + ", MerNo:" + MerNo + ", AddActPrize:" + AddActPrize + ", IsPre:" + IsPre, "机具补录日志");
  381. return "success";
  382. }
  383. public IActionResult CheckMachine2(string right)
  384. {
  385. ViewBag.RightInfo = RightInfo;
  386. ViewBag.right = right;
  387. return View();
  388. }
  389. [HttpPost]
  390. public string CheckMachine2Do(string MakerCode, string PosSn, string MerNo = "", int AddActPrize = 0)
  391. {
  392. if (string.IsNullOrEmpty(MakerCode))
  393. {
  394. return "请输入创客编号";
  395. }
  396. if (string.IsNullOrEmpty(PosSn))
  397. {
  398. return "请输入机具SN";
  399. }
  400. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  401. if (pos == null)
  402. {
  403. return "机具SN不存在";
  404. }
  405. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  406. if (user == null)
  407. {
  408. return "创客编号不存在";
  409. }
  410. if (pos.BindingState == 0)
  411. {
  412. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == PosSn);
  413. if (bind != null)
  414. {
  415. pos.BindingState = 1;
  416. pos.BindingTime = bind.CreateTime;
  417. db.SaveChanges();
  418. MerNo = bind.MerNo;
  419. }
  420. }
  421. decimal CreditTrade = 0;
  422. bool check = spdb.TradeRecord.Any(m => m.TradeSnNo == pos.PosSn);
  423. if (check)
  424. {
  425. string BindingTime = pos.BindingTime == null ? DateTime.Now.AddMonths(-1).ToString("yyyyMM") : pos.BindingTime.Value.ToString("yyyyMM");
  426. string SpTradeRecordId = function.ReadInstance("/PublicParams/SpTradeRecordId" + BindingTime + ".txt");
  427. int StartId = int.Parse(function.CheckInt(SpTradeRecordId));
  428. if (pos.BrandId == 1)
  429. {
  430. 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;
  431. }
  432. else if (pos.BrandId == 2)
  433. {
  434. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "2").Sum(m => m.TradeAmount);
  435. }
  436. else if (pos.BrandId == 3)
  437. {
  438. 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;
  439. }
  440. else if (pos.BrandId == 4 || pos.BrandId == 5)
  441. {
  442. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "4").Sum(m => m.TradeAmount) / 100;
  443. }
  444. else if (pos.BrandId == 6)
  445. {
  446. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "6").Sum(m => m.TradeAmount) / 100;
  447. }
  448. else if (pos.BrandId == 8)
  449. {
  450. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "8").Sum(m => m.TradeAmount) / 100;
  451. }
  452. else if (pos.BrandId == 9)
  453. {
  454. CreditTrade = spdb.TradeRecord.Where(m => m.Id > StartId && m.TradeSnNo == pos.PosSn && m.ProductType == "9").Sum(m => m.TradeAmount) / 100;
  455. }
  456. pos.CreditTrade = CreditTrade;
  457. db.SaveChanges();
  458. StatTradeAmount(pos.PosSn);
  459. }
  460. if (AddActPrize == 1)
  461. {
  462. if (string.IsNullOrEmpty(pos.SeoKeyword) || pos.SeoKeyword == "0")
  463. {
  464. bool has = spdb.ActivateRecord.Any(m => m.SnNo == pos.PosSn);
  465. if (has)
  466. {
  467. SpModels.ActivateRecord chkAct = spdb.ActivateRecord.Where(m => m.SnNo == pos.PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SpModels.ActivateRecord();
  468. pos.SeoKeyword = chkAct.SeoTitle;
  469. db.SaveChanges();
  470. }
  471. }
  472. AddAct(pos.Id);
  473. }
  474. if (pos.BuyUserId > 0)
  475. {
  476. if (pos.CreditTrade < 1000)
  477. {
  478. // pos.IsPurchase = 99;
  479. db.SaveChanges();
  480. return "该机具贷记卡累计交易不足1000";
  481. }
  482. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  483. {
  484. // pos.IsPurchase = 0;
  485. pos.ActivationState = 1;
  486. pos.ActivationTime = DateTime.Now;
  487. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  488. if (pos.ActivationState == 1 && mer != null)
  489. {
  490. mer.ActiveStatus = 1;
  491. mer.MerStandardDate = DateTime.Now;
  492. }
  493. }
  494. else if (pos.CreditTrade >= 1000 && pos.ActivationState == 1)
  495. {
  496. if (AddActPrize == 1)
  497. {
  498. return "激活奖励已补录";
  499. }
  500. else
  501. {
  502. return "数据正常,无需补录";
  503. }
  504. }
  505. db.SaveChanges();
  506. return "success";
  507. }
  508. pos.UserId = user.Id;
  509. pos.BuyUserId = user.Id;
  510. // if (pos.CreditTrade < 1000)
  511. // {
  512. // pos.IsPurchase = 99;
  513. // }
  514. if (pos.CreditTrade >= 1000 && pos.ActivationState == 0)
  515. {
  516. // pos.IsPurchase = 0;
  517. pos.ActivationState = 1;
  518. pos.ActivationTime = DateTime.Now;
  519. }
  520. PosMerchantInfo merchant = new PosMerchantInfo();
  521. if (!string.IsNullOrEmpty(MerNo))
  522. {
  523. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  524. if (merchant == null)
  525. {
  526. int TopUserId = 0;
  527. if (!string.IsNullOrEmpty(user.ParentNav))
  528. {
  529. TopUserId = int.Parse(user.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  530. }
  531. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerNo == MerNo);
  532. if (bind == null)
  533. {
  534. return "该机具尚未绑定";
  535. }
  536. SpModels.Merchants Mer = spdb.Merchants.FirstOrDefault(m => m.MerNo == MerNo);
  537. if (Mer == null)
  538. {
  539. return "该机具尚未绑定";
  540. }
  541. PosMerchantInfo add = db.PosMerchantInfo.Add(new PosMerchantInfo()
  542. {
  543. CreateDate = Mer.CreateTime,
  544. UpdateDate = Mer.UpdateTime,
  545. TopUserId = TopUserId,
  546. MerUserType = user.MerchantType,
  547. BrandId = int.Parse(Mer.ProductType),
  548. SnStoreId = pos.StoreId,
  549. SnType = pos.PosSnType,
  550. UserId = user.Id,
  551. MgrName = Mer.AgentName,
  552. MerStatus = 1,
  553. KqSnNo = Mer.SnNo,
  554. KqMerNo = Mer.MerNo,
  555. MerIdcardNo = Mer.MerIdcardNo,
  556. MerRealName = Mer.MerRealName,
  557. MerchantMobile = Mer.MerMobile,
  558. MerchantName = Mer.MerName,
  559. MerchantNo = Mer.MerNo,
  560. }).Entity;
  561. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == Mer.MerNo);
  562. if (forMerNo == null)
  563. {
  564. forMerNo = db.MachineForMerNo.Add(new MachineForMerNo()
  565. {
  566. MerNo = Mer.MerNo,
  567. SnId = pos.Id,
  568. }).Entity;
  569. }
  570. else
  571. {
  572. forMerNo.SnId = pos.Id;
  573. }
  574. }
  575. }
  576. else
  577. {
  578. if (pos.BindMerchantId > 0)
  579. {
  580. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  581. }
  582. else
  583. {
  584. return "找不到机具所属商户";
  585. }
  586. }
  587. merchant.UserId = user.Id;
  588. if (pos.ActivationState == 1)
  589. {
  590. merchant.ActiveStatus = 1;
  591. merchant.MerStandardDate = DateTime.Now;
  592. }
  593. if (pos.BindMerchantId == 0)
  594. {
  595. pos.BindMerchantId = merchant.Id;
  596. }
  597. db.SaveChanges();
  598. return "success";
  599. }
  600. public void AddAct(int posid = 0)
  601. {
  602. WebCMSEntities db = new WebCMSEntities();
  603. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.ActivationState == 1 && !string.IsNullOrEmpty(m.SeoKeyword) && m.Id == posid);
  604. if (pos != null)
  605. {
  606. // PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId && !string.IsNullOrEmpty(m.MerIdcardNo));
  607. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  608. if (merchant != null)
  609. {
  610. // PosMerchantOtherInfo otherInfo = db.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == merchant.MerIdcardNo && m.PrizeFlag1 == 0);
  611. // if (otherInfo != null)
  612. // {
  613. // otherInfo.PrizeFlag1 = 1;
  614. // db.SaveChanges();
  615. string ParentNav = "";
  616. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  617. if (user != null)
  618. {
  619. int GetUserId = user.Id;
  620. ParentNav = user.ParentNav;
  621. int TopUserId = 1;
  622. if (!string.IsNullOrEmpty(ParentNav))
  623. {
  624. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  625. if (ParentNavList.Length > 1)
  626. {
  627. TopUserId = int.Parse(ParentNavList[1]);
  628. }
  629. else if (ParentNavList.Length == 1)
  630. {
  631. TopUserId = int.Parse(ParentNavList[0]);
  632. }
  633. }
  634. List<decimal> prizes = new List<decimal>();
  635. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  636. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 8 || pos.BrandId == 9)
  637. {
  638. ActPrize = ActPrize / 100;
  639. }
  640. if (ActPrize > 0)
  641. {
  642. if (ActPrize == 99)
  643. {
  644. ActPrize = 100;
  645. }
  646. else if (ActPrize == 199)
  647. {
  648. ActPrize = 200;
  649. }
  650. else if (ActPrize == 299)
  651. {
  652. ActPrize = 300;
  653. }
  654. else if (ActPrize == 249)
  655. {
  656. ActPrize = 260;
  657. }
  658. prizes.Add(ActPrize);
  659. if (pos.BrandId == 6 && pos.ActivationState == 1 && pos.CreditTrade >= 10000 && pos.BindingTime > DateTime.Now.AddDays(-60))
  660. {
  661. prizes.Add(40);
  662. }
  663. }
  664. else if (pos.BrandId == 6 && ActPrize == 0)
  665. {
  666. prizes.Add(50);
  667. }
  668. foreach (decimal prize in prizes)
  669. {
  670. int ChangeType = prize == 40 ? 12 : 0;
  671. bool check = db.ActiveReward.Any(m => m.KqSnNo == pos.PosSn && m.RewardAmount == prize);
  672. if (!check)
  673. {
  674. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  675. db.ActiveReward.Add(new ActiveReward()
  676. {
  677. CreateDate = DateTime.Now,
  678. UpdateDate = DateTime.Now,
  679. UserId = GetUserId, //创客
  680. MerchantId = pos.BindMerchantId, //商户
  681. StandardDate = pos.ActivationTime, //达标日期
  682. RewardAmount = prize, //奖励金额
  683. BrandId = pos.BrandId, //品牌
  684. UserNav = ParentNav, //创客父级
  685. DirectBuddyNo = merchant.UserId, //商户直属创客
  686. KqMerNo = merchant.KqMerNo, //渠道商户编号
  687. KqSnNo = pos.PosSn, //渠道SN号
  688. SnType = pos.PosSnType, //机具类型
  689. SnApplyUserId = pos.BuyUserId, //机具申请创客
  690. ActType = 0, //激活类型
  691. SnStoreId = pos.StoreId, //SN仓库
  692. RewardTips = "激活奖励", //奖励描述
  693. Remark = "激活奖励", //备注
  694. ActDate = pos.ActivationTime, //激活时间
  695. TopUserId = TopUserId, //顶级创客
  696. SeoTitle = machineUser.RealName,
  697. });
  698. db.SaveChanges();
  699. string IdBrand = GetUserId + "_" + pos.BrandId;
  700. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  701. if (userData == null)
  702. {
  703. userData = db.UserMachineData.Add(new UserMachineData()
  704. {
  705. IdBrand = IdBrand,
  706. }).Entity;
  707. db.SaveChanges();
  708. }
  709. userData.ActProfit += prize;
  710. db.SaveChanges();
  711. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  712. if (account == null)
  713. {
  714. account = db.UserAccount.Add(new UserAccount()
  715. {
  716. Id = GetUserId,
  717. UserId = GetUserId,
  718. }).Entity;
  719. db.SaveChanges();
  720. }
  721. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  722. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  723. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  724. account.BalanceAmount += prize;
  725. account.TotalAmount += prize;
  726. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  727. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  728. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  729. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  730. {
  731. CreateDate = DateTime.Now,
  732. UpdateDate = DateTime.Now,
  733. UserId = GetUserId, //创客
  734. ChangeType = ChangeType, //变动类型
  735. ProductType = pos.BrandId, //产品类型
  736. ChangeAmount = prize, //变更金额
  737. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  738. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  739. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  740. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  741. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  742. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  743. }).Entity;
  744. db.SaveChanges();
  745. RedisDbconn.Instance.Set("UserAccount:" + GetUserId, account);
  746. string dateString = pos.ActivationTime.Value.ToString("yyyyMMdd");
  747. string monthString = pos.ActivationTime.Value.ToString("yyyyMM");
  748. // 激活奖励列表
  749. List<string> dates = RedisDbconn.Instance.GetList<string>("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId);
  750. if (!dates.Contains(dateString))
  751. {
  752. RedisDbconn.Instance.AddList("ActiveRewardDay:" + GetUserId + ":" + pos.BrandId, dateString);
  753. }
  754. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + dateString, prize);
  755. List<string> months = RedisDbconn.Instance.GetList<string>("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId);
  756. if (!months.Contains(monthString))
  757. {
  758. RedisDbconn.Instance.AddList("ActiveRewardMonth:" + GetUserId + ":" + pos.BrandId, monthString);
  759. }
  760. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:" + GetUserId + ":" + pos.BrandId + ":" + monthString, prize);
  761. // 激活奖励详情
  762. List<int> actPrizeList = RedisDbconn.Instance.GetList<int>("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString);
  763. if (!actPrizeList.Contains(pos.BindMerchantId))
  764. {
  765. RedisDbconn.Instance.AddList("ActiveRewardDetail:" + GetUserId + ":" + pos.BrandId + ":" + dateString, pos.BindMerchantId);
  766. }
  767. RedisDbconn.Instance.AddNumber("ActiveRewardAmt:mer:" + pos.BindMerchantId + ":" + pos.BrandId + ":" + dateString, prize);
  768. //收支明细
  769. RedisDbconn.Instance.AddList("UserAccountRecord:" + GetUserId + ":1:" + monthString, userAccountRecord);
  770. RedisDbconn.Instance.AddNumber("UserAccount:" + GetUserId + ":1:" + monthString, prize);
  771. }
  772. }
  773. }
  774. // }
  775. }
  776. }
  777. db.Dispose();
  778. }
  779. //重置交易额
  780. public void StatTradeAmount(string PosSn, int StartId = 0)
  781. {
  782. DateTime start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  783. if (DateTime.Now.Day == 1)
  784. {
  785. start = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-01 00:00:00");
  786. }
  787. DateTime end = DateTime.Now;
  788. SycnSpTradeService.Instance.Start(PosSn, start, end, StartId);
  789. RedisDbconn.Instance.AddList("ResetTradeAmountList", PosSn);
  790. }
  791. #endregion
  792. #region 设置商户代理
  793. public IActionResult SetMerAgent(string right)
  794. {
  795. ViewBag.RightInfo = RightInfo;
  796. ViewBag.right = right;
  797. return View();
  798. }
  799. [HttpPost]
  800. public string SetMerAgentDo(string MakerCode, string PosSn, string MerNo, int IsSend = 0)
  801. {
  802. if (string.IsNullOrEmpty(MakerCode))
  803. {
  804. return "请输入创客编号";
  805. }
  806. if (string.IsNullOrEmpty(PosSn))
  807. {
  808. return "请输入机具SN";
  809. }
  810. if (string.IsNullOrEmpty(MerNo))
  811. {
  812. return "请输入商户编号";
  813. }
  814. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  815. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  816. if (pos == null)
  817. {
  818. return "机具SN不存在";
  819. }
  820. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  821. if (user == null)
  822. {
  823. return "创客编号不存在";
  824. }
  825. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo);
  826. if (merchant == null)
  827. {
  828. return "商户编号不存在";
  829. }
  830. pos.SeoTitle = user.Id.ToString();
  831. pos.UserId = user.Id;
  832. if (pos.BindMerchantId == 0)
  833. {
  834. pos.BindMerchantId = merchant.Id;
  835. if (IsSend == 1)
  836. {
  837. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  838. {
  839. UserId = pos.BuyUserId, //接收创客
  840. MsgType = 2,
  841. Title = "商户型代理设置成功", //标题
  842. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已经成功给下级代理" + user.RealName + "" + MakerCode + ",设置为商户型代理,设置成功后的新增交易的分润归商户型代理所有",
  843. CreateDate = DateTime.Now,
  844. }));
  845. }
  846. }
  847. user.MerchantType = 1;
  848. merchant.UserId = user.Id;
  849. merchant.MerUserType = 1;
  850. db.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
  851. {
  852. CreateDate = DateTime.Now,
  853. IsRecyc = (ulong)pos.IsPurchase,
  854. CreditAmount = pos.CreditTrade,
  855. PosSnType = pos.PosSnType,
  856. ActDate = pos.ActivationTime,
  857. BindDate = pos.BindingTime,
  858. ActStatus = (ulong)pos.ActivationState,
  859. BindStatus = (ulong)pos.BindingState,
  860. MerNo = MerNo,
  861. PosSn = pos.PosSn,
  862. Note = "后台设置商户型创客",
  863. ToUserId = user.Id,
  864. FromUserId = pos.BuyUserId,
  865. });
  866. db.SaveChanges();
  867. return "success";
  868. }
  869. #endregion
  870. #region 取消商户代理
  871. public IActionResult CancelMerAgent(string right)
  872. {
  873. ViewBag.RightInfo = RightInfo;
  874. ViewBag.right = right;
  875. return View();
  876. }
  877. [HttpPost]
  878. public string CancelMerAgentDo(string MakerCode, string PosSn, int IsSend = 0)
  879. {
  880. if (string.IsNullOrEmpty(MakerCode))
  881. {
  882. return "请输入创客编号";
  883. }
  884. if (string.IsNullOrEmpty(PosSn))
  885. {
  886. return "请输入机具SN";
  887. }
  888. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  889. KqProducts kqProducts = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId);
  890. if (pos == null)
  891. {
  892. return "机具SN不存在";
  893. }
  894. Users user = db.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
  895. if (user == null)
  896. {
  897. return "创客编号不存在";
  898. }
  899. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == PosSn);
  900. pos.UserId = pos.BuyUserId;
  901. merchant.UserId = pos.BuyUserId;
  902. merchant.MerUserType = 0;
  903. user.MerchantType = 0;
  904. db.SaveChanges();
  905. if (pos.BindMerchantId == 0)
  906. {
  907. pos.BindMerchantId = merchant.Id;
  908. if (IsSend == 1)
  909. {
  910. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  911. {
  912. UserId = pos.BuyUserId, //接收创客
  913. MsgType = 2,
  914. Title = "商户型代理取消成功", //标题
  915. Summary = "您的 " + kqProducts.Name + " SN:" + pos.PosSn + "已给下级代理" + user.RealName + "" + MakerCode + "取消成功",
  916. CreateDate = DateTime.Now,
  917. }));
  918. }
  919. }
  920. string text = string.Format("取消商户代理,创客编号: " + user.MakerCode + ",机具SN:" + pos.PosSn + ",操作人:" + SysRealName + ",Time:" + DateTime.Now + "");
  921. function.WriteLog(text, "CancelMerAgent");//取消商户型代理日志
  922. return "success";
  923. }
  924. #endregion
  925. #region 查看SP原始数据日志
  926. public IActionResult SeeSpLog(string right)
  927. {
  928. ViewBag.RightInfo = RightInfo;
  929. ViewBag.right = right;
  930. return View();
  931. }
  932. #endregion
  933. #region 查询机具信息
  934. public IActionResult SeeSnDetail(string right)
  935. {
  936. ViewBag.RightInfo = RightInfo;
  937. ViewBag.right = right;
  938. return View();
  939. }
  940. [HttpPost]
  941. public string SeeSnDetailDo(string PosSn)
  942. {
  943. if (string.IsNullOrEmpty(PosSn))
  944. {
  945. return "请输入机具SN";
  946. }
  947. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  948. if (pos == null)
  949. {
  950. return "机具SN不存在";
  951. }
  952. if (pos.Status == -1)
  953. {
  954. Users posUsers = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  955. decimal Deposits = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  956. if (pos.BrandId != 2 && pos.BrandId != 7)
  957. {
  958. Deposits = Deposits / 100;
  959. }
  960. string DepositGets = "未领取";
  961. string DepositUsers = "";
  962. ActiveReward rewards = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  963. if (rewards.Id > 0)
  964. {
  965. Users user = db.Users.FirstOrDefault(m => m.Id == rewards.UserId) ?? new Users();
  966. DepositGets = "已领取";
  967. DepositUsers = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  968. }
  969. string ActiveTimes = rewards.CreateDate == null ? "" : rewards.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  970. string results = "该机具为故障机" + "\n";
  971. results += "押金返现实际返现对象:" + DepositUsers + "\n";
  972. results += "押金:" + Deposits + "\n";
  973. results += "是否返现:" + DepositGets + ",领取时间:" + ActiveTimes + "\n";
  974. return results;
  975. }
  976. string merInfo = "";
  977. string merName = "";
  978. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  979. if (mer != null)
  980. {
  981. merInfo = mer.KqMerNo;
  982. merName = mer.MerchantName;
  983. }
  984. else
  985. {
  986. merInfo = "未找到商户";
  987. }
  988. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId) ?? new StoreHouse();
  989. Users posUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  990. Users posSubUser = db.Users.FirstOrDefault(m => m.Id == pos.UserId) ?? new Users();
  991. int TopUserId = 0;
  992. if (!string.IsNullOrEmpty(posUser.ParentNav))
  993. {
  994. string[] ParentNavs = posUser.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  995. if (ParentNavs.Length > 1)
  996. {
  997. TopUserId = int.Parse(ParentNavs[1]);
  998. }
  999. if (ParentNavs.Length == 1)
  1000. {
  1001. TopUserId = int.Parse(ParentNavs[0]);
  1002. }
  1003. }
  1004. Users posTopUser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  1005. string bindResult = "", bindTime = "";
  1006. if (pos.BindingState == 0)
  1007. {
  1008. SpModels.BindRecord bind = spdb.BindRecord.FirstOrDefault(m => m.MerSnNo == pos.PosSn);
  1009. if (bind != null)
  1010. {
  1011. if (bind.Status != 1)
  1012. {
  1013. bindResult = "执行中";
  1014. }
  1015. }
  1016. else
  1017. {
  1018. bindResult = "未绑定";
  1019. }
  1020. }
  1021. else
  1022. {
  1023. bindResult = "已绑定";
  1024. bindTime = pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1025. }
  1026. string activeResult = "", activeTime = "";
  1027. if (pos.ActivationState == 0)
  1028. {
  1029. if (pos.CreditTrade < 1000)
  1030. {
  1031. activeResult = "未刷满1000";
  1032. }
  1033. else if (pos.TransferTime == null)
  1034. {
  1035. activeResult = "未激活, 需补录";
  1036. }
  1037. }
  1038. else
  1039. {
  1040. activeResult = "已激活";
  1041. activeTime = pos.ActivationTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1042. }
  1043. string tradeAmount = pos.CreditTrade.ToString();
  1044. decimal Deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  1045. if (pos.BrandId != 2 && pos.BrandId != 7)
  1046. {
  1047. Deposit = Deposit / 100;
  1048. }
  1049. string DepositGet = "未领取";
  1050. string DepositUser = "";
  1051. string DepositToUser = "";
  1052. decimal headAmount = 0;
  1053. decimal footAmount = 0;
  1054. ActiveReward reward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.RewardAmount != 40) ?? new ActiveReward();
  1055. if (reward.Id > 0)
  1056. {
  1057. Users user = db.Users.FirstOrDefault(m => m.Id == reward.UserId) ?? new Users();
  1058. DepositGet = "已领取";
  1059. DepositUser = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1060. var fAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 0);
  1061. if (fAmount != null)
  1062. {
  1063. headAmount = fAmount.RewardAmount;
  1064. }
  1065. var lAmount = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.ActType == 1);
  1066. if (lAmount != null)
  1067. {
  1068. footAmount = lAmount.RewardAmount;
  1069. }
  1070. }
  1071. string DepositGet6 = "未领取";
  1072. string DepositUser6 = "";
  1073. ActiveReward lisreward = db.ActiveReward.FirstOrDefault(m => m.KqSnNo == pos.PosSn && m.BrandId == 6 && m.RewardAmount == 40) ?? new ActiveReward();
  1074. if (lisreward.Id > 0)
  1075. {
  1076. Users user = db.Users.FirstOrDefault(m => m.Id == lisreward.UserId) ?? new Users();
  1077. DepositGet6 = "已领取";
  1078. DepositUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1079. }
  1080. string FluxGet6 = "未领取";
  1081. string FluxUser6 = "";
  1082. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  1083. if (flux.Id > 0)
  1084. {
  1085. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  1086. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  1087. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1088. }
  1089. Users touser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1090. DepositToUser = "创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile;
  1091. string OpenUser10 = "未领取";
  1092. string OpenUser20 = "未领取";
  1093. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  1094. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  1095. if (openreward.Id > 0)
  1096. {
  1097. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1098. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1099. }
  1100. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  1101. if (openreward.Id > 0)
  1102. {
  1103. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  1104. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  1105. }
  1106. MachineApply apply = db.MachineApply.FirstOrDefault(m => m.SwapSnExpand.Contains(pos.PosSn)) ?? new MachineApply();
  1107. Orders applyorder = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  1108. MachineChangeDetail change = db.MachineChangeDetail.FirstOrDefault(m => m.OutSnNo == pos.PosSn) ?? new MachineChangeDetail();
  1109. string RecycFlag = pos.IsPurchase == 1 ? "已申请循环" : "未申请循环";
  1110. string SendStatus = applyorder.SendStatus == 1 ? "已发货" : "未发货";
  1111. string ApplyDate = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1112. string SendDate = applyorder.SendDate == null ? "" : applyorder.SendDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1113. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1114. string TransferTime = pos.TransferTime == null ? "" : pos.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1115. string RecycEndDate = pos.RecycEndDate == null ? "" : pos.RecycEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1116. string ActiveTime = reward.CreateDate == null ? "" : reward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1117. string ActiveTime6 = lisreward.CreateDate == null ? "" : lisreward.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1118. string result = "";
  1119. result += "机具SN:" + pos.PosSn + "\n";
  1120. result += "商户编号:" + merInfo + ",商户姓名:" + merName + "\n";
  1121. result += "商户型机器/直拓机器:创客编号:" + posSubUser.MakerCode + ",姓名:" + posSubUser.RealName + ",手机号:" + posSubUser.Mobile + "\n";
  1122. if (change.Id > 0)
  1123. {
  1124. result += "换机来源机具SN:" + change.BackSnNo + "\n";
  1125. }
  1126. result += "机具所属人:创客编号:" + posUser.MakerCode + ",姓名:" + posUser.RealName + ",手机号:" + posUser.Mobile + "\n";
  1127. result += "机器持有人顶级:创客编号:" + posTopUser.MakerCode + ",姓名:" + posTopUser.RealName + ",手机号:" + posTopUser.Mobile + "\n";
  1128. result += "机器所属仓库:仓库编号:" + store.StoreNo + ",仓库名称:" + store.StoreName + "\n";
  1129. if (pos.PreUserId > 0)
  1130. {
  1131. Users smallStoreUser = db.Users.FirstOrDefault(m => m.Id == pos.PreUserId) ?? new Users();
  1132. PreSendStockDetail preSend = db.PreSendStockDetail.FirstOrDefault(m => m.SnId == pos.Id && m.ToUserId == pos.PreUserId && m.Status == 1) ?? new PreSendStockDetail();
  1133. string preSendDate = preSend.CreateDate == null ? "" : preSend.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  1134. result += "机具所属小分仓:创客编号:" + smallStoreUser.MakerCode + ",姓名:" + smallStoreUser.RealName + ",手机号:" + smallStoreUser.Mobile + ",预发时间:" + preSendDate + "\n";
  1135. }
  1136. else
  1137. {
  1138. result += "机具所属小分仓:暂无小分仓\n";
  1139. }
  1140. result += "入库时间:" + CreateDate + "\n";
  1141. result += "循环到期时间:" + RecycEndDate + "\n";
  1142. result += "划拨时间:" + TransferTime + "\n";
  1143. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  1144. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  1145. result += "贷记卡(总)交易额:" + tradeAmount + "\n";
  1146. result += "是否循环:" + RecycFlag + ",申请循环时间:" + ApplyDate + "\n";
  1147. result += "申请循环后的SN:" + applyorder.SnNos + "\n";
  1148. result += "是否发货:" + SendStatus + ",发货时间:" + SendDate + "\n";
  1149. result += "押金:" + Deposit + "\n";
  1150. result += "是否返现:" + DepositGet + ",领取时间:" + ActiveTime + "\n";
  1151. result += "返现金额:" + headAmount + " " + " " + footAmount + "\n";//TODO: 添加返现金额和额外奖励
  1152. result += "押金返现应返现对象:" + DepositToUser + "\n";
  1153. result += "押金返现实际返现对象:" + DepositUser + "\n";
  1154. if (pos.BrandId == 6)
  1155. {
  1156. result += "立刷10000奖励:" + DepositGet6 + ",领取时间:" + ActiveTime6 + "\n";
  1157. result += "立刷10000奖励发放人:" + DepositUser6 + "\n";
  1158. }
  1159. result += "流量费:" + FluxGet6 + "\n";
  1160. result += "流量费发放对象:" + FluxUser6 + "\n";
  1161. result += "开机奖20:" + OpenUser20 + "\n";
  1162. result += "开机奖10:" + OpenUser10 + "\n";
  1163. return result;
  1164. }
  1165. //解析金控日志
  1166. // public decimal CheckLog(DateTime startDate, string PosSn)
  1167. // {
  1168. // bool op = true;
  1169. // decimal result = 0;
  1170. // DateTime today = DateTime.Now;
  1171. // int i = 0;
  1172. // while (op)
  1173. // {
  1174. // DateTime check = DateTime.Parse(startDate.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(i);
  1175. // if (check <= today)
  1176. // {
  1177. // string source = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/GetLog?date=" + check.Year + "-" + check.Month + "-" + check.Day);
  1178. // MatchCollection mc = Regex.Matches(source, "{.*?2022年飞天系列-小宝电签.*?}"); //激活
  1179. // foreach (Match sub in mc)
  1180. // {
  1181. // string content = sub.Value;
  1182. // JsonData jsonObj = JsonMapper.ToObject(content);
  1183. // decimal serviceAmount = decimal.Parse(jsonObj["serviceAmount"].ToString());
  1184. // string posSnCheck = jsonObj["posSn"].ToString();
  1185. // if (posSnCheck == PosSn && serviceAmount > 0)
  1186. // {
  1187. // result = serviceAmount / 100;
  1188. // op = false;
  1189. // }
  1190. // }
  1191. // }
  1192. // else
  1193. // {
  1194. // op = false;
  1195. // }
  1196. // i += 1;
  1197. // }
  1198. // return result;
  1199. // }
  1200. #endregion
  1201. #region 生成机具兑换码
  1202. public IActionResult MakeCoupons(string right)
  1203. {
  1204. ViewBag.RightInfo = RightInfo;
  1205. ViewBag.right = right;
  1206. return View();
  1207. }
  1208. [HttpPost]
  1209. public string MakeCouponsDo(int Kind, int Number)
  1210. {
  1211. DateTime checkTime = DateTime.Parse("1900-01-01");
  1212. string checkTimeString = RedisDbconn.Instance.Get<string>("MakerCouponsQueueCheckTime");
  1213. if (!string.IsNullOrEmpty(checkTimeString))
  1214. {
  1215. checkTime = DateTime.Parse(checkTimeString);
  1216. }
  1217. if (checkTime.AddHours(1) < DateTime.Now)
  1218. {
  1219. RedisDbconn.Instance.Set("MakerCouponsQueueCheckTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1220. RedisDbconn.Instance.AddList("MakerCouponsQueue:" + Kind, Number);
  1221. return "生成程序已执行";
  1222. }
  1223. return "请稍后再试";
  1224. }
  1225. #endregion
  1226. #region 导出没有刷满1000的机具
  1227. public IActionResult ExportPos(string right)
  1228. {
  1229. ViewBag.RightInfo = RightInfo;
  1230. ViewBag.right = right;
  1231. return View();
  1232. }
  1233. [HttpPost]
  1234. public JsonResult ExportPosDo()
  1235. {
  1236. WebCMSEntities db = new WebCMSEntities();
  1237. List<PosMachinesTwo> poses = db.PosMachinesTwo.Where(m => m.CreditTrade < 1000 && m.BindingState == 1).ToList();
  1238. int total = poses.Count;
  1239. int index = 0;
  1240. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  1241. foreach (PosMachinesTwo pos in poses)
  1242. {
  1243. index += 1;
  1244. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  1245. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  1246. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  1247. Users ppuser = db.Users.FirstOrDefault(m => m.Id == puser.ParentUserId) ?? new Users();
  1248. Dictionary<string, object> item = new Dictionary<string, object>();
  1249. string TopRealName = "";
  1250. string TopMakerCode = "";
  1251. string TopMobile = "";
  1252. string ParentNav = user.ParentNav;
  1253. if (!string.IsNullOrEmpty(ParentNav))
  1254. {
  1255. string[] navlist = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  1256. if (navlist.Length > 1)
  1257. {
  1258. int TopId = int.Parse(function.CheckInt(navlist[1]));
  1259. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopId) ?? new Users();
  1260. TopRealName = tuser.RealName;
  1261. TopMakerCode = tuser.MakerCode;
  1262. TopMobile = tuser.Mobile;
  1263. }
  1264. }
  1265. item.Add("TopRealName", TopRealName); //顶级姓名
  1266. item.Add("TopMakerCode", TopMakerCode); //顶级编号
  1267. item.Add("UpUpRealName", ppuser.RealName); //上上级姓名
  1268. item.Add("UpRealName", puser.RealName); //上级姓名
  1269. item.Add("RealName", user.RealName); //代理姓名
  1270. item.Add("MakerCode", user.MakerCode); //代理编号
  1271. item.Add("Mobile", user.Mobile); //代理手机号
  1272. item.Add("MerchantName", merchant.MerchantName); //客户姓名
  1273. item.Add("MerchantMobile", merchant.MerchantMobile); //客户电话
  1274. item.Add("OpenTime", pos.BindingTime == null ? "" : pos.BindingTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //开机日期
  1275. item.Add("Sn", pos.PosSn); //SN
  1276. list.Add(item);
  1277. RedisDbconn.Instance.Set("ExportPosCheck", index + " / " + total);
  1278. }
  1279. db.Dispose();
  1280. Dictionary<string, object> result = new Dictionary<string, object>();
  1281. result.Add("Status", "1");
  1282. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1283. result.Add("Obj", list);
  1284. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1285. ReturnFields.Add("TopRealName", "顶级姓名"); //顶级姓名
  1286. ReturnFields.Add("TopMakerCode", "顶级编号"); //顶级编号
  1287. ReturnFields.Add("UpUpRealName", "上上级姓名"); //上上级姓名
  1288. ReturnFields.Add("UpRealName", "上级姓名"); //上级姓名
  1289. ReturnFields.Add("RealName", "代理姓名"); //代理姓名
  1290. ReturnFields.Add("MakerCode", "代理编号"); //代理编号
  1291. ReturnFields.Add("Mobile", "代理手机号"); //代理手机号
  1292. ReturnFields.Add("MerchantName", "客户姓名"); //客户姓名
  1293. ReturnFields.Add("MerchantMobile", "客户电话"); //客户电话
  1294. ReturnFields.Add("OpenTime", "开机日期"); //开机日期
  1295. ReturnFields.Add("Sn", "SN"); //SN
  1296. result.Add("Fields", ReturnFields);
  1297. RedisDbconn.Instance.Set("ExportPosCheck", "finish");
  1298. return Json(result);
  1299. }
  1300. public string ExportPosCheck()
  1301. {
  1302. string content = RedisDbconn.Instance.Get<string>("ExportPosCheck");
  1303. if (content == "finish")
  1304. {
  1305. RedisDbconn.Instance.Clear("ExportPosCheck");
  1306. }
  1307. return content;
  1308. }
  1309. #endregion
  1310. #region 更换机具
  1311. public IActionResult ChangePos(string right)
  1312. {
  1313. ViewBag.RightInfo = RightInfo;
  1314. ViewBag.right = right;
  1315. return View();
  1316. }
  1317. [HttpPost]
  1318. public string ChangePosDo(string OldSn, string NewSn, string BackStoreNo, string OutStoreNo, string MerNo = "", int IsSend = 0)
  1319. {
  1320. if (string.IsNullOrEmpty(OldSn))
  1321. {
  1322. return "请输入原机具SN";
  1323. }
  1324. if (string.IsNullOrEmpty(NewSn))
  1325. {
  1326. return "请输入新机具SN";
  1327. }
  1328. string[] OldSnList = OldSn.Split('\n');
  1329. string[] NewSnList = NewSn.Split('\n');
  1330. if (OldSnList.Length != NewSnList.Length)
  1331. {
  1332. return "原机具SN数量和新机具SN数量不一致";
  1333. }
  1334. WebCMSEntities db = new WebCMSEntities();
  1335. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == OldSn);
  1336. StoreForCode storeForBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1337. StoreForCode storeForOut = db.StoreForCode.FirstOrDefault(m => m.Code == OutStoreNo) ?? new StoreForCode();
  1338. StoreHouse BackStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBack.StoreId) ?? new StoreHouse();
  1339. StoreHouse OutStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForOut.StoreId) ?? new StoreHouse();
  1340. string ChangeNo = "BMC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3);
  1341. KqProducts oldPosBrand = new KqProducts();
  1342. KqProducts newPosBrand = new KqProducts();
  1343. MachineChange add = db.MachineChange.Add(new MachineChange()
  1344. {
  1345. CreateDate = DateTime.Now,
  1346. UpdateDate = DateTime.Now,
  1347. CreateMan = SysUserName + "-" + SysRealName,
  1348. ChangeNo = ChangeNo, //转换单号
  1349. UserId = 0, //创客
  1350. ChangeTime = DateTime.Now, //转换时间
  1351. BackStoreId = BackStore.Id, //退回仓库
  1352. BackStoreName = BackStore.StoreName, //退回仓库名称
  1353. Remark = "机具更换", //订单备注
  1354. BackStoreUserId = BackStore.UserId, //退回仓库归属人
  1355. OutProductType = int.Parse(OutStore.BrandId), //出库产品类型
  1356. OutProductName = OutStore.ProductName, //出库产品名称
  1357. OutStoreId = OutStore.Id, //出库仓库
  1358. OutStoreName = OutStore.StoreName, //出库仓库名称
  1359. OutStoreAreas = OutStore.Areas, //出库仓库所在地区
  1360. OutStoreAddress = OutStore.Address, //出库仓库地址
  1361. OutStoreManager = "", //出库仓库联系人
  1362. OutStoreManagerMobile = OutStore.ManageMobile, //出库仓库联系人手机号
  1363. }).Entity;
  1364. db.SaveChanges();
  1365. int BackProductType = 0;
  1366. string BackProductName = "";
  1367. string ChangeDeviceName = "";
  1368. string ChangeSnExpand = "";
  1369. for (int i = 0; i < OldSnList.Length; i++)
  1370. {
  1371. string OldSnNum = OldSnList[i];
  1372. string NewSnNum = NewSnList[i];
  1373. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1374. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1375. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId);
  1376. if (oldpos == null)
  1377. {
  1378. return "原机具SN不正确";
  1379. }
  1380. // if (oldpos.BindingState != 1)
  1381. // {
  1382. // return "原机具未绑定";
  1383. // }
  1384. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId);
  1385. if (newpos == null)
  1386. {
  1387. return "新机具SN不正确";
  1388. }
  1389. oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1390. newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1391. PosMerchantInfo merchant = new PosMerchantInfo();
  1392. if (!string.IsNullOrEmpty(MerNo))
  1393. {
  1394. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerNo) ?? new PosMerchantInfo();
  1395. }
  1396. else
  1397. {
  1398. merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == oldpos.BindMerchantId) ?? new PosMerchantInfo();
  1399. }
  1400. newpos.BindMerchantId = merchant.Id;
  1401. newpos.BuyUserId = oldpos.BuyUserId;
  1402. newpos.UserId = oldpos.UserId;
  1403. newpos.RecycEndDate = oldpos.RecycEndDate;
  1404. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1405. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1406. newpos.CreditTrade = oldpos.CreditTrade;
  1407. newpos.PosSnType = oldpos.PosSnType;
  1408. newpos.TransferTime = oldpos.TransferTime;
  1409. newpos.IsPurchase = oldpos.IsPurchase;
  1410. newpos.BindingState = oldpos.BindingState;
  1411. newpos.ActivationState = oldpos.ActivationState;
  1412. newpos.BindingTime = oldpos.BindingTime;
  1413. newpos.ActivationTime = oldpos.ActivationTime;
  1414. newpos.IsFirst = oldpos.IsFirst;
  1415. // bool checkActReward = db.ActiveReward.Any(m => m.KqMerNo == merchant.KqMerNo);
  1416. // if (!checkActReward)
  1417. // {
  1418. newpos.SeoKeyword = oldpos.SeoKeyword;
  1419. newpos.PrizeParams = oldpos.PrizeParams;
  1420. newpos.LeaderUserId = oldpos.LeaderUserId;
  1421. // }
  1422. // oldpos.BuyUserId = 0;
  1423. // oldpos.UserId = 0;
  1424. oldpos.Status = -1;
  1425. //对应调整客小爽企业版数据
  1426. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == oldpos.Id);
  1427. if (posInfo != null)
  1428. {
  1429. posInfo.PosSn = newpos.PosSn;
  1430. posInfo.PosId = newpos.Id;
  1431. db.SaveChanges();
  1432. }
  1433. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == merchant.KqMerNo);
  1434. if (forMerNo != null)
  1435. {
  1436. forMerNo.SnId = newpos.Id;
  1437. }
  1438. merchant.KqSnNo = NewSn;
  1439. db.MachineChangeDetail.Add(new MachineChangeDetail()
  1440. {
  1441. CreateDate = DateTime.Now,
  1442. UpdateDate = DateTime.Now,
  1443. CreateMan = SysUserName + "-" + SysRealName,
  1444. ChangeNo = ChangeNo, //订单号
  1445. ChangeId = add.Id, //订单Id
  1446. BackProductType = oldpos.BrandId, //退回产品类型
  1447. BackProductName = oldPosBrand.Name, //退回产品名称
  1448. UserId = 0, //创客
  1449. BackSnNo = oldpos.PosSn, //设备SN编号
  1450. OutProductType = newpos.BrandId, //出库产品类型
  1451. OutProductName = newPosBrand.Name, //出库产品名称
  1452. OutSnNo = newpos.PosSn, //出库设备SN编号
  1453. OutSnType = newpos.PosSnType, //出库SN机具类型
  1454. Remark = "机具更换", //备注
  1455. BackSnType = oldpos.PosSnType, //退回SN机具类型
  1456. });
  1457. db.SaveChanges();
  1458. BackProductType = oldpos.BrandId;
  1459. BackProductName = newPosBrand.Name;
  1460. ChangeDeviceName = oldpos.DeviceName;
  1461. ChangeSnExpand += oldpos.PosSn + "\n";
  1462. PublicFunction.SycnMachineCount(oldpos.BuyUserId, oldpos.BrandId);
  1463. }
  1464. add.BackProductType = BackProductType; //退回产品类型
  1465. add.BackProductName = BackProductName; //退回产品名称
  1466. add.ChangeDeviceName = ChangeDeviceName; //转换机具名称
  1467. add.ChangeDeviceNum = OldSnList.Length; //转换机具数量
  1468. add.ChangeSnExpand = ChangeSnExpand; //机具SN
  1469. BackStore.LaveNum += OldSnList.Length; //退回仓库库存
  1470. OutStore.LaveNum -= OldSnList.Length; //出货仓库库存
  1471. db.SaveChanges();
  1472. db.Dispose();
  1473. if (IsSend == 1)
  1474. {
  1475. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1476. {
  1477. UserId = pos.BuyUserId, //接收创客
  1478. MsgType = 2,
  1479. Title = "换绑成功通知", //标题
  1480. Summary = "您的 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为客户换绑为" + newPosBrand.Name + "SN:" + NewSn + "请告知客户进行绑定。",
  1481. CreateDate = DateTime.Now,
  1482. }));
  1483. }
  1484. return "success";
  1485. }
  1486. #endregion
  1487. #region 坏机换新
  1488. public IActionResult ChangeBadPos(string right)
  1489. {
  1490. ViewBag.RightInfo = RightInfo;
  1491. ViewBag.right = right;
  1492. return View();
  1493. }
  1494. [HttpPost]
  1495. public string ChangeBadPosDo(string ChangeType, string MakerCode, string StoreCode, string OldSn, string NewSn, string FromStoreNo, string BackStoreNo, int IsSend = 0)
  1496. {
  1497. string[] OldSnList;
  1498. string[] NewSnList;
  1499. decimal amount = 0;
  1500. //创客坏机换新
  1501. if (ChangeType == "0")
  1502. {
  1503. if (string.IsNullOrEmpty(MakerCode))
  1504. {
  1505. return "请输入创客编号";
  1506. }
  1507. if (string.IsNullOrEmpty(OldSn))
  1508. {
  1509. return "请输入坏机SN";
  1510. }
  1511. if (string.IsNullOrEmpty(NewSn))
  1512. {
  1513. return "请输入新机SN";
  1514. }
  1515. if (string.IsNullOrEmpty(FromStoreNo))
  1516. {
  1517. return "请输入新机发货仓库编号";
  1518. }
  1519. if (string.IsNullOrEmpty(BackStoreNo))
  1520. {
  1521. return "请输入坏机退回仓库编号";
  1522. }
  1523. OldSnList = OldSn.Split('\n');
  1524. NewSnList = NewSn.Split('\n');
  1525. if (OldSnList.Length != NewSnList.Length)
  1526. {
  1527. return "原机具SN数量和新机具SN数量不一致";
  1528. }
  1529. for (int i = 0; i < OldSnList.Length; i++)
  1530. {
  1531. string OldSnNum = OldSnList[i];
  1532. string NewSnNum = NewSnList[i];
  1533. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
  1534. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1535. if (storeForCodeFrom.StoreId == 0)
  1536. {
  1537. return "您输入的新机发货仓库编号不存在";
  1538. }
  1539. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1540. if (storeForCodeBack.StoreId == 0)
  1541. {
  1542. return "您输入的坏机退回仓库编号不存在";
  1543. }
  1544. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1545. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1546. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  1547. if (oldpos.Id == 0)
  1548. {
  1549. return "您输入的坏机SN不存在或者不在" + MakerCode + "名下";
  1550. }
  1551. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0) ?? new PosMachinesTwo();
  1552. if (newpos.Id == 0)
  1553. {
  1554. return "您输入的新机SN不存在";
  1555. }
  1556. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1557. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1558. {
  1559. return "您输入的新机发货仓库不符新机机具对应品牌";
  1560. }
  1561. if (newpos.StoreId != storeFrom.Id)
  1562. {
  1563. return "您输入的新机SN不在新机发货仓库";
  1564. }
  1565. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1566. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1567. {
  1568. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1569. }
  1570. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1571. if (brandInfo.Name.Contains("大POS"))
  1572. {
  1573. amount = 300;
  1574. }
  1575. if (brandInfo.Name.Contains("电签"))
  1576. {
  1577. amount = 200;
  1578. }
  1579. // var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1580. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1581. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1582. // storeUserAcount.ValidAmount += amount;
  1583. storeFromUserAcount.ValidAmount += amount;
  1584. storeBackUserAcount.ValidAmount -= amount;
  1585. newpos.BuyUserId = oldpos.BuyUserId;
  1586. newpos.UserId = oldpos.UserId;
  1587. newpos.RecycEndDate = oldpos.RecycEndDate;
  1588. newpos.ScanQrTrade = oldpos.ScanQrTrade;
  1589. newpos.DebitCardTrade = oldpos.DebitCardTrade;
  1590. newpos.CreditTrade = oldpos.CreditTrade;
  1591. newpos.PosSnType = oldpos.PosSnType;
  1592. newpos.TransferTime = oldpos.TransferTime;
  1593. newpos.IsPurchase = oldpos.IsPurchase;
  1594. newpos.BindingState = oldpos.BindingState;
  1595. newpos.ActivationState = oldpos.ActivationState;
  1596. newpos.BindingTime = oldpos.BindingTime;
  1597. newpos.ActivationTime = oldpos.ActivationTime;
  1598. newpos.IsFirst = oldpos.IsFirst;
  1599. newpos.SeoKeyword = oldpos.SeoKeyword;
  1600. newpos.PrizeParams = oldpos.PrizeParams;
  1601. newpos.LeaderUserId = oldpos.LeaderUserId;
  1602. newpos.BindMerchantId = oldpos.BindMerchantId;
  1603. newpos.StoreId = oldpos.StoreId;
  1604. newpos.UserId = oldpos.UserId;
  1605. newpos.PreUserId = oldpos.PreUserId;
  1606. oldpos.StoreId = storeBack.Id;
  1607. oldpos.BuyUserId = 0;
  1608. oldpos.UserId = 0;
  1609. oldpos.Status = -1;
  1610. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == newpos.BindMerchantId);
  1611. if(merchant != null)
  1612. {
  1613. merchant.KqSnNo = newpos.PosSn;
  1614. merchant.ActiveStatus = newpos.ActivationState;
  1615. }
  1616. db.SaveChanges();
  1617. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1618. {
  1619. CreateDate = DateTime.Now,
  1620. CreateMan = SysUserName + "-" + SysRealName,
  1621. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1622. OutStoreId = storeFrom.Id,
  1623. BackStoreId = storeBack.Id,
  1624. OutProductType = newpos.BrandId,
  1625. BackProductType = oldpos.BrandId,
  1626. UserId = userForMakerCode.UserId, //创客
  1627. }).Entity;
  1628. db.SaveChanges();
  1629. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1630. {
  1631. CreateDate = DateTime.Now,
  1632. CreateMan = SysUserName + "-" + SysRealName,
  1633. OutSnNo = OldSnNum,
  1634. BackSnNo = NewSnNum,
  1635. ChangeNo = add.ChangeNo, //转换单号
  1636. ChangeId = add.Id, //转换记录Id
  1637. UserId = add.UserId, //创客
  1638. }).Entity;
  1639. db.SaveChanges();
  1640. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1641. if (IsSend == 1)
  1642. {
  1643. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1644. {
  1645. UserId = userForMakerCode.UserId, //接收创客
  1646. MsgType = 2,
  1647. Title = "坏机换新成功通知", //标题
  1648. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1649. CreateDate = DateTime.Now,
  1650. }));
  1651. }
  1652. }
  1653. }
  1654. //仓库坏机换新
  1655. else
  1656. {
  1657. if (string.IsNullOrEmpty(StoreCode))
  1658. {
  1659. return "请输入仓库编号";
  1660. }
  1661. if (string.IsNullOrEmpty(OldSn))
  1662. {
  1663. return "请输入坏机SN";
  1664. }
  1665. if (string.IsNullOrEmpty(NewSn))
  1666. {
  1667. return "请输入新机SN";
  1668. }
  1669. if (string.IsNullOrEmpty(FromStoreNo))
  1670. {
  1671. return "请输入新机发货仓库编号";
  1672. }
  1673. if (string.IsNullOrEmpty(BackStoreNo))
  1674. {
  1675. return "请输入坏机退回仓库编号";
  1676. }
  1677. OldSnList = OldSn.Split('\n');
  1678. NewSnList = NewSn.Split('\n');
  1679. if (OldSnList.Length != NewSnList.Length)
  1680. {
  1681. return "原机具SN数量和新机具SN数量不一致";
  1682. }
  1683. for (int i = 0; i < OldSnList.Length; i++)
  1684. {
  1685. string OldSnNum = OldSnList[i];
  1686. string NewSnNum = NewSnList[i];
  1687. StoreHouse store = new StoreHouse();
  1688. StoreForCode storeForBadCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreCode) ?? new StoreForCode();
  1689. if (storeForBadCode.StoreId > 0)
  1690. {
  1691. store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForBadCode.StoreId);
  1692. }
  1693. StoreForCode storeForCodeFrom = db.StoreForCode.FirstOrDefault(m => m.Code == FromStoreNo) ?? new StoreForCode();
  1694. if (storeForCodeFrom.StoreId == 0)
  1695. {
  1696. return "您输入的新机发货仓库编号不存在";
  1697. }
  1698. StoreForCode storeForCodeBack = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1699. if (storeForCodeBack.StoreId == 0)
  1700. {
  1701. return "您输入的坏机退回仓库编号不存在";
  1702. }
  1703. MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1704. MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1705. PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0 && m.StoreId == storeForBadCode.StoreId) ?? new PosMachinesTwo();
  1706. if (oldpos.Id == 0)
  1707. {
  1708. return "您输入的坏机SN不存在或者不在仓库" + StoreCode + "中";
  1709. }
  1710. PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BindingState == 0) ?? new PosMachinesTwo();
  1711. if (newpos.Id == 0)
  1712. {
  1713. return "您输入的新机SN不存在";
  1714. }
  1715. StoreHouse storeFrom = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeFrom.StoreId);
  1716. if (Convert.ToInt32(storeFrom.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1717. {
  1718. return "您输入的新机发货仓库不符新机机具对应品牌";
  1719. }
  1720. if (newpos.StoreId != storeFrom.Id)
  1721. {
  1722. return "您输入的新机SN不在新机发货仓库";
  1723. }
  1724. StoreHouse storeBack = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCodeBack.StoreId);
  1725. if (Convert.ToInt32(storeBack.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1726. {
  1727. return "您输入的坏机退回仓库不符坏机机具对应品牌";
  1728. }
  1729. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1730. if (brandInfo.Name.Contains("大POS"))
  1731. {
  1732. amount = 300;
  1733. }
  1734. if (brandInfo.Name.Contains("电签"))
  1735. {
  1736. amount = 200;
  1737. }
  1738. var storeUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == store.UserId) ?? new UserAccount();
  1739. var storeFromUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeFrom.UserId) ?? new UserAccount();
  1740. var storeBackUserAcount = db.UserAccount.FirstOrDefault(m => m.Id == storeBack.UserId) ?? new UserAccount();
  1741. // storeUserAcount.ValidAmount += amount;
  1742. storeFromUserAcount.ValidAmount += amount;
  1743. storeBackUserAcount.ValidAmount -= amount;
  1744. newpos.StoreId = oldpos.StoreId;
  1745. newpos.BuyUserId = oldpos.BuyUserId;
  1746. newpos.UserId = oldpos.UserId;
  1747. newpos.LeaderUserId = oldpos.LeaderUserId;
  1748. newpos.PreUserId = oldpos.PreUserId;
  1749. newpos.IsFirst = oldpos.IsFirst;
  1750. newpos.TransferTime = oldpos.TransferTime;
  1751. oldpos.StoreId = storeBack.Id;
  1752. oldpos.BuyUserId = 0;
  1753. oldpos.UserId = 0;
  1754. db.SaveChanges();
  1755. BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1756. {
  1757. CreateDate = DateTime.Now,
  1758. CreateMan = SysUserName + "-" + SysRealName,
  1759. ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1760. OutStoreId = storeFrom.Id,
  1761. BackStoreId = storeBack.Id,
  1762. OutProductType = newpos.BrandId,
  1763. BackProductType = oldpos.BrandId,
  1764. UserId = store.UserId, //创客
  1765. }).Entity;
  1766. db.SaveChanges();
  1767. BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1768. {
  1769. CreateDate = DateTime.Now,
  1770. CreateMan = SysUserName + "-" + SysRealName,
  1771. OutSnNo = OldSnNum,
  1772. BackSnNo = NewSnNum,
  1773. ChangeNo = add.ChangeNo, //转换单号
  1774. ChangeId = add.Id, //转换记录Id
  1775. UserId = add.UserId, //创客
  1776. }).Entity;
  1777. db.SaveChanges();
  1778. var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1779. if (IsSend == 1)
  1780. {
  1781. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1782. {
  1783. UserId = store.UserId, //接收创客
  1784. MsgType = 2,
  1785. Title = "坏机换新成功通知", //标题
  1786. Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSnNum + "已经成功为您换为" + oldPosBrand.Name + "SN:" + NewSnNum + "。",
  1787. CreateDate = DateTime.Now,
  1788. }));
  1789. }
  1790. }
  1791. }
  1792. // for (int i = 0; i < OldSnList.Length; i++)
  1793. // {
  1794. // string OldSnNum = OldSnList[i];
  1795. // string NewSnNum = NewSnList[i];
  1796. // StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == BackStoreNo) ?? new StoreForCode();
  1797. // MachineForSnNo oldForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == OldSnNum) ?? new MachineForSnNo();
  1798. // MachineForSnNo newForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == NewSnNum) ?? new MachineForSnNo();
  1799. // StoreHouse oldStore = new StoreHouse();
  1800. // PosMachinesTwo oldpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == oldForSnNo.SnId && m.BindingState == 0);
  1801. // if (storeForCode.StoreId > 0)
  1802. // {
  1803. // StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId);
  1804. // if (Convert.ToInt32(store.BrandId) != Convert.ToInt32(oldpos.BrandId))
  1805. // {
  1806. // return "您输入的仓库不符机具对应品牌";
  1807. // }
  1808. // oldStore = db.StoreHouse.FirstOrDefault(m => m.Id == oldpos.StoreId);
  1809. // oldpos.Status = -1;
  1810. // oldpos.StoreId = store.Id;
  1811. // }
  1812. // if (oldpos == null)
  1813. // {
  1814. // return "原机具SN不正确或者不符合换机条件";
  1815. // }
  1816. // PosMachinesTwo newpos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == newForSnNo.SnId && m.BuyUserId == 0 && m.UserId == 0 && m.BindingState == 0);
  1817. // if (newpos == null)
  1818. // {
  1819. // return "新机具SN不正确或者不为仓库机";
  1820. // }
  1821. // if (oldpos.BrandId != newpos.BrandId)
  1822. // {
  1823. // return "新机具和旧机具品牌不相同";
  1824. // }
  1825. // var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1826. // if (brandInfo.Name.Contains("大POS"))
  1827. // {
  1828. // amount = 300;
  1829. // }
  1830. // if (brandInfo.Name.Contains("电签"))
  1831. // {
  1832. // amount = 200;
  1833. // }
  1834. // var storehouse = db.StoreHouse.FirstOrDefault(m => m.Id == newpos.StoreId) ?? new StoreHouse();
  1835. // storehouse.LaveNum -= 1;
  1836. // var userAcount = db.UserAccount.FirstOrDefault(m => m.Id == storehouse.UserId) ?? new UserAccount();
  1837. // if (oldpos.StoreId != newpos.StoreId)
  1838. // {
  1839. // userAcount.ValidAmount += amount;
  1840. // newpos.StoreId = oldpos.StoreId;
  1841. // newpos.BuyUserId = oldpos.BuyUserId;
  1842. // newpos.UserId = oldpos.UserId;
  1843. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1844. // newpos.PreUserId = oldpos.PreUserId;
  1845. // newpos.IsFirst = oldpos.IsFirst;
  1846. // newpos.TransferTime = oldpos.TransferTime;
  1847. // }
  1848. // else
  1849. // {
  1850. // newpos.BuyUserId = oldpos.BuyUserId;
  1851. // newpos.UserId = oldpos.UserId;
  1852. // newpos.LeaderUserId = oldpos.LeaderUserId;
  1853. // newpos.PreUserId = oldpos.PreUserId;
  1854. // newpos.IsFirst = oldpos.IsFirst;
  1855. // newpos.TransferTime = oldpos.TransferTime;
  1856. // }
  1857. // db.SaveChanges();
  1858. // var oldPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == oldpos.BrandId) ?? new KqProducts();
  1859. // var newPosBrand = db.KqProducts.FirstOrDefault(m => m.Id == newpos.BrandId) ?? new KqProducts();
  1860. // var UserId = 0;
  1861. // if (oldpos.BuyUserId == 0)
  1862. // {
  1863. // UserId = oldStore.UserId;
  1864. // }
  1865. // else
  1866. // {
  1867. // UserId = oldpos.BuyUserId;
  1868. // }
  1869. // BrokenMachineChange add = db.BrokenMachineChange.Add(new BrokenMachineChange()
  1870. // {
  1871. // CreateDate = DateTime.Now,
  1872. // CreateMan = SysUserName + "-" + SysRealName,
  1873. // ChangeNo = "BPC" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(3), //转换单号
  1874. // UserId = UserId, //创客
  1875. // }).Entity;
  1876. // db.SaveChanges();
  1877. // BrokenMachineChangeDetail adds = db.BrokenMachineChangeDetail.Add(new BrokenMachineChangeDetail()
  1878. // {
  1879. // CreateDate = DateTime.Now,
  1880. // CreateMan = SysUserName + "-" + SysRealName,
  1881. // OutSnNo = OldSnNum,
  1882. // BackSnNo = NewSnNum,
  1883. // ChangeNo = add.ChangeNo, //转换单号
  1884. // ChangeId = add.Id, //转换记录Id
  1885. // UserId = add.UserId, //创客
  1886. // }).Entity;
  1887. // db.SaveChanges();
  1888. // if (IsSend == 1)
  1889. // {
  1890. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  1891. // {
  1892. // UserId = UserId, //接收创客
  1893. // MsgType = 2,
  1894. // Title = "坏机换新成功通知", //标题
  1895. // Summary = "您的坏机 " + oldPosBrand.Name + " SN:" + OldSn + "已经成功为您换为" + newPosBrand.Name + "SN:" + NewSn + "。",
  1896. // CreateDate = DateTime.Now,
  1897. // }));
  1898. // }
  1899. // }
  1900. return "success";
  1901. }
  1902. #endregion
  1903. #region 机具解绑
  1904. public IActionResult Unbind(string right)
  1905. {
  1906. ViewBag.RightInfo = RightInfo;
  1907. ViewBag.right = right;
  1908. return View();
  1909. }
  1910. [HttpPost]
  1911. public string UnbindDo(string PosSn, string MakerCode, string MerNo, int IsSend = 0)
  1912. {
  1913. if (string.IsNullOrEmpty(PosSn))
  1914. {
  1915. return "请输入机具SN";
  1916. }
  1917. if (string.IsNullOrEmpty(MakerCode))
  1918. {
  1919. return "请输入创客编号";
  1920. }
  1921. MachineForSnNo forSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn);
  1922. if (forSnNo == null)
  1923. {
  1924. return "机具SN不存在";
  1925. }
  1926. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == forSnNo.SnId);
  1927. if (pos == null)
  1928. {
  1929. return "机具SN不存在";
  1930. }
  1931. if (string.IsNullOrEmpty(MerNo) && pos.BrandId != 1 && pos.BrandId != 3)
  1932. {
  1933. return "请输入商户编号";
  1934. }
  1935. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  1936. if (forMakerCode == null)
  1937. {
  1938. return "创客不存在";
  1939. }
  1940. MachineForMerNo forMerNo = db.MachineForMerNo.FirstOrDefault(m => m.MerNo == MerNo);
  1941. if (forMerNo == null && pos.BrandId != 1 && pos.BrandId != 3)
  1942. {
  1943. return "商户编号不存在";
  1944. }
  1945. if (pos.BuyUserId != forMakerCode.UserId)
  1946. {
  1947. return "机具SN和创客不匹配";
  1948. }
  1949. if (pos.ActivationState == 1)
  1950. {
  1951. return "机具已激活,不能解绑";
  1952. }
  1953. if (pos.BuyUserId == 0)
  1954. {
  1955. return "机具是仓库机,不支持解绑";
  1956. }
  1957. if (pos.BindingState == 0)
  1958. {
  1959. return "机具未绑定,不支持解绑";
  1960. }
  1961. if (pos.BindingTime < DateTime.Now.AddDays(-30) && SysUserName != "admin")
  1962. {
  1963. return "机具绑定已超过30天,不支持解绑";
  1964. }
  1965. if (forMerNo != null)
  1966. {
  1967. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  1968. if (merchant != null)
  1969. {
  1970. //机具解绑删除客小爽企业版对应数据
  1971. var merInfo = db.BusinessPartnerMerchant.FirstOrDefault(m => m.MerchantId == merchant.Id);
  1972. if (merInfo != null)
  1973. {
  1974. db.BusinessPartnerMerchant.Remove(merInfo);
  1975. }
  1976. var posInfo = db.BusinessPartnerPos.FirstOrDefault(m => m.PosId == pos.Id);
  1977. if (posInfo != null)
  1978. {
  1979. db.BusinessPartnerPos.Remove(posInfo);
  1980. }
  1981. db.PosMerchantInfo.Remove(merchant);
  1982. }
  1983. db.MachineForMerNo.Remove(forMerNo);
  1984. db.SaveChanges();
  1985. }
  1986. db.MachineUnBind.Add(new MachineUnBind()
  1987. {
  1988. CreateDate = DateTime.Now,
  1989. SeoTitle = SysUserName + "-" + SysRealName,
  1990. MerchantId = pos.BindMerchantId,
  1991. AuditDate = DateTime.Now,
  1992. AuditDesc = "平台操作解绑",
  1993. AuditStatus = 1,
  1994. SnNo = pos.PosSn,
  1995. BrandId = pos.BrandId,
  1996. UserId = pos.BuyUserId,
  1997. ApplyNo = "U" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8),
  1998. });
  1999. pos.BindMerchantId = 0;
  2000. pos.BindingState = 0;
  2001. pos.BindingTime = DateTime.Parse("1900-01-01");
  2002. pos.UserId = pos.BuyUserId;
  2003. string IdBrand = pos.BuyUserId + "_" + pos.BrandId;
  2004. db.SaveChanges();
  2005. PublicFunction.SycnMachineCount(pos.BuyUserId, pos.BrandId);
  2006. if (IsSend == 1)
  2007. {
  2008. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  2009. {
  2010. UserId = pos.BuyUserId, //接收创客
  2011. MsgType = 2,
  2012. Title = "解绑成功通知", //标题
  2013. Summary = "" + PosSn + "机具已成功解绑,当前机具如需绑定同一客户请再2个工作日后再进行绑定,直接绑定会导致数控异常,相关损失由您本人承担。",
  2014. CreateDate = DateTime.Now,
  2015. }));
  2016. }
  2017. return "success";
  2018. }
  2019. #endregion
  2020. #region 通过券码修改盟主标记
  2021. public IActionResult ChangeSignQuan(string right)
  2022. {
  2023. ViewBag.RightInfo = RightInfo;
  2024. ViewBag.right = right;
  2025. return View();
  2026. }
  2027. [HttpPost]
  2028. public string ChangeSignQuanDo(string Coupons, string MakerCode)
  2029. {
  2030. if (string.IsNullOrEmpty(Coupons))
  2031. {
  2032. return "请输入机具券码,多个券码用回车分隔";
  2033. }
  2034. if (string.IsNullOrEmpty(MakerCode))
  2035. {
  2036. return "请输入创客编号";
  2037. }
  2038. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2039. if (forMakerCode == null)
  2040. {
  2041. return "创客不存在";
  2042. }
  2043. string[] SnList = Coupons.Split('\n');
  2044. foreach (var item in SnList)
  2045. {
  2046. var coupos = db.PosCoupons.FirstOrDefault(m => m.ExchangeCode == item && m.LeaderUserId == 0);
  2047. if (coupos == null)
  2048. {
  2049. return "机具券不存在";
  2050. }
  2051. else
  2052. {
  2053. coupos.LeaderUserId = forMakerCode.UserId;
  2054. }
  2055. }
  2056. db.SaveChanges();
  2057. return "success";
  2058. }
  2059. #endregion
  2060. #region 通过机具SN修改盟主标记
  2061. public IActionResult ChangeSignSn(string right)
  2062. {
  2063. ViewBag.RightInfo = RightInfo;
  2064. ViewBag.right = right;
  2065. return View();
  2066. }
  2067. [HttpPost]
  2068. public string ChangeSignSnDo(string PosSn, string MakerCode)
  2069. {
  2070. if (string.IsNullOrEmpty(PosSn))
  2071. {
  2072. return "请输入机具SN,多个SN用回车分隔";
  2073. }
  2074. if (string.IsNullOrEmpty(MakerCode))
  2075. {
  2076. return "请输入创客编号";
  2077. }
  2078. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2079. if (forMakerCode == null)
  2080. {
  2081. return "创客不存在";
  2082. }
  2083. string[] SnList = PosSn.Split('\n');
  2084. foreach (var item in SnList)
  2085. {
  2086. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item && m.LeaderUserId == 0);
  2087. if (pos == null)
  2088. {
  2089. return "该机具不存在";
  2090. }
  2091. else
  2092. {
  2093. pos.LeaderUserId = forMakerCode.UserId;
  2094. }
  2095. }
  2096. db.SaveChanges();
  2097. return "success";
  2098. }
  2099. #endregion
  2100. #region 机具循环列表
  2101. /// <summary>
  2102. /// 根据条件查询机具循环列表
  2103. /// </summary>
  2104. /// <returns></returns>
  2105. public IActionResult Loop(string right, string SwapSnExpand, string SnNos)
  2106. {
  2107. ViewBag.RightInfo = RightInfo;
  2108. ViewBag.right = right;
  2109. ViewBag.SwapSnExpand = SwapSnExpand;
  2110. ViewBag.SnNos = SnNos;
  2111. return View();
  2112. }
  2113. #endregion
  2114. #region 根据条件查询机具循环列表
  2115. /// <summary>
  2116. /// 机具循环列表
  2117. /// </summary>
  2118. /// <returns></returns>
  2119. public IActionResult LoopData(string SwapSnExpand, string SnNos, int page = 1, int limit = 30)
  2120. {
  2121. Dictionary<string, string> Fields = new Dictionary<string, string>();
  2122. Fields.Add("SwapSnExpand", "1"); //申请机具SN
  2123. Fields.Add("SnNos", "1"); //发货机具SN
  2124. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  2125. if (!string.IsNullOrEmpty(SwapSnExpand))
  2126. {
  2127. var apply = db.MachineApply.FirstOrDefault(m => m.Status > -1 && m.SwapSnExpand.Contains(SwapSnExpand)) ?? new MachineApply();
  2128. var order = db.Orders.FirstOrDefault(m => m.Id == apply.QueryCount) ?? new Orders();
  2129. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2130. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2131. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2132. for (int i = 0; i < SnNoList.Length; i++)
  2133. {
  2134. Dictionary<string, object> data = new Dictionary<string, object>();
  2135. data["ApplyNo"] = apply.ApplyNo;
  2136. data["OrderNo"] = order.OrderNo;
  2137. data["MakerCode"] = user.MakerCode;
  2138. data["RealName"] = user.RealName;
  2139. if (SnNoList.Length > i)
  2140. {
  2141. string SourceSn = SnNoList[i].Split(':')[0];
  2142. data["ComeSn"] = SnNoList[i];
  2143. data["ComeSnParam"] = SourceSn;
  2144. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2145. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2146. if (pos.LeaderUserId > 0)
  2147. {
  2148. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2149. data["ComeSnMakerCode"] = leader.MakerCode;
  2150. data["ComeSnRealName"] = leader.RealName;
  2151. }
  2152. }
  2153. if (OrderSnNo.Length > i)
  2154. {
  2155. string SendSn = OrderSnNo[i];
  2156. data["SendSn"] = OrderSnNo[i];
  2157. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? 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["SendSnMakerCode"] = leader.MakerCode;
  2163. data["SendSnRealName"] = leader.RealName;
  2164. }
  2165. }
  2166. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2167. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2168. dataList.Add(data);
  2169. }
  2170. }
  2171. else if (!string.IsNullOrEmpty(SnNos))
  2172. {
  2173. var order = db.Orders.FirstOrDefault(m => m.Status > -1 && m.SnNos.Contains(SnNos)) ?? new Orders();
  2174. var apply = db.MachineApply.FirstOrDefault(m => m.Id == order.Sort) ?? new MachineApply();
  2175. var user = db.Users.FirstOrDefault(m => m.Id == apply.UserId) ?? new Users();
  2176. string[] SnNoList = function.CheckNull(apply.SwapSnExpand).TrimEnd('\n').Split('\n');
  2177. string[] OrderSnNo = function.CheckNull(order.SnNos).Split(',');
  2178. for (int i = 0; i < OrderSnNo.Length; i++)
  2179. {
  2180. Dictionary<string, object> data = new Dictionary<string, object>();
  2181. data["ApplyNo"] = apply.ApplyNo;
  2182. data["OrderNo"] = order.OrderNo;
  2183. data["MakerCode"] = user.MakerCode;
  2184. data["RealName"] = user.RealName;
  2185. if (SnNoList.Length > i)
  2186. {
  2187. string SourceSn = SnNoList[i].Split(':')[0];
  2188. data["ComeSn"] = SnNoList[i];
  2189. data["ComeSnParam"] = SourceSn;
  2190. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SourceSn) ?? new MachineForSnNo();
  2191. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineFor.SnId) ?? new PosMachinesTwo();
  2192. if (pos.LeaderUserId > 0)
  2193. {
  2194. Users leader = db.Users.FirstOrDefault(m => m.Id == pos.LeaderUserId) ?? new Users();
  2195. data["ComeSnMakerCode"] = leader.MakerCode;
  2196. data["ComeSnRealName"] = leader.RealName;
  2197. }
  2198. }
  2199. if (OrderSnNo.Length > i)
  2200. {
  2201. string SendSn = OrderSnNo[i];
  2202. data["SendSn"] = OrderSnNo[i];
  2203. MachineForSnNo machineFor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SendSn) ?? 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["SendSnMakerCode"] = leader.MakerCode;
  2209. data["SendSnRealName"] = leader.RealName;
  2210. }
  2211. }
  2212. data["CreateDate"] = apply.CreateDate == null ? "" : apply.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  2213. data["Status"] = order.Status == 2 ? "已发货" : "未发货";
  2214. dataList.Add(data);
  2215. }
  2216. }
  2217. Dictionary<string, object> obj = new Dictionary<string, object>();
  2218. obj.Add("code", 0);
  2219. obj.Add("msg", "");
  2220. obj.Add("count", dataList.Count);
  2221. obj.Add("data", dataList);
  2222. return Json(obj);
  2223. }
  2224. #endregion
  2225. #region 查询创客直推奖
  2226. public IActionResult Prize100(string right)
  2227. {
  2228. ViewBag.RightInfo = RightInfo;
  2229. ViewBag.right = right;
  2230. return View();
  2231. }
  2232. [HttpPost]
  2233. public Dictionary<string, string> Prize100Do(string MakerCode)
  2234. {
  2235. Dictionary<string, string> dic = new Dictionary<string, string>();
  2236. string result = "";
  2237. UserForMakerCode forMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  2238. if (forMakerCode == null)
  2239. {
  2240. result += "创客编号不存在\n";
  2241. dic.Add("code", "1");
  2242. dic.Add("result", result);
  2243. return dic;
  2244. }
  2245. int OrderCount = db.Orders.Count(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600);
  2246. if (OrderCount == 0)
  2247. {
  2248. result += "该创客未下单\n";
  2249. dic.Add("code", "1");
  2250. dic.Add("result", result);
  2251. return dic;
  2252. }
  2253. if (OrderCount > 1)
  2254. {
  2255. result += "该创客已不是首笔下单\n";
  2256. dic.Add("code", "1");
  2257. dic.Add("result", result);
  2258. return dic;
  2259. }
  2260. Orders order = db.Orders.FirstOrDefault(m => m.UserId == forMakerCode.UserId && m.PayStatus == 1 && m.TotalPrice == 600) ?? new Orders();
  2261. if (order.PayStatus < 1)
  2262. {
  2263. result += "未付款\n";
  2264. dic.Add("code", "1");
  2265. dic.Add("result", result);
  2266. return dic;
  2267. }
  2268. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
  2269. Users puser = db.Users.FirstOrDefault(m => m.Id == user.ParentUserId) ?? new Users();
  2270. result += "订单号:" + order.OrderNo + "\n";
  2271. result += "下单创客\n创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile + "\n";
  2272. result += "上级创客\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2273. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2274. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2275. if (machineCount + ActiveCount >= 3)
  2276. {
  2277. string IsGet = "未发放";
  2278. int ToUserId = 0;
  2279. UserAccountRecord item = db.UserAccountRecord.FirstOrDefault(m => m.QueryCount == order.Id && m.ChangeType == 112);
  2280. if (item == null)
  2281. {
  2282. DateTime start = order.PayDate.Value.AddMinutes(-2);
  2283. DateTime end = order.PayDate.Value.AddMinutes(2);
  2284. item = db.UserAccountRecord.FirstOrDefault(m => m.UserId == puser.Id && m.ChangeType == 112 && m.ChangeAmount == 100 && m.CreateDate >= start && m.CreateDate <= end);
  2285. }
  2286. if (item != null)
  2287. {
  2288. IsGet = "已发放(发放时间:" + item.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2289. ToUserId = item.UserId;
  2290. dic.Add("code", "1");
  2291. }
  2292. else
  2293. {
  2294. dic.Add("id", order.Id.ToString());
  2295. dic.Add("code", "0");
  2296. }
  2297. Users touser = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  2298. result += "是否发放:" + IsGet + "\n";
  2299. result += "应该发放对象\n创客编号:" + puser.MakerCode + ",姓名:" + puser.RealName + ",手机号:" + puser.Mobile + "\n";
  2300. result += "实际发放对象\n创客编号:" + touser.MakerCode + ",姓名:" + touser.RealName + ",手机号:" + touser.Mobile + "\n";
  2301. }
  2302. else
  2303. {
  2304. result += "上级创客未满足条件\n购买机:" + machineCount + "台,激活机:" + ActiveCount + "台\n";
  2305. dic.Add("code", "1");
  2306. }
  2307. dic.Add("result", result);
  2308. return dic;
  2309. }
  2310. public string AddPrize100(int Id)
  2311. {
  2312. Orders order = db.Orders.FirstOrDefault(m => m.Id == Id);
  2313. if (order != null)
  2314. {
  2315. //机具券逻辑
  2316. OrderProduct pro = db.OrderProduct.FirstOrDefault(m => m.OrderId == Id);
  2317. if (pro != null)
  2318. {
  2319. //推荐下单奖励
  2320. if (pro.ProductId == 10 || pro.ProductId == 11)
  2321. {
  2322. int OrderId = order.Id;
  2323. bool checkPrize = db.UserAccountRecord.Any(m => m.QueryCount == OrderId && m.ChangeType == 112);
  2324. if (!checkPrize)
  2325. {
  2326. Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId);
  2327. if (user != null)
  2328. {
  2329. bool directPrize = false; //直推奖标记
  2330. int ParentUserId = user.ParentUserId;
  2331. // List<int> proids = new List<int>();
  2332. // proids.Add(10);
  2333. // proids.Add(11);
  2334. while (ParentUserId > 0)
  2335. {
  2336. Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId) ?? new Users();
  2337. int machineCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.PosSnType == 0); //判断是否拥有3台购买机
  2338. int ActiveCount = db.PosMachinesTwo.Count(m => m.UserId == ParentUserId && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2339. int couponCount = db.PosCoupons.Count(m => m.UserId == ParentUserId && m.IsUse == 0); //判断是否拥有3张券
  2340. if ((machineCount + ActiveCount + couponCount >= 3 || puser.LeaderLevel > 0) && !directPrize)
  2341. {
  2342. DirectPrize(db, order.Id, ParentUserId, pro.ProductCount);
  2343. directPrize = true;
  2344. db.SaveChanges();
  2345. return "发放成功";
  2346. }
  2347. ParentUserId = puser.ParentUserId;
  2348. }
  2349. }
  2350. }
  2351. return "已发放,请勿重复发放";
  2352. }
  2353. }
  2354. }
  2355. return "操作失败";
  2356. }
  2357. public void DirectPrize(WebCMSEntities db, int OrderId, int UserId, int Count = 1)
  2358. {
  2359. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
  2360. if (account == null)
  2361. {
  2362. account = db.UserAccount.Add(new UserAccount()
  2363. {
  2364. Id = UserId,
  2365. UserId = UserId,
  2366. }).Entity;
  2367. db.SaveChanges();
  2368. }
  2369. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2370. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2371. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2372. account.BalanceAmount += 100 * Count;
  2373. account.TotalAmount += 100 * Count;
  2374. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2375. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2376. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2377. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2378. {
  2379. CreateDate = DateTime.Now,
  2380. UpdateDate = DateTime.Now,
  2381. UserId = UserId, //创客
  2382. ChangeType = 112, //变动类型
  2383. ChangeAmount = 100 * Count, //变更金额
  2384. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2385. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2386. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2387. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2388. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2389. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2390. QueryCount = OrderId,
  2391. }).Entity;
  2392. db.SaveChanges();
  2393. }
  2394. #endregion
  2395. #region 查询机具开机奖
  2396. public IActionResult OpenPrize(string right)
  2397. {
  2398. ViewBag.RightInfo = RightInfo;
  2399. ViewBag.right = right;
  2400. return View();
  2401. }
  2402. [HttpPost]
  2403. public Dictionary<string, string> OpenPrizeDo(string PosSn)
  2404. {
  2405. Dictionary<string, string> dic = new Dictionary<string, string>();
  2406. string result = "";
  2407. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2408. if (pos == null)
  2409. {
  2410. result += "机具SN号不存在\n";
  2411. dic.Add("code", "1");
  2412. dic.Add("result", result);
  2413. return dic;
  2414. }
  2415. if (pos.BindingState == 0)
  2416. {
  2417. result += "机具未绑定\n";
  2418. dic.Add("code", "1");
  2419. dic.Add("result", result);
  2420. return dic;
  2421. }
  2422. if (pos.ActivationState == 0)
  2423. {
  2424. result += "机具未激活\n";
  2425. dic.Add("code", "1");
  2426. dic.Add("result", result);
  2427. return dic;
  2428. }
  2429. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2430. if (merchant == null)
  2431. {
  2432. result += "商户不存在\n";
  2433. dic.Add("code", "1");
  2434. dic.Add("result", result);
  2435. return dic;
  2436. }
  2437. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2438. result += "机具号:" + PosSn + "\n";
  2439. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2440. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2441. string OpenUser10 = "未领取";
  2442. string OpenUser20 = "未领取";
  2443. var OpenRewardDetail = db.OpenRewardDetail.Where(m => m.SnNo == pos.PosSn).ToList();
  2444. OpenRewardDetail openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 20) ?? new OpenRewardDetail();
  2445. if (openreward.Id > 0)
  2446. {
  2447. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2448. OpenUser20 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2449. }
  2450. openreward = OpenRewardDetail.FirstOrDefault(m => m.CreditRewardAmount == 10) ?? new OpenRewardDetail();
  2451. if (openreward.Id > 0)
  2452. {
  2453. Users user = db.Users.FirstOrDefault(m => m.Id == openreward.UserId) ?? new Users();
  2454. OpenUser10 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2455. }
  2456. result += "开机奖20:" + OpenUser20 + "\n";
  2457. result += "开机奖10:" + OpenUser10 + "\n";
  2458. dic.Add("id", pos.Id.ToString());
  2459. dic.Add("code", "0");
  2460. dic.Add("result", result);
  2461. return dic;
  2462. }
  2463. public string AddOpenPrize(int Id)
  2464. {
  2465. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2466. if (pos == null)
  2467. {
  2468. return "机具未激活";
  2469. }
  2470. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2471. {
  2472. return "绑定已超过30天";
  2473. }
  2474. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2475. if (ActPrize == 0)
  2476. {
  2477. return "机具无押金";
  2478. }
  2479. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2480. if (merchant == null)
  2481. {
  2482. return "商户不存在";
  2483. }
  2484. bool check = db.OpenRewardDetail.Any(m => m.SnNo == pos.PosSn);
  2485. if (check)
  2486. {
  2487. return "开机奖励已发放,请勿重复操作";
  2488. }
  2489. // 从机具所属人上级开始分开机奖励
  2490. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId);
  2491. if (user != null)
  2492. {
  2493. if (!string.IsNullOrEmpty(user.ParentNav))
  2494. {
  2495. decimal Prize = 20;
  2496. List<string> PrizeFlag = new List<string>();
  2497. string[] ParentNavs = user.ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2498. for (int i = ParentNavs.Length - 1; i >= 0; i--)
  2499. {
  2500. int UserId = int.Parse(ParentNavs[i]);
  2501. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId && m.AuthFlag == 1);
  2502. if (puser != null && Prize > 0)
  2503. {
  2504. int machineCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.PosSnType == 0); //判断是否拥有3台购买机
  2505. int ActiveCount = db.PosMachinesTwo.Count(m => m.BuyUserId == puser.Id && m.ActivationState == 1); //判断是否拥有3台激活机(不限购买或赠送)
  2506. int couponCount = db.PosCoupons.Count(m => m.UserId == puser.Id && m.IsUse == 0); //判断是否拥有3张券
  2507. if (machineCount + ActiveCount + couponCount >= 3)
  2508. {
  2509. int pTopUserId = 0;
  2510. if (!string.IsNullOrEmpty(puser.ParentNav))
  2511. {
  2512. pTopUserId = int.Parse(puser.ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
  2513. }
  2514. Users machineUser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2515. OpenRewardDetail detail = db.OpenRewardDetail.Add(new OpenRewardDetail()
  2516. {
  2517. CreateDate = DateTime.Now,
  2518. UpdateDate = DateTime.Now,
  2519. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2520. TradeDate = pos.ActivationTime, //达标日期
  2521. UserId = puser.Id, //创客
  2522. BrandId = pos.BrandId, //品牌
  2523. ProductName = RelationClass.GetKqProductBrandInfo(pos.BrandId), //产品名称
  2524. MerchantId = pos.BindMerchantId, //商户
  2525. DirectUserId = merchant.UserId, //商户直属人
  2526. SnNo = pos.PosSn, //SN号
  2527. MerNo = merchant.KqMerNo, //渠道商户号
  2528. SnType = pos.PosSnType, //机具类型
  2529. StandardDate = pos.ActivationTime, //商户的激活日期
  2530. SnStoreId = pos.StoreId, //SN仓库
  2531. MerBuddyType = puser.MerchantType, //商户创客类型
  2532. RewardType = 1, //奖励类型 1-开机直接奖励,2-开机间接奖励
  2533. RewardTips = "开机奖励", //奖励描述
  2534. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2535. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2536. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2537. RewardDesc = "开机奖励", //奖励描述
  2538. TopUserId = pTopUserId, //顶级创客
  2539. SeoTitle = machineUser.RealName,
  2540. }).Entity;
  2541. db.OpenReward.Add(new OpenReward()
  2542. {
  2543. CreateDate = DateTime.Now,
  2544. UpdateDate = DateTime.Now,
  2545. TradeMonth = DateTime.Now.ToString("yyyyMM"), //交易月
  2546. TradeDate = DateTime.Now, //达标日期
  2547. UserId = puser.Id, //创客
  2548. BrandId = pos.BrandId, //品牌
  2549. RewardType = 2, //奖励类型
  2550. CreditTradeAmt = pos.CreditTrade, //贷记卡交易总金额
  2551. DebitTradeAmt = pos.DebitCardTrade, //借记卡交易总金额
  2552. CreditRewardAmount = Prize, //贷记卡交易奖励金额
  2553. RewardDesc = "开机奖励", //奖励描述
  2554. TopUserId = pTopUserId, //顶级创客
  2555. });
  2556. string IdBrand = puser.Id + "_" + pos.BrandId;
  2557. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2558. if (userData == null)
  2559. {
  2560. userData = db.UserMachineData.Add(new UserMachineData()
  2561. {
  2562. IdBrand = IdBrand,
  2563. }).Entity;
  2564. db.SaveChanges();
  2565. }
  2566. userData.OpenProfit += Prize;
  2567. db.SaveChanges();
  2568. //账户入库
  2569. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == puser.Id);
  2570. if (account == null)
  2571. {
  2572. account = db.UserAccount.Add(new UserAccount()
  2573. {
  2574. Id = puser.Id,
  2575. UserId = puser.Id,
  2576. }).Entity;
  2577. db.SaveChanges();
  2578. }
  2579. //收支明细入库
  2580. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2581. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2582. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2583. account.BalanceAmount += Prize;
  2584. account.TotalAmount += Prize;
  2585. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2586. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2587. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2588. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2589. {
  2590. CreateDate = DateTime.Now,
  2591. UpdateDate = DateTime.Now,
  2592. UserId = puser.Id, //创客
  2593. ChangeType = 50, //变动类型
  2594. ProductType = pos.BrandId, //产品类型
  2595. ChangeAmount = Prize, //变更金额
  2596. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2597. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2598. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2599. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2600. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2601. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2602. }).Entity;
  2603. db.SaveChanges();
  2604. RedisDbconn.Instance.Set("UserAccount:" + puser.Id, account);
  2605. string dateString = DateTime.Now.ToString("yyyyMMdd");
  2606. string monthString = DateTime.Now.ToString("yyyyMM");
  2607. // 开机奖励列表
  2608. List<string> dates = RedisDbconn.Instance.GetList<string>("OpenRewardDay:" + puser.Id + ":" + pos.BrandId);
  2609. if (!dates.Contains(dateString))
  2610. {
  2611. RedisDbconn.Instance.AddList("OpenRewardDay:" + puser.Id + ":" + pos.BrandId, dateString);
  2612. }
  2613. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + dateString, Prize);
  2614. List<string> months = RedisDbconn.Instance.GetList<string>("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId);
  2615. if (!months.Contains(monthString))
  2616. {
  2617. RedisDbconn.Instance.AddList("OpenRewardMonth:" + puser.Id + ":" + pos.BrandId, monthString);
  2618. }
  2619. RedisDbconn.Instance.AddNumber("OpenRewardAmt:" + puser.Id + ":" + pos.BrandId + ":" + monthString, Prize);
  2620. // 开机奖励详情
  2621. RedisDbconn.Instance.AddList("OpenRewardDetail:" + puser.Id + ":" + pos.BrandId + ":" + dateString, detail);
  2622. //收支明细
  2623. RedisDbconn.Instance.AddList("UserAccountRecord:" + puser.Id + ":1:" + monthString, userAccountRecord);
  2624. RedisDbconn.Instance.AddNumber("UserAccount:" + puser.Id + ":1:" + monthString, Prize);
  2625. Prize -= 10;
  2626. PrizeFlag.Add(Prize.ToString("f0"));
  2627. }
  2628. }
  2629. }
  2630. string result = "";
  2631. if (!PrizeFlag.Contains("20"))
  2632. {
  2633. result += "20元奖励未发,请检查上级是否满足条件\n";
  2634. }
  2635. if (!PrizeFlag.Contains("10"))
  2636. {
  2637. result += "10元奖励未发,请检查上级是否满足条件\n";
  2638. }
  2639. if (string.IsNullOrEmpty(result))
  2640. {
  2641. return "发放成功";
  2642. }
  2643. return result;
  2644. }
  2645. }
  2646. db.Dispose();
  2647. return "操作失败";
  2648. }
  2649. #endregion
  2650. #region 查询机具流量费分佣
  2651. public IActionResult FluxPrize(string right)
  2652. {
  2653. ViewBag.RightInfo = RightInfo;
  2654. ViewBag.right = right;
  2655. return View();
  2656. }
  2657. [HttpPost]
  2658. public Dictionary<string, string> FluxPrizeDo(string PosSn)
  2659. {
  2660. Dictionary<string, string> dic = new Dictionary<string, string>();
  2661. string result = "";
  2662. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  2663. if (pos == null)
  2664. {
  2665. result += "机具SN号不存在\n";
  2666. dic.Add("code", "1");
  2667. dic.Add("result", result);
  2668. return dic;
  2669. }
  2670. if (pos.BindingState == 0)
  2671. {
  2672. result += "机具未绑定\n";
  2673. dic.Add("code", "1");
  2674. dic.Add("result", result);
  2675. return dic;
  2676. }
  2677. if (pos.ActivationState == 0)
  2678. {
  2679. result += "机具未激活\n";
  2680. dic.Add("code", "1");
  2681. dic.Add("result", result);
  2682. return dic;
  2683. }
  2684. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2685. if (merchant == null)
  2686. {
  2687. result += "商户不存在\n";
  2688. dic.Add("code", "1");
  2689. dic.Add("result", result);
  2690. return dic;
  2691. }
  2692. Users buyuser = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2693. result += "机具号:" + PosSn + "\n";
  2694. result += "机具所属人:\n创客编号:" + buyuser.MakerCode + ",姓名:" + buyuser.RealName + ",手机号:" + buyuser.Mobile + "\n";
  2695. result += "商户信息\n商户编号:" + merchant.KqMerNo + ",姓名:" + merchant.MerchantName + ",手机号:" + merchant.MerchantMobile + "\n";
  2696. string FluxGet6 = "未领取";
  2697. string FluxUser6 = "";
  2698. FluxProfitDetail flux = db.FluxProfitDetail.FirstOrDefault(m => m.SnNo == pos.PosSn) ?? new FluxProfitDetail();
  2699. if (flux.Id > 0)
  2700. {
  2701. Users user = db.Users.FirstOrDefault(m => m.Id == flux.UserId) ?? new Users();
  2702. FluxGet6 = "已领取(领取时间:" + flux.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + ")";
  2703. FluxUser6 = "创客编号:" + user.MakerCode + ",姓名:" + user.RealName + ",手机号:" + user.Mobile;
  2704. }
  2705. result += "流量费:" + FluxGet6 + "\n";
  2706. result += "流量费发放对象:" + FluxUser6 + "\n";
  2707. dic.Add("id", pos.Id.ToString());
  2708. dic.Add("code", "0");
  2709. dic.Add("result", result);
  2710. return dic;
  2711. }
  2712. public string AddFluxPrize(int Id)
  2713. {
  2714. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id && m.ActivationState == 1);
  2715. if (pos == null)
  2716. {
  2717. return "机具未激活";
  2718. }
  2719. if (pos.BindingTime < DateTime.Now.AddDays(-30))
  2720. {
  2721. return "绑定已超过30天";
  2722. }
  2723. decimal ActPrize = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  2724. if (ActPrize == 0)
  2725. {
  2726. return "机具无押金";
  2727. }
  2728. PosMerchantInfo merchant = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  2729. if (merchant == null)
  2730. {
  2731. return "商户不存在";
  2732. }
  2733. if (pos.BrandId == 6)
  2734. {
  2735. return "立刷不支持流量费分佣";
  2736. }
  2737. if (decimal.Parse(function.CheckNum(pos.SeoKeyword)) <= 0)
  2738. {
  2739. return "无押金机,不支持流量费分佣";
  2740. }
  2741. bool check = db.FluxProfitDetail.Any(m => m.MerNo == merchant.KqMerNo);
  2742. if (check)
  2743. {
  2744. return "开机奖励已发放,请勿重复操作";
  2745. }
  2746. SpModels.TradeFluxRecord trade = spdb.TradeFluxRecord.FirstOrDefault(m => m.TradeSnNo == pos.PosSn);
  2747. if (trade != null)
  2748. {
  2749. try
  2750. {
  2751. string OrderNo = trade.TradeSerialNo; //单号
  2752. DateTime TradeDate = trade.CreateDate.Value;
  2753. string TradeMonth = TradeDate.ToString("yyyyMM");
  2754. decimal FeeAmount = trade.FeeAmount; //流量费
  2755. if (trade.ProductType == "1" || trade.ProductType == "4" || trade.ProductType == "6" || trade.ProductType == "8" || trade.ProductType == "9")
  2756. {
  2757. FeeAmount = FeeAmount / 100;
  2758. }
  2759. string TradeSnNo = trade.TradeSnNo; //机具SN
  2760. decimal FluxProfit = 0;
  2761. if (trade.ProductType == "1" && FeeAmount == 60)
  2762. {
  2763. FluxProfit = 24;
  2764. }
  2765. else if (trade.ProductType == "7" && FeeAmount == 46)
  2766. {
  2767. FluxProfit = 10;
  2768. }
  2769. else if (trade.ProductType != "1" && FeeAmount == 48)
  2770. {
  2771. FluxProfit = 12;
  2772. }
  2773. if (FluxProfit > 0)
  2774. {
  2775. Users user = db.Users.FirstOrDefault(m => m.Id == pos.BuyUserId) ?? new Users();
  2776. int GetUserId = user.Id;
  2777. int TopUserId = 0;
  2778. string ParentNav = user.ParentNav;
  2779. if (!string.IsNullOrEmpty(ParentNav))
  2780. {
  2781. string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
  2782. if (ParentNavList.Length > 1)
  2783. {
  2784. TopUserId = int.Parse(ParentNavList[1]);
  2785. }
  2786. else if (ParentNavList.Length == 1)
  2787. {
  2788. TopUserId = int.Parse(ParentNavList[0]);
  2789. }
  2790. }
  2791. FluxProfitSummary fluxProfit = db.FluxProfitSummary.FirstOrDefault(m => m.UserId == GetUserId && m.BrandId == pos.BrandId && m.TradeMonth == TradeMonth);
  2792. if (fluxProfit == null)
  2793. {
  2794. fluxProfit = db.FluxProfitSummary.Add(new FluxProfitSummary()
  2795. {
  2796. CreateDate = DateTime.Now,
  2797. UpdateDate = DateTime.Now,
  2798. UserId = GetUserId, //创客
  2799. BrandId = pos.BrandId,
  2800. TopUserId = TopUserId, //顶级创客
  2801. TradeMonth = TradeMonth, //交易月
  2802. MerUserType = user.MerchantType, //商户创客类型
  2803. Remark = "流量卡分佣", //备注
  2804. }).Entity;
  2805. db.SaveChanges();
  2806. }
  2807. fluxProfit.FluxProfitAmt += FluxProfit; //流量分润总金额
  2808. db.FluxProfitDetail.Add(new FluxProfitDetail()
  2809. {
  2810. CreateDate = DateTime.Now,
  2811. UpdateDate = DateTime.Now,
  2812. RecordNo = OrderNo, //单号
  2813. TradeDate = TradeDate.ToString("yyyyMMdd"), //交易日期
  2814. TradeTime = TradeDate.ToString("HHmmss"), //交易时间
  2815. TradeMonth = TradeMonth, //交易月
  2816. UserId = GetUserId, //创客
  2817. MerchantId = pos.BindMerchantId, //商户
  2818. MerchantUserId = pos.UserId, //商户直属人
  2819. MerNo = merchant.KqMerNo, //渠道商户编号
  2820. SnNo = pos.PosSn, //渠道SN号
  2821. FluxOrderNo = OrderNo, //流量扣费单号
  2822. TradeOrderNo = OrderNo, //交易流水号
  2823. TradeAmt = trade.TradeAmount, //商户交易额
  2824. FluxFeeAmt = FeeAmount, //流量费
  2825. FluxProfitAmt = FluxProfit, //流量分润总金额
  2826. PosType = pos.PosSnType.ToString(), //POS类型
  2827. Remark = "流量卡分佣", //备注
  2828. BrandId = pos.BrandId, //品牌
  2829. TopUserId = TopUserId, //顶级创客
  2830. MerUserType = user.MerchantType, //商户创客类型
  2831. });
  2832. string IdBrand = user.Id + "_" + pos.BrandId;
  2833. UserMachineData userData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == IdBrand);
  2834. if (userData == null)
  2835. {
  2836. userData = db.UserMachineData.Add(new UserMachineData()
  2837. {
  2838. IdBrand = IdBrand,
  2839. }).Entity;
  2840. db.SaveChanges();
  2841. }
  2842. userData.FluxProfit += FluxProfit;
  2843. db.SaveChanges();
  2844. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == GetUserId);
  2845. if (account == null)
  2846. {
  2847. account = db.UserAccount.Add(new UserAccount()
  2848. {
  2849. Id = GetUserId,
  2850. UserId = GetUserId,
  2851. }).Entity;
  2852. db.SaveChanges();
  2853. }
  2854. decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额
  2855. decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额
  2856. decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额
  2857. account.BalanceAmount += FluxProfit;
  2858. account.TotalAmount += FluxProfit;
  2859. decimal AfterTotalAmount = account.TotalAmount; //变更后总金额
  2860. decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额
  2861. decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额
  2862. UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
  2863. {
  2864. CreateDate = DateTime.Now,
  2865. UpdateDate = DateTime.Now,
  2866. UserId = GetUserId, //创客
  2867. ChangeType = 60, //变动类型
  2868. ProductType = pos.BrandId, //产品类型
  2869. ChangeAmount = FluxProfit, //变更金额
  2870. BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
  2871. AfterTotalAmount = AfterTotalAmount, //变更后总金额
  2872. BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
  2873. AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
  2874. BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
  2875. AfterBalanceAmount = AfterBalanceAmount, //变更后余额
  2876. }).Entity;
  2877. db.SaveChanges();
  2878. spdb.Dispose();
  2879. db.Dispose();
  2880. return "发放成功";
  2881. }
  2882. }
  2883. catch (Exception ex)
  2884. {
  2885. function.WriteLog(DateTime.Now.ToString() + "\n$" + trade.Id + "$\n" + ex.ToString(), "流量卡分佣异常");
  2886. }
  2887. }
  2888. spdb.Dispose();
  2889. db.Dispose();
  2890. return "操作失败";
  2891. }
  2892. #endregion
  2893. #region 设置立刷费率
  2894. public IActionResult LisFee(string right)
  2895. {
  2896. ViewBag.RightInfo = RightInfo;
  2897. ViewBag.right = right;
  2898. return View();
  2899. }
  2900. [HttpPost]
  2901. public string LisFeeDo(string PosSns, decimal Fee, string Kind, string Fix)
  2902. {
  2903. if (string.IsNullOrEmpty(PosSns))
  2904. {
  2905. return "请输入机具号";
  2906. }
  2907. string result = SysUserName + "设置\n";
  2908. string[] PosSnList = PosSns.Split('\n');
  2909. int total = PosSnList.Length;
  2910. int index = 0;
  2911. foreach (string SubPosSn in PosSnList)
  2912. {
  2913. index += 1;
  2914. string PosSn = SubPosSn.Replace("\r", "");
  2915. result += PosSn + ":" + Fee + "\n";
  2916. if (Kind == "M5")
  2917. {
  2918. result += SetLiSFee(PosSn, Fee) + "\n";
  2919. }
  2920. else if (Kind == "N1")
  2921. {
  2922. result += SetLiSDeposit(PosSn, (int)Fee);
  2923. }
  2924. RedisDbconn.Instance.Set("LisFeeProcess:" + SysId, index + " / " + total);
  2925. }
  2926. result += "\n\n";
  2927. function.WriteLog(result, "设置立刷费率");
  2928. return result;
  2929. }
  2930. public string LisFeeProcess()
  2931. {
  2932. return RedisDbconn.Instance.Get<string>("LisFeeProcess:" + SysId);
  2933. }
  2934. #region 立刷
  2935. string LiSAgentId = "50814834";
  2936. 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=";
  2937. string LiSReqUrl = "https://openapi.jlpay.com/access/charge/"; //请求url
  2938. public string LiSSign(string data)
  2939. {
  2940. var rsa = RSA.Create();
  2941. var key = Convert.FromBase64String(LiSPrivateKey);
  2942. var content = Encoding.UTF8.GetBytes(data);
  2943. rsa.ImportPkcs8PrivateKey(key, out _);
  2944. var result = rsa.SignData(content, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  2945. return Convert.ToBase64String(result);
  2946. }
  2947. // 设置费率
  2948. public string SetLiSFee(string sn, decimal serviceFee)
  2949. {
  2950. Dictionary<string, object> dic = new Dictionary<string, object>();
  2951. dic.Add("agentId", LiSAgentId);
  2952. dic.Add("deviceSn", sn);
  2953. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2954. Dictionary<string, object> item = new Dictionary<string, object>();
  2955. item.Add("feeCalcType", "M5");
  2956. item.Add("fixed", "0");
  2957. item.Add("rate", serviceFee);
  2958. feeList.Add(item);
  2959. dic.Add("feeList", feeList);
  2960. dic.Add("signMethod", "02");
  2961. string content = LiSAgentId + sn + "M50" + serviceFee + "02";
  2962. string signstr = LiSSign(content);
  2963. dic.Add("signData", signstr);
  2964. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2965. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2966. return result;
  2967. }
  2968. // 设置押金
  2969. public string SetLiSDeposit(string sn, int serviceFee)
  2970. {
  2971. serviceFee = serviceFee * 100;
  2972. Dictionary<string, object> dic = new Dictionary<string, object>();
  2973. dic.Add("agentId", LiSAgentId);
  2974. dic.Add("deviceSn", sn);
  2975. List<Dictionary<string, object>> feeList = new List<Dictionary<string, object>>();
  2976. Dictionary<string, object> item = new Dictionary<string, object>();
  2977. item.Add("feeCalcType", "N1");
  2978. item.Add("fixed", "1");
  2979. item.Add("rate", serviceFee);
  2980. feeList.Add(item);
  2981. dic.Add("feeList", feeList);
  2982. dic.Add("signMethod", "02");
  2983. string content = LiSAgentId + sn + "N11" + serviceFee + "02";
  2984. string signstr = LiSSign(content);
  2985. dic.Add("signData", signstr);
  2986. string req = Newtonsoft.Json.JsonConvert.SerializeObject(dic);
  2987. string result = function.PostWebRequest(LiSReqUrl + "FEE003", req, new Dictionary<string, string>(), "application/json");
  2988. return result;
  2989. }
  2990. #endregion
  2991. #endregion
  2992. #region 查询商户型创客设置信息
  2993. public IActionResult SeeMerchantType(string right)
  2994. {
  2995. ViewBag.RightInfo = RightInfo;
  2996. ViewBag.right = right;
  2997. return View();
  2998. }
  2999. [HttpPost]
  3000. public string SeeMerchantTypeDo(string PosSn)
  3001. {
  3002. if (string.IsNullOrEmpty(PosSn))
  3003. {
  3004. return "请输入机具SN或者创客编号";
  3005. }
  3006. SetMerchantTypeRecord pos = new SetMerchantTypeRecord();
  3007. if (PosSn.StartsWith("K"))
  3008. {
  3009. UserForMakerCode userfor = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == PosSn) ?? new UserForMakerCode();
  3010. bool check = db.SetMerchantTypeRecord.Any(m => m.ToUserId == userfor.UserId);
  3011. if (check)
  3012. {
  3013. pos = db.SetMerchantTypeRecord.Where(m => m.ToUserId == userfor.UserId).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3014. }
  3015. }
  3016. else
  3017. {
  3018. bool check = db.SetMerchantTypeRecord.Any(m => m.PosSn == PosSn);
  3019. if (check)
  3020. {
  3021. pos = db.SetMerchantTypeRecord.Where(m => m.PosSn == PosSn).OrderByDescending(m => m.Id).FirstOrDefault() ?? new SetMerchantTypeRecord();
  3022. }
  3023. }
  3024. if (pos.Id == 0)
  3025. {
  3026. return "查无信息";
  3027. }
  3028. Users setUser = db.Users.FirstOrDefault(m => m.Id == pos.FromUserId) ?? new Users();
  3029. Users toUser = db.Users.FirstOrDefault(m => m.Id == pos.ToUserId) ?? new Users();
  3030. string CreateDate = pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3031. string bindTime = pos.BindDate == null ? "" : pos.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3032. string activeTime = pos.ActDate == null ? "" : pos.ActDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  3033. string bindResult = pos.BindStatus == 1 ? "已绑定" : "未绑定";
  3034. string activeResult = pos.ActStatus == 1 ? "已激活" : "未激活";
  3035. string RecycFlag = pos.IsRecyc == 1 ? "已循环" : "未循环";
  3036. string result = "";
  3037. result += "机具SN:" + pos.PosSn + "\n";
  3038. result += "操作人:创客编号:" + setUser.MakerCode + ",姓名:" + setUser.RealName + ",手机号:" + setUser.Mobile + "\n";
  3039. result += "操作对象:创客编号:" + toUser.MakerCode + ",姓名:" + toUser.RealName + ",手机号:" + toUser.Mobile + "\n";
  3040. result += "商户编号:" + pos.MerNo + "\n";
  3041. result += "操作时间:" + pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "\n";
  3042. result += "绑定状态:" + bindResult + "(绑定时间:" + bindTime + ")\n";
  3043. result += "激活状态:" + activeResult + "(激活时间:" + activeTime + ")\n";
  3044. result += "贷记卡交易额:" + pos.CreditAmount + "\n";
  3045. result += "是否循环:" + RecycFlag + "\n";
  3046. return result;
  3047. }
  3048. #endregion
  3049. }
  3050. }