SysToolsController.cs 160 KB

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