hallHandler.js 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554
  1. 'use strict';
  2. var https = require('https');
  3. var http = require('http');
  4. var md5 = require('md5');
  5. var hallLogic = require('./hallLogic');
  6. var util = require('util');
  7. var quick = require('quick-pomelo');
  8. var P = quick.Promise;
  9. var _ = require('lodash');
  10. var uuid = require('node-uuid');
  11. var C = require('../../../../share/constant');
  12. var confHall = require('../../../config/hallConfig') || {};
  13. var configCommon = require('../../../../share/configCommon');//////TL++配置相关的公共方法
  14. // var compateDate = require('../../../../share/compateDate');
  15. var logger = quick.logger.getLogger('fhmj', __filename);
  16. // var confActive = require('../../../config/hallConfig').active || {};
  17. var Handler = function (app) {
  18. // console.warn("????? Handler==============");
  19. this.app = app;
  20. this.users = {};
  21. this.calculateTimer = null
  22. ////文字验证码的文库
  23. this.wordList = "当时记得这篇桂林山水也是在小学二年级出现要求通会背有一次因为不还被老师罚站后来对甲天下印象特别深刻太理解描写景的那些词准确意思只听讲美所以候就想着长大了定去看体作者述种可惜已过而立之我欣赏愿望直没能实但"
  24. // console.warn("活动配置内容 ??? Handler() "+typeof require.cache[require.resolve('./hallHandler')]);
  25. this.hallLogic = new hallLogic(this.app);
  26. this.lconfigCommon = new configCommon(this.app);
  27. // this.lcompateDate = new compateDate();
  28. };
  29. module.exports = function (app) {
  30. // setInterval(() => checkVersion(), 5000);
  31. // console.warn("活动配置内容 ??? exports() "+typeof require.cache[require.resolve('./hallHandler')]);
  32. return new Handler(app);
  33. };
  34. var proto = Handler.prototype;
  35. proto.checkVersion2 = P.coroutine(function* () {
  36. // let confCodeVer = require('../../../config/VersionConfig').codeVer || {};
  37. // console.warn("检查版本bbb "+JSON.stringify(confCodeVer));
  38. // delete require.cache[require.resolve('../../../config/VersionConfig')];
  39. // let confCodeVer2 = require('../../../config/VersionConfig').codeVer || {};
  40. // if(confCodeVer.hallConfig && confCodeVer2.hallConfig && confCodeVer.hallConfig != confCodeVer2.hallConfig){
  41. // delete require.cache[require.resolve('../../../config/hallConfig')];
  42. // confHall = require('../../../config/hallConfig') || {};
  43. // console.warn("hallConfig 已经更新了")
  44. // }
  45. // if(confCodeVer.hallLogic && confCodeVer2.hallLogic && confCodeVer.hallLogic != confCodeVer2.hallLogic){
  46. // delete require.cache[require.resolve('./hallLogic')];
  47. // hallLogic = require('./hallLogic');
  48. // this.hallLogic = new hallLogic(this.app);
  49. // console.warn("hallLogic 已经更新了 ")
  50. // }
  51. // if(confCodeVer.configCommon && confCodeVer2.configCommon && confCodeVer.configCommon != confCodeVer2.configCommon){
  52. // delete require.cache[require.resolve('../../../../share/configCommon')];
  53. // configCommon = require('../../../../share/configCommon');
  54. // this.lconfigCommon = new configCommon(this.app);
  55. // console.warn("configCommon 已经更新了 ")
  56. // }
  57. // if(confCodeVer.pdkLogic && confCodeVer2.pdkLogic && confCodeVer.pdkLogic != confCodeVer2.pdkLogic){
  58. // // delete require.cache[require.resolve('../../../paodekuai/logic')];
  59. // // require('../../../paodekuai/logic')
  60. // // delete require.cache[require.resolve('./logic')];
  61. // // require('./logic')
  62. // // delete require.cache[require.resolve('../../game/handler/paodekuaiHandler')];
  63. // // require('../../game/handler/paodekuaiHandler')
  64. // // console.warn("pdkLogic 已经更新了 ")
  65. // }
  66. });
  67. // proto.xxxxx = P.coroutine(function* (c1,c2,c3,c4) {
  68. // console.error("开始给玩家发送消息 ",c1,c2,c3,c4);
  69. // let tempData = {
  70. // userId: c1,
  71. // account: c2,
  72. // longitude: c3,
  73. // latitude: c4
  74. // }
  75. // console.error("开始给玩家发送消息 222")
  76. // //////向其他玩家广播该玩家位置
  77. // //yield this.pushMsgAsync(-1, 'paodekuai_event', { type: M.COAST_PLAYERLOCATION, data: tempData });
  78. // yield this.app.controllers.push.broadcastAsync('broadcast', tempData);
  79. // console.error("给玩家发送消息完成 ",c1,c2,c3,c4);
  80. // return { code: C.OK, data: tempData };
  81. // });
  82. // // 发送消息
  83. // proto.pushMsgAsync = P.coroutine(function* (cidOrIds, route, msg) {
  84. // var playerIds = [];
  85. // if (Array.isArray(cidOrIds)) playerIds = cidOrIds;
  86. // else {
  87. // if (cidOrIds < 0 || cidOrIds >= this.users.length) {
  88. // for (let user of this.users) {
  89. // // console.warn("大厅给前端主动发消息 user.id "+user.data.id);
  90. // if (user) playerIds.push(user.id);
  91. // }
  92. // } else {
  93. // let user = this.users[cidOrIds];
  94. // if (user) playerIds.push(user.id);
  95. // }
  96. // }
  97. // if (playerIds.length > 0) {
  98. // let channelId = 'xct:' + this.id;
  99. // return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg);
  100. // }
  101. // });
  102. // 玩家信息
  103. proto.userInfo = P.coroutine(function* (msg, session, next) {
  104. if (!session.uid) {
  105. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  106. }
  107. var nowTime = Date.now();
  108. var uid = session.uid;
  109. var user = this.users[uid];
  110. if (user && nowTime - user.utime < 5000) {
  111. return next(null, { code: C.OK, data: user.data });
  112. }
  113. return this.app.models.Player.findByIdReadOnlyAsync(uid, 'diamond')
  114. .then(player => {
  115. var data = user ? user.data : { diamond: 0 };
  116. if (player) {
  117. data.diamond = player.diamond;
  118. if (user) user.utime = nowTime;
  119. else this.users[uid] = { utime: nowTime, data: data };
  120. }
  121. return { code: C.OK, data: data };
  122. }).nodeify(next);
  123. });
  124. //////TL++,得到用户钻石,充值完成之后前端访问这个用于更新前端的钻石显示
  125. proto.getUserDiamond = P.coroutine(function* (msg, session, next) {
  126. if (!session.uid) {
  127. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  128. }
  129. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'diamond ');
  130. if (player) {
  131. return next(null, { code: C.OK, data: {diamond:player.diamond} });
  132. }
  133. return next(null, { code: C.OK, data: {diamond:-1} });
  134. });
  135. //////TL++,得到服务器的当前时间戳 大厅的方法不能在游戏中访问
  136. proto.getNowTime = P.coroutine(function* (msg, session, next) {
  137. if (!session.uid) {
  138. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  139. }
  140. let nowTime = Date.now();
  141. // console.warn("得到服务器的当前时间戳");
  142. return next(null, { code: C.OK, data: {nowTime:nowTime} });
  143. });
  144. //////TL++,得到用户同步的信息
  145. proto.getUserTongBuInfo = P.coroutine(function* (msg, session, next) {
  146. if (!session.uid) {
  147. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  148. }
  149. var toplayerID = "";
  150. var toplayer = yield this.app.models.Player.findByIdAsync(session.uid, 'synPlayer');
  151. if (toplayer) {
  152. if(toplayer.synPlayer) toplayerID = toplayer.synPlayer;
  153. else return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_FOUND });/////玩家未找到
  154. }
  155. else{
  156. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_FOUND });/////玩家未找到
  157. }
  158. var player = yield this.app.models.Player.findByIdAsync(toplayerID, 'diamond userId name headurl synPlayer formId');
  159. if (player ) {
  160. if(player.synPlayer == session.uid){
  161. return next(null, { code: C.OK, data: {diamond:player.diamond,userId:player.userId,name:player.name,headurl:player.headurl,formId:player.formId} });
  162. }
  163. else{
  164. /////校验失败
  165. player.synPlayer = "";
  166. yield player.saveAsync();
  167. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_FOUND });
  168. }
  169. }
  170. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_FOUND });
  171. });
  172. //////TL++,钻石同步操作(同步到微信和同步到闲聊都用这个)
  173. proto.opZSTB = P.coroutine(function* (msg, session, next) {
  174. if (!session.uid) {
  175. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  176. }
  177. var outplayerID = "";/////钻石转出人的ID
  178. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'diamond synPlayer');
  179. if (player) {
  180. outplayerID = player.synPlayer;
  181. }
  182. else
  183. {
  184. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN});/////玩家未找到
  185. }
  186. if(outplayerID == '')
  187. {
  188. return next(null, { code: C.ERROR, msg: C.HTTP_NOTSAME_BINDPLAYER});/////玩家未找到
  189. }
  190. var outplayer = yield this.app.models.Player.findByIdAsync(outplayerID, 'diamond synPlayer');
  191. if (outplayer) {
  192. if(outplayer.synPlayer != session.uid)
  193. {
  194. return next(null, { code: C.ERROR, msg: C.HTTP_NOTSAME_BINDPLAYER});/////玩家未找到
  195. }
  196. if(outplayer.diamond <= 0)
  197. {
  198. return next(null, { code: C.OK, data: {opdiamond:0,newdiamond:player.diamond} });
  199. }
  200. let ylzs = outplayer.diamond;/////原来钻石
  201. let ylzs2 = player.diamond;/////原来钻石
  202. let opDiamondCount=outplayer.diamond;
  203. outplayer.diamond = 0;
  204. yield outplayer.saveAsync();
  205. // 钻石记录
  206. var diamondrecord = new this.app.models.DiamondRecord({
  207. _id: uuid.v1(),
  208. playerId: outplayerID,
  209. dType: 8,//8同步转出 9同步转入
  210. dSource: ylzs,
  211. dSwap: -1*opDiamondCount,
  212. dNow: 0,
  213. tableId: session.uid
  214. });c
  215. yield diamondrecord.saveAsync();
  216. player.diamond += opDiamondCount;
  217. yield player.saveAsync();
  218. var diamondrecord = new this.app.models.DiamondRecord({
  219. _id: uuid.v1(),
  220. playerId: session.uid,
  221. dType: 9,//8同步转出 9同步转入
  222. dSource: ylzs2,
  223. dSwap: opDiamondCount,
  224. dNow: player.diamond,
  225. tableId: outplayerID
  226. });
  227. yield diamondrecord.saveAsync();
  228. return next(null, { code: C.OK, data: {opdiamond:opDiamondCount,newdiamond:player.diamond} });
  229. }
  230. else
  231. {
  232. return next(null, { code: C.ERROR, msg: C.HTTP_NOTSAME_BINDPLAYER});/////玩家未找到
  233. }
  234. });
  235. // 修改资料
  236. proto.modifyInfo = P.coroutine(function* (msg, session, next) {
  237. if (!session.uid) {
  238. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  239. }
  240. if (!msg.name && !msg.headurl) {
  241. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  242. }
  243. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'name headurl');
  244. if (player) {
  245. if (msg.name && msg.name != player.name) player.name = msg.name;
  246. //if (msg.headurl && msg.headurl != player.headurl) player.headurl = msg.headurl;
  247. if (player.isModified()) yield player.saveAsync();
  248. }
  249. return next(null, { code: C.OK });
  250. });
  251. ////设置用户信息
  252. proto.setUserInfo = P.coroutine(function* (msg, session, next) {
  253. if (!session.uid) {
  254. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  255. }
  256. let msg2 = "";
  257. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'name headurl sex');
  258. if (player) {
  259. let isNeedSet = false;
  260. if (msg.sex && msg.sex != player.sex){
  261. player.sex = msg.sex;
  262. isNeedSet = true;
  263. }
  264. if(isNeedSet){
  265. yield player.saveAsync();
  266. msg2 = "修改成功";
  267. }
  268. }
  269. let resData = {
  270. sex : player.sex
  271. }
  272. return next(null, { code: C.OK, msg:msg2,data: resData });
  273. });
  274. // ts++请求得到外接小游戏的钻石
  275. proto.getSmallGameCoin = P.coroutine(function* (msg, session, next) {
  276. if (!session.uid) {
  277. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  278. }
  279. let result = {
  280. code:C.FAILD,
  281. userid:0,
  282. diamond:0
  283. }
  284. // var player = yield this.app.models.Player.findByIdAsync(session.uid, 'account userId diamond');
  285. // if (player) {
  286. // let account = player.account;
  287. // let pid = session.uid;
  288. // let uid = player.userId;
  289. // console.warn("请求得到外接小游戏的钻石 "+session.uid);
  290. // let url = "http://aa.bb.cc.com/StartGame/CalculateRateByPoint.aspx?action=xxxx&userid="+uid+"&pwd="+account+"&pid="+pid;
  291. // http.get(url, (res) => {
  292. // res.setEncoding('utf8');
  293. // let data = '';
  294. // res.on('data', (chunk) => {
  295. // console.warn("res.on('data' "+JSON.stringify(data)+" chunk "+JSON.stringify(chunk));
  296. // data += chunk;
  297. // let data2 = JSON.stringify(chunk);
  298. // console.warn("res.on('data222 ' "+data2);
  299. // let resJson = JSON.parse(chunk);
  300. // result.code = C.OK;
  301. // result.userid = resJson.userid;
  302. // console.warn("res.on('data333 ' "+JSON.stringify(result));
  303. // });
  304. // res.on('end', () => {
  305. // console.warn("res.on('end' "+JSON.stringify(data));
  306. // console.warn("res.on('end' result "+JSON.stringify(result));
  307. // });
  308. // }).on('error', (err) => {
  309. // console.warn(`Error: ${err.message}`);
  310. // });
  311. // player.diamond += 10;
  312. // yield player.saveAsync();
  313. // result.diamond = player.diamond;
  314. // }
  315. // console.warn("res.on('end' result "+JSON.stringify(result));
  316. return next(null, { code: C.OK, data: result});
  317. });
  318. // ts++得到绑定手机信息
  319. proto.getBindPhoneInfo = P.coroutine(function* (msg, session, next) {
  320. this.checkVersion2()
  321. // console.warn("???????????????????????/");
  322. if (!session.uid) {
  323. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  324. }
  325. let tel = "";
  326. let pwd = "";
  327. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'tel pwd');
  328. if (player) {
  329. tel = player.tel;
  330. pwd = player.pwd;
  331. }
  332. let list1 = [];
  333. for (var i = 0; i < this.wordList.length; i++) {
  334. list1[i] = i;
  335. }
  336. let list2 = _.shuffle(list1);
  337. let list3 = list2.splice(0, 6)
  338. let list4 = _.shuffle(list3);
  339. let list5 = list4.splice(0, 3)
  340. let allWords = "";
  341. for (var i = 0; i < list3.length; i++) {
  342. let ri = list3[i];
  343. allWords += this.wordList[ri];
  344. }
  345. let targetWords = "";
  346. for (var i = 0; i < list5.length; i++) {
  347. let ri = list5[i];
  348. targetWords += this.wordList[ri];
  349. }
  350. let data = {
  351. tel:tel,
  352. pwd:pwd,
  353. allWords:allWords,
  354. targetWords:targetWords
  355. }
  356. return next(null, { code: C.OK, data: data});
  357. });
  358. // ts++请求发送手机短信验证码
  359. proto.sendSMSCode = P.coroutine(function* (msg, session, next) {
  360. if (!session.uid) {
  361. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  362. }
  363. if (!msg.phoneStr || msg.phoneStr.length != 11) {
  364. return next(null, { code: C.ERROR, msg: 111 });//"手机号参数错误"
  365. }
  366. let phoneStr = msg.phoneStr
  367. if (!msg.targetWords || msg.targetWords.length != 3) {
  368. return next(null, { code: C.ERROR, msg: 112 });//"目标文字参数错误"
  369. }
  370. if (!msg.cliekedWords || msg.cliekedWords.length != 3) {
  371. return next(null, { code: C.ERROR, msg: 113 });//"点击文字参数错误"
  372. }
  373. if(msg.targetWords != msg.cliekedWords){
  374. return next(null, { code: C.ERROR, msg: 114 });//"点击文字和目标文字不匹配"
  375. }
  376. // 判断的是否是JSON字符串
  377. let getIsAJsonStr22 = function (str) {
  378. // console.warn("判断的是否是JSON字符串。 "+str);
  379. if (typeof str == 'string') {
  380. try {
  381. var obj = JSON.parse(str);
  382. if (typeof obj == 'object' && obj) {
  383. return true;
  384. } else {
  385. //不是就返回false
  386. return false;
  387. }
  388. }
  389. catch (e) {
  390. return false;
  391. }
  392. }
  393. return false;
  394. }
  395. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'tel pwd');
  396. if (player) {
  397. //把生成的验证码存入用户的pwd字段,用于待用户输入的验证码提交上来之后进行正确性验证
  398. let yzm = _.random(100000, 999999);
  399. player.pwd = ""+yzm;
  400. yield player.saveAsync();
  401. //下面是请求java的发送短信接口
  402. // console.warn("请求java的发送短信接口 ",phoneStr,yzm);
  403. let code = yzm;
  404. let phone = phoneStr;
  405. let key = "xxxxx"
  406. let time = Date.now();
  407. let str1 = ""+phone+key+code;
  408. let md51 = md5(str1).toUpperCase();
  409. let str2 = ""+md51+time;
  410. let md52 = md5(str2).toUpperCase();
  411. let sign = md52;
  412. let post_data={
  413. code: code,
  414. phone: phone,
  415. sign: sign,
  416. time: time
  417. };//请求数据
  418. let reqdata = JSON.stringify(post_data);
  419. let options = {
  420. hostname: 'aa.bb.com',
  421. port: '',
  422. path: '/sms/sendSms',
  423. method: 'POST',
  424. rejectUnauthorized: false,
  425. requestCert: true,
  426. headers: {
  427. 'Content-Type': 'Application/json',
  428. "Content-Length":reqdata.length
  429. }
  430. };
  431. var req = https.request(options, function (res) {
  432. });
  433. req.write(reqdata);
  434. req.on('response', function (response2) {
  435. // console.warn("请求到这里了???222 response2.headers "+JSON.stringify(response2.headers) );
  436. req.end();
  437. let body2 = "";
  438. response2.on('data', function (chunk) {
  439. body2 = chunk.toString();
  440. // console.warn("请求到这里了???555 chunk "+body2);
  441. if(!getIsAJsonStr22(body2)){
  442. console.error("接口返回值非json字符串。 "+body2);
  443. return next(null, { code: C.ERROR, msg: 115 });//"验证码发送失败"
  444. }
  445. let result = JSON.parse(body2)
  446. // console.warn("请求到这里了???56 chunk "+result.success);
  447. if(result.success){
  448. console.warn("发送短信验证码成功 "+JSON.stringify(result) );
  449. return next(null, { code: C.OK, data: result});
  450. }
  451. else{
  452. console.error("请求发送验证码出错了 "+body2);
  453. return next(null, { code: C.ERROR, msg: 115 });//"验证码发送失败"
  454. }
  455. // console.warn("这里都到返回值了222 ")
  456. });
  457. // console.warn("请求到这里了???666 body2 "+body2)
  458. });
  459. req.on('error', function (e) {
  460. req.end();
  461. console.error(new Error('request YZM error: ' + e.message));
  462. return next(null, { code: C.ERROR, msg: 116 });//"请求验证码失败"
  463. });
  464. }
  465. });
  466. // ts++设置绑定手机号
  467. proto.setBindPhone = P.coroutine(function* (msg, session, next) {
  468. if (!session.uid) {
  469. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  470. }
  471. if (!msg.phoneStr || msg.phoneStr.length != 11) {
  472. return next(null, { code: C.ERROR, msg: 111 });//"手机号参数错误"
  473. }
  474. let phoneStr = msg.phoneStr
  475. if (!msg.yzm || msg.yzm.length != 6) {
  476. return next(null, { code: C.ERROR, msg: 112 });//"验证码参数错误"
  477. }
  478. let yzm = msg.yzm
  479. var yPlayers = yield this.app.models.Player.findMongoAsync({ tel: phoneStr },'_id userId tel pwd');
  480. // console.warn("????? 设置绑定手机号 ",yPlayers.length,yPlayers[0]._id,session.uid);
  481. if (yPlayers.length > 1 || (yPlayers.length == 1 && yPlayers[0]._id != session.uid)){
  482. return next(null, { code: C.ERROR, msg: 117 });//"手机号已被绑定过"
  483. }
  484. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'userId tel pwd');
  485. if (player) {
  486. if(yzm != player.pwd) return next(null, { code: C.ERROR, msg: 113 });//"验证码数据错误"
  487. player.tel = phoneStr;
  488. // player.pwd = "";
  489. yield player.saveAsync();
  490. }
  491. yield this.hallLogic.setBindPhone(msg, session, next,player.userId)
  492. let data = {
  493. phoneStr:phoneStr
  494. }
  495. return next(null, { code: C.OK, data: data});
  496. });
  497. ////上面3个方法是大厅绑定手机号所需的方法,下面是手机号登陆时验证所输入的手机号进行短信验证
  498. // ts++得到绑定手机信息
  499. proto.getBindPhoneInfo2 = P.coroutine(function* (msg, session, next) {
  500. let list1 = [];
  501. for (var i = 0; i < this.wordList.length; i++) {
  502. list1[i] = i;
  503. }
  504. let list2 = _.shuffle(list1);
  505. let list3 = list2.splice(0, 6)
  506. let list4 = _.shuffle(list3);
  507. let list5 = list4.splice(0, 3)
  508. let allWords = "";
  509. for (var i = 0; i < list3.length; i++) {
  510. let ri = list3[i];
  511. allWords += this.wordList[ri];
  512. }
  513. let targetWords = "";
  514. for (var i = 0; i < list5.length; i++) {
  515. let ri = list5[i];
  516. targetWords += this.wordList[ri];
  517. }
  518. let data = {
  519. allWords:allWords,
  520. targetWords:targetWords
  521. }
  522. return next(null, { code: C.OK, data: data});
  523. });
  524. // ts++请求发送手机短信验证码
  525. proto.sendSMSCode2 = P.coroutine(function* (msg, session, next) {
  526. if (!msg.phoneStr || msg.phoneStr.length != 11) {
  527. return next(null, { code: C.ERROR, msg: 111 });//"手机号参数错误"
  528. }
  529. let phoneStr = msg.phoneStr
  530. if (!msg.targetWords || msg.targetWords.length != 3) {
  531. return next(null, { code: C.ERROR, msg: 112 });//"目标文字参数错误"
  532. }
  533. if (!msg.cliekedWords || msg.cliekedWords.length != 3) {
  534. return next(null, { code: C.ERROR, msg: 113 });//"点击文字参数错误"
  535. }
  536. if(msg.targetWords != msg.cliekedWords){
  537. return next(null, { code: C.ERROR, msg: 114 });//"点击文字和目标文字不匹配"
  538. }
  539. // 判断的是否是JSON字符串
  540. let getIsAJsonStr22 = function (str) {
  541. // if(1 == 1) return true;
  542. // console.warn("判断的是否是JSON字符串。 "+str);
  543. if (typeof str == 'string') {
  544. try {
  545. var obj = JSON.parse(str);
  546. if (typeof obj == 'object' && obj) {
  547. return true;
  548. } else {
  549. //不是就返回false
  550. return false;
  551. }
  552. }
  553. catch (e) {
  554. return false;
  555. }
  556. }
  557. return false;
  558. }
  559. //把生成的验证码存入用户的pwd字段,用于待用户输入的验证码提交上来之后进行正确性验证
  560. let yzm = _.random(100000, 999999);
  561. var tel = yield this.app.models.Tel.findByIdAsync(phoneStr, 'tel pwd bindTime');
  562. if (tel) {
  563. // if(tel.bindTime > 0) return next(null, { code: C.ERROR, msg: 117 });//"手机号已被绑定过"
  564. tel.pwd = ""+yzm;
  565. tel.bindTime = 0;
  566. yield tel.saveAsync();
  567. }
  568. else{
  569. // 手机号登录信息表,为了在登陆的时候带手机号参数上来
  570. var newTel = new this.app.models.Tel({
  571. _id: phoneStr,
  572. tel: phoneStr,
  573. pwd: ""+yzm,//
  574. bindTime: 0
  575. });
  576. yield newTel.saveAsync();
  577. }
  578. //下面是请求java的发送短信接口
  579. console.warn("请求java的发送短信接口1 ",phoneStr,yzm);
  580. let code = yzm;
  581. let phone = phoneStr;
  582. let key = "xxxxxxxx"
  583. let time = Date.now();
  584. let str1 = ""+phone+key+code;
  585. let md51 = md5(str1).toUpperCase();
  586. let str2 = ""+md51+time;
  587. let md52 = md5(str2).toUpperCase();
  588. let sign = md52;
  589. let post_data={
  590. code: code,
  591. phone: phone,
  592. sign: sign,
  593. time: time
  594. };//请求数据
  595. let reqdata = JSON.stringify(post_data);
  596. let options = {
  597. hostname: 'aa.bb.com',
  598. port: '',
  599. path: '/sms/sendSms',
  600. method: 'POST',
  601. rejectUnauthorized: false,
  602. requestCert: true,
  603. headers: {
  604. 'Content-Type': 'Application/json',
  605. "Content-Length":reqdata.length
  606. }
  607. };
  608. var req = https.request(options, function (res) {
  609. });
  610. req.write(reqdata);
  611. req.on('response', function (response2) {
  612. // console.warn("请求到这里了???222 response2.headers "+JSON.stringify(response2.headers) );
  613. req.end();
  614. let body2 = "";
  615. response2.on('data', function (chunk) {
  616. body2 = chunk.toString();
  617. // console.warn("请求到这里了???555 chunk "+body2);
  618. if(!getIsAJsonStr22(body2)){
  619. console.error("接口返回值非json字符串1。 "+body2);
  620. return next(null, { code: C.ERROR, msg: 115 });//"验证码发送失败"
  621. }
  622. let result = JSON.parse(body2)
  623. // console.warn("请求到这里了???56 chunk "+result.success);
  624. if(result.success){
  625. console.warn("发送短信验证码成功1 "+JSON.stringify(result) );
  626. return next(null, { code: C.OK, data: result});
  627. }
  628. else{
  629. console.error("请求发送验证码出错了1 "+body2);
  630. return next(null, { code: C.ERROR, msg: 115 });//"验证码发送失败"
  631. }
  632. // console.warn("这里都到返回值了222 ")
  633. });
  634. // console.warn("请求到这里了???666 body2 "+body2)
  635. });
  636. req.on('error', function (e) {
  637. req.end();
  638. console.error(new Error('request YZM error1: ' + e.message));
  639. return next(null, { code: C.ERROR, msg: 116 });//"请求验证码失败"
  640. });
  641. });
  642. // ts++设置绑定手机号
  643. proto.setBindPhone2 = P.coroutine(function* (msg, session, next) {
  644. if (!msg.phoneStr || msg.phoneStr.length != 11) {
  645. return next(null, { code: C.ERROR, msg: 111 });//"手机号参数错误"
  646. }
  647. let phoneStr = msg.phoneStr
  648. if (!msg.yzm || msg.yzm.length != 6) {
  649. return next(null, { code: C.ERROR, msg: 112 });//"验证码参数错误"
  650. }
  651. let yzm = msg.yzm
  652. var tels = yield this.app.models.Tel.findMongoAsync({ tel: phoneStr },'_id tel pwd bindTime');
  653. if (tels.length != 1){
  654. return next(null, { code: C.ERROR, msg: 117 });//"手机号已被绑定过"
  655. }
  656. else{
  657. if(yzm != tels[0].pwd) return next(null, { code: C.ERROR, msg: 113 });//"验证码数据错误"
  658. tels[0].bindTime = Date.now();
  659. yield tels[0].saveAsync();
  660. var yPlayers = yield this.app.models.Player.findMongoAsync({ tel: phoneStr },'_id userId tel pwd');
  661. if (yPlayers.length == 1){
  662. yPlayers[0].pwd = yzm;
  663. yield yPlayers[0].saveAsync();
  664. }
  665. }
  666. //给用户发邮件送绑定手机的奖品
  667. // yield this.hallLogic.setBindPhone(msg, session, next,player.userId)
  668. let data = {
  669. phoneStr:phoneStr,
  670. yzm:yzm
  671. }
  672. return next(null, { code: C.OK, data: data});
  673. });
  674. // ts++活动信息
  675. proto.activityInfo = P.coroutine(function* (msg, session, next) {
  676. if (!session.uid) {
  677. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  678. }
  679. // console.warn("require.cache "+require.cache.length+" " +require.cache.toString().replace("\r\n",""))
  680. // console.warn("require.cache000 "+typeof require.cache + " "+ typeof require.cache[require.resolve('../../../config/hallConfig')]);
  681. // delete require.cache[require.resolve('../../../config/hallConfig')];
  682. // let confActive = require('../../../config/hallConfig').active || {};
  683. // delete require.cache[require.resolve('./hallHandler')];
  684. // require('./hallHandler')
  685. this.checkVersion2();
  686. let confActive = confHall.active || {};
  687. // console.warn("活动配置内容aaa "+JSON.stringify(confActive));
  688. // console.warn("活动配置内容bbb "+typeof require.cache[require.resolve('./hallHandler')]);
  689. // console.warn("require.cache222 "+typeof require.cache + " "+ typeof require.cache[require.resolve('../../../config/hallConfig')]);
  690. // console.warn("require.cache333 "+require.cache[require.resolve('../../../config/hallConfig')]);
  691. // console.warn("require.cache333 "+JSON.stringify(require.cache[require.resolve('../../../config/hallConfig')]));
  692. // console.warn("require.cache222 "+JSON.stringify(require.cache));
  693. let spreadCount = 0;
  694. let spreadRebate = 0;
  695. let spreadRebateOut = 0;
  696. let diamond = 0;
  697. var player = yield this.app.models.Player.findByIdReadOnlyAsync(session.uid, 'diamond spreadCount spreadRebate spreadRebateOut');
  698. if (player) {
  699. spreadCount=player.spreadCount;
  700. spreadRebate=player.spreadRebate;
  701. spreadRebateOut=player.spreadRebateOut;
  702. diamond=player.diamond;
  703. }
  704. //人数
  705. let s1=3;
  706. let s2=6;
  707. let s3=9;
  708. let s4=12;
  709. let s5=15;
  710. //对就返利
  711. let r1=300;
  712. let r2=600;
  713. let r3=900;
  714. let r4=1200;
  715. let r5=1500;
  716. let activeInfoList = confActive.list || [];
  717. let xzdsjc = Date.now();
  718. let hdqjcz = 0;//活动期间充值
  719. let hdqjdj = 0;//活动期间完成对局数
  720. // let lcIsOpen = false;//累充送钻石活动是否开启
  721. // let ljdjIsOpen = false;//累计对局送钻石活动是否开启
  722. for (var i = 0; i < activeInfoList.length; i++) {
  723. let yxhdxx = activeInfoList[i];
  724. if(yxhdxx && yxhdxx.open && yxhdxx.startTime && yxhdxx.endTime) {
  725. if(xzdsjc >= yxhdxx.startTime && xzdsjc < yxhdxx.endTime){
  726. if(yxhdxx.type == 1) {
  727. s1 = yxhdxx.reachAndRewardInfo[0].reachCount;
  728. r1 = yxhdxx.reachAndRewardInfo[0].rewardCount;
  729. s2 = yxhdxx.reachAndRewardInfo[1].reachCount;
  730. r2 = yxhdxx.reachAndRewardInfo[1].rewardCount;
  731. s3 = yxhdxx.reachAndRewardInfo[2].reachCount;
  732. r3 = yxhdxx.reachAndRewardInfo[2].rewardCount;
  733. s4 = yxhdxx.reachAndRewardInfo[3].reachCount;
  734. r4 = yxhdxx.reachAndRewardInfo[3].rewardCount;
  735. s5 = yxhdxx.reachAndRewardInfo[4].reachCount;
  736. r5 = yxhdxx.reachAndRewardInfo[4].rewardCount;
  737. }
  738. if(yxhdxx.type == 2) {
  739. // lcIsOpen = true;
  740. var opts = {
  741. paystate: 1,//支付状态 0未支付 1成功
  742. playerId: session.uid,
  743. time: { $gte: yxhdxx.startTime, $lt: yxhdxx.endTime }
  744. };
  745. var list = yield this.app.models.PayRecord.findMongoAsync(opts, 'paydiamond payreward total_fee');//
  746. for (var j = 0; j < list.length; j++) {
  747. // hdqjcz += list[i].paydiamond;
  748. // hdqjcz += list[i].payreward;
  749. hdqjcz += list[j].total_fee/100;
  750. }
  751. //下面是从钻石变更记录数据表中读取任务的是否已领取的情况
  752. var cxlqopts = {
  753. playerId: session.uid,
  754. dType: 13,//活动类型
  755. registerTime: { $gte: yxhdxx.startTime, $lt: yxhdxx.endTime }
  756. };
  757. var lqqklist = yield this.app.models.DiamondRecord.findMongoAsync(cxlqopts, 'dType dSwap tableId ');//
  758. let lcszylqxbs = [];//13活动期间累充送钻石已经领取下标数组
  759. for (var z = 0; z < lqqklist.length; z++) {
  760. lcszylqxbs[lcszylqxbs.length] = Number(lqqklist[z].tableId)
  761. }
  762. // console.warn("活动领取情况lc "+JSON.stringify(lqqklist)+" 活动累充已领下标 "+JSON.stringify(lcszylqxbs));
  763. for (var j = 0; j < activeInfoList[i].reachAndRewardInfo.length; j++) {
  764. activeInfoList[i].reachAndRewardInfo[j].isylq = lcszylqxbs.indexOf(j) != -1;
  765. }
  766. }
  767. if(yxhdxx.type == 3) {
  768. // ljdjIsOpen = true;
  769. var opts = {
  770. "users._id": session.uid,
  771. stime: { $gte: yxhdxx.startTime, $lt: yxhdxx.endTime }
  772. };
  773. // logger.warn("hall countMongoAsync users._id111--------" + session.uid );
  774. hdqjdj = yield this.app.models.FHMJTables.countMongoAsync(opts);
  775. //下面是从钻石变更记录数据表中读取任务的是否已领取的情况
  776. var cxlqopts = {
  777. playerId: session.uid,
  778. dType: 14,//活动类型
  779. registerTime: { $gte: yxhdxx.startTime, $lt: yxhdxx.endTime }
  780. };
  781. var lqqklist = yield this.app.models.DiamondRecord.findMongoAsync(cxlqopts, 'dType dSwap tableId ');//
  782. let zjszylqxbs = [];//14活动期间组局领钻石已经领取下标数组
  783. for (var z = 0; z < lqqklist.length; z++) {
  784. zjszylqxbs[zjszylqxbs.length] = Number(lqqklist[z].tableId)
  785. }
  786. // console.warn("活动领取情况zj "+JSON.stringify(lqqklist)+" 活动组局已领下标 "+JSON.stringify(zjszylqxbs));
  787. for (var j = 0; j < activeInfoList[i].reachAndRewardInfo.length; j++) {
  788. activeInfoList[i].reachAndRewardInfo[j].isylq = zjszylqxbs.indexOf(j) != -1;
  789. }
  790. }
  791. }
  792. }
  793. }
  794. // if(lcIsOpen){
  795. // var opts = {
  796. // paystate: 0,//支付状态 0未支付 1成功
  797. // playerId: session.uid,
  798. // time: { $gte: 1, $lt: 9999999 }
  799. // };
  800. // var onlineCount = yield app.models.Player.countMongoAsync(opts);
  801. // }
  802. let data = {
  803. hdqjcz: hdqjcz,
  804. hdqjdj: hdqjdj,
  805. nowTime: xzdsjc,
  806. activeInfoList:activeInfoList,
  807. diamond: diamond,
  808. spreadCount: spreadCount,
  809. spreadRebate: spreadRebate,
  810. spreadRebateOut: spreadRebateOut,
  811. s1:s1,
  812. s2:s2,
  813. s3:s3,
  814. s4:s4,
  815. s5:s5,
  816. r1:r1,
  817. r2:r2,
  818. r3:r3,
  819. r4:r4,
  820. r5:r5
  821. }
  822. return next(null, { code: C.OK, data: data});
  823. });
  824. // ts++活动领取处理
  825. proto.activityIn = P.coroutine(function* (msg, session, next) {
  826. if (!session.uid) {
  827. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  828. }
  829. let spreadCount = 0;
  830. let spreadRebate = 0;
  831. let spreadRebateOut = 0;
  832. let diamond = 0;
  833. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'diamond spreadCount spreadRebate spreadRebateOut');
  834. if (player) {
  835. spreadCount=player.spreadCount;
  836. spreadRebate=player.spreadRebate;
  837. spreadRebateOut=player.spreadRebateOut;
  838. diamond = player.diamond;
  839. if (spreadRebate>0) {
  840. let diamondSource = diamond;
  841. let diamondNew = diamond+spreadRebate;
  842. player.spreadRebate = 0;
  843. player.spreadRebateOut += spreadRebate;
  844. player.diamond += spreadRebate;
  845. yield player.saveAsync();
  846. // 钻石记录
  847. var diamondrecord = new this.app.models.DiamondRecord({
  848. _id: uuid.v1(),
  849. playerId: session.uid,
  850. dType: 6,//活动奖励
  851. dSource: diamondSource,
  852. dSwap: spreadRebate,
  853. dNow: diamondNew
  854. });
  855. yield diamondrecord.saveAsync();
  856. diamond += spreadRebate;
  857. spreadRebateOut += spreadRebate;
  858. spreadRebate=0;
  859. }
  860. }
  861. return next(null, { code: C.OK, data: { diamond: diamond, spreadCount: spreadCount, spreadRebate: spreadRebate, spreadRebateOut: spreadRebateOut } });
  862. });
  863. // ts++其他活动领取处理(比如活动期间的,累充,累计对局,回归用户每日免费领取,回归用户充值送钻等等)
  864. proto.otherActivityIn = P.coroutine(function* (msg, session, next) {
  865. if (!session.uid) {
  866. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  867. }
  868. let type = Number(msg.type) || 0;
  869. if(!(type && type > 0) ){
  870. return next(null, { code: C.ERROR, msg: "type参数错误"+type });
  871. }
  872. let index = Number(msg.index)
  873. if(type == 2 || type == 3){
  874. if(!(index >= 0 )){
  875. return next(null, { code: C.ERROR, msg: "index参数错误"+index });
  876. }
  877. }
  878. let xzdsjc = Date.now();
  879. let confActive = confHall.active || {};
  880. let activeInfoList = confActive.list || [];
  881. // console.warn("其他活动领取处理 活动配置内容 "+JSON.stringify(confActive));
  882. let activeData = null;
  883. // console.warn("其他活动领取处理 activeInfoList.length "+activeInfoList.length+" type "+type+" index "+index);
  884. for (var i = 0; i < activeInfoList.length; i++) {
  885. let yxhdxx = activeInfoList[i];
  886. if(yxhdxx && yxhdxx.open && yxhdxx.startTime && yxhdxx.endTime) {
  887. if(xzdsjc >= yxhdxx.startTime && xzdsjc < yxhdxx.endTime){
  888. if(yxhdxx.type == type) {
  889. activeData = yxhdxx;
  890. break;
  891. }
  892. }
  893. }
  894. }
  895. if(!activeData){
  896. return next(null, { code: C.ERROR, msg: "目前不在活动期间内"+type });
  897. }
  898. let lzType = 0;//领钻类型
  899. if(type == 2) lzType = 13;//13活动期间累充送钻石
  900. else if(type == 3) lzType = 14;//14活动期间组局领钻
  901. if(lzType > 0 && index != 10000){//单项领取,一键领取不在这里进行处理
  902. var opts = {
  903. playerId: session.uid,
  904. dType: lzType,//活动类型
  905. tableId: index+"",//活动下标
  906. registerTime: { $gte: activeData.startTime, $lt: activeData.endTime }
  907. };
  908. var lqcs = yield this.app.models.DiamondRecord.countMongoAsync(opts);
  909. // console.warn("该活动的领取次数 "+lqcs)
  910. if(lqcs > 0) return next(null, { code: C.ERROR, msg: "已经领取过" });
  911. }
  912. let klqList = [];//可领取列表
  913. let addDimand = 0;
  914. if(type == 1){
  915. //领取活动期间邀新送钻
  916. }
  917. else if(type == 2){
  918. //领取活动期间累充送钻
  919. var opts = {
  920. paystate: 1,//支付状态 0未支付 1成功
  921. playerId: session.uid,
  922. time: { $gte: activeData.startTime, $lt: activeData.endTime }
  923. };
  924. let hdqjcz = 0;
  925. var list = yield this.app.models.PayRecord.findMongoAsync(opts, 'paydiamond payreward ');//
  926. for (var i = 0; i < list.length; i++) {
  927. // hdqjcz += list[i].paydiamond;
  928. // hdqjcz += list[i].payreward;
  929. hdqjcz += list[i].total_fee/100;
  930. }
  931. if(index == 10000){
  932. //下面是从钻石变更记录数据表中读取任务的是否已领取的情况
  933. var cxlqopts = {
  934. playerId: session.uid,
  935. dType: 13,//活动类型
  936. registerTime: { $gte: activeData.startTime, $lt: activeData.endTime }
  937. };
  938. var lqqklist = yield this.app.models.DiamondRecord.findMongoAsync(cxlqopts, 'dType dSwap tableId ');//
  939. let lcszylqxbs = [];//13活动期间累充送钻石已经领取下标数组
  940. for (var z = 0; z < lqqklist.length; z++) {
  941. lcszylqxbs[lcszylqxbs.length] = Number(lqqklist[z].tableId)
  942. }
  943. for (var i = 0; i < activeData.reachAndRewardInfo.length; i++) {
  944. let targetCount = activeData.reachAndRewardInfo[i].reachCount;//任务的目标值
  945. // console.warn("活动期间累计充值: 一键领取 "+hdqjcz + " 要求充值 "+targetCount);
  946. let iswlq = lcszylqxbs.indexOf(i) == -1;//是否未领取
  947. if(iswlq && hdqjcz >= targetCount){//已达成而且未领取
  948. let rewardType = activeData.reachAndRewardInfo[i].rewardType
  949. if(rewardType == 1){
  950. addDimand += activeData.reachAndRewardInfo[i].rewardCount
  951. klqList[klqList.length] = {
  952. dSwap: activeData.reachAndRewardInfo[i].rewardCount,
  953. tableId: i+"",
  954. }
  955. }
  956. }
  957. }
  958. }
  959. else{
  960. let targetCount = activeData.reachAndRewardInfo[index].reachCount;//任务的目标值
  961. // console.warn("活动期间累计充值: "+hdqjcz + " 要求充值 "+targetCount);
  962. if(hdqjcz >= targetCount){
  963. let rewardType = activeData.reachAndRewardInfo[index].rewardType
  964. if(rewardType == 1){
  965. addDimand = activeData.reachAndRewardInfo[index].rewardCount
  966. }
  967. }
  968. else{
  969. return next(null, { code: C.ERROR, msg: "该项任务未达成2" });
  970. }
  971. }
  972. }
  973. else if(type == 3){
  974. //领取活动期间累计组局领钻
  975. let hdqjdj = 0;
  976. var opts = {
  977. "users._id": session.uid,
  978. stime: { $gte: activeData.startTime, $lt: activeData.endTime }
  979. };
  980. // logger.warn("hall countMongoAsync users._id222--------" + session.uid );
  981. hdqjdj = yield this.app.models.FHMJTables.countMongoAsync(opts);
  982. if(index == 10000){
  983. //下面是从钻石变更记录数据表中读取任务的是否已领取的情况
  984. var cxlqopts = {
  985. playerId: session.uid,
  986. dType: 14,//活动类型
  987. registerTime: { $gte: activeData.startTime, $lt: activeData.endTime }
  988. };
  989. var lqqklist = yield this.app.models.DiamondRecord.findMongoAsync(cxlqopts, 'dType dSwap tableId ');//
  990. let zjszylqxbs = [];//14活动期间组局领钻石已经领取下标数组
  991. for (var z = 0; z < lqqklist.length; z++) {
  992. zjszylqxbs[zjszylqxbs.length] = Number(lqqklist[z].tableId)
  993. }
  994. // console.warn("活动期间累计对局数一键领取 hdqjdj "+hdqjdj + " zjszylqxbs "+JSON.stringify(zjszylqxbs));
  995. for (var i = 0; i < activeData.reachAndRewardInfo.length; i++) {
  996. let iswlq = zjszylqxbs.indexOf(i) == -1;//是否未领取
  997. let targetCount = activeData.reachAndRewardInfo[i].reachCount;//任务的目标值
  998. // console.warn("活动期间累计对局数一键领取 iswlq "+iswlq + " targetCount "+targetCount )
  999. if(iswlq && hdqjdj >= targetCount){
  1000. let rewardType = activeData.reachAndRewardInfo[i].rewardType
  1001. if(rewardType == 1){
  1002. addDimand += activeData.reachAndRewardInfo[i].rewardCount
  1003. klqList[klqList.length] = {
  1004. dSwap: activeData.reachAndRewardInfo[i].rewardCount,
  1005. tableId: i+"",
  1006. }
  1007. }
  1008. }
  1009. }
  1010. // console.warn("活动期间累计对局数一键领取 : "+hdqjdj + " klqList "+JSON.stringify(klqList));
  1011. }
  1012. else{
  1013. let targetCount = activeData.reachAndRewardInfo[index].reachCount;//任务的目标值
  1014. // console.warn("活动期间累计对局数: "+hdqjdj + " 要求对局数 "+targetCount);
  1015. if(hdqjdj >= targetCount){
  1016. let rewardType = activeData.reachAndRewardInfo[index].rewardType
  1017. if(rewardType == 1){
  1018. addDimand = activeData.reachAndRewardInfo[index].rewardCount
  1019. }
  1020. }
  1021. else{
  1022. return next(null, { code: C.ERROR, msg: "该项任务未达成3" });
  1023. }
  1024. }
  1025. }
  1026. else if(type == 4){
  1027. //领取活动期间回归每日免费领钻
  1028. }
  1029. else if(type == 5){
  1030. //领取活动期间回归每日首充送钻
  1031. }
  1032. let getGoodsList = [];
  1033. // console.warn("活动期间 addDimand : "+addDimand)
  1034. if(addDimand > 0){
  1035. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'diamond');
  1036. let yxzss = player.diamond;//原先钻石数
  1037. player.diamond += addDimand;
  1038. yield player.saveAsync();
  1039. // 钻石记录
  1040. /* dType:类型 1为注册2为充值3坐下4退分5礼物6活动7后台 8同步转出 9同步转入10签到11每日奖励12分享赠送,
  1041. 13活动期间累充送钻石,14活动期间组局领钻,15活动期间回归用户每日领钻,
  1042. 16活动期间回归用户每日充值奖励钻石,只有11没有统计
  1043. */
  1044. if(index == 10000){
  1045. if(lzType > 0 && klqList.length > 0){
  1046. let dimandChangeList = [];
  1047. let yxzss2 = yxzss;
  1048. for (var i = 0; i < klqList.length; i++) {
  1049. let zssItem = [yxzss2,yxzss2+klqList[i].dSwap]
  1050. dimandChangeList[dimandChangeList.length] = zssItem;
  1051. yxzss2 += klqList[i].dSwap
  1052. }
  1053. for (var i = 0; i < klqList.length; i++) {
  1054. var diamondrecord = new this.app.models.DiamondRecord({
  1055. _id: uuid.v1(),
  1056. playerId: session.uid,
  1057. dType: lzType,//后台
  1058. dSource: dimandChangeList[i][0],
  1059. dSwap: klqList[i].dSwap,
  1060. dNow: dimandChangeList[i][1],
  1061. tableId: klqList[i].tableId,
  1062. });
  1063. yield diamondrecord.saveAsync();
  1064. }
  1065. }
  1066. }
  1067. else{
  1068. if(lzType > 0){
  1069. var diamondrecord = new this.app.models.DiamondRecord({
  1070. _id: uuid.v1(),
  1071. playerId: session.uid,
  1072. dType: lzType,//后台
  1073. dSource: yxzss,
  1074. dSwap: addDimand,
  1075. dNow: player.diamond,
  1076. tableId: index+"",
  1077. });
  1078. yield diamondrecord.saveAsync();
  1079. }
  1080. }
  1081. getGoodsList[getGoodsList.length] = {
  1082. rewardT: 1,//钻石
  1083. rewardC: addDimand
  1084. }
  1085. }
  1086. let returndata = {
  1087. type: type,
  1088. index: index,
  1089. getGoodsList: getGoodsList,
  1090. }
  1091. return next(null, { code: C.OK,data:returndata });
  1092. });
  1093. // 签到信息
  1094. proto.signInfo = P.coroutine(function* (msg, session, next) {
  1095. if (!session.uid) {
  1096. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1097. }
  1098. this.checkVersion2();
  1099. var today = new Date();
  1100. today.setHours(0);
  1101. today.setMinutes(0);
  1102. today.setSeconds(0);
  1103. today.setMilliseconds(0);
  1104. var signinfo = yield this.app.models.SignInfo.findByIdAsync(session.uid);
  1105. if (!signinfo) {
  1106. signinfo = new this.app.models.SignInfo({ _id: session.uid });
  1107. yield signinfo.saveAsync();
  1108. } else if (signinfo.lastTime < today.getTime() - 86400000) {
  1109. signinfo.keep = 0;
  1110. yield signinfo.saveAsync();
  1111. } else if (signinfo.keep >= 7 && signinfo.lastTime < today.getTime()) {
  1112. signinfo.keep = 0;
  1113. yield signinfo.saveAsync();
  1114. }
  1115. var hasSign = signinfo.lastTime < today.getTime() ? 0 : 1;
  1116. var hasShare = signinfo.shareTime < today.getTime() ? 0 : 1;
  1117. let signAwards = confHall.signAwards || {};
  1118. let data = {
  1119. keep: signinfo.keep,
  1120. signAwards:signAwards,
  1121. hasSign: hasSign,
  1122. hasShare: hasShare
  1123. }
  1124. return next(null, { code: C.OK, data:data });
  1125. });
  1126. // 签到处理
  1127. proto.signIn = P.coroutine(function* (msg, session, next) {
  1128. if (!session.uid) {
  1129. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1130. }
  1131. var today = new Date();
  1132. today.setHours(0);
  1133. today.setMinutes(0);
  1134. today.setSeconds(0);
  1135. today.setMilliseconds(0);
  1136. var signinfo = yield this.app.models.SignInfo.findByIdAsync(session.uid, '-shareTime');
  1137. if (!signinfo) {
  1138. signinfo = new this.app.models.SignInfo({ _id: session.uid });
  1139. } else if (signinfo.lastTime < today.getTime() - 86400000) {
  1140. signinfo.keep = 0;
  1141. } else if (signinfo.keep >= 7 && signinfo.lastTime < today.getTime()) {
  1142. signinfo.keep = 0;
  1143. }
  1144. if (signinfo.lastTime >= today.getTime()) {
  1145. return next(null, { code: C.FAILD, msg: C.HALL_ALREADY_SIGN });
  1146. }
  1147. signinfo.keep += 1;
  1148. signinfo.lastTime = Date.now();
  1149. yield signinfo.saveAsync();
  1150. let signAwards = confHall.signAwards || {};
  1151. var diamond = signAwards[signinfo.keep] || 0;
  1152. let diamondNew = 0;
  1153. if (diamond > 0) {
  1154. let player = yield this.app.models.Player.findByIdAsync(session.uid, 'diamond userId');
  1155. // player.diamond += diamond;
  1156. // diamondNew = player.diamond+diamond;
  1157. // yield player.saveAsync();
  1158. // // 钻石记录
  1159. // var diamondrecord = new this.app.models.DiamondRecord({
  1160. // _id: uuid.v1(),
  1161. // playerId: session.uid,
  1162. // dType: 10,//签到
  1163. // dSource: player.diamond - diamond,
  1164. // dSwap: diamond,
  1165. // dNow: player.diamond
  1166. // });
  1167. // yield diamondrecord.saveAsync();
  1168. //上面是通过恭喜获得直接领取下面是签到之后钻石通过邮件给玩家发放
  1169. yield this.lconfigCommon.senMailToPlayer(session.uid,player.userId,13,13,1,1,diamond,"sign");
  1170. let signrecord = new this.app.models.SignRecord({ _id: uuid.v1(), uid: session.uid, diamond: diamond });
  1171. yield signrecord.saveAsync();
  1172. }
  1173. return next(null, { code: C.OK, diamond: diamond,diamondNew:diamondNew });
  1174. });
  1175. // 实名认证
  1176. proto.shiMingRenZheng = P.coroutine(function* (msg, session, next) {
  1177. if (!session.uid) {
  1178. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1179. }
  1180. if (!msg.name && !msg.cardId) {
  1181. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  1182. }
  1183. if (msg.name.length <= 0 || msg.cardId.length <= 0) {
  1184. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  1185. }
  1186. // console.warn("使命认证传上来的 name "+msg.name+" cardId "+msg.cardId);
  1187. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'smName smCardId');
  1188. if (player) {
  1189. player.smName = msg.name;
  1190. player.smCardId = msg.cardId;
  1191. yield player.saveAsync();
  1192. }
  1193. let data = {
  1194. name: msg.name,
  1195. cardId: msg.cardId
  1196. }
  1197. return next(null, { code: C.OK, data: data });
  1198. });
  1199. // 2020国庆签到和邀请新人任务完成信息
  1200. proto.activeSignInfo = P.coroutine(function* (msg, session, next) {
  1201. if (!session.uid) {
  1202. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1203. }
  1204. var uid = session.uid;
  1205. var acType = parseInt(msg.acType)||0;
  1206. let startTime = 1601481600000;////20201001零点的时间戳,用来查询数据库
  1207. let endTime = startTime + 86400000*8;////20201001这天截止的时间戳
  1208. let wcqk = [];////活动期间完成情况
  1209. if(acType == 1) wcqk = [[0,2],[0,2],[0,2],[0,2],[0,2],[0,2],[0,2],[0,2]];//[已完成,任务总局数]
  1210. if(acType == 2){
  1211. wcqk = [[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]];//[完成任务人数,总奖励]
  1212. uid = parseInt(msg.uid)||0 ;//+ '';
  1213. }
  1214. var opts = { stime: { $gte: startTime, $lt: endTime },type: { $gte: acType, $lt: acType+1 }};
  1215. opts['rid'] = uid;
  1216. var list = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts, 'totalfee type gameCount stime succState', { sort: { stime: 1 } });//
  1217. // console.warn("2020国庆签到和邀请新人任务完成信息------------------length",list.length,uid,acType,msg.acType);
  1218. let startTime2 = 1601481600000;////20201001零点的时间戳,用来当天的完成情况
  1219. let endTime2 = startTime + 86400000;////20201001这天截止的时间戳
  1220. let rwzjl = 0;////任务总奖励
  1221. let index = 0;
  1222. for (let i = 0; i < list.length; ++i) {
  1223. if(acType == 1 && list[i].type == 1){////国庆签到
  1224. index = Math.floor((list[i].stime-startTime)/86400000);////今天是活动的第几天
  1225. wcqk[index][0] = list[i].gameCount;
  1226. wcqk[index][1] = 2;
  1227. if(list[i].succState){
  1228. rwzjl += list[i].totalfee;
  1229. }
  1230. }
  1231. else if(acType == 2 && list[i].type == 2){////国庆邀请
  1232. if(list[i].succState){
  1233. index = Math.floor((list[i].stime-startTime)/86400000);////今天是活动的第几天
  1234. wcqk[index][0]++;////这天被自己邀请的人完成任务的人数
  1235. wcqk[index][1]+=list[i].totalfee;////这天被自己邀请的人完成任务的奖励总额
  1236. rwzjl += list[i].totalfee;
  1237. }
  1238. }
  1239. }
  1240. let jlffqk = 0;////0:未领取,1已领取,2已发放
  1241. var opts2 = {type: { $gte: acType, $lt: acType+1 }};
  1242. opts2['rid'] = session.uid;
  1243. var list2 = yield this.app.models.ActiveReceiveRecord.findMongoAsync(opts2, 'type payState', { sort: { time: 1 } });//
  1244. if(list2.length > 0){
  1245. if(list2[0].payState == 1) jlffqk = 1;
  1246. else jlffqk = 2;
  1247. }
  1248. let jtshddjt = Math.ceil((Date.now()-startTime)/86400000);////今天是活动的第几天
  1249. let data = {
  1250. rwzjl: rwzjl,
  1251. wcqk: wcqk,
  1252. acType: acType,
  1253. jlffqk: jlffqk,
  1254. jtshddjt: jtshddjt
  1255. }
  1256. return next(null, { code: C.OK, data: data });
  1257. });
  1258. // 得到该日2020国庆邀请新人该日任务的详细信息
  1259. proto.getActiveYQXQ = P.coroutine(function* (msg, session, next) {
  1260. if (!session.uid) {
  1261. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1262. }
  1263. var uid = session.uid;
  1264. var acType = parseInt(msg.acType)||0;
  1265. if(acType == 2){
  1266. uid = parseInt(msg.uid)||0 ;
  1267. }
  1268. var dayIndex = parseInt(msg.dayIndex)||0;////查询活动日期的下标
  1269. let startTime = 1601481600000 + 86400000*dayIndex;////20201001零点的时间戳,用来查询数据库
  1270. let endTime = startTime + 86400000;////20201001这天截止的时间戳
  1271. let wcqk = [];////活动期间完成情况
  1272. var opts = { stime: { $gte: startTime, $lt: endTime },type: { $gte: acType, $lt: acType+1 }};
  1273. opts['rid'] = uid;
  1274. var list = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts, 'rewardtype totalfee type sname suid gameCount succtime succState', { sort: { stime: 1 } });//
  1275. // console.warn("2020国庆签到和邀请新人任务完成信息------------------length",list.length,uid,acType,msg.acType,dayIndex);
  1276. for (let i = 0; i < list.length; ++i) {
  1277. if(acType == 2 && list[i].type == 2){////国庆邀请
  1278. if(list[i].succState){
  1279. let item = {
  1280. rewardtype: list[i].rewardtype,
  1281. totalfee: list[i].totalfee,
  1282. sname: list[i].sname,
  1283. suid: list[i].suid,
  1284. succtime: list[i].succtime
  1285. }
  1286. wcqk[wcqk.length] = item;
  1287. }
  1288. }
  1289. }
  1290. let jtshddjt = dayIndex + 1;//Math.ceil((Date.now()-startTime)/86400000);////今天是活动的第几天
  1291. let data = {
  1292. wcqk: wcqk,
  1293. acType: acType,
  1294. jtshddjt: jtshddjt
  1295. }
  1296. return next(null, { code: C.OK, data: data });
  1297. });
  1298. // 2020国庆签到和邀请新人任务领取奖励
  1299. proto.activeSignLQJL = P.coroutine(function* (msg, session, next) {
  1300. if (!session.uid) {
  1301. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1302. }
  1303. var uid = session.uid;
  1304. var acType = parseInt(msg.acType)||0;
  1305. if(acType == 2){
  1306. uid = parseInt(msg.uid)||0 ;//+ '';
  1307. }
  1308. let startTime = 1601481600000;////20201001零点的时间戳,用来查询数据库
  1309. let endTime = startTime + 86400000*8;////20201001这天截止的时间戳
  1310. if (Date.now() < endTime) {
  1311. return next(null, { code: C.ERROR, msg: "请您活动结束之后统一领取。" });
  1312. }
  1313. var opts2 = {type: { $gte: acType, $lt: acType+1 }};
  1314. opts2['rid'] = session.uid;
  1315. var list2 = yield this.app.models.ActiveReceiveRecord.findMongoAsync(opts2, 'type payState', { sort: { time: 1 } });//
  1316. // console.warn("2020国庆签到和邀请新人任务领取奖励------------------length",list2.length,uid,acType,msg.acType);
  1317. if(list2.length > 0){
  1318. if(list2[0].payState == 1) return next(null, { code: C.ERROR, msg: "当前活动您的奖励正在等待发放" });
  1319. else return next(null, { code: C.ERROR, msg: "当前活动您的奖励已发放" });
  1320. }
  1321. var opts = { stime: { $gte: startTime, $lt: endTime },type: { $gte: acType, $lt: acType+1 }};
  1322. opts['rid'] = uid;
  1323. var list = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts, 'rid suid rewardtype totalfee type succtime succState', { sort: { succtime: 1 } });//
  1324. // console.warn("2020国庆签到和邀请新人任务领取奖励------------------length",list.length,uid,acType,msg.acType);
  1325. if(list.length == 0) return next(null, { code: C.ERROR, msg: "当前活动您没有可领取的奖励" });
  1326. let rwzjl = 0;////任务总奖励
  1327. let retype = 0;// 奖励类型
  1328. let ruid = 0;// 此条奖励领取的玩家userId
  1329. for (let i = 0; i < list.length; ++i) {
  1330. if(list[i].succState && list[i].type == acType){////该活动的所有记录
  1331. rwzjl += list[i].totalfee;
  1332. retype = list[i].rewardtype;
  1333. if(ruid == 0){
  1334. if(acType == 1) ruid = list[i].suid;////国庆签到
  1335. else if(acType == 2) ruid = parseInt(list[i].rid);////国庆邀请
  1336. }
  1337. }
  1338. }
  1339. var activereciverec = new this.app.models.ActiveReceiveRecord({
  1340. _id: uuid.v1(), // UUID
  1341. rewardtype: retype, // 奖励类型,0红包
  1342. type: acType, //活动类型:1国庆签到2国庆邀请
  1343. rid: session.uid, // 此条奖励领取的玩家id
  1344. ruid: ruid, // 此条奖励领取的玩家userId
  1345. outSwap: rwzjl, // 领取金额
  1346. totalFee: 0, // 发放金额
  1347. payState: 1, // 支付状态 1为未支付 2人工支付 3支付成功
  1348. });
  1349. yield activereciverec.saveAsync();
  1350. let jtshddjt = Math.ceil((Date.now()-startTime)/86400000);////今天是活动的第几天
  1351. let jlffqk = 1;////0:未领取,1已领取,2已发放
  1352. let data = {
  1353. acType: acType,
  1354. jlffqk: jlffqk,
  1355. jtshddjt: jtshddjt
  1356. }
  1357. return next(null, { code: C.OK, data: data });
  1358. });
  1359. // 查询钻石充值赠送
  1360. proto.getPayGiven = P.coroutine(function* (msg, session, next) {
  1361. if (!session.uid) {
  1362. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1363. }
  1364. var uid = session.uid;
  1365. let total_fee = parseInt(msg.total_fee) || 0;
  1366. // delete require.cache[require.resolve('../../../../http/conf.json')];
  1367. let conf2 = require('../../../../http/conf.json');
  1368. let giveList = conf2.give_diamonds || {};
  1369. let diamondsList = conf2.pay_diamonds || {};
  1370. let RMBData = conf2.pay_RMB_Fen || {};
  1371. let RMBList = [];
  1372. for (let item in RMBData) {
  1373. RMBList.push(RMBData[item]);
  1374. }
  1375. var value2 = giveList[total_fee];
  1376. //下面是玩家每日充值上限逻辑
  1377. // let wjsx0 = yield this.app.models.PayLimit.findByIdReadOnlyAsync("quanjutop", 'paytop paytotal dataTime');
  1378. // if (wjsx0){
  1379. // wjsx0.removeAsync();
  1380. // console.warn("删除quanjutop");
  1381. // }
  1382. // let wjsx1 = yield this.app.models.PayLimit.findByIdReadOnlyAsync("2abnnnnnn12a@my2019", 'paytop paytotal dataTime');
  1383. // if (wjsx1){
  1384. // wjsx1.removeAsync();
  1385. // console.warn("删除12a");
  1386. // }
  1387. // let wjsx2 = yield this.app.models.PayLimit.findByIdReadOnlyAsync("2abnnnnnn12b@my2019", 'paytop paytotal dataTime');
  1388. // if (wjsx2){
  1389. // wjsx2.removeAsync();
  1390. // console.warn("删除12b");
  1391. // }
  1392. let jrzcz = 0;//今日总充值
  1393. let jrczsx = 50000;//今日充值上限
  1394. var startTime = this.lconfigCommon.getTodaySJC();
  1395. let wjsx = yield this.app.models.PayLimit.findByIdReadOnlyAsync(uid, 'paytop paytotal dataTime');
  1396. if (wjsx) {
  1397. if (startTime == wjsx.dataTime) {
  1398. jrzcz = wjsx.paytotal;//今日总充值
  1399. }
  1400. if (wjsx.paytop >= 0) {
  1401. jrczsx = wjsx.paytop;//玩家上限
  1402. }
  1403. else{
  1404. let qjsx = yield this.app.models.PayLimit.findByIdReadOnlyAsync('quanjutop', 'paytop');
  1405. if (qjsx) {
  1406. jrczsx = qjsx.paytop;//全局上限
  1407. }
  1408. }
  1409. }
  1410. else{
  1411. var endTime = startTime + 86400000;
  1412. var opts = { time: { $gte: startTime, $lt: endTime },playerId: uid, paystate: { $gte: 1 }};
  1413. var list = yield this.app.models.PayRecord.findMongoAsync(opts, 'total_fee');
  1414. for (let i = 0; i < list.length; ++i) {
  1415. jrzcz += list[i].total_fee;
  1416. }
  1417. let qjsx = yield this.app.models.PayLimit.findByIdReadOnlyAsync('quanjutop', 'paytop');
  1418. if (qjsx) {
  1419. jrczsx = qjsx.paytop;//全局上限
  1420. }
  1421. else{
  1422. var newqjsx = new this.app.models.PayLimit({
  1423. _id: 'quanjutop',
  1424. userId: 1,
  1425. name: '全局充值上限',
  1426. paytop: 50000,
  1427. paytotal: 0,
  1428. dataTime: startTime,
  1429. });
  1430. yield newqjsx.saveAsync();
  1431. jrczsx = newqjsx.paytop;
  1432. }
  1433. var newwjsx = new this.app.models.PayLimit({
  1434. _id: uid,
  1435. userId: 0,
  1436. name: '',
  1437. paytop: -1,
  1438. paytotal: jrzcz,
  1439. dataTime: startTime,
  1440. });
  1441. yield newwjsx.saveAsync();
  1442. }
  1443. // console.warn("查询钻石充值赠送 jrzcz "+jrzcz+" jrczsx "+jrczsx);
  1444. let jpqsysj = 0;//记牌器剩余时间
  1445. let sfscjpq = 1;//是否首次充值记牌器,用于前端是否展示半价
  1446. let sfzsmfsy = 1;//是否展示免费试用
  1447. let jipaiqi = yield this.app.models.JiPaiQi.findByIdAsync(session.uid, 'times0 times1 times2 jpqdqsj lastBuyTime');
  1448. if (jipaiqi) {
  1449. if(jipaiqi.jpqdqsj > 0) {
  1450. jpqsysj = jipaiqi.jpqdqsj - Date.now();
  1451. sfzsmfsy = 0;
  1452. }
  1453. if(jipaiqi.times1 > 0 || jipaiqi.times2 > 0) sfscjpq = 0;
  1454. }
  1455. let data = {
  1456. currtime: Date.now(),
  1457. jrzcz: jrzcz,
  1458. jrczsx: jrczsx,
  1459. giveList: giveList,
  1460. diamondsList: diamondsList,
  1461. RMBList: RMBList,
  1462. jpqsysj: jpqsysj,
  1463. sfscjpq: sfscjpq,
  1464. sfzsmfsy: sfzsmfsy,
  1465. value2: value2
  1466. }
  1467. return next(null, { code: C.OK, data: data });
  1468. });
  1469. ////推广员查询
  1470. proto.tgyInfo = P.coroutine(function* (msg, session, next) {
  1471. if (!session.uid) {
  1472. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1473. }
  1474. var uid = session.uid;
  1475. let tgState = 1;////未申请=1;正在审核=2;审核成功=3,审核失败=4
  1476. let myUrl = "";
  1477. var agenterList = yield this.app.models.Agenter.findMongoAsync({playerId:uid}, 'myUrl');
  1478. if (agenterList.length > 0) {
  1479. myUrl = agenterList[0].myUrl + "/agent";
  1480. tgState = 3;
  1481. }
  1482. else{
  1483. var player = yield this.app.models.tgApply.findByIdReadOnlyAsync(uid, 'tgState');
  1484. if (player) {
  1485. tgState = player.tgState;
  1486. }
  1487. }
  1488. return next(null, { code: C.OK, tgState: tgState,myUrl:myUrl });
  1489. });
  1490. ////申请推广员
  1491. proto.applyTGY = P.coroutine(function* (msg, session, next) {
  1492. if (!session.uid) {
  1493. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1494. }
  1495. ////所申请的推广员姓名
  1496. if(!msg.tgName || msg.tgName == ""){
  1497. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  1498. }
  1499. ////所申请的推广员手机号
  1500. if(!msg.tgPhone || msg.tgPhone == ""){
  1501. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  1502. }
  1503. ////所申请的推广员微信号
  1504. if(!msg.tgWXNumber || msg.tgWXNumber == ""){
  1505. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  1506. }
  1507. var uid = session.uid;
  1508. let tgState = 2;////未申请=1;正在审核=2;审核成功=3,审核失败=4
  1509. // console.warn("申请推广员 tgName "+msg.tgName+" tgPhone "+msg.tgPhone+" tgWXNumber "+msg.tgWXNumber);
  1510. var player = yield this.app.models.tgApply.findByIdReadOnlyAsync(uid);
  1511. if (!player) {
  1512. var tgapply = new this.app.models.tgApply({
  1513. _id: uid,
  1514. applyType: 1,
  1515. parenteId:"",
  1516. tgName: msg.tgName,
  1517. tgPhone: msg.tgPhone,
  1518. tgWXNumber: msg.tgWXNumber,
  1519. tgState: tgState
  1520. });
  1521. yield tgapply.saveAsync();
  1522. }
  1523. else{
  1524. return next(null, { code: C.FAILD, msg: C.HALL_ALREADY_BNCFTJ});
  1525. }
  1526. return next(null, { code: C.OK, tgState: tgState });
  1527. });
  1528. // 分享处理
  1529. proto.share = P.coroutine(function* (msg, session, next) {
  1530. if (!session.uid) {
  1531. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1532. }
  1533. var today = new Date();
  1534. today.setHours(0);
  1535. today.setMinutes(0);
  1536. today.setSeconds(0);
  1537. today.setMilliseconds(0);
  1538. var signinfo = yield this.app.models.SignInfo.findByIdAsync(session.uid, 'shareTime');
  1539. if (!signinfo) {
  1540. signinfo = new this.app.models.SignInfo({
  1541. _id: session.uid
  1542. });
  1543. }
  1544. var diamond = 0;
  1545. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'shareGive');
  1546. // console.warn("22检查是否维护状态",whdata);
  1547. if (whdata) {
  1548. if(whdata.shareGive || whdata.shareGive == 0){///
  1549. /////维护状态中
  1550. diamond = whdata.shareGive;
  1551. }
  1552. else{
  1553. let whdata2 = yield this.app.models.WHstate.findByIdAsync('wh', 'shareGive');
  1554. if (whdata2) {
  1555. whdata2.shareGive = 50;
  1556. yield whdata2.saveAsync();
  1557. diamond = 50;
  1558. }
  1559. }
  1560. }
  1561. if (signinfo.shareTime < today.getTime() && diamond > 0) {
  1562. signinfo.shareTime = Date.now();
  1563. yield signinfo.saveAsync();
  1564. let player = yield this.app.models.Player.findByIdAsync(session.uid, 'diamond');
  1565. player.diamond += diamond;
  1566. yield player.saveAsync();
  1567. // 钻石记录
  1568. var diamondrecord = new this.app.models.DiamondRecord({
  1569. _id: uuid.v1(),
  1570. playerId: session.uid,
  1571. dType: 12,//分享
  1572. dSource: player.diamond - diamond,
  1573. dSwap: diamond,
  1574. dNow: player.diamond
  1575. });
  1576. yield diamondrecord.saveAsync();
  1577. }
  1578. else{
  1579. diamond = 0;
  1580. }
  1581. return next(null, { code: C.OK, diamond: diamond });
  1582. });
  1583. // 统计信息
  1584. proto.gameInfo = P.coroutine(function* (msg, session, next) {
  1585. // console.warn("统计信息gameInfo",session.uid,msg);
  1586. if (!session.uid) {
  1587. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1588. }
  1589. //var time= new Date();
  1590. //var today= util.format('%d-%d-%d', time.getFullYear(), time.getMonth() + 1, time.getDate());
  1591. //var today = new Date();
  1592. // today.setHours(0);
  1593. // today.setMinutes(0);
  1594. // today.setSeconds(0);
  1595. // today.setMilliseconds(0);
  1596. //var uid = session.uid +'-'+today;//今天
  1597. //console.warn("ts+++++统计信息",uid);
  1598. //var uid1 = session.uid +'-'+ new Date(new Date().getTime() - 86400000).Format("yyyy-MM-dd");//昨天
  1599. let ttCount=0;
  1600. let winCount=0;
  1601. // let gamer = yield this.app.models.SXGamer.findByIdReadOnlyAsync(uid, 'ttCount winCount');
  1602. // if (gamer)
  1603. // {
  1604. // ttCount+= gamer.ttCount;
  1605. // winCount+= gamer.winCount;
  1606. // }
  1607. // let gamer1 = yield this.app.models.SXGamer.findByIdReadOnlyAsync(uid1, 'ttCount winCount');
  1608. // if (gamer1)
  1609. // {
  1610. // ttCount+= gamer1.ttCount;
  1611. // winCount+= gamer1.winCount;
  1612. // }
  1613. var list = [];
  1614. list.push({ gameId: 10007, ttCount: ttCount, winCount: winCount });
  1615. return next(null, { code: C.OK, list: list });
  1616. //uid = '85456dda-5119-a2bc-3c2d-f17f74a19fa6@my2016'/////TL++
  1617. // var uid = '12e3cf2b-4b54-f782-c041-9d959c0a0d25@my2016'
  1618. // var list = [];
  1619. // for (let gameId = 10001; gameId <= 10009; ++gameId) {
  1620. // let gamer = null;
  1621. // switch (gameId) {
  1622. // case 10003: gamer = yield this.app.models.NNGamer.findByIdReadOnlyAsync(uid, 'ttCount winCount'); break;
  1623. // case 10006: gamer = yield this.app.models.TWGamer.findByIdReadOnlyAsync(uid, 'ttCount winCount'); break;
  1624. // case 10007: gamer = yield this.app.models.SXGamer.findByIdReadOnlyAsync(uid, 'ttCount winCount'); break;
  1625. // }
  1626. // if (gamer) list.push({ gameId: gameId, ttCount: gamer.ttCount, winCount: gamer.winCount });
  1627. // }
  1628. // return next(null, { code: C.OK, list: list });
  1629. });
  1630. // 历史战绩
  1631. proto.getHistory = P.coroutine(function* (msg, session, next) {
  1632. // console.warn("历史战绩getHistory");
  1633. if (!session.uid) {
  1634. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1635. }
  1636. var data = { ttCount: '0', winCount: '0', winRate: '0', listCount: '0', list: [] };
  1637. //console.warn("2222历史记录getHistory",session.uid);
  1638. var uid = session.uid;
  1639. //uid = 'o79wPwCrz9fMdTg2vQ1PePqGB1es@my2019'
  1640. //console.warn("历史战绩uid",uid);
  1641. var today = new Date();
  1642. today.setHours(0);
  1643. today.setMinutes(0);
  1644. today.setSeconds(0);
  1645. today.setMilliseconds(0);
  1646. let ttCount=0;
  1647. let winCount=0;
  1648. let winRate=0;
  1649. let listCount=0;
  1650. var startTime =today.getTime() - 86400000;
  1651. var endTime =today.getTime() + 86400000;
  1652. //console.warn("历史战绩Time",startTime,endTime);
  1653. var opts = { time: { $gte: startTime, $lt: endTime },over: { $gte: 1 }};
  1654. opts['users._id'] = uid;
  1655. // logger.warn("hall findMongoAsync users._id333--------" + uid );
  1656. var list = yield this.app.models.FHMJTables.findMongoAsync(opts, '_id gameId tableNo agentId type kind other playerCount round over ctime stime time endMode sszj users', { sort: { time: -1 } ,limit:10});//ownerId sszjFile
  1657. // console.warn("战绩-------------------length",list.length);
  1658. for (let i = 0; i < list.length; ++i) {
  1659. let record = list[i];
  1660. ttCount++;
  1661. let user = record.users.id(uid);//////词句报错所以
  1662. if(user)
  1663. {
  1664. if(user.score>0)winCount++;
  1665. }
  1666. if(i<10)
  1667. {
  1668. listCount++;
  1669. let item = {
  1670. _id:record._id,
  1671. gameId: record.gameId,
  1672. tableNo: record.tableNo,
  1673. agentId: record.agentId,
  1674. type: record.type,
  1675. kind: record.kind,
  1676. other: record.other,
  1677. playerCount: record.playerCount,
  1678. round: record.round,
  1679. over: record.over,
  1680. time: record.time,
  1681. ctime: record.ctime,
  1682. stime: record.stime,
  1683. // sszjFile: record.sszjFile,
  1684. sszj: record.sszj,
  1685. users: record.users };
  1686. //console.warn("战绩-------------------",item);
  1687. data.list.push(item);
  1688. }
  1689. }
  1690. if(ttCount>0)
  1691. {
  1692. winRate=parseInt(winCount*100/ttCount);
  1693. }
  1694. data.ttCount=String(ttCount);
  1695. data.winCount=String(winCount);
  1696. data.winRate=String(winRate);
  1697. data.listCount=String(listCount);
  1698. return next(null, { code: C.OK, data: data });
  1699. });
  1700. ////得到玩家信息 参数为6位数的玩家ID
  1701. proto.getPeopleInfo = P.coroutine(function* (msg, session, next) {
  1702. // console.warn("得到玩家信息 参数为6位数的玩家ID",msg);
  1703. if (!session.uid) {
  1704. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1705. }
  1706. if (!msg.userId) {
  1707. return next(null, { code: C.ERROR, msg: C.HALL_NOT_PLAYER });
  1708. }
  1709. let uid = "" + msg.userId;
  1710. if (uid.length != 6) {
  1711. return next(null, { code: C.ERROR, msg: C.HALL_NOT_PLAYER });
  1712. }
  1713. uid = parseInt(uid);
  1714. let player = yield this.app.models.Player.findMongoAsync({userId:uid}, 'userId name headurl');
  1715. if (player.length > 0) {
  1716. let playerdata = player[0];
  1717. // console.warn("得到玩家信息 ",uid,playerdata);
  1718. let jrzcz = 0;//今日总充值
  1719. let jrczsx = 50000;//今日充值上限
  1720. var startTime = this.lconfigCommon.getTodaySJC();
  1721. let wjsx = yield this.app.models.PayLimit.findByIdReadOnlyAsync(playerdata._id, 'paytop paytotal dataTime');
  1722. if (wjsx) {
  1723. if (startTime == wjsx.dataTime) {
  1724. jrzcz = wjsx.paytotal;//今日总充值
  1725. }
  1726. if (wjsx.paytop >= 0) {
  1727. jrczsx = wjsx.paytop;//玩家上限
  1728. }
  1729. else{
  1730. let qjsx = yield this.app.models.PayLimit.findByIdReadOnlyAsync('quanjutop', 'paytop');
  1731. if (qjsx) {
  1732. jrczsx = qjsx.paytop;//全局上限
  1733. }
  1734. }
  1735. }
  1736. else{
  1737. var endTime = startTime + 86400000;
  1738. var opts = { time: { $gte: startTime, $lt: endTime },playerId: uid, paystate: { $gte: 1 }};
  1739. var list = yield this.app.models.PayRecord.findMongoAsync(opts, 'total_fee');
  1740. for (let i = 0; i < list.length; ++i) {
  1741. jrzcz += list[i].total_fee;
  1742. }
  1743. let qjsx = yield this.app.models.PayLimit.findByIdReadOnlyAsync('quanjutop', 'paytop');
  1744. if (qjsx) {
  1745. jrczsx = qjsx.paytop;//全局上限
  1746. }
  1747. }
  1748. let sfscjpq = 1;//是否首次充值记牌器,用于前端是否展示半价
  1749. let jipaiqi = yield this.app.models.JiPaiQi.findByIdAsync(playerdata._id, 'times0 times1 times2 jpqdqsj lastBuyTime');
  1750. if (jipaiqi) {
  1751. if(jipaiqi.times1 > 0 || jipaiqi.times2 > 0) sfscjpq = 0;
  1752. }
  1753. let data22 = {
  1754. userId : playerdata.userId,
  1755. jrzcz: jrzcz,
  1756. jrczsx: jrczsx,
  1757. sfscjpq: sfscjpq,
  1758. name : playerdata.name,
  1759. headurl : playerdata.headurl
  1760. }
  1761. return next(null, { code: C.OK, data : data22});
  1762. }
  1763. return next(null, { code: C.ERROR, msg: C.HALL_NOT_PLAYER });
  1764. });
  1765. // 房间记录
  1766. proto.tableRecord = P.coroutine(function* (msg, session, next) {
  1767. // console.warn("取数据酷读取战绩",msg.tid);
  1768. if (!session.uid) {
  1769. return next(null, { code: C.ERROR,tid:'', msg: C.PLAYER_NOT_LOGIN });
  1770. }
  1771. if (!msg.tid) {
  1772. return next(null, { code: C.FAILD, tid:'',msg: C.GAME_PARAM_ERROR });
  1773. }
  1774. // logger.warn("hall findByIdReadOnlyAsync tid444--------" + msg.tid );
  1775. var record = yield this.app.models.FHMJTables.findByIdReadOnlyAsync(msg.tid);
  1776. if (!record) {
  1777. // console.warn("这个房间没有战绩",msg.tid);
  1778. return next(null, { code: C.FAILD,tid:msg.tid, msg: C.TABLE_NOT_FOUND });
  1779. }
  1780. let data = {
  1781. _id:record._id,
  1782. gameId: record.gameId,
  1783. tableNo: record.tableNo,
  1784. type: record.type,
  1785. kind: record.kind,
  1786. round: record.round,
  1787. over: record.over,
  1788. time: record.time,
  1789. ctime: record.ctime,
  1790. sszjFile: record.sszjFile,
  1791. sszj: record.sszj,
  1792. users: record.users
  1793. };
  1794. // console.warn("这个房间de战绩shi",record);
  1795. return next(null, { code: C.OK, data: data });
  1796. });
  1797. //ts++得到下一局的信息
  1798. proto.getTableNext = P.coroutine(function* (msg, session, next) {
  1799. // console.warn("000得到下一局的信息-------------------",msg);
  1800. if (!session.uid) {
  1801. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1802. }
  1803. // console.warn("得到下一局的信息-------------------",msg.tid);
  1804. if (!msg.tid) {
  1805. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  1806. }
  1807. // logger.warn("hall findByIdReadOnlyAsync tid555--------" + msg.tid );
  1808. var record = yield this.app.models.FHMJTables.findByIdReadOnlyAsync(msg.tid,'_id gameId tableNo type kind round over time playerCount other');
  1809. //console.warn("得到下一局的信息-------------------",(!record),record);
  1810. if (!record) {
  1811. // console.warn("得到下一局的信息查找桌子不存在");
  1812. return next(null, { code: C.FAILD, msg: C.TABLE_NOT_FOUND });
  1813. }
  1814. let data = {
  1815. _id:record._id,
  1816. gameId: record.gameId,
  1817. tableNo: record.tableNo,
  1818. type: record.type,
  1819. kind: record.kind,
  1820. round: record.round,
  1821. over: record.over,
  1822. time: record.time
  1823. };
  1824. //console.warn("xxx得到下一局的信息-------------------",data)
  1825. return next(null, { code: C.OK, data: data });
  1826. });
  1827. // tl++得到比赛时间,在大厅里使用
  1828. proto.getBiSaiHall = P.coroutine(function* (msg, session, next) {
  1829. if (!session.uid) {
  1830. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1831. }
  1832. if (!msg.aid) {
  1833. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  1834. }
  1835. let uid = session.uid;
  1836. let agentId = msg.aid;
  1837. let aidsub = agentId.substr(0, 9);
  1838. // console.warn("获取比赛信息 aidsub "+aidsub+" agentId "+agentId);
  1839. let bsIndex = aidsub.indexOf("promote_");
  1840. if(bsIndex == -1) return next(null, { code: C.FAILD, msg: "is not compete aid" });//非比赛链接
  1841. let nowTime = Date.now();
  1842. let jrStart = this.lconfigCommon.getTodaySJC();
  1843. // nowTime = 1684925400000;
  1844. // jrStart = 1681920000000;
  1845. var opts = {
  1846. stime: { $gte: jrStart },
  1847. outTime: {$gt: nowTime}//过期时间大于当前时间
  1848. };
  1849. opts['aid'] = agentId;
  1850. let timelist = yield this.app.models.RaceTimeInfos.findMongoAsync(opts, 'aid agentNo stime etime bigRound gameId round playerCount other outTime', { sort: { stime: 1 } });
  1851. let bsInfo = null;
  1852. for (var i = 0; i < timelist.length; i++) {
  1853. if(timelist[i].stime >= nowTime || (timelist[i].stime <= nowTime && timelist[i].etime > nowTime)){
  1854. bsInfo = timelist[i];
  1855. break;
  1856. }
  1857. }
  1858. let data = {
  1859. bsInfo:bsInfo,
  1860. jrStart:jrStart,
  1861. nowTime:nowTime
  1862. }
  1863. return next(null, { code: C.OK, data: data });
  1864. });
  1865. // tl++得到比赛信息
  1866. proto.getBiSaiInfo = P.coroutine(function* (msg, session, next) {
  1867. if (!session.uid) {
  1868. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  1869. }
  1870. if (!msg.aid) {
  1871. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  1872. }
  1873. let uid = session.uid;
  1874. let agentId = msg.aid;
  1875. let aidsub = agentId.substr(0, 9);
  1876. // console.warn("获取比赛信息 aidsub "+aidsub+" agentId "+agentId);
  1877. let bsIndex = aidsub.indexOf("promote_");
  1878. if(bsIndex == -1) return next(null, { code: C.FAILD, msg: "is not compete aid" });//非比赛链接
  1879. let nowTime = Date.now();
  1880. let jrStart = this.lconfigCommon.getTodaySJC();
  1881. // nowTime = 1684925400000;
  1882. // jrStart = 1681920000000;
  1883. var opts = {
  1884. stime: { $gte: jrStart },
  1885. outTime: {$gt: nowTime}//过期时间大于当前时间
  1886. };
  1887. opts['aid'] = agentId;
  1888. let timelist = yield this.app.models.RaceTimeInfos.findMongoAsync(opts, 'aid agentNo stime etime bigRound gameId round playerCount other outTime', { sort: { stime: 1 } });
  1889. // if(timelist.length == 0){
  1890. // console.warn("没有数据,插入测试数据");
  1891. // var newRaceTime = this.app.models.RaceTimeInfos({
  1892. // _id: uuid.v1(), // UUID 标识
  1893. // aid: "promote_1001_hNzm6WDMfGLUFdSPFu", // 比赛代理的标识
  1894. // agentNo: 880003,// 比赛代理编号
  1895. // stime: 1681867800000, // 该次比赛的开始时间
  1896. // etime: 1681871400000, // 该次比赛的结束时间
  1897. // gameId: 10006, // 该次比赛的游戏id 10006为长沙麻将,10007为红中麻将,10008为跑得快
  1898. // bigRound: 3, //本场比赛的大局数量,统计战绩时使用
  1899. // round: 12, // 该次比赛的游戏局数
  1900. // playerCount: 4, // 该次比赛的游戏人数
  1901. // other: 79 // 该次比赛的游戏规则
  1902. // });
  1903. // yield newRaceTime.saveAsync();
  1904. // var newRaceTime1 = this.app.models.RaceTimeInfos({
  1905. // _id: uuid.v1(), // UUID 标识
  1906. // aid: "promote_1001_hNzm6WDMfGLUFdSPFu", // 比赛代理的标识
  1907. // agentNo: 880003,// 比赛代理编号
  1908. // stime: 1681885800000, // 该次比赛的开始时间
  1909. // etime: 1681889400000, // 该次比赛的结束时间
  1910. // gameId: 10007, // 该次比赛的游戏id 10006为长沙麻将,10007为红中麻将,10008为跑得快
  1911. // bigRound: 3, //本场比赛的大局数量,统计战绩时使用
  1912. // round: 16, // 该次比赛的游戏局数
  1913. // playerCount: 3, // 该次比赛的游戏人数
  1914. // other: 9 // 该次比赛的游戏规则
  1915. // });
  1916. // yield newRaceTime1.saveAsync();
  1917. // var newRaceTime2 = this.app.models.RaceTimeInfos({
  1918. // _id: uuid.v1(), // UUID 标识
  1919. // aid: "promote_1001_hNzm6WDMfGLUFdSPFu", // 比赛代理的标识
  1920. // agentNo: 880003,// 比赛代理编号
  1921. // stime: 1681896600000, // 该次比赛的开始时间
  1922. // etime: 1681900200000, // 该次比赛的结束时间
  1923. // gameId: 10008, // 该次比赛的游戏id 10006为长沙麻将,10007为红中麻将,10008为跑得快
  1924. // bigRound: 3, //本场比赛的大局数量,统计战绩时使用
  1925. // round: 10, // 该次比赛的游戏局数
  1926. // playerCount: 3, // 该次比赛的游戏人数
  1927. // other: 74 // 该次比赛的游戏规则
  1928. // });
  1929. // yield newRaceTime2.saveAsync();
  1930. // var newRaceTime3 = this.app.models.RaceTimeInfos({
  1931. // _id: uuid.v1(), // UUID 标识
  1932. // aid: "promote_1001_hNzm6WDMfGLUFdSPFu", // 比赛代理的标识
  1933. // agentNo: 880003,// 比赛代理编号
  1934. // stime: 1681977600000, // 该次比赛的开始时间
  1935. // etime: 1681981200000, // 该次比赛的结束时间
  1936. // gameId: 10008, // 该次比赛的游戏id 10006为长沙麻将,10007为红中麻将,10008为跑得快
  1937. // bigRound: 3, //本场比赛的大局数量,统计战绩时使用
  1938. // round: 10, // 该次比赛的游戏局数
  1939. // playerCount: 2, // 该次比赛的游戏人数
  1940. // other: 74 // 该次比赛的游戏规则
  1941. // });
  1942. // yield newRaceTime3.saveAsync();
  1943. // var newRaceTime4 = this.app.models.RaceTimeInfos({
  1944. // _id: uuid.v1(), // UUID 标识
  1945. // aid: "promote_1001_hNzm6WDMfGLUFdSPFu", // 比赛代理的标识
  1946. // agentNo: 880003,// 比赛代理编号
  1947. // stime: 1682150400000, // 该次比赛的开始时间
  1948. // etime: 1682154000000, // 该次比赛的结束时间
  1949. // gameId: 10008, // 该次比赛的游戏id 10006为长沙麻将,10007为红中麻将,10008为跑得快
  1950. // bigRound: 3, //本场比赛的大局数量,统计战绩时使用
  1951. // round: 10, // 该次比赛的游戏局数
  1952. // playerCount: 3, // 该次比赛的游戏人数
  1953. // other: 74 // 该次比赛的游戏规则
  1954. // });
  1955. // yield newRaceTime4.saveAsync();
  1956. // }
  1957. let xzsfcybs = false;//现在是否处于比赛时间
  1958. let ckszbsccxx = null;//此刻所处比赛场的比赛信息
  1959. for (var i = 0; i < timelist.length; i++) {
  1960. if(timelist[i].stime <= nowTime && nowTime < timelist[i].outTime){
  1961. xzsfcybs = true;
  1962. ckszbsccxx = timelist[i];
  1963. break;
  1964. }
  1965. }
  1966. if(xzsfcybs){
  1967. // console.warn("现在是处于比赛时间 设置定时器检查人数变化");
  1968. }
  1969. else{
  1970. this.app.controllers.bisai.clearPlayers(agentId);
  1971. // console.warn("现在不是处于比赛时间 清空匹配列表");
  1972. }
  1973. let wantBSUList = this.app.controllers.bisai.getPlayers(agentId)
  1974. // console.warn("hallhander 得到列表 长度111 "+wantBSUList.length + JSON.stringify(wantBSUList));
  1975. let nowCount = wantBSUList.length;//目前正在匹配的玩家个数
  1976. let allScore = 0;//本场比赛该玩家目前的总分
  1977. let over = 0;////本场比赛该玩家完成的大局数
  1978. if(xzsfcybs && ckszbsccxx){
  1979. timelist = [ckszbsccxx];
  1980. var opts = {
  1981. stime: { $gte: ckszbsccxx.stime, $lt: ckszbsccxx.etime },
  1982. over: { $gte: 1 }
  1983. };
  1984. opts['agentId'] = agentId;
  1985. opts['users._id'] = uid;
  1986. var list = yield this.app.models.FHMJTables.findMongoAsync(opts, '_id gameId tableNo agentId type kind other playerCount round over ctime stime time endMode users', { sort: { stime: 1 } ,limit:xzsfcybs.bigRound});
  1987. // console.warn("战绩-------------------length",list.length);
  1988. for (let i = 0; i < list.length; ++i) {
  1989. let bjus = list[i].users;
  1990. for (let j = 0; j < bjus.length; ++j) {
  1991. if(bjus[j]._id == uid){
  1992. allScore += bjus[j].score;
  1993. }
  1994. }
  1995. }
  1996. over = list.length;
  1997. }
  1998. let data = {
  1999. timelist:timelist,
  2000. nowTime:nowTime,
  2001. jrStart:jrStart,
  2002. nowCount:nowCount,
  2003. allScore:allScore,
  2004. over:over,
  2005. }
  2006. return next(null, { code: C.OK, data: data });
  2007. });
  2008. // tl++得到是否禁赛
  2009. proto.getIsJinSai = P.coroutine(function* (msg, session, next) {
  2010. if (!session.uid) {
  2011. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2012. }
  2013. let uid = session.uid;
  2014. var jinsai = yield this.app.models.JinSaiInfo.findByIdAsync(uid, '_id userId');
  2015. if (jinsai) return next(null, { code: C.FAILD, msg: "您已被禁赛。" });
  2016. return next(null, { code: C.OK, data: {} });
  2017. });
  2018. // tl++开始/继续比赛
  2019. proto.toBiSai = P.coroutine(function* (msg, session, next) {
  2020. if (!session.uid) {
  2021. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2022. }
  2023. if (!msg.aid) {
  2024. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2025. }
  2026. let uid = session.uid;
  2027. let agentId = msg.aid;
  2028. let aidsub = agentId.substr(0, 9);
  2029. // console.warn("开始/继续比赛 aidsub "+aidsub+" agentId "+agentId);
  2030. let bsIndex = aidsub.indexOf("promote_");
  2031. if(bsIndex == -1) return next(null, { code: C.FAILD, msg: "is not compete aid" });//非比赛链接
  2032. let nowTime2 = Date.now();
  2033. // nowTime2 = 1681977609000;
  2034. var opts = {
  2035. stime: { $lte: nowTime2 },
  2036. etime: { $gt: nowTime2 },
  2037. outTime: {$gt: nowTime2}//过期时间大于当前时间
  2038. };
  2039. opts['aid'] = agentId;
  2040. let timelist = yield this.app.models.RaceTimeInfos.findMongoAsync(opts, 'aid agentNo stime etime bigRound gameId round playerCount other outTime', { sort: { stime: 1 } });
  2041. // console.warn(">>>>>>>>>>>>>>>.. "+timelist.length);
  2042. if(timelist.length == 0){
  2043. // setTimeout(() => this.dsqjcrsbh(null,-1,agentId),500);
  2044. this.app.controllers.bisai.setNowBSInfo([],agentId);
  2045. return next(null, { code: C.FAILD, msg: "current no compate"});
  2046. }
  2047. else if(timelist.length > 1){
  2048. // setTimeout(() => this.dsqjcrsbh(null,-1,agentId),500);
  2049. this.app.controllers.bisai.setNowBSInfo([],agentId);
  2050. return next(null, { code: C.FAILD, msg: "current have more compate"});
  2051. }
  2052. var notTogthers = yield this.app.models.NotGameTogther.findMongoAsync({ },'_id uidList pidList');
  2053. this.app.controllers.bisai.setNotGameTogther(notTogthers);
  2054. // console.warn("不能同桌的玩家信息hhh "+JSON.stringify(notTogthers));
  2055. this.app.controllers.bisai.setNowBSInfo(timelist,agentId);
  2056. this.app.controllers.bisai.addPlayer(uid,agentId);
  2057. let wantBSUList = this.app.controllers.bisai.getPlayers(agentId);
  2058. // console.warn("hallhander 得到列表 长度222 "+wantBSUList.length + JSON.stringify(wantBSUList));
  2059. let nowCount = wantBSUList.length;//目前正在匹配的玩家个数
  2060. let allCount = timelist[0].playerCount;
  2061. let kxzz = this.app.controllers.bisai.getKXTables(agentId);//该比赛链接空闲桌子
  2062. // setTimeout(() => this.dsqjcrsbh(timelist[0],-1,agentId),500);
  2063. if(kxzz.length < 1){
  2064. //匹配人数大于等于2时系统创房
  2065. // console.warn("匹配人数大于等于2时系统创房 ");
  2066. // delete require.cache[require.resolve('../../../../share/configCommon')];
  2067. // configCommon = require('../../../../share/configCommon');
  2068. // this.lconfigCommon = new configCommon(this.app);
  2069. // let data = yield this.lconfigCommon.toBiSai(msg, session,wantBSUList); //创建房间
  2070. let creatData = {
  2071. playerId:"system_promote",
  2072. round:timelist[0].round,
  2073. type:1,
  2074. gameKind:1,
  2075. playerAllCount:timelist[0].playerCount,
  2076. upId:"",
  2077. other:timelist[0].other,
  2078. agentId:msg.aid
  2079. }
  2080. this.app.rpc.game.paodekuaiRemote.creatTable.toServer("game-server-11", creatData, (fh) => {
  2081. // console.warn("创建房间完成 ",fh);
  2082. });
  2083. }
  2084. else{
  2085. this.app.controllers.bisai.addTable(kxzz[0],agentId,allCount);
  2086. }
  2087. // setTimeout(() => this.dsqjcrsbh(timelist[0],-1,agentId),5000);
  2088. let data = {
  2089. aid:agentId,
  2090. nowCount: wantBSUList.length,
  2091. allCount: allCount
  2092. }
  2093. return next(null, { code: C.OK, data: data });
  2094. });
  2095. // // tl++取消匹配
  2096. // proto.cancelPiPei = P.coroutine(function* (msg, session, next) {
  2097. // if (!session.uid) {
  2098. // return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2099. // }
  2100. // let uid = session.uid;
  2101. // this.app.controllers.bisai.delPlayer(uid);
  2102. // return next(null, { code: C.OK});
  2103. // });
  2104. // tl++获取比赛排名
  2105. proto.getBiSaiPaiMing = P.coroutine(function* (msg, session, next) {
  2106. if (!session.uid) {
  2107. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2108. }
  2109. if (!msg.aid) {
  2110. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2111. }
  2112. let uid = session.uid;
  2113. let agentId = msg.aid;
  2114. let aidsub = agentId.substr(0, 9);
  2115. // console.warn("获取比赛排名 aidsub "+aidsub+" agentId "+agentId);
  2116. let bsIndex = aidsub.indexOf("promote_");
  2117. if(bsIndex == -1) return next(null, { code: C.FAILD, msg: "is not compete aid" });//非比赛链接
  2118. let nowTime = Date.now();
  2119. let jrStart = this.lconfigCommon.getTodaySJC();
  2120. // nowTime = 1684925400000;
  2121. // jrStart = 1681920000000;
  2122. var opts = {
  2123. stime: { $gte: jrStart },
  2124. outTime: {$gt: nowTime}//过期时间大于当前时间
  2125. };
  2126. opts['aid'] = agentId;
  2127. let timelist = yield this.app.models.RaceTimeInfos.findMongoAsync(opts, 'aid agentNo stime etime bigRound gameId round playerCount other outTime', { sort: { stime: 1 } });
  2128. if(timelist.length == 0){
  2129. this.app.controllers.bisai.setNowBSInfo([],agentId);
  2130. return next(null, { code: C.FAILD, msg: "today no compate"});
  2131. }
  2132. let userid = msg.userid||1;
  2133. let userList = [];//今日比赛所有参与的玩家uid
  2134. let nameList = [];//今日比赛所有参与的玩家昵称
  2135. let scoreList = [];//今日比赛所有参与的玩家的分数
  2136. let ccList = [];//今日比赛所有参与的玩家已经统计分数的场次
  2137. let ckszbsccxx = timelist[0];//此刻所处比赛场的比赛信息
  2138. let iszzpm = false;//是否是最终排名(比赛过程中统计的排名并非本场比赛最终的排名)
  2139. if(ckszbsccxx){
  2140. let jlbspmgbsj = (ckszbsccxx.etime + 15*60*1000) - nowTime;//距离比赛排名公布时间
  2141. if(jlbspmgbsj >= 0 && nowTime >= ckszbsccxx.etime){
  2142. //比赛结束时间15分钟之后才去统计比赛排名
  2143. let da = {
  2144. aid:agentId,
  2145. gbpmsjwd: true,//公布排名时间未到
  2146. jlbspmgbsj:jlbspmgbsj
  2147. }
  2148. // console.warn("还未到比赛公布战绩的时间 "+jlbspmgbsj);
  2149. return next(null, { code: C.OK, data: da });
  2150. }
  2151. if(jlbspmgbsj < 0) iszzpm = true;
  2152. var opts = {
  2153. stime: { $gte: ckszbsccxx.stime, $lt: ckszbsccxx.etime },
  2154. over: { $gte: 1 }
  2155. };
  2156. opts['agentId'] = agentId;
  2157. var list = yield this.app.models.FHMJTables.findMongoAsync(opts, 'tableNo users', { sort: { stime: 1 } });
  2158. // console.warn("战绩-------------------length",list.length);
  2159. for (let i = 0; i < list.length; ++i) {
  2160. let bjus = list[i].users;//本局users
  2161. for (let j = 0; j < bjus.length; ++j) {
  2162. let wjszxb = userList.indexOf(bjus[j].userId);//玩家所在下标
  2163. if(wjszxb == -1){
  2164. let xwjxb = userList.length;//新玩家下标
  2165. userList[xwjxb] = bjus[j].userId;//今日比赛所有参与的玩家
  2166. nameList[xwjxb] = bjus[j].name;//今日比赛所有参与的玩家昵称
  2167. scoreList[xwjxb] = bjus[j].score;//今日比赛所有参与的玩家的分数
  2168. ccList[xwjxb] = 1;//今日比赛所有参与的玩家已经统计分数的场次
  2169. }
  2170. else{
  2171. if(ccList[wjszxb] < ckszbsccxx.bigRound){//每个玩家止统计今日的前三场战绩
  2172. scoreList[wjszxb] += bjus[j].score;//今日比赛所有参与的玩家的分数
  2173. ccList[wjszxb] += 1;//今日比赛所有参与的玩家已经统计分数的场次
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. let infoList = [];
  2180. for (let i = 0; i < userList.length; ++i) {
  2181. infoList[i] = {
  2182. name:nameList[i],
  2183. score:scoreList[i],
  2184. uid:userList[i]
  2185. }
  2186. }
  2187. var scorersSort = _.sortBy(infoList, (i) => i.score);
  2188. let qsmInfoList = [];//分数前十名
  2189. _.reverse(scorersSort);
  2190. for (let i = 0; i < 10; ++i) {
  2191. qsmInfoList[i] = scorersSort[i];
  2192. }
  2193. let zjmcxx = null;//自己的分数信息
  2194. for (let i = 0; i < scorersSort.length; ++i) {
  2195. if(scorersSort[i] && scorersSort[i].uid == userid){
  2196. zjmcxx = scorersSort[i];
  2197. zjmcxx.mc = i;
  2198. break;
  2199. }
  2200. }
  2201. let data = {
  2202. aid:agentId,
  2203. infoList:qsmInfoList,
  2204. zjmcxx:zjmcxx,
  2205. iszzpm: iszzpm
  2206. }
  2207. return next(null, { code: C.OK, data: data });
  2208. });
  2209. // tl++获取比赛奖品
  2210. proto.getBiSaiJiangPin = P.coroutine(function* (msg, session, next) {
  2211. if (!session.uid) {
  2212. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2213. }
  2214. if (!msg.aid) {
  2215. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2216. }
  2217. let uid = session.uid;
  2218. let agentId = msg.aid;
  2219. let aidsub = agentId.substr(0, 9);
  2220. // console.warn("获取比赛排名 aidsub "+aidsub+" agentId "+agentId);
  2221. let bsIndex = aidsub.indexOf("promote_");
  2222. if(bsIndex == -1) return next(null, { code: C.FAILD, msg: "is not compete aid" });//非比赛链接
  2223. let nowTime = Date.now();
  2224. let jrStart = this.lconfigCommon.getTodaySJC();
  2225. // nowTime = 1684925400000;
  2226. // jrStart = 1681920000000;
  2227. var opts = {
  2228. stime: { $gte: jrStart },
  2229. outTime: {$gt: nowTime}//过期时间大于当前时间
  2230. };
  2231. opts['aid'] = agentId;
  2232. let timelist = yield this.app.models.RaceTimeInfos.findMongoAsync(opts, 'aid agentNo stime etime bigRound gameId round playerCount other outTime', { sort: { stime: 1 } });
  2233. if(timelist.length == 0){
  2234. this.app.controllers.bisai.setNowBSInfo([],agentId);
  2235. let wbsdata = {
  2236. aid:agentId,
  2237. nowPlayerCount:0
  2238. }
  2239. return next(null, { code: C.OK, wbsdata: data });//今日无比赛
  2240. }
  2241. let userList = [];//今日比赛所有参与的玩家uid
  2242. let ckszbsccxx = timelist[0];//此刻所处比赛场的比赛信息
  2243. if(ckszbsccxx){
  2244. var opts = {
  2245. stime: { $gte: ckszbsccxx.stime, $lt: ckszbsccxx.etime },
  2246. over: { $gte: 1 }
  2247. };
  2248. opts['agentId'] = agentId;
  2249. var list = yield this.app.models.FHMJTables.findMongoAsync(opts, 'tableNo users', { sort: { stime: 1 } });
  2250. // console.warn("战绩-------------------length",list.length);
  2251. for (let i = 0; i < list.length; ++i) {
  2252. let bjus = list[i].users;//本局users
  2253. for (let j = 0; j < bjus.length; ++j) {
  2254. let wjszxb = userList.indexOf(bjus[j].userId);//玩家所在下标
  2255. if(wjszxb == -1){
  2256. let xwjxb = userList.length;//新玩家下标
  2257. userList[xwjxb] = bjus[j].userId;//今日比赛所有参与的玩家
  2258. }
  2259. }
  2260. }
  2261. }
  2262. let data = {
  2263. aid:agentId,
  2264. nowPlayerCount:userList.length
  2265. }
  2266. return next(null, { code: C.OK, data: data });
  2267. });
  2268. ////获得是否已领取比赛奖品(4~6名发钻石)
  2269. proto.getIsTakeBSPrize = P.coroutine(function* (msg, session, next) {
  2270. let res = yield this.hallLogic.getIsTakeBSPrize(msg, session);
  2271. return next(null, res);
  2272. });
  2273. ////领取比赛奖品(4~6名发钻石)
  2274. proto.takeBSPrize = P.coroutine(function* (msg, session, next) {
  2275. let res = yield this.hallLogic.takeBSPrize(msg, session);
  2276. return next(null, res);
  2277. });
  2278. // 得到排行榜信息(得到小游戏的排行榜信息)
  2279. proto.getPaiHangInfo = P.coroutine(function* (msg, session, next) {
  2280. if (!session.uid) {
  2281. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2282. }
  2283. let uid = session.uid;
  2284. let limit = 10;//前10名上榜
  2285. var jrStart = this.lconfigCommon.getTodaySJC();
  2286. var opts = {
  2287. time1: jrStart,
  2288. quan1: { $gt: 0}
  2289. };
  2290. let fields = 'name headurl userId cost1 quan1 time1';
  2291. var list = yield this.app.models.SGJPaiHang.findMongoAsync(opts, fields, { sort: { quan1: -1 } ,limit:limit});
  2292. let pmInfos = [];
  2293. for (let i = 0; i < list.length; ++i) {
  2294. // console.warn("排序之后 ",i,list[i]);
  2295. let mc = i + 1;//名次=数组下标+1
  2296. let diamond = 0;
  2297. if(mc == 1) diamond = 20000;
  2298. else if(mc == 2) diamond = 10000;
  2299. else if(mc == 3) diamond = 5000;
  2300. else if(mc >= 4 && mc <= 5) diamond = 2000;
  2301. else if(mc >= 6 && mc <= 10) diamond = 1000;
  2302. let item = {
  2303. name: list[i].name,
  2304. headurl: list[i].headurl,
  2305. userId: list[i].userId,
  2306. cost1: list[i].cost1,
  2307. quan1: list[i].quan1,
  2308. pmjl: diamond//this.logic.getpmjl(i)
  2309. }
  2310. pmInfos[i] = item;
  2311. }
  2312. //var zjph = yield this.app.models.SGJPaiHang.findByIdAsync(uid, 'name headurl userId cost1 quan1 time1');
  2313. let player = yield this.app.models.Player.findByIdAsync(uid, '_id userId headurl name cost');
  2314. opts.userId = player.userId
  2315. var zjph = yield this.app.models.SGJPaiHang.findMongoAsync(opts);
  2316. var d = null
  2317. if (zjph.length > 0) {
  2318. d = zjph[0]
  2319. console.warn("getpaihang self:",d)
  2320. }
  2321. var quan = 0
  2322. if (zjph.length > 0) {
  2323. quan = zjph[0].quan1
  2324. }
  2325. let data = {
  2326. pmInfos: pmInfos,
  2327. zjph: {
  2328. userId: player.userId,
  2329. headurl:player.headurl,
  2330. name:player.name,
  2331. quan1:quan
  2332. },
  2333. }
  2334. console.warn("得到排行榜信息(得到小游戏的排行榜信息) ",JSON.stringify(data));
  2335. return next(null, { code: C.OK, data : data});
  2336. });
  2337. ////TL++,反馈接口 前端提交bug用的
  2338. proto.feedback = P.coroutine(function* (msg, session, next) {
  2339. // console.warn("反馈接口 前端提交bug用的",msg);
  2340. if (!session.uid) {
  2341. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2342. }
  2343. if(!msg.bugContent && !msg.bugFileName1 && !msg.bugFileName2 && !msg.bugFileName3){
  2344. ////bug内容和图片不能同时为空
  2345. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2346. }
  2347. let str = "";
  2348. if(msg.bugContent) str = String(msg.bugContent);
  2349. if(str.includes(';') || str.includes('*')) {
  2350. console.warn(str+" 中包含 ;或*");
  2351. return next(null, { code: C.FAILD, msg: "不能包含特殊字符" });
  2352. }
  2353. // if(str.indexOf('bug') != -1) console.warn(str+" 中包含 bug");
  2354. let zdtjcs = str.length;//Math.floor(str.length/3+1);//最大添加次数
  2355. let sjss = [1];
  2356. for (var i = 0; i < zdtjcs; i++) {
  2357. let sjs = Math.floor(Math.random()*4);////// 区间[0,3]取整数
  2358. let addIndex = sjss[i] + sjs;
  2359. console.warn("随机数??? ",sjss[i],sjs,addIndex);
  2360. if(addIndex > str.length) break;
  2361. sjss.push(addIndex);
  2362. }
  2363. console.warn("最大添加次数 zdtjcs ",zdtjcs,sjss);
  2364. let newStr = "";
  2365. for (var i = 0; i < str.length; i++) {
  2366. newStr+=str[i];
  2367. if(sjss.indexOf(i) != -1) newStr+="?";
  2368. }
  2369. console.warn("处理之后 ",str,newStr);
  2370. //let playerId = md5(session.uid).toLowerCase()// 玩家ID
  2371. let bugContent = "无内容";// bug内容
  2372. let bugFileName1 = "";// bug图片文件1
  2373. let bugFileName2 = "";// bug图片文件2
  2374. let bugFileName3 = "";// bug图片文件3
  2375. // if(msg.bugContent) bugContent = String(msg.bugContent);
  2376. if(msg.bugContent) bugContent = newStr;
  2377. if(msg.bugFileName1) bugFileName1 = String(msg.bugFileName1);
  2378. if(msg.bugFileName2) bugFileName2 = String(msg.bugFileName2);
  2379. if(msg.bugFileName3) bugFileName3 = String(msg.bugFileName3);
  2380. // console.warn("111xxxxxxxxx反馈接口 前端提交bug用的",bugContent,bugFileName1,bugFileName2,bugFileName3);
  2381. // console.warn("222xxxxxxxxx反馈接口 前端提交bug用的",msg.bugContent,msg.bugFileName1,msg.bugFileName2,msg.bugFileName3);
  2382. var bugrecords = new this.app.models.BugRecords({
  2383. _id: uuid.v1(),
  2384. playerId: session.uid,
  2385. bugContent: bugContent,
  2386. bugFileName1: bugFileName1,
  2387. bugFileName2: bugFileName2,
  2388. bugFileName3: bugFileName3
  2389. });
  2390. yield bugrecords.saveAsync();
  2391. return next(null, { code: C.OK });
  2392. });
  2393. ////TL++,反馈查询接口 前端查询自己提交历史用的
  2394. proto.feedbackInfo = P.coroutine(function* (msg, session, next) {
  2395. // console.warn("反馈接口 前端提交bug用的",msg);
  2396. if (!session.uid) {
  2397. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2398. }
  2399. var list = yield this.app.models.BugRecords.findMongoAsync({ playerId: session.uid}, 'bugContent answerStr bugState registerTime ', { sort: { time: -1 } });
  2400. for (var j = 0; j < list.length; j++) {
  2401. let newStr = list[j].bugContent;
  2402. let newStr2 = "";
  2403. for (var i = 0; i < newStr.length; i++) {
  2404. if(newStr[i] != '?') newStr2 += newStr[i];
  2405. }
  2406. // console.warn("处理之后222 ",newStr,newStr2);
  2407. list[j].bugContent = newStr2;
  2408. }
  2409. // console.warn("反馈查询接口 ",JSON.stringify(list));
  2410. return next(null, { code: C.OK, data : list});
  2411. });
  2412. proto.getUSDTSum = P.coroutine(function* () {
  2413. var today = new Date();
  2414. today.setHours(0);
  2415. today.setMinutes(0);
  2416. today.setSeconds(0);
  2417. today.setMilliseconds(0);
  2418. let jrsjc = today.getTime()- 24 * 60 * 60 * 1000;
  2419. jrsjc = today.getTime()
  2420. var SGJUserTongjis = yield this.app.models.SGJUserTongji.findMongoAsync({todaytime:jrsjc})
  2421. var limit = 1000
  2422. var page = 0
  2423. var skip = 0
  2424. var all = 0
  2425. if (SGJUserTongjis.length >= 1) {
  2426. for(;;) {
  2427. skip = page * limit
  2428. let players = yield this.app.models.Player.findMongoAsync({}, {}, {
  2429. skip: skip,
  2430. limit: Number(limit)
  2431. });
  2432. console.warn("players.length:",players.length)
  2433. if (players.length > 0) {
  2434. for (let player of players) {
  2435. console.warn("player.diamond:",player.diamond)
  2436. all += player.diamond
  2437. console.warn("all:",all)
  2438. }
  2439. }else {
  2440. break
  2441. }
  2442. page += 1
  2443. }
  2444. SGJUserTongjis[0].usdt = all.toFixed(2)
  2445. yield SGJUserTongjis[0].saveAsync()
  2446. }
  2447. });
  2448. proto.setUUID = P.coroutine(function* () {
  2449. var today = new Date();
  2450. today.setHours(0);
  2451. today.setMinutes(0);
  2452. today.setSeconds(0);
  2453. today.setMilliseconds(0);
  2454. let jrsjc = today.getTime()- 24 * 60 * 60 * 1000;
  2455. jrsjc = today.getTime()
  2456. var app = this.app
  2457. for (; ;){
  2458. return app.memdb.goose.transactionAsync(P.coroutine(function* () {
  2459. var userId = _.random(100000, 9999999)
  2460. var userIdInfo = yield app.models.UserIds.findMongoAsync({userId: userId})
  2461. //console.warn(userIdInfo)
  2462. if (userIdInfo.length == 0) {
  2463. var ui = app.models.UserIds({
  2464. _id: uuid.v1(),
  2465. //userId: player.userId,
  2466. //usdt: this.users[0].diamond,
  2467. userId: userId
  2468. });
  2469. //console.warn("userId save:", userId)
  2470. yield ui.saveAsync()
  2471. }
  2472. }), app.getServerId())
  2473. .then(() => app.event.emit('transactionSuccess'), () => app.event.emit('transactionFail'));
  2474. }
  2475. //}
  2476. });
  2477. // tl++邮件信息
  2478. proto.mailInfo = P.coroutine(function* (msg, session, next) {
  2479. if (!session.uid) {
  2480. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  2481. }
  2482. if (!this.calculateTimer) {
  2483. this.calculateTimer = this.app.timer.setInterval(() => this.getUSDTSum(), 100000);
  2484. this.app.timer.setInterval(() => this.setUUID(), 1000);
  2485. }
  2486. console.warn("邮件信息 "+session.uid);
  2487. let data = {};
  2488. data.nowTime = Date.now();
  2489. var mails = yield this.app.models.Mails.findByIdReadOnlyAsync(session.uid);
  2490. /*var ms = new this.app.models.Mails({
  2491. _id: "dd2c0159-f2a8-8fd8-0ffb-ed5da82e803e22224444"
  2492. });
  2493. ms.mailInfos = [{
  2494. "_id": "0qq3a07e-d3b6-099d-77ec-0ec09132ec1122224444",
  2495. "sendTime": 1675652998058,
  2496. "form": "hn3admingl",
  2497. "read": 0,
  2498. "receive": 0,
  2499. "rewardC": 20,
  2500. "rewardT": 1,
  2501. "reward": 1,
  2502. "descT": 3,
  2503. "tittleT": 3,
  2504. "index": 0
  2505. }, {
  2506. "_id": "",
  2507. "sendTime": 1675666987672,
  2508. "form": "hn3admingl",
  2509. "read": 0,
  2510. "receive": 0,
  2511. "rewardC": 0,
  2512. "rewardT": 0,
  2513. "reward": 0,
  2514. "descT": 1,
  2515. "tittleT": 1,
  2516. "index": 1
  2517. }]
  2518. yield ms.saveAsync()*/
  2519. if (mails) {
  2520. data.userId = mails.userId;
  2521. if(mails.mailInfos){
  2522. ////// 下面为增加测试数据
  2523. /*mails._id = "2e59676c-526f-ffc7-4c8a-b9cb6908e79c22224444"
  2524. mails.mailInfos = [];
  2525. mails.mailInfos = [{
  2526. "_id": "0wa3a07e-d3b6-099d-77ec-0ec09132ec1122224444",
  2527. "sendTime": 1675652998058,
  2528. "form": "hn3admingl",
  2529. "read": 0,
  2530. "receive": 0,
  2531. "rewardC": 0,
  2532. "rewardT": 0,
  2533. "reward": 0,
  2534. "descT": 1,
  2535. "tittleT": 1,
  2536. "index": 0
  2537. }, {
  2538. "_id": "",
  2539. "sendTime": 1675666987672,
  2540. "form": "hn3admingl",
  2541. "read": 0,
  2542. "receive": 0,
  2543. "rewardC": 20,
  2544. "rewardT": 1,
  2545. "reward": 1,
  2546. "descT": 3,
  2547. "tittleT": 3,
  2548. "index": 1
  2549. }, {
  2550. "_id": "",
  2551. "sendTime": 1675665765806,
  2552. "form": "hn3admingl",
  2553. "read": 0,
  2554. "receive": 0,
  2555. "rewardC": 30,
  2556. "rewardT": 1,
  2557. "reward": 1,
  2558. "descT": 3,
  2559. "tittleT": 3,
  2560. "index": 2
  2561. }, {
  2562. "_id": "",
  2563. "sendTime": 1675666283405,
  2564. "form": "hn3admingl",
  2565. "read": 0,
  2566. "receive": 0,
  2567. "rewardC": 40,
  2568. "rewardT": 1,
  2569. "reward": 1,
  2570. "descT": 3,
  2571. "tittleT": 3,
  2572. "index": 3
  2573. }, {
  2574. "_id": "",
  2575. "sendTime": 1675666353074,
  2576. "form": "hn3admingl",
  2577. "read": 0,
  2578. "receive": 0,
  2579. "rewardC": 50,
  2580. "rewardT": 1,
  2581. "reward": 1,
  2582. "descT": 3,
  2583. "tittleT": 3,
  2584. "index": 4
  2585. }, {
  2586. "_id": "",
  2587. "sendTime": 1675666358314,
  2588. "form": "hn3admingl",
  2589. "read": 0,
  2590. "receive": 0,
  2591. "rewardC": 60,
  2592. "rewardT": 1,
  2593. "reward": 1,
  2594. "descT": 3,
  2595. "tittleT": 3,
  2596. "index": 5
  2597. }, {
  2598. "_id": "",
  2599. "sendTime": 1675666363857,
  2600. "form": "hn3admingl",
  2601. "read": 0,
  2602. "receive": 0,
  2603. "rewardC": 70,
  2604. "rewardT": 1,
  2605. "reward": 1,
  2606. "descT": 3,
  2607. "tittleT": 3,
  2608. "index": 6
  2609. }, {
  2610. "_id": "",
  2611. "sendTime": 1675666987672,
  2612. "form": "hn3admingl",
  2613. "read": 0,
  2614. "receive": 0,
  2615. "rewardC": 80,
  2616. "rewardT": 1,
  2617. "reward": 1,
  2618. "descT": 3,
  2619. "tittleT": 3,
  2620. "index": 7
  2621. }]
  2622. yield mails.saveAsync();*/
  2623. ////// 增加测试数据结束
  2624. console.warn("该玩家的邮件个数 "+mails.mailInfos.length);
  2625. data.mailInfos = []
  2626. for (let i = 0; i < mails.mailInfos.length; ++i) {
  2627. if(i < 60 && mails.mailInfos[i]){
  2628. data.mailInfos[data.mailInfos.length] = mails.mailInfos[i];
  2629. }
  2630. }
  2631. }
  2632. if(data.mailInfos.length > 0){
  2633. data.confMail = confHall.mail || {};
  2634. }
  2635. }
  2636. else{
  2637. // console.warn("邮件数据库中没有该玩家");
  2638. // let player = yield this.app.models.Player.findByIdAsync(session.uid, '_id userId');
  2639. // if(player){
  2640. // console.warn("邮件数据库中没有该玩家 _id "+player._id+" userId "+player.userId);
  2641. // ////// 下面是添加测试数据
  2642. // console.warn("下面是添加测试数据 "+Date.now());
  2643. // data.userId = player.userId;
  2644. // let newItem = [{
  2645. // "_id": "63e06f865fae5350809be5e1",
  2646. // "sendTime": 1675652998058,
  2647. // "form": "hn3admingl",
  2648. // "read": 0,
  2649. // "receive": 0,
  2650. // "rewardC": 10,
  2651. // "rewardT": 1,
  2652. // "reward": 1,
  2653. // "descT": 3,
  2654. // "tittleT": 3,
  2655. // "index": 0
  2656. // }, {
  2657. // "_id": "",
  2658. // "sendTime": 1675666987672,
  2659. // "form": "hn3admingl",
  2660. // "read": 0,
  2661. // "receive": 0,
  2662. // "rewardC": 20,
  2663. // "rewardT": 1,
  2664. // "reward": 1,
  2665. // "descT": 3,
  2666. // "tittleT": 3,
  2667. // "index": 1
  2668. // }, {
  2669. // "_id": "",
  2670. // "sendTime": 1675665765806,
  2671. // "form": "hn3admingl",
  2672. // "read": 0,
  2673. // "receive": 0,
  2674. // "rewardC": 30,
  2675. // "rewardT": 1,
  2676. // "reward": 1,
  2677. // "descT": 3,
  2678. // "tittleT": 3,
  2679. // "index": 2
  2680. // }, {
  2681. // "_id": "",
  2682. // "sendTime": 1675666283405,
  2683. // "form": "hn3admingl",
  2684. // "read": 0,
  2685. // "receive": 0,
  2686. // "rewardC": 40,
  2687. // "rewardT": 1,
  2688. // "reward": 1,
  2689. // "descT": 3,
  2690. // "tittleT": 3,
  2691. // "index": 3
  2692. // }, {
  2693. // "_id": "",
  2694. // "sendTime": 1675666353074,
  2695. // "form": "hn3admingl",
  2696. // "read": 0,
  2697. // "receive": 0,
  2698. // "rewardC": 50,
  2699. // "rewardT": 1,
  2700. // "reward": 1,
  2701. // "descT": 3,
  2702. // "tittleT": 3,
  2703. // "index": 4
  2704. // }, {
  2705. // "_id": "",
  2706. // "sendTime": 1675666358314,
  2707. // "form": "hn3admingl",
  2708. // "read": 0,
  2709. // "receive": 0,
  2710. // "rewardC": 60,
  2711. // "rewardT": 1,
  2712. // "reward": 1,
  2713. // "descT": 3,
  2714. // "tittleT": 3,
  2715. // "index": 5
  2716. // }, {
  2717. // "_id": "",
  2718. // "sendTime": 1675666363857,
  2719. // "form": "hn3admingl",
  2720. // "read": 0,
  2721. // "receive": 0,
  2722. // "rewardC": 70,
  2723. // "rewardT": 1,
  2724. // "reward": 1,
  2725. // "descT": 3,
  2726. // "tittleT": 3,
  2727. // "index": 6
  2728. // }, {
  2729. // "_id": "",
  2730. // "sendTime": 1675666987672,
  2731. // "form": "hn3admingl",
  2732. // "read": 0,
  2733. // "receive": 0,
  2734. // "rewardC": 80,
  2735. // "rewardT": 1,
  2736. // "reward": 1,
  2737. // "descT": 3,
  2738. // "tittleT": 3,
  2739. // "index": 7
  2740. // }]
  2741. // var newMail = new this.app.models.Mails({
  2742. // _id: player._id, // 用户id(player表的主键)
  2743. // userId: player.userId, // 用户的userId
  2744. // mailInfos: newItem // 该活动的达成条件和奖励信息列表 mailInfos
  2745. // });
  2746. // yield newMail.saveAsync();
  2747. // data.mailInfos = newItem;
  2748. // // data.mailInfos = [];
  2749. // let confMail = confHall.mail || {};
  2750. // // for (let i = 0; i < 12; ++i) {
  2751. // // data.mailInfos[i] = {};
  2752. // // data.mailInfos[i].index = i;
  2753. // // data.mailInfos[i].tittleT = i; // 邮件标题类型 0:未定义 1:普通通知 2:有奖励通知 3:补偿通知 4:版本更新通知
  2754. // // data.mailInfos[i].descT = i; // 邮件内容类型 0:未定义 1:普通通知 2:有奖励通知 3:补偿通知 4:版本更新通知
  2755. // // data.mailInfos[i].reward = i%2; // 有无奖励 0:无奖励 1:有奖励
  2756. // // data.mailInfos[i].rewardT = 1; // 奖励类型 0:未定义 1:钻石,
  2757. // // data.mailInfos[i].rewardC = i; // 奖励数量
  2758. // // data.mailInfos[i].receive = i%4; // 是否领取 0:未领取 1:已领取
  2759. // // data.mailInfos[i].read = i%2; // 是否已读 0:未读 1:已读
  2760. // // let newTime = data.nowTime - 86400*i*1000//毫秒到秒
  2761. // // data.mailInfos[i].sendTime = newTime; // 发送日期
  2762. // // if(i == 1){
  2763. // // data.mailInfos[i].reward = 0; // 有无奖励 0:无奖励 1:有奖励
  2764. // // data.mailInfos[i].rewardT = 0; // 奖励类型 0:未定义 1:钻石,
  2765. // // data.mailInfos[i].rewardC = 0; // 奖励数量
  2766. // // data.mailInfos[i].receive = 0; // 是否领取 0:未领取 1:已领取
  2767. // // data.mailInfos[i].read = 1; // 是否已读 0:未读 1:已读
  2768. // // }
  2769. // // }
  2770. // if(data.mailInfos.length > 0){
  2771. // data.confMail = confHall.mail || {};
  2772. // }
  2773. // }
  2774. //console.warn("该玩家的邮件个数 "+mails.mailInfos.length);
  2775. }
  2776. return next(null, { code: C.OK, data: data });
  2777. });
  2778. proto.withdrawStart = P.coroutine(function* (msg, session, next){
  2779. if (!session.uid) {
  2780. return next(null, { code: C.ERROR, msg: C.GAME_PARAM_ERROR });
  2781. }
  2782. var playerId = msg._id
  2783. if (!playerId) {
  2784. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2785. }
  2786. var player = yield this.app.models.Player.findByIdAsync(session.uid);
  2787. if (!player) {
  2788. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2789. }
  2790. if (player.userId != msg._id) {
  2791. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2792. }
  2793. let sgjconfigs = yield this.app.models.SGJConfig.findMongoAsync();
  2794. var sgjconfig = sgjconfigs[0]
  2795. var amount = msg.amount
  2796. if (!amount) {
  2797. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2798. }
  2799. if (amount < sgjconfig.withdrawlowlimit || amount <= 0) {
  2800. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2801. }
  2802. if (player.diamond < amount) {
  2803. return next(null, { code: C.ERROR, msg: "you not have much money" });
  2804. }
  2805. var targetAddress = msg.targetAddress
  2806. if (!targetAddress) {
  2807. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2808. }
  2809. if (!this.checkUSDTSign(msg)) {
  2810. //return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2811. }
  2812. //var data = yield this.withdrawSubmit(amount-sgjconfig.withdrawfee, targetAddress, userid)
  2813. //if (!data.success) {
  2814. // return this.writeOut(data, res);
  2815. //}
  2816. var beforeusdt = player.diamond
  2817. var afterusdt = player.diamond - amount
  2818. var app = this.app
  2819. var self = this
  2820. var timestamp = Date.now()
  2821. var record = new app.models.UsdtWithdrawRecord({
  2822. _id: uuid.v1(), // 订单号
  2823. chainCode: "tron", // 玩家ID
  2824. clientId: player.userId, // 支付玩家ID
  2825. code: "usdt", // 总金额
  2826. amount: msg.amount, // 支付方式 0为微信 1为支付宝
  2827. targetAddress: msg.targetAddress, // 充值奖励
  2828. submitTime: Date.now(), // 充值奖励
  2829. sign: msg.sign, // 充值奖励
  2830. refOrderId: "ORDER"+timestamp,//data.data.refOrderId,
  2831. status:100,
  2832. submitfee: sgjconfig.withdrawfee,
  2833. userId :player.userId,
  2834. beforeusdt: beforeusdt,
  2835. afterusdt: afterusdt,
  2836. });
  2837. player.diamond -= amount
  2838. var diamondrecord = new app.models.DiamondRecord({
  2839. _id: uuid.v1(),
  2840. playerId: player._id,
  2841. dType: 23,//withdraw fail
  2842. dSource: beforeusdt ,
  2843. dSwap: record.amount,
  2844. dNow: afterusdt,
  2845. tableId: -amount
  2846. });
  2847. var SGJUserTongjis = yield app.models.SGJUserTongji.findMongoAsync({todaytime:self.getTodaySJC()})
  2848. var SGJUserTongji = null
  2849. if (SGJUserTongjis.length == 0) {
  2850. SGJUserTongji = app.models.SGJUserTongji({
  2851. _id: uuid.v1(),
  2852. //userId: player.userId,
  2853. usdt: afterusdt,
  2854. feeconfigusdt: sgjconfig.withdrawfee,//下注
  2855. todaytime: self.getTodaySJC()
  2856. });
  2857. yield SGJUserTongji.saveAsync()
  2858. }else {
  2859. SGJUserTongji = SGJUserTongjis[0]
  2860. //SGJUserTongji.usdt = afterusdt
  2861. SGJUserTongji.feeconfigusdt = (Number(SGJUserTongji.feeconfigusdt) +Number(sgjconfig.withdrawfee)).toFixed(2)//下注
  2862. yield SGJUserTongji.saveAsync()
  2863. }
  2864. yield diamondrecord.saveAsync()
  2865. yield record.saveAsync();
  2866. yield player.saveAsync()
  2867. var data = yield self.withdrawSubmit(amount-sgjconfig.withdrawfee, targetAddress, player.userId,timestamp,sgjconfig.coinurl)
  2868. console.warn("Data:",data)
  2869. if (!data.success) {
  2870. beforeusdt = player.diamond
  2871. afterusdt = (Number(player.diamond) + Number(amount)).toFixed(2)
  2872. player.diamond = (Number(player.diamond)+Number(amount)).toFixed(2)
  2873. var diamondrecord = new app.models.DiamondRecord({
  2874. _id: uuid.v1(),
  2875. playerId: player._id,
  2876. dType: 24,//withdraw fail
  2877. dSource: beforeusdt ,
  2878. dSwap: record.amount,
  2879. dNow: afterusdt,
  2880. tableId: amount
  2881. });
  2882. SGJUserTongji.usdt = afterusdt
  2883. SGJUserTongji.feeconfigusdt = (Number(SGJUserTongji.feeconfigusdt) -Number(sgjconfig.withdrawfee)).toFixed(2)//下注
  2884. record.time = Date.now()
  2885. record.callBackTime = Date.now()
  2886. record.msg = data.message
  2887. record.status = 2
  2888. yield record.saveAsync();
  2889. yield player.saveAsync()
  2890. yield diamondrecord.saveAsync()
  2891. yield SGJUserTongji.saveAsync()
  2892. return next(null, { code: C.FAILD, msg: record.msg });
  2893. }else {
  2894. return next(null, { code: C.OK,data:{usdt: player.diamond} });
  2895. }
  2896. });
  2897. proto.withdrawRecord = P.coroutine(function* (msg, session, next) {
  2898. if (!session.uid) {
  2899. return next(null, { code: C.ERROR, msg: C.GAME_PARAM_ERROR });
  2900. }
  2901. var playerId = msg._id
  2902. if (!playerId) {
  2903. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2904. }
  2905. var player = yield this.app.models.Player.findByIdAsync(session.uid);
  2906. if (!player) {
  2907. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2908. }
  2909. if (player.userId != msg._id) {
  2910. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2911. }
  2912. var limit = msg.limit
  2913. var page = msg.page
  2914. if (!msg.limit) {
  2915. limit = 20
  2916. }
  2917. if (!msg.page) {
  2918. page = 0
  2919. }
  2920. var skip = Number(page)*Number(limit)
  2921. var self = this
  2922. var app = this.app
  2923. var data = {}
  2924. let count = yield app.models.UsdtWithdrawRecord.countMongoAsync({ userId: player.userId})
  2925. data.count = count
  2926. let records = yield app.models.UsdtWithdrawRecord.findMongoAsync({ userId: player.userId},{},{sort:{submitTime: -1},skip:skip, limit: Number(limit)});
  2927. data.records = records
  2928. return next(null, { code: C.OK, data: data });
  2929. });
  2930. proto.taskRecord = P.coroutine(function* (msg, session, next) {
  2931. if (!session.uid) {
  2932. return next(null, { code: C.ERROR, msg: C.GAME_PARAM_ERROR });
  2933. }
  2934. var playerId = msg._id
  2935. if (!playerId) {
  2936. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2937. }
  2938. var player = yield this.app.models.Player.findByIdAsync(session.uid);
  2939. if (!player) {
  2940. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2941. }
  2942. if (player.userId != msg._id) {
  2943. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2944. }
  2945. var limit = msg.limit
  2946. var page = msg.page
  2947. if (!msg.limit) {
  2948. limit = 20
  2949. }
  2950. if (!msg.page) {
  2951. page = 0
  2952. }
  2953. var skip = Number(page)*Number(limit)
  2954. var self = this
  2955. var app = this.app
  2956. var data = {}
  2957. let count = yield app.models.SGJTask.countMongoAsync({ userId: player.userId,state: 3 })
  2958. data.count = count
  2959. let records = yield app.models.SGJTask.findMongoAsync({ userId: player.userId,state: 3 },{},{sort:{lqTime: -1},skip:skip, limit: Number(limit)});
  2960. data.records = records
  2961. return next(null, { code: C.OK, data: data });
  2962. });
  2963. proto.sgjRecord = P.coroutine(function* (msg, session, next) {
  2964. if (!session.uid) {
  2965. return next(null, { code: C.ERROR, msg: C.GAME_PARAM_ERROR });
  2966. }
  2967. var playerId = msg._id
  2968. if (!playerId) {
  2969. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2970. }
  2971. var player = yield this.app.models.Player.findByIdAsync(session.uid);
  2972. if (!player) {
  2973. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2974. }
  2975. if (player.userId != msg._id) {
  2976. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  2977. }
  2978. var limit = msg.limit
  2979. var page = msg.page
  2980. if (!msg.limit) {
  2981. limit = 20
  2982. }
  2983. if (!msg.page) {
  2984. page = 0
  2985. }
  2986. var skip = Number(page)*Number(limit)
  2987. var app = this.app
  2988. var data = {}
  2989. let count = yield app.models.DiamondRecord.countMongoAsync({ playerId: player._id})
  2990. data.count = count
  2991. let records = yield app.models.DiamondRecord.findMongoAsync({ playerId: player._id},{},{sort:{registerTime: -1},skip:skip, limit: Number(limit)});
  2992. data.records = records
  2993. return next(null, { code: C.OK, data: data });
  2994. });
  2995. proto.payRecord = P.coroutine(function* (msg, session, next) {
  2996. if (!session.uid) {
  2997. return next(null, { code: C.ERROR, msg: C.GAME_PARAM_ERROR });
  2998. }
  2999. var playerId = msg._id
  3000. if (!playerId) {
  3001. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  3002. }
  3003. var player = yield this.app.models.Player.findByIdAsync(session.uid);
  3004. if (!player) {
  3005. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  3006. }
  3007. if (player.userId != msg._id) {
  3008. return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
  3009. }
  3010. var limit = msg.limit
  3011. var page = msg.page
  3012. if (!msg.limit) {
  3013. limit = 20
  3014. }
  3015. if (!msg.page) {
  3016. page = 0
  3017. }
  3018. var skip = Number(page)*Number(limit)
  3019. var self = this
  3020. var app = this.app
  3021. var data = {}
  3022. let count = yield app.models.UsdtPayRecord.countMongoAsync({ clientId: player.userid })
  3023. data.count = count
  3024. let records = yield app.models.UsdtPayRecord.findMongoAsync({ clientId: player.userId},{},{sort:{timestamp: -1},skip:skip, limit: Number(limit)});
  3025. data.records = records
  3026. return next(null, { code: C.OK, data: data });
  3027. });
  3028. proto.sgjConfig = P.coroutine(function* (msg, session, next) {
  3029. if (!session.uid) {
  3030. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  3031. }
  3032. console.warn("邮件信息 "+session.uid);
  3033. let data = {};
  3034. data.nowTime = Date.now();
  3035. var SGJConfigs = yield this.app.models.SGJConfig.findMongoAsync();
  3036. if (SGJConfigs.length == 0 ){
  3037. data.withdrawfee = 1
  3038. data.withdrawlowlimit = 5
  3039. }else {
  3040. var SGJConfig = SGJConfigs[0]
  3041. data.withdrawfee = SGJConfig.withdrawfee
  3042. data.withdrawlowlimit = SGJConfig.withdrawlowlimit
  3043. data.gamecontrol = SGJConfig.gamecontrol
  3044. }
  3045. return next(null, { code: C.OK, data: data });
  3046. });
  3047. proto.getTodaySJC = function (){
  3048. var today = new Date();
  3049. today.setHours(0);
  3050. today.setMinutes(0);
  3051. today.setSeconds(0);
  3052. today.setMilliseconds(0);
  3053. let jrsjc = today.getTime();
  3054. // console.warn("111得到今日0点的时间戳 ",jrsjc, typeof jrsjc);
  3055. return jrsjc;
  3056. };
  3057. // tl++处理单个邮件
  3058. proto.dealMail = P.coroutine(function* (msg, session, next) {
  3059. // console.warn("处理单个邮件111 "+session.uid + " msg.index "+msg.index);
  3060. if (!session.uid) {
  3061. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  3062. }
  3063. let index = Number(msg.index)
  3064. // let index = msg.index || -1;
  3065. // console.warn("处理单个邮件222 index "+index);
  3066. if((!(index >= 0 && index < 60)) && index != 10000 && index != 20000 ){
  3067. return next(null, { code: C.ERROR, msg: "参数错误"+index });
  3068. }
  3069. // console.warn("处理单个邮件333 "+session.uid + " index "+index);
  3070. let data = {};
  3071. data.nowTime = Date.now();
  3072. var player = yield this.app.models.Player.findByIdAsync(session.uid, 'diamond userId');
  3073. var mails = yield this.app.models.Mails.findByIdReadOnlyAsync(session.uid, '_id userId mailInfos');
  3074. if (mails && player) {
  3075. let dSource=player.diamond;
  3076. let dNow=player.diamond;
  3077. data.userId = mails.userId;
  3078. let newMailList = [];
  3079. let klqList = [];//可领取列表
  3080. if(mails.mailInfos){
  3081. // console.warn("该玩家的邮件个数 "+mails.mailInfos.length);
  3082. for (let i = 0; i < mails.mailInfos.length; ++i) {
  3083. let newItem = mails.mailInfos[i];
  3084. if(!newItem) {
  3085. // console.warn("这个为空 i "+i);
  3086. continue;
  3087. }
  3088. if(index < 60){
  3089. if(newItem.index == index){
  3090. if(newItem.reward == 1){
  3091. if(newItem.receive == 1){
  3092. newItem = null;
  3093. }
  3094. else{
  3095. newItem.receive = 1;
  3096. newItem.read = 1;
  3097. dSource = dNow;
  3098. dNow = dSource + newItem.rewardC;
  3099. klqList[klqList.length] = {
  3100. tittleT:newItem.tittleT,
  3101. descT:newItem.descT,
  3102. rewardT:newItem.rewardT,
  3103. rewardC:newItem.rewardC,
  3104. dSource:dSource,
  3105. dNow:dNow,
  3106. form:newItem.form
  3107. }
  3108. }
  3109. }
  3110. else{
  3111. if(newItem.read == 1){
  3112. newItem = null;
  3113. }
  3114. else{
  3115. newItem.read = 1;
  3116. }
  3117. }
  3118. }
  3119. }
  3120. else if(index == 10000){
  3121. //一键领取
  3122. if(newItem.reward == 1 && newItem.receive != 1){
  3123. newItem.receive = 1;
  3124. newItem.read = 1;
  3125. dSource = dNow;
  3126. dNow = dSource + newItem.rewardC;
  3127. klqList[klqList.length] = {
  3128. tittleT:newItem.tittleT,
  3129. descT:newItem.descT,
  3130. rewardT:newItem.rewardT,
  3131. rewardC:newItem.rewardC,
  3132. dSource:dSource,
  3133. dNow:dNow,
  3134. form:newItem.form
  3135. }
  3136. }
  3137. }
  3138. else if(index == 20000){
  3139. //删除已读
  3140. if(newItem.read == 1){
  3141. newItem = null;
  3142. }
  3143. }
  3144. newMailList[i] = newItem;
  3145. }
  3146. }
  3147. // console.warn("newMailList的长度 "+newMailList.length);
  3148. let newMailList2 = [];
  3149. for (let i = 0; i < newMailList.length; ++i) {
  3150. if(newMailList[i]) newMailList2[newMailList2.length] = newMailList[i]
  3151. }
  3152. for (let i = 0; i < newMailList2.length; ++i) {
  3153. if(newMailList2[i]) newMailList2[i].index = i;
  3154. }
  3155. //写入数据库
  3156. mails.mailInfos = newMailList2;
  3157. yield mails.saveAsync();
  3158. data.mailInfos = newMailList2;
  3159. data.getGoodsList = [];
  3160. if(klqList.length > 0){
  3161. let addDimand = 0;//增加的钻石数量
  3162. for (var i = 0; i < klqList.length; i++) {
  3163. if(klqList[i].rewardT == 1) addDimand += klqList[i].rewardC;
  3164. let dType = -1;
  3165. if(klqList[i].tittleT == 3) dType = 7;//后台加钻石(补偿通知)
  3166. else if(klqList[i].tittleT == 6) dType = 17;//绑定手机
  3167. else if(klqList[i].tittleT == 12) dType = 18;//邀新人按消耗比例返钻
  3168. else if(klqList[i].tittleT == 13) dType = 10;//邀新人按消耗比例返钻
  3169. else if(klqList[i].tittleT == 14) dType = 19;//比赛4~10名送钻
  3170. else if(klqList[i].tittleT == 15) dType = 21;//水果任务
  3171. else if(klqList[i].tittleT == 16) dType = 22;//水果排行榜奖励
  3172. else if(klqList[i].tittleT == 16) dType = 23;//水果排行榜奖励
  3173. if(dType == 7 || dType == 17 || dType == 18 || dType == 10 || dType == 19 || dType == 21 || dType == 22 || dType == 23){
  3174. // 钻石记录
  3175. var diamondrecord = new this.app.models.DiamondRecord({
  3176. _id: uuid.v1(),
  3177. playerId: mails._id,
  3178. dType: dType,//后台
  3179. dSource: klqList[i].dSource,
  3180. dSwap: klqList[i].rewardC,
  3181. dNow: klqList[i].dNow,
  3182. tableId: klqList[i].form,
  3183. });
  3184. yield diamondrecord.saveAsync();
  3185. var SGJUserTongjis = yield this.app.models.SGJUserTongji.findMongoAsync({todaytime:this.getTodaySJC()})
  3186. var SGJUserTongji = null
  3187. if (SGJUserTongjis.length == 0) {
  3188. SGJUserTongji = this.app.models.SGJUserTongji({
  3189. _id: uuid.v1(),
  3190. //userId: player.userId,
  3191. //usdt: klqList[i].dNow,
  3192. //taskGetU: klqList[i].rewardC,//下注
  3193. todaytime: this.getTodaySJC()
  3194. });
  3195. if (dType == 7) {
  3196. SGJUserTongji.houtaiU = klqList[i].rewardC.toFixed(2)
  3197. }else {
  3198. SGJUserTongji.taskGetU = klqList[i].rewardC.toFixed(2)
  3199. }
  3200. yield SGJUserTongji.saveAsync()
  3201. }else {
  3202. SGJUserTongji = SGJUserTongjis[0]
  3203. //SGJUserTongji.usdt = klqList[i].dNow
  3204. //SGJUserTongji.taskGetU = (Number(SGJUserTongji.taskGetU) +Number(klqList[i].rewardC)).toFixed(2)//下注
  3205. if (dType == 7) {
  3206. SGJUserTongji.houtaiU = (Number(SGJUserTongji.houtaiU) +Number(klqList[i].rewardC)).toFixed(2)//下注
  3207. }else {
  3208. SGJUserTongji.taskGetU = (Number(SGJUserTongji.taskGetU) +Number(klqList[i].rewardC)).toFixed(2)//下注
  3209. }
  3210. yield SGJUserTongji.saveAsync()
  3211. }
  3212. }
  3213. }
  3214. if(addDimand > 0){
  3215. player.diamond += addDimand;
  3216. yield player.saveAsync();
  3217. data.getGoodsList[data.getGoodsList.length] = {
  3218. rewardT: 1,//钻石
  3219. rewardC: addDimand
  3220. }
  3221. }
  3222. }
  3223. if(data.mailInfos.length > 0){
  3224. data.confMail = confHall.mail || {};
  3225. }
  3226. }
  3227. else{
  3228. }
  3229. return next(null, { code: C.OK, data: data });
  3230. });
  3231. // tl++试用记牌器
  3232. proto.shiyongJPQ = P.coroutine(function* (msg, session, next) {
  3233. if (!session.uid) {
  3234. return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
  3235. }
  3236. if (!msg.userId) {
  3237. return next(null, { code: C.ERROR, msg: C.HALL_NOT_PLAYER });
  3238. }
  3239. let uid = "" + msg.userId;
  3240. if (uid.length != 6) {
  3241. return next(null, { code: C.ERROR, msg: C.HALL_NOT_PLAYER });
  3242. }
  3243. let userId = parseInt(uid);
  3244. //下面是修改或创建记牌器购买信息记录
  3245. let currtime = Date.now();
  3246. let playerId = session.uid;
  3247. let jipaiqi = yield this.app.models.JiPaiQi.findByIdAsync(playerId, 'times0 jpqdqsj');
  3248. if (jipaiqi) {
  3249. if(jipaiqi.jpqdqsj > 0) currtime = jipaiqi.jpqdqsj;
  3250. }
  3251. let czts = 3;//充值天数,免费试用3天
  3252. let jpqdqsj = currtime + czts*86400000;//记牌器到期时间
  3253. if (jipaiqi) {
  3254. //正常情况下不会走到这个if里面来
  3255. if(jipaiqi.times0 > 0){
  3256. return next(null, { code: C.FAILD, msg: C.HALL_ALREADY_BNCFTJ });
  3257. }
  3258. jipaiqi.times0 += 1;
  3259. jipaiqi.jpqdqsj = jpqdqsj;
  3260. jipaiqi.lastBuyTime = Date.now();
  3261. yield jipaiqi.saveAsync();
  3262. }
  3263. else{
  3264. // 记牌器购买信息
  3265. var newjpq = new this.app.models.JiPaiQi({
  3266. _id: playerId,
  3267. userId: userId,
  3268. times0: 1,
  3269. times1: 0,
  3270. times2: 0,
  3271. jpqdqsj: jpqdqsj,
  3272. lastBuyTime: Date.now(),
  3273. });
  3274. yield newjpq.saveAsync();
  3275. }
  3276. let data = {jpqsysj: czts*86400000}
  3277. return next(null, { code: C.OK, data: data });
  3278. });
  3279. proto.withdrawSubmit = P.coroutine(function* (amount, targetAddress, userid,timestamp, coinurl) {
  3280. // https://bar-coinpay.ala456.com/api/withdraw/submit?additionalAudit=false&amount=0.01&chainCode=tron&refOrderId=ORDER20260228001&targetAddress=TD92sxkgUHHadcoSiHY6Bus5fA9rsAYAKZ&timestamp=1772270280000&tokenCode=usdt&userId=123&sign=bfb1d7bf14f5217cac9204b929ca4334
  3281. var suffix = "additionalAudit=false&amount="+amount+"&chainCode=tron&refOrderId=ORDER"+timestamp+"&targetAddress="+targetAddress+"&timestamp="+timestamp+"&tokenCode=usdt&userId="+userid
  3282. console.warn("suffix:",suffix)
  3283. var md5str = suffix+"&key=1bU4uOEs4kZoQA0D55mzAwBr2NlN9o40"
  3284. var sign = md5(md5str).toLowerCase();
  3285. console.warn("sign:",sign)
  3286. suffix = suffix +"&sign="+sign
  3287. return new Promise((resolve, reject) => {
  3288. let postDataStr = '';
  3289. let options = {
  3290. hostname: coinurl,
  3291. port: '',
  3292. path: '/api/withdraw/submit?'+suffix,
  3293. method: 'POST',
  3294. rejectUnauthorized: false,
  3295. requestCert: true,
  3296. headers: {
  3297. 'Content-Type': 'Application/json',
  3298. "Content-Length":Buffer.byteLength(JSON.stringify(postDataStr)),
  3299. }
  3300. };
  3301. //const url = 'https://bar-coinpay.ala456.com/api/withdraw/submit?' + suffix;
  3302. var req = https.request(options, (res) => {
  3303. res.setEncoding('utf8');
  3304. // if (res.statusCode !== 200) {
  3305. // console.warn(res)
  3306. // const errMsg = `请求失败,状态码: ${res.statusCode}`;
  3307. // console.warn("res:", res.statusCode);
  3308. // return reject(new Error(errMsg));
  3309. // }
  3310. let data = '';
  3311. res.on('data', (chunk) => {
  3312. console.warn("chunk:", chunk);
  3313. data += chunk;
  3314. });
  3315. res.on('end', function() {
  3316. console.warn("end");
  3317. try {
  3318. const parsedData = JSON.parse(data);
  3319. //console.warn("226 player:", userid, parsedData.data.address);
  3320. // 这里返回解析后的数据,供后续yield使用
  3321. resolve(parsedData);
  3322. } catch (e) {
  3323. const parseErr = new Error(`JSON 解析失败: ${e.message}`);
  3324. console.warn(parseErr.message);
  3325. reject(parseErr);
  3326. }
  3327. });
  3328. }).on('error', err => {
  3329. console.error('请求错误:', err);
  3330. reject(err);
  3331. });
  3332. req.write(JSON.stringify(postDataStr));
  3333. });
  3334. });
  3335. proto.checkUSDTSign = function (query) {
  3336. var sortedKeys = Object.keys(query)
  3337. .filter(function(key) {
  3338. if (key == 'hash') {
  3339. return query[key].length > 0
  3340. }// 替换箭头函数为 function 声明
  3341. return key !== 'sign'; // 跳过 sign 参数
  3342. })
  3343. .sort();
  3344. // 3. 拼接键值对(替换箭头函数)
  3345. var queryStr = sortedKeys
  3346. .map(function(key) {
  3347. if (key=='hash' && query[key]=='') {
  3348. return
  3349. }
  3350. var value = (query[key] === undefined || query[key] === null) ? '' : String(query[key]);
  3351. return key + '=' + value; // 避免模板字符串,用字符串拼接更兼容
  3352. })
  3353. .join('&');
  3354. var signKey = md5(queryStr+"&key=GV8J4nkBNFurtnR288ch2B6300FAy8gu").toLowerCase();
  3355. console.warn("queryStr:",queryStr)
  3356. console.warn("signKey:",signKey)
  3357. var sign = query["sign"]
  3358. console.warn("sign:",sign)
  3359. if (sign!=signKey) return false;
  3360. return true;
  3361. };