SysToolsController.cs 140 KB

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