SysToolsController.cs 184 KB

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