SysToolsController.cs 160 KB

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