hallHandler.js 138 KB

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