SysToolsController.cs 160 KB

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