SysToolsController.cs 150 KB

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