member.php 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229
  1. <?php
  2. defined( 'IN_WEB') or die( 'Include Error!');
  3. class ModelMember {
  4. public $secretkey = '#$^&*+_)is!@~/good=<>[]';
  5. private $_attr = ["money"=>1,"spins"=>2,"shield"=>3,"star"=>4,"diamond"=>5];
  6. /**
  7. * 获取玩家资源属性
  8. */
  9. public function getAttr() {
  10. return $this->_attr;
  11. }
  12. /**
  13. * Notes:初始化一些用户信息
  14. * User: wsc
  15. * Time: 2020/4/22 14:13
  16. * @param $uid
  17. */
  18. public function initSomeInfo($uid){
  19. //清空默认攻击列表
  20. $dLKey = okeys::defaultAttactList($uid);
  21. oo::commonOprRedis('Userinfo')->delete($dLKey);
  22. }
  23. /**
  24. * api请求更换websocket每次更新玩家sid、lid、lang
  25. * @param array $arr
  26. * @return bool
  27. */
  28. public function setUserDefinedInfo($uid, array $arr = []) {
  29. oo::commonOprRedis('Userinfo')->hMset(okeys::userDefinedInfo($uid), $arr);
  30. // $ttl = oo::commonOprRedis('Userinfo')->ttl(okeys::userDefinedInfo($uid));//保护时间
  31. // if($ttl == -1){
  32. oo::commonOprRedis('user')->expire(okeys::userDefinedInfo($uid), oo::redisRandomExpire(24*3600));
  33. // }
  34. }
  35. //====================用户基本信息相关======================
  36. /**
  37. * 获取用户基础信息
  38. * @param int $uid
  39. * @param mixed $array 需要获取用户信息的字段
  40. * @param bool $flag true表示需要更新最后登录时间和用户VIP标志位,还有用户的昵称、性别、国家等信息
  41. * @param string $info 用户的FB信息
  42. * @return mixed
  43. */
  44. public function getUserInfo( $uid, $array = NULL, $flag = false, $info = NULL){
  45. if (!$uid = oo::functions()->uint( $uid)) {
  46. return 0;
  47. }
  48. //从新缓存中读取
  49. $userInfo = oo::commonOprRedis('userinfo')->hGetAll(okeys::t_userinfoNew($uid));
  50. if(empty($userInfo)){
  51. $userInfo = oo::commonOprDb('userinfo')->getOne("SELECT * FROM ".otable::userinfo($uid)." WHERE uid='{$uid}'", MYSQLI_ASSOC);
  52. if(empty($userInfo)){
  53. return 0;
  54. }
  55. if(empty($userInfo['isFb'])){ //非fb,重新查一次t_account表
  56. $infoArr = self::getAccount($userInfo['siteuid']);
  57. (!empty($infoArr) && $infoArr['uid'] == $uid) ? $userInfo['isFb'] = 1 : $userInfo['isFb'] = 0;
  58. }
  59. if (isset($userInfo['nick'])){
  60. $nickJson = json_encode($userInfo['nick']);
  61. empty($nickJson) && $userInfo['nick'] = oo::functions()->phutil_utf8ize( $userInfo['nick']);
  62. $userInfo['nick'] = oo::functions()->escapeNick($userInfo['nick']);
  63. }
  64. //设置进入新缓存
  65. oo::commonOprRedis('userinfo')->hMset(okeys::t_userinfoNew($uid), $userInfo);
  66. oo::commonOprRedis('userinfo')->expire(okeys::t_userinfoNew($uid), oo::redisRandomExpire(7*24*60*60));
  67. }
  68. //如果vip过期了,且avatar头像还在,清理头像框
  69. if(!empty($userInfo['avatar']) && $userInfo['vip_expire'] < time()){
  70. $userInfo['avatar'] = 0;
  71. $userInfo['avatarBox'] = json_encode([]);
  72. }
  73. if ($flag && !empty($userInfo['status'])){
  74. if(!$userInfo['isFb']){
  75. if(isset($info['ssiteuid'])){
  76. $userInfo['siteuid'] = $info['ssiteuid'];
  77. }
  78. $infoArr = self::getAccount($userInfo['siteuid']);
  79. if(!empty($infoArr) && $infoArr['uid'] == $uid){
  80. $userInfo['isFb'] = 1;
  81. //防止缓存过期,更新全量数据
  82. oo::commonOprRedis('userinfo')->hMset(okeys::t_userinfoNew($uid), $userInfo);
  83. }
  84. }
  85. if(isset($info['snick']) && empty($info['snick'])){
  86. $updateInfo['snick'] = $uid;
  87. }
  88. foreach($info as $k=>$v){
  89. if($k[0] == 's'){
  90. $updateInfo[substr($k,1)] = oo::functions()->escape($v);
  91. }else{
  92. $updateInfo[$k] = $v;
  93. }
  94. }
  95. self::updateUserInfo($uid,$updateInfo);
  96. }
  97. if(!empty($array)){
  98. foreach ($userInfo as $key=>$row){
  99. if(!in_array($key,$array)){
  100. unset($userInfo[$key]);
  101. }
  102. }
  103. }
  104. return $userInfo;
  105. }
  106. /**
  107. * 批量返回用户基本信息
  108. * @param array $mainkey 需要批量拉取的主键
  109. * @param array $userinfo 返回用户信息数组,引用方式
  110. * @return mixed <0,失败; =0,没有记录; >1,有记录
  111. */
  112. public function getUserInfoMulti( $mainkey, &$userinfo ){
  113. if(empty($mainkey['keylist'])) {
  114. return 0;
  115. }
  116. $mainkey['keylist'] = array_unique($mainkey['keylist']);
  117. foreach ($mainkey['keylist'] as $uid) {
  118. $tmp = oo::commonOprRedis('userinfo')->hGetAll(okeys::t_userinfoNew($uid));
  119. if(!empty($tmp)){
  120. $userinfo[] = $tmp;
  121. }
  122. }
  123. if(empty($userinfo)){
  124. return 0;
  125. }
  126. return 1;
  127. }
  128. /**
  129. * 插入用户基本信息
  130. * @param userinfo 用户信息数组
  131. * @param uid 插入用户信息后返回的uid
  132. * @return <0,失败; =0,成功
  133. */
  134. public function setUserInfo( $userinfo, $uid )
  135. {
  136. $siteuid = isset( $userinfo['siteuid'] ) ? intval( $userinfo['siteuid'] ) : 0;
  137. if ( empty( $siteuid ) )
  138. {
  139. return -1;
  140. }
  141. $array = array(
  142. 'isiteuid' => $siteuid,
  143. 'snick' => isset( $userinfo['nick'] ) ? addslashes(htmlspecialchars( $userinfo['nick']) ) : $uid,
  144. 'ssex' => isset( $userinfo['sex'] ) ? htmlspecialchars( $userinfo['sex'] ) : '',
  145. 'semail' => isset( $userinfo['email'] ) ? htmlspecialchars( $userinfo['email'] ) : '',
  146. 'ss_picture' => isset( $userinfo['s_picture'] ) ? htmlspecialchars( $userinfo['s_picture'] ) : '',
  147. 'sm_picture' => isset( $userinfo['m_picture'] ) ? htmlspecialchars( $userinfo['m_picture'] ) : '',
  148. 'sb_picture' => isset( $userinfo['b_picture'] ) ? htmlspecialchars( $userinfo['b_picture'] ) : '',
  149. 'istatus' => 1,
  150. 'icreatetime' => time(),
  151. 'ilasttime' => time(),
  152. 'slocale' => isset( $userinfo['locale'] ) ? $userinfo['locale'] : '',
  153. 'slocationid' => isset( $userinfo['locationid'] ) ? $userinfo['locationid'] : '',
  154. 'slocationname' => isset( $userinfo['locationname'] ) ? $userinfo['locationname'] : '',
  155. 'shometownid' => isset( $userinfo['hometownid'] ) ? $userinfo['hometownid'] : '',
  156. 'shometownname' => isset( $userinfo['hometownname'] ) ? $userinfo['hometownname'] : '',
  157. 'iinviteuid' => 0,
  158. 'isound' => 70,
  159. 'iinvite' => 0,
  160. 'ilogin_plat' => isset( $userinfo['plat']) ? $userinfo['plat'] : 0,
  161. 'iversion' => isset( $userinfo['version'])? $userinfo['version'] : '1.0.0',
  162. 'itoken' => isset( $userinfo['mac']) ? $userinfo['mac'] : '1.0.0',
  163. 'imac' => isset( $userinfo['token']) ? $userinfo['token'] : '1.0.0',
  164. );
  165. $ikey = '';
  166. $ivalue = '';
  167. foreach($array as $k=>$v){
  168. $ikey = $ikey.substr($k,1).',';
  169. if($k[0] == 's'){
  170. $v = oo::functions()->escape($v);
  171. }
  172. $ivalue = $ivalue."'".$v."',";
  173. }
  174. $ikey = trim($ikey,',');
  175. $ivalue = trim($ivalue,',');
  176. $sql = "INSERT INTO ".otable::userinfo($uid)." (uid,{$ikey}) VALUE('{$uid}',{$ivalue})";
  177. $res = oo::commonOprDb('userinfo')->query($sql);
  178. if($res === true){
  179. $ret = 0;
  180. }else{
  181. $ret = -1;
  182. }
  183. return $ret;
  184. }
  185. /**
  186. * 插入用户基本信息(1.10更新: 用户缓存从string类型替换成hash)
  187. * @param int $uid 插入用户信息后返回的uid
  188. * @param array $array 需要更新的用户信息数组
  189. * @return int -1失败, 1成功
  190. */
  191. public function updateUserInfo( $uid, $array = NULL ){
  192. if(empty($array)) {
  193. return 0;
  194. }
  195. $userInfo = self::getUserInfo($uid);
  196. if(empty($userInfo)){
  197. return 0;
  198. }
  199. ///15天未登录的玩家,好友召回业务添加///
  200. if(empty($userInfo['lasttime']) || $userInfo['lasttime'] + 24 * 15 * 3600 < time()){
  201. oo::commonOprModel('friend')->dealCallBackFriend($uid);
  202. }
  203. ///超过7天未登录的玩家,facebook、adjust邀请也算邀请成功///
  204. if(empty($userInfo['lasttime']) || $userInfo['lasttime'] + 24 * 7 * 3600 < time()){
  205. oo::commonOprRedis('User')->setex(okeys::AdjustBackInviteStatus($uid),3,3*24*60*60);
  206. }
  207. foreach($array as $k=>$v){
  208. $userInfo[$k] = $v;
  209. }
  210. //全量字段更新
  211. oo::commonOprRedis('userinfo')->hMset(okeys::t_userinfoNew($uid), $userInfo);
  212. oo::commonOprRedis('userinfo')->expire(okeys::t_userinfoNew($uid), oo::redisRandomExpire(7*24*60*60));
  213. $updateSql = '';
  214. $nick = "";
  215. foreach($array as $k=>$v){
  216. $updateSql .= $k.'='."'{$v}',";
  217. if($k == "nick"){
  218. $nick = $v;
  219. }
  220. }
  221. $updateSql = trim($updateSql, ',');
  222. $sql = "UPDATE ".otable::userinfo($uid)." SET {$updateSql} WHERE uid={$uid} LIMIT 1";
  223. $res = oo::commonOprDb('userinfo')->query($sql);
  224. if(!empty($nick)){
  225. oo::commonOprModel('ta')->setEventData($uid,'user_set',["nick_name"=>$nick]);
  226. }
  227. return $res === true ? 1 : -1;
  228. }
  229. /**
  230. * 更新FB siteuid和uid
  231. * @param $siteUid
  232. * @param $uid
  233. * @param $newUid
  234. * @return bool
  235. * Created by: Owen
  236. * Created on: 2020/5/22 19:57
  237. */
  238. public function updateAccount($siteUid, $uid ,$newUid){
  239. if (!$siteUid || !$uid || !$newUid) {
  240. return false;
  241. }
  242. $tb = otable::taccount($siteUid);
  243. $sql = "UPDATE {$tb} SET uid={$newUid} WHERE uid={$uid} AND siteuid='{$siteUid}'";
  244. oo::commonOprRedis('user')->delete(okeys::account($siteUid));
  245. // oo::commonOprCache('account')->delete(okeys::account($siteUid));
  246. return oo::commonOprDb('account')->query($sql);
  247. }
  248. /**
  249. * 插入siteuid和uid
  250. * @param unknown $siteuid 平台uid,例如facebook、新浪平台的用户id
  251. * @param unknown $uid 游戏uid
  252. * @return unknown <0,失败; =0,成功
  253. */
  254. public function setAccount( $siteuid, $uid ) {
  255. if (!$siteuid || !$uid) {
  256. return -1;
  257. }
  258. $siteuid = (int)$siteuid;
  259. $uid = (int)$uid;
  260. $now = time();
  261. $tb = otable::taccount($siteuid);
  262. $query = "insert ignore into {$tb} (siteuid,uid,createtime) values ('{$siteuid}','{$uid}','{$now}')";
  263. $ret = oo::commonOprDb('account')->query($query);
  264. if ($ret) {
  265. // oo::commonOprCache('account')->set(okeys::account($siteuid), array('uid'=>$uid,'createtime'=>$now));
  266. oo::commonOprRedis('user')->hMset(okeys::account($siteuid), array('uid'=>$uid,'createtime'=>$now));
  267. //更新玩家信息
  268. $this->updateUserInfo($uid, ['isFb' => 1]);
  269. return 0;
  270. } else {
  271. oo::logs()->debug3(['siteuid' => $siteuid, 'uid' => $uid],'duplicate_account');
  272. return -2;
  273. }
  274. }
  275. /**
  276. * 根据siteuid返回uid
  277. * @param string $siteuid 平台uid,例如facebook、新浪平台的用户id
  278. * @return mixed|number
  279. */
  280. public function getAccount($siteuid){
  281. $siteuid = (int)$siteuid;
  282. if (!$siteuid) return 0;
  283. // $cache = oo::commonOprCache('account')->get(okeys::account($siteuid));
  284. $cache =oo::commonOprRedis('user')->hGetAll(okeys::account($siteuid));
  285. if ($cache && isset($cache['uid'])) {
  286. return $cache;
  287. }
  288. $tb = otable::taccount($siteuid);
  289. $query = "select siteuid, uid, createtime from {$tb} where siteuid='{$siteuid}' limit 1";
  290. $row = oo::commonOprDb('account')->getOne($query, MYSQLI_ASSOC);
  291. if ($row) {
  292. $account = array('uid'=>(int)$row['uid'],'createtime'=>(int)$row['createtime']);
  293. // oo::commonOprCache('account')->set(okeys::account($siteuid), $account, 7*86400);
  294. oo::commonOprRedis('user')->hMset(okeys::account($siteuid), $account);
  295. oo::commonOprRedis('user')->expire(okeys::account($siteuid),oo::redisRandomExpire(7*86400));
  296. return $account;
  297. } else {
  298. return 0;
  299. }
  300. }
  301. /**
  302. * 根据siteuid批量返回uid
  303. * @param unknown $mainkey 平台uid,例如facebook、新浪平台的用户id
  304. * @param unknown $need
  305. * @param unknown $account 返回数组,引用方式
  306. * @return unknown|number <0,失败; =0,没有记录; >1,有记录
  307. */
  308. public function getAccountMulti( $mainkey, $need, &$account )
  309. {
  310. if (!$mainkey || $mainkey['keyname']!='siteuid' || !$mainkey['keylist'] || !is_array($mainkey['keylist'])) {
  311. return -1;
  312. }
  313. $account = array();
  314. foreach ($mainkey['keylist'] as $siteuid) {
  315. $key = okeys::account($siteuid);
  316. $cache = oo::commonOprRedis('user')->hGetAll($key);
  317. $row = isset($cache) ? $cache : $this->getAccount($siteuid);
  318. if (!$row) continue;
  319. $account[] = array(
  320. 'siteuid' => $siteuid,
  321. 'uid' => (int)$row['uid'],
  322. 'createtime' => (int)$row['createtime'],
  323. );
  324. }
  325. if (count($account) == 0) {
  326. return 0;
  327. }
  328. return 1;
  329. }
  330. public function getAccountMulti2( $mainkey, $need, &$account )
  331. {
  332. // if (!$mainkey || $mainkey['keyname']!='siteuid' || !$mainkey['keylist'] || !is_array($mainkey['keylist'])) {
  333. // return -1;
  334. // }
  335. // $keys = array();
  336. // foreach ($mainkey['keylist'] as $siteuid) {
  337. // $keys[] = okeys::account($siteuid);
  338. // }
  339. // $cache = oo::commonOprCache('account')->getMulti($keys);
  340. // $account = array();
  341. // foreach ($mainkey['keylist'] as $siteuid) {
  342. // $key = okeys::account($siteuid);
  343. // $row = isset($cache[$key]) ? $cache[$key] : $this->getAccount($siteuid);
  344. // if (!$row) continue;
  345. // $account[] = array(
  346. // 'siteuid' => $siteuid,
  347. // 'uid' => (int)$row['uid'],
  348. // 'createtime' => (int)$row['createtime'],
  349. // );
  350. // }
  351. // if (count($account) == 0) {
  352. // return 0;
  353. // }
  354. // return 1;
  355. }
  356. /**
  357. * 插入用户信息
  358. * @param uid 游戏uid
  359. * @return <0,失败; =0,没有记录; >1,有记录
  360. */
  361. public function createMtkey( $siteuid )
  362. {
  363. return md5($siteuid.$this->secretkey.date('YW'));
  364. }
  365. /**
  366. * 获取用户MTKEY
  367. * @param unknown $mtkey
  368. * @return boolean|array <mixed/false, mixed>
  369. */
  370. public function getUserInfoByMtkey($mtkey){
  371. if ($mtkey == '') {
  372. return false;
  373. }
  374. $res = oo::commonOprRedis('usercache')->hGetAll(okeys::php_mtkey($mtkey));
  375. return $res;
  376. }
  377. /**
  378. * 通过MTKEY保存用户基础信息
  379. * @param array $userinfo
  380. * @return boolean|Ambigous <true/false, boolean>
  381. */
  382. public function setUserInfoByMtkey($userinfo){
  383. if (empty($userinfo)) {
  384. return false;
  385. }
  386. $srvMtkey = $this->createMtkey($userinfo['id']);
  387. $expire = oo::redisRandomExpire(3 * 86400);
  388. $res = oo::commonOprRedis('usercache')->hMset(okeys::php_mtkey($srvMtkey),$userinfo);
  389. oo::commonOprRedis('usercache')->expire(okeys::php_mtkey($srvMtkey),$expire);
  390. return $res;
  391. }
  392. /**
  393. * 获取fb 信息
  394. * @param unknown $mtkey
  395. * @return boolean|array <mixed/false, mixed>
  396. */
  397. public function getFbInfoByToken($token){
  398. $res = oo::commonOprRedis('usercache')->get(okeys::FbInfoByToken($token)) ?? "";
  399. return json_decode($res,true);
  400. }
  401. /**
  402. * 设置fb 信息
  403. * @param unknown $mtkey
  404. * @return boolean|array <mixed/false, mixed>
  405. */
  406. public function setFbInfoByToken($token,$info){
  407. return oo::commonOprRedis('usercache')->setex(okeys::FbInfoByToken($token),json_encode($info),30*60);
  408. }
  409. /**
  410. * Notes:获取用户基本信息封装
  411. * User: wsc
  412. * Time: 2020/4/2 14:36
  413. * @param $uid
  414. * @return array
  415. */
  416. public function getUserBasic($uid){
  417. $data = [];
  418. $temp_array = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  419. $temp_info = oo::commonOprModel('member')->getUserInfo($uid);
  420. $data['uid'] = intval($uid);
  421. $data['star'] = $temp_array['star'];
  422. $data['coins'] = intval($temp_array['money']);
  423. $data['money'] = intval($temp_array['money']);
  424. $data['levelId'] = intval($temp_array['levelId']);
  425. $data['spins'] = intval($temp_array['spins']);
  426. $data['shield'] = intval($temp_array['shield']);
  427. $data['diamond'] = intval($temp_array['diamond']);
  428. $data['siteuid'] = $temp_info['siteuid'];
  429. $data['nick'] = $temp_info['nick'];
  430. $data['sex'] = $temp_info['sex'];
  431. $data['s_picture'] = $temp_info['s_picture'];
  432. $data['signature'] = $temp_info['signature'];
  433. $data['u_flag'] = intval($temp_info['u_flag']);
  434. $data['vip'] = $temp_info['vip'];//是否是vip
  435. $data['vipLv'] = $temp_info['vipLv'];//vip等级
  436. $data['vipExpire'] = $temp_info['vip_expire'];//vip过期时间
  437. $data['vipPoint'] = $temp_info['vipPoint'];//vip积分
  438. $data['avatar'] = intval($temp_info['avatar']);
  439. $data['isFb'] = intval($temp_info['isFb']);//
  440. $data['login_plat'] =intval($temp_info['login_plat']);//平台:1安卓,2ios
  441. $data['version'] = $temp_info['version'];
  442. return $data;
  443. }
  444. //===================================================
  445. /**
  446. * Notes:获取用户的资产信息 【金币money、体力spins、盾牌shield、星星数star、等级levelId】
  447. * User: wsc
  448. * Time: 2020/6/8 19:38
  449. * @param $uid
  450. * @param string $from
  451. * @return mixed
  452. */
  453. public function getUserAssetsInfo($uid,$from=""){
  454. if(!$uid){
  455. return [];
  456. }
  457. $data = oo::commonOprModel('attr')->get($uid);
  458. $data['levelId'] = $this->getUserLevelId($uid);
  459. return $data;
  460. }
  461. /**
  462. * Notes:设置用户属性
  463. * User: wsc
  464. * Time: 2020/6/9 14:21
  465. * @param $uid
  466. * @param $arr --["money"=>1,"spins"=>1,"shield"=>1,"star"=>1]中任意或组合
  467. * @param $rid config/common/config.reason.php
  468. * @param $t --符号 + -
  469. * @param $reason --原因
  470. * @return bool
  471. */
  472. public function optProperty($uid, $arr,$t,$rid,$reason = ""){
  473. $arr = array_filter($arr);
  474. if (!$uid || !is_array($arr) || empty($arr) || empty($t)) {
  475. return false;
  476. }
  477. if(!empty($arr['shield']) && $t == '+'){ //累加盾牌添加上限验证
  478. $maxShield = oo::commonOprModel('member')->getUserLevelUpLimit($uid,'shield');
  479. $curShield = oo::commonOprModel('attr')->get($uid, 'shield');
  480. $addShield = max(0,$maxShield - $curShield);
  481. $addSpins = intval($arr['shield'] - $addShield);
  482. $arr['shield'] = min($addShield,$arr['shield']);
  483. if($addSpins > 0){
  484. $arr['spins'] = empty($arr['spins']) ? $addSpins : $arr['spins'] + $addSpins;
  485. }
  486. if(empty($arr['shield'])){
  487. unset($arr['shield']);
  488. }
  489. }
  490. foreach ($arr as $k=>$v){
  491. if(in_array($k,array_keys($this->_attr))){
  492. $fun = $t=="+"?"add":"del";
  493. $resCount = oo::commonOprModel('attr')->$fun($uid,$k,$v,$rid,$reason);//写入缓存,及流水,统计
  494. }
  495. if($k == 'spins' && $t == '-' && $v > 0){
  496. $this->userSpinConsume($uid, $v); //玩家当天体力消耗值
  497. }
  498. }
  499. $res = $resCount<0?false:($resCount==0?true:$resCount);
  500. return $res;
  501. }
  502. /**
  503. * 玩家当天体力消耗记录,保留4天,排行榜分房使用
  504. * @param int $uid
  505. * @param int $consumeNum 单次消耗体力数量
  506. */
  507. public function userSpinConsume($uid, $consumeNum = 0) {
  508. //消耗体力累计
  509. $consumeKey = okeys::userspinconsume($uid, date('Ymd'));
  510. $incrRet = oo::commonOprRedis('usercache')->incrBy($consumeKey, $consumeNum);
  511. if($incrRet <= $consumeNum){ //保留过去4天数据
  512. oo::commonOprRedis('usercache')->expire($consumeKey, 5 * 24 * 3600);
  513. }
  514. }
  515. /**
  516. * 同意发货
  517. * @param $uid
  518. * @param $propsId int 奖品Id common/props.php
  519. * @param $num int 道具数量
  520. * @param $rid int 来源
  521. * @param $ext string|int 附加说明
  522. * @param array $value array|string|int 附加道具信息 例如卡片信息数组
  523. * @param mixed $source 源数据
  524. * @return mixed
  525. * Created by: Owen
  526. * Created on: 2020/12/14 14:40
  527. */
  528. public function sendReward($uid,$propsId,$num,$rid,$ext,$value=[],&$source = []){
  529. $res = null;
  530. $isActProp =false;//是否是道具活动
  531. switch (intval($propsId)){
  532. case 13://随机金卡
  533. if(!empty($value[0])&&isset($value[0]['id'])&&!empty($value[0]['id'])){
  534. $cid = $value[0]['id'];
  535. oo::commonOprRedis('activity')->sRemove(okeys::userCacheShowCardList($uid),$cid);//已展示的金卡中去掉
  536. oo::commonOprModel('card')->getCardByType($uid,7,0,[$cid]);
  537. $res = $value;
  538. }else{
  539. $cardData = oo::commonOprModel('card')->getRandomCard($uid);
  540. if(!empty($cardData)){
  541. oo::commonOprModel('card')->getCardByType($uid,7,0,[$cardData['id']]);
  542. $res = [$cardData];
  543. }
  544. }
  545. break;
  546. case 14://金币
  547. $res =oo::commonOprModel('member')->optProperty($uid,['money'=>$num],'+',$rid,$ext);
  548. break;
  549. case 15://体力
  550. $res = oo::commonOprModel('member')->optProperty($uid,['spins'=>$num],'+',$rid,$ext);
  551. break;
  552. case 16://盾牌
  553. $res = oo::commonOprModel('member')->optProperty($uid,['shield'=>$num],'+',$rid,$ext);
  554. break;
  555. case 17://卡片
  556. oo::commonOprModel('card')->getCardByType($uid,7,0,[$num]);
  557. $res = $num;
  558. break;
  559. case 18://小丑卡
  560. oo::commonOprModel('statistics')->jokerCardSta($propsId,1,$uid,$ext,$rid);//小丑卡统计
  561. $res = $source['value'] = oo::commonOprModel('card')->setJokerCard($uid);
  562. break;
  563. case 19:case 20:case 21:case 29:case 30://宝箱类
  564. $res = $source['value'] = oo::commonOprModel('props')->rewardChest($uid,$propsId,$ext,$rid,intval($source['value']['skin']));
  565. break;
  566. case 22://钻石
  567. $res =oo::commonOprModel('member')->optProperty($uid,['diamond'=>$num],'+',$rid,$ext);
  568. break;
  569. case 23://头像框
  570. $res = oo::commonOprModel('user')->rewardAvatarBox($uid,$num);
  571. break;
  572. case 24://vip积分
  573. break;
  574. case 38://通行证经验
  575. $res = $source['value'] = oo::commonOprModel('activitynew')->addTrafficPermitNumByProps($uid,$num,$rid,$ext);
  576. break;
  577. default :
  578. $actProp = oo::commonOprModel('activitynew')->specialActTypeList;
  579. $propArr = funs::array_column_ext($actProp,'propsId',-1);
  580. if(in_array($propsId,$propArr)){//道具型活动
  581. $isActProp =true;
  582. $propArr = array_flip($propArr);
  583. $setAid = 0;
  584. if($propsId == 41 && !empty($value['skin'])){
  585. //四选一活动
  586. $setAid = $value['skin'];
  587. }else if($propsId == 41 && empty($value['skin']) && !empty($source['value']['skin'])){
  588. $setAid = $source['value']['skin'];
  589. }
  590. $res = oo::commonOprModel('activitynew')->openSpecialAct($uid,$propArr[$propsId],$num * 60,$setAid);
  591. }else{
  592. $ret = oo::commonOprModel('props')->addUserProps($uid,$propsId,$num,0,$rid,$ext);
  593. if($ret==['code'=>1]){
  594. $res =$num;
  595. }
  596. }
  597. break;
  598. }
  599. if($isActProp&&$res){//道具活动加流水
  600. oo::commonOprModel('currency')->log($uid,$propsId,"+",$num,$num,$rid,$ext);
  601. }
  602. return $res;
  603. }
  604. //=========================用户统计=============================
  605. /**
  606. * Notes:各类变化汇总统计,money,spins变化来源分类合计统计 (wsc-6.10-废弃)
  607. * User: wsc
  608. * Time: 2020/6/6 16:48
  609. * @param $t
  610. * @param $key
  611. * @param $num
  612. * @param string $reason
  613. */
  614. public function PropertyStatistics($t,$key,$num,$reason = ""){
  615. if($t == "+"){
  616. $okey = okeys::PropertyAdd($key);
  617. }else if($t == "-"){
  618. $okey = okeys::PropertyLow($key);
  619. }
  620. oo::commonOprRedis('statistics')->incrBy($okey,intval($num));
  621. if($key == 'money' && $reason != ""){
  622. if($t == "+"){
  623. foreach (self::moneyAddType() as $keys=>$row){
  624. if(strpos($reason,$row) !== false){
  625. oo::commonOprRedis('statistics')->incrBy("Statistics:{$key}{$t}{$keys}",$num);
  626. }
  627. }
  628. }else if($t == "-"){
  629. foreach (self::moneyLowType() as $keys=>$row){
  630. if(strpos($reason,$row) !== false){
  631. oo::commonOprRedis('statistics')->incrBy("Statistics:{$key}{$t}{$keys}",$num);
  632. }
  633. }
  634. }
  635. }else if($key == 'spins' && $reason != ""){
  636. if($t == "+"){
  637. foreach (self::sipnAddType() as $keys=>$row){
  638. if(strpos($reason,$row) !== false){
  639. oo::commonOprRedis('statistics')->incrBy("Statistics:{$key}{$t}{$keys}",$num);
  640. }
  641. }
  642. }else if($t == "-"){
  643. foreach (self::sipnLowType() as $keys=>$row){
  644. if(strpos($reason,$row) !== false){
  645. oo::commonOprRedis('statistics')->incrBy("Statistics:{$key}{$t}{$keys}",$num);
  646. }
  647. }
  648. }
  649. }
  650. }
  651. public function getUserBasicsStatistics($uid){
  652. $key = okeys::userBasicsStatistics($uid);
  653. $res =oo::commonOprRedis('userinfo')->hGetAll($key);
  654. if(empty($res)){
  655. $tb = otable::statistics();
  656. $sql = "SELECT * FROM {$tb} WHERE uid={$uid} LIMIT 1";
  657. $data = oo::commonOprDb('common')->getOne($sql,1);
  658. if(!empty($data)){
  659. // oo::logs()->debug3($data,'recover_user_statistics.log');//写恢复日志
  660. unset($data['uid']);
  661. unset($data['id']);
  662. }else{
  663. $sql2 = " INSERT INTO {$tb} (uid) VALUES ({$uid}) ";
  664. oo::commonOprDb('common')->query($sql2,1);
  665. $data = ['money'=>0,'damage'=>0,'destroy'=>0,'coinbya'=>0,'stealnum'=>0,'allstealnum'=>0,'stealcoin'=>0,'defense'=>0,'damaged'=>0,'destroyed'=>0,'stealed'=>0,'loginTime'=>0];
  666. }
  667. oo::commonOprRedis('userinfo')->hMset($key,$data);
  668. oo::commonOprRedis('userinfo')->expire($key,oo::redisRandomExpire(86400*7));
  669. }
  670. return $res;
  671. }
  672. public function saveUserBasicsStatistics($uid,$type,$num){
  673. $key = okeys::userBasicsStatistics($uid);
  674. $ret = oo::commonOprRedis('userinfo')->hIncrBy($key,$type,$num);
  675. /** 数据落地标识 */
  676. oo::commonOprRedis('Usercache')->zAdd(okeys::Landing("STATISTICS", $uid),time(),$uid);
  677. return $ret;
  678. }
  679. /**
  680. * Notes:获取个人统计
  681. * User: wsc
  682. * Time: 2020/6/9 14:30
  683. * @param $uid
  684. * @param string $type
  685. * @return array
  686. */
  687. // public function getStatistics($uid,$type=""){
  688. // $key = okeys::userBasicsStatistics($uid);
  689. // $res =oo::commonOprRedis('userinfo')->hGetAll($key);
  690. // $fieldArr = ['money','damage','destroy','coinbya','stealnum','allstealnum','stealcoin','defense','damaged','destroyed','stealed','loginTime'];
  691. // if(empty($res)||count($res)<count($fieldArr)){//缓存数据不全或无缓存时,先恢复数据
  692. // oo::commonOprModel('recoverdata')->recoverUserBasicsStatistics($uid);
  693. // $res =oo::commonOprRedis('userinfo')->hGetAll($key);
  694. // }
  695. // return $res;
  696. // }
  697. /**
  698. * 保存个人统计
  699. * @param $uid
  700. * @param $type
  701. * @param $num
  702. * @return bool
  703. * Created by: Owen
  704. * Created on: 2020/4/10 16:09
  705. */
  706. public function saveStatistics($uid,$type,$num){
  707. return true;//过度返回,之后删除整个方法
  708. $ret =false;
  709. //$this->getStatistics($uid,$type);//恢复可能没有的数据
  710. $key = okeys::userBasicsStatistics($uid);
  711. $ret = oo::commonOprRedis('userinfo')->hIncrBy($key,$type,$num);
  712. /** 数据落地标识 */
  713. oo::commonOprRedis('Usercache')->zAdd(okeys::Landing("STATISTICS", $uid),time(),$uid);
  714. return $ret;
  715. }
  716. /**
  717. * 保存个人统计 -- 数组
  718. * @param $uid
  719. * @param $data
  720. * @return bool
  721. * Created by: Owen
  722. * Created on: 2020/4/10 15:28
  723. */
  724. // public function saveStatisticsByArray($uid,$data){
  725. // $ret = false;
  726. // if(!empty($data)){
  727. // foreach ($data as $k=>$v){
  728. // $ret = self::saveStatistics($uid,$k,$v);
  729. // }
  730. // }
  731. // return $ret;
  732. // }
  733. /**
  734. * 判断是否为游客
  735. * @param unknown $uid
  736. * @return number 1游客 0FB
  737. */
  738. public function isVistor( $uid ) {
  739. $userInfo = $this->getUserInfo($uid);
  740. if ($userInfo == 0) {
  741. return 1;
  742. }
  743. $siteUid = $userInfo['siteuid'];
  744. $account = $this->getAccount($siteUid);
  745. if ( $account <= 0 ) {
  746. return 1;
  747. }
  748. return 0;
  749. }
  750. /**
  751. * Notes:个人老虎机相关配置
  752. * User: wsc
  753. * Time: 2020/6/9 14:31
  754. * @param $uid
  755. * @return array
  756. */
  757. public function getUserConfig($uid){
  758. $memberAssets = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  759. $trun_arr = oo::commonOprModel('slot')->getSlotTurnConfig($memberAssets['levelId']);
  760. $turnplateConfig = array_column($trun_arr, 'prize');
  761. $spins_arr = oo::commonOprModel('slot')->getSpinsTurnConfig(1);
  762. $turnspinsConfig = array_column($spins_arr, 'prize');
  763. $confs = oo::commonOprModel('level')->getLevelConf($memberAssets['levelId']);
  764. $coin_arr = json_decode($confs['coinConfig'],true);
  765. return [
  766. 'turnplateConfig'=>$turnplateConfig,
  767. 'turnspinsConfig'=>$turnspinsConfig,
  768. 'buildConfig'=>$coin_arr,
  769. 'slotConfig'=>oo::commonOprModel('slot')->getSlotImgConfig($uid),
  770. ];
  771. }
  772. /**
  773. * 首冲
  774. * @param $uid
  775. * @param $gid
  776. * @return mixed
  777. * Created by: Owen
  778. * Created on: 2019/7/10 17:42
  779. * Description:
  780. */
  781. public function getUserFirstPayStatus($uid,$gid = 601){
  782. $cacheKey = okeys::firstPay($uid,$gid);
  783. $cache = oo::commonOprRedis('User')->get($cacheKey);
  784. if($cache !== false){
  785. return $cache;
  786. }
  787. $tb = otable::payment($uid);
  788. $sql = "SELECT * FROM {$tb} WHERE uid={$uid} AND status=2 AND gid= {$gid}";
  789. $ret = oo::commonOprDb('payment')->getOne($sql,MYSQLI_ASSOC);
  790. if(empty($ret)){
  791. oo::commonOprRedis('User')->setex($cacheKey,0,oo::redisRandomExpire(3*24*60*60));
  792. return 0;
  793. }else{
  794. oo::commonOprRedis('User')->setex($cacheKey,1,oo::redisRandomExpire(3*24*60*60));
  795. return 1;
  796. }
  797. }
  798. /**
  799. * 新首充礼包状态
  800. * @param $uid
  801. * @return array|bool
  802. * Created by: Owen
  803. * Created on: 2020/8/18 15:29
  804. */
  805. public function getUserFirstPayStatus2($uid){
  806. $minLevelId = oo::commonOprModel('readconfig')->getSysCon('FirstPay','minLevelId') ?? 2;
  807. $maxLevelId = oo::commonOprModel('readconfig')->getSysCon('FirstPay','maxLevelId') ?? 4;
  808. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  809. $userLevelId = $userAssetsInfo['levelId'];
  810. if($userLevelId >= $maxLevelId || $userLevelId < $minLevelId){
  811. return false;
  812. }
  813. if(oo::commonOprRedis('User')->delete(okeys::FirstPayLevelLock($uid))){
  814. return false;
  815. }
  816. if(self::getUserFirstPayStatus($uid,602)){
  817. return false;
  818. }
  819. return [
  820. 'gid' => 602,
  821. 'maxLevelId' => $maxLevelId,
  822. ];
  823. }
  824. /**
  825. * 保护时间
  826. * @param $uid
  827. * @param $time
  828. * Created by: Owen
  829. * Created on: 2020/1/2 15:34
  830. */
  831. public function setUserStealProtect($uid,$time,$isSteal=false){
  832. if($isSteal){
  833. oo::commonOprModel('steal')->setBeStealNum($uid);
  834. }
  835. oo::commonOprModel('steal')->setProteTime($uid,$time);
  836. }
  837. /**
  838. * 体力限制
  839. * @param $uid
  840. * @return int
  841. * Created by: owen
  842. * Created on: 2020/2/6 18:20
  843. */
  844. public function getSpinsUpLimit($uid){
  845. $totalPayNum = oo::commonOprModel('payment')->getUserDayPayNum($uid);
  846. if($totalPayNum<0.99){
  847. return 500;
  848. }else if($totalPayNum<=1.99){
  849. return 1000;
  850. }else if($totalPayNum<=19.99){
  851. return 2000;
  852. }else if($totalPayNum<=99){
  853. return 5000;
  854. }else if($totalPayNum>100){
  855. return 10000;
  856. }
  857. }
  858. //====================签到相关========================
  859. /**
  860. * 签到奖励
  861. * @param $uid
  862. * @return string
  863. * Created by: Owen
  864. * Created on: 2020/4/24 16:51
  865. */
  866. public function getSignInReward($uid){
  867. $signInToday = oo::commonOprRedis('User')->get(okeys::SignInToday($uid));
  868. if($signInToday){
  869. return oo::response(-1,[],'今日已签到');
  870. }
  871. $signInTimes = oo::commonOprRedis('User')->get(okeys::SignInTimes($uid));
  872. $id = $signInTimes + 1;
  873. $config = oo::commonOprModel('config')->getSignInConfig($id);
  874. $monthly = oo::commonOprModel('payment')->getSpinMonthly($uid,1001);
  875. $monthly = empty($monthly)?0:$monthly['num'];
  876. $monthlyPro = oo::commonOprModel('payment')->getSpinMonthly($uid,1002);
  877. $monthlyPro = empty($monthlyPro)?0:$monthlyPro['num'];
  878. $bet = max(1,$monthly,$monthlyPro);
  879. $version = oo::commonOprModel('user')->getUserVersion($uid);
  880. //1.8.5vip特权取消额外签到倍率,改为vip订阅的特权
  881. if(!oo::compareVersion($version,"1.8.5")){
  882. if(oo::commonOprModel('newvip')->checkVip($uid)) {
  883. $config = oo::commonOprModel('newvip')->getUserVipLv($uid, true,false,155);
  884. $bet = max(intval($config['signInBet']), $bet);
  885. }
  886. }else{
  887. $subVip = oo::commonOprModel('newvip')->checkSubVip($uid);
  888. if($subVip && !empty($subVip['vipSignBet'])){
  889. $bet = max(intval($subVip['vipSignBet']), $bet);
  890. }
  891. }
  892. if($config['type'] == 1){
  893. $reward = [
  894. 'money' => $config['num']*$bet
  895. ];
  896. oo::commonOprModel('member')->optProperty($uid,$reward,'+',15,'签到奖励');
  897. }else if($config['type'] == 2){
  898. $reward = [
  899. 'spins' => $config['num']*$bet
  900. ];
  901. oo::commonOprModel('member')->optProperty($uid,$reward,'+',15,'签到奖励');
  902. }else if($config['type'] == 3){
  903. oo::commonOprModel('props')->addUserProps($uid,$config['num'],1*$bet,0,15);
  904. $reward['card'] = [];
  905. }
  906. oo::commonOprRedis('User')->setex(okeys::SignInToday($uid),1,oo::todayDeadline());
  907. $expireTime = $id >= 7 ? oo::todayDeadline() : oo::todayDeadline() + 86400;
  908. oo::commonOprRedis('User')->setex(okeys::SignInTimes($uid),$id,$expireTime);
  909. //召回活动任务
  910. // oo::commonOprModel('callback')->doCallbackTask($uid, 4, $id);
  911. //签到率统计
  912. oo::commonOprModel('statistics')->signInSta($uid,'all');
  913. if($monthly){
  914. oo::commonOprModel('statistics')->signInSta($uid,'1001');
  915. }
  916. if($monthlyPro){
  917. oo::commonOprModel('statistics')->signInSta($uid,'1002');
  918. }
  919. return oo::response(1,$reward);
  920. }
  921. /**
  922. * 新版签到奖励
  923. * @param $uid
  924. * @return string
  925. * Created by: Owen
  926. * Created on: 2020/4/24 17:16
  927. */
  928. public function getSignInReward2($uid){
  929. $signInToday = oo::commonOprRedis('User')->get(okeys::SignInToday($uid));
  930. if($signInToday){
  931. return oo::response(-1,[],'今日已签到');
  932. }
  933. $signInTimes = oo::commonOprRedis('User')->get(okeys::SignInTimes($uid));
  934. $id = $signInTimes + 1;
  935. $version = oo::commonOprModel('user')->getUserVersion($uid);
  936. if(oo::compareVersion($version,"1.7.7")){
  937. $config = oo::commonOprModel('config')->signInConfByUserGroup($uid,$id);
  938. }else{
  939. $config = oo::commonOprModel('config')->getSignInConfig($id,true,$this->getSignInSectionId($uid));
  940. }
  941. $monthly = oo::commonOprModel('payment')->getSpinMonthly($uid,1001);
  942. $monthly = empty($monthly)?0:$monthly['num'];
  943. $monthlyPro = oo::commonOprModel('payment')->getSpinMonthly($uid,1002);
  944. $monthlyPro = empty($monthlyPro)?0:$monthlyPro['num'];
  945. $bet = max(1,$monthly,$monthlyPro);
  946. //1.8.5vip特权取消额外签到倍率,改为vip订阅的特权
  947. if(!oo::compareVersion($version,"1.8.5")){
  948. if(oo::commonOprModel('newvip')->checkVip($uid)) {
  949. $vipConfig = oo::commonOprModel('newvip')->getUserVipLv($uid,true,false,155);
  950. $bet = max($bet,$vipConfig['signInBet']);
  951. }
  952. }else{
  953. $subVip = oo::commonOprModel('newvip')->checkSubVip($uid);
  954. if($subVip && !empty($subVip['vipSignBet'])){
  955. $bet = max(intval($subVip['vipSignBet']), $bet);
  956. }
  957. }
  958. $reward = [];
  959. $coins = intval(oo::commonOprModel('goods')->getGoodCoins($uid,$config['coins']['coins']));
  960. $coinBet = round($config['coins']['bet'],2);
  961. $coins = intval($coins * $coinBet);
  962. if($coins){
  963. $reward['money'] = intval($coins * $bet);
  964. }
  965. if($config['spins']){
  966. $reward['spins'] = intval($config['spins'] * $bet);
  967. }
  968. if(!empty($reward)){
  969. oo::commonOprModel('member')->optProperty($uid,$reward,'+',15,'签到奖励:'.$id);
  970. }
  971. if($config['props']){
  972. foreach ($config['props'] as $row){
  973. oo::commonOprModel('props')->addUserProps($uid,$row['propsId'],$row['num'] * $bet,0,15);
  974. }
  975. }
  976. self::updateUserSignInProgress($uid,['signInDay'=>1],false);
  977. oo::commonOprRedis('User')->setex(okeys::SignInToday($uid),1,oo::todayDeadline());
  978. $expireTime = $id >= 7 ? oo::todayDeadline() : oo::todayDeadline() + 86400;
  979. oo::commonOprRedis('User')->setex(okeys::SignInTimes($uid),$id,$expireTime);
  980. if(oo::compareVersion($version,"1.7.7")){
  981. oo::commonOprRedis('User')->expire(okeys::SignInUserGroupId($uid),$expireTime); // 分组签到的配置与签到周期绑定一致的结束时间
  982. }
  983. //召回活动-签到任务
  984. if(oo::compareVersion($version,"1.8.4")){
  985. oo::commonOprModel('callback')->doTask($uid, 4, 1);
  986. }
  987. //签到率统计
  988. oo::commonOprModel('statistics')->signInSta($uid,'all');
  989. if($monthly){
  990. oo::commonOprModel('statistics')->signInSta($uid,'1001');
  991. }
  992. if($monthlyPro){
  993. oo::commonOprModel('statistics')->signInSta($uid,'1002');
  994. }
  995. //数数事件-完成签到
  996. $curUserSignInProgress=self::getUserSignInProgress($uid);
  997. oo::commonOprModel('ta')->setEventData($uid,'sign',["sign_total_days"=>$curUserSignInProgress['signInDay'],"sign_continuity_days"=>$id]);
  998. return oo::response(1,$reward);
  999. }
  1000. /**
  1001. * 获取用户签到进度
  1002. * @param $uid
  1003. * @return array|mixed
  1004. * Created by: Owen
  1005. * Created on: 2020/4/24 14:55
  1006. */
  1007. public function getUserSignInProgress($uid){
  1008. $cacheKey = okeys::UserSignInProgress($uid);
  1009. $cache = oo::commonOprRedis('common')->get($cacheKey);
  1010. if($cache){
  1011. return self::signInProgressRefresh(json_decode($cache,true));
  1012. }
  1013. $tb = otable::UserSignInProgress();
  1014. $ret= oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE uid={$uid} LIMIT 1",MYSQLI_ASSOC);
  1015. if(empty($ret)){
  1016. $ret = [
  1017. 'uid' => $uid,
  1018. 'rewardDay' => [],
  1019. 'signInDay' => 0,
  1020. ];
  1021. oo::commonOprRedis('common')->setex($cacheKey,json_encode($ret,JSON_NUMERIC_CHECK),oo::redisRandomExpire(7*24*60*60));
  1022. oo::commonOprDb('common')->query("INSERT INTO {$tb} (uid) VALUE ({$uid})");
  1023. return self::signInProgressRefresh($ret);
  1024. }
  1025. $ret['rewardDay'] = json_decode($ret['rewardDay'],true);
  1026. oo::commonOprRedis('common')->setex($cacheKey,json_encode($ret,JSON_NUMERIC_CHECK),oo::redisRandomExpire(7*24*60*60));
  1027. return self::signInProgressRefresh($ret);
  1028. }
  1029. /**
  1030. * 更新签到进度数据
  1031. * @param $uid
  1032. * @param $updateInfo
  1033. * @param bool $set
  1034. * @return bool
  1035. * Created by: Owen
  1036. * Created on: 2020/4/24 15:07
  1037. */
  1038. public function updateUserSignInProgress($uid,$updateInfo,$set = false){
  1039. $curUserSignInProgress = self::getUserSignInProgress($uid);
  1040. foreach ($updateInfo as $key=>$row){
  1041. if($set){
  1042. $curUserSignInProgress[$key] = $row;
  1043. }else{
  1044. $curUserSignInProgress[$key] +=$row;
  1045. }
  1046. }
  1047. $cacheKey = okeys::UserSignInProgress($uid);
  1048. oo::commonOprRedis('common')->setex($cacheKey,json_encode($curUserSignInProgress,JSON_NUMERIC_CHECK),oo::redisRandomExpire(7*24*60*60));
  1049. $tb = otable::UserSignInProgress();
  1050. $rewardDay = addslashes(json_encode($curUserSignInProgress['rewardDay']));
  1051. $signInDay = $curUserSignInProgress['signInDay'];
  1052. return oo::commonOprDb('common')->query("UPDATE {$tb} SET `rewardDay` = '{$rewardDay}' ,`signInDay`={$signInDay} WHERE `uid` = {$uid}");
  1053. }
  1054. /**
  1055. * 刷新
  1056. * @param $info
  1057. * @return mixed
  1058. * Created by: Owen
  1059. * Created on: 2020/4/27 15:49
  1060. */
  1061. public function signInProgressRefresh($info){
  1062. if($info['signInDay'] >= 30){
  1063. if(!oo::commonOprRedis('common')->get(okeys::SignInProgressRefresh($info['uid']))){
  1064. //新版签到等级区间 获取用户所在区间
  1065. $section_id = $this->getSignInSectionId($info['uid']);
  1066. $version = oo::commonOprModel('user')->getUserVersion($info['uid']);
  1067. if(oo::compareVersion($version,'1.7.0')){
  1068. $config = oo::commonOprModel('config')->getSignInProgressConfig(0,$section_id,2);
  1069. }else{
  1070. $config = oo::commonOprModel('config')->getSignInProgressConfig(0,$section_id);
  1071. }
  1072. $progressCount = count($config);
  1073. if($progressCount <= count($info['rewardDay'])){
  1074. $curUserSignInProgress = [
  1075. 'uid' => $info['uid'],
  1076. 'rewardDay' => [],
  1077. 'signInDay' => 0,
  1078. ];
  1079. $cacheKey = okeys::UserSignInProgress($info['uid']);
  1080. oo::commonOprRedis('common')->setex($cacheKey,json_encode($curUserSignInProgress,JSON_NUMERIC_CHECK),oo::redisRandomExpire(7*24*60*60));
  1081. $tb = otable::UserSignInProgress();
  1082. $rewardDay = addslashes(json_encode($curUserSignInProgress['rewardDay']));
  1083. $signInDay = $curUserSignInProgress['signInDay'];
  1084. oo::commonOprDb('common')->query("UPDATE {$tb} SET `rewardDay` = '{$rewardDay}' ,`signInDay`={$signInDay} WHERE `uid` = {$curUserSignInProgress['uid']}");
  1085. $info['rewardDay'] = [];
  1086. $info['signInDay'] = 0;
  1087. }
  1088. }
  1089. }
  1090. return $info;
  1091. }
  1092. /**
  1093. * 领取签到阶段奖励
  1094. * @param $uid
  1095. * @param $progress
  1096. * @return string
  1097. * Created by: Owen
  1098. * Created on: 2020/4/24 15:26
  1099. */
  1100. public function getSignInProgressReward($uid,$progress){
  1101. $curUserSignInProgress = self::getUserSignInProgress($uid);
  1102. if(in_array($progress,$curUserSignInProgress['rewardDay'])){
  1103. return oo::response(-2,[],'奖励已领取');
  1104. }
  1105. if($progress > $curUserSignInProgress['signInDay']){
  1106. return oo::response(-3,[],'进度未达标');
  1107. }
  1108. $version = oo::commonOprModel('user')->getUserVersion($uid);
  1109. if(oo::compareVersion($version,'1.7.0')){
  1110. $config = oo::commonOprModel('config')->getSignInProgressConfig($progress,$this->getSignInSectionId($uid),2);
  1111. }else{
  1112. $config = oo::commonOprModel('config')->getSignInProgressConfig($progress,$this->getSignInSectionId($uid));
  1113. }
  1114. if(empty($config)){
  1115. return oo::response(-4,[],'奖励配置异常');
  1116. }
  1117. $curUserSignInProgress['rewardDay'][] = $progress;
  1118. $newProgress = array_unique($curUserSignInProgress['rewardDay']);
  1119. $ret = self::updateUserSignInProgress($uid,['rewardDay'=>$newProgress],true);
  1120. if($ret){
  1121. if(count($newProgress) == $config['count']){
  1122. oo::commonOprRedis('common')->setex(okeys::SignInProgressRefresh($uid),1,oo::todayDeadline());
  1123. }
  1124. $coins = oo::commonOprModel('goods')->getGoodCoins($uid,$config['coins']['coins']);
  1125. $coins = intval($coins * $config['coins']['bet']);
  1126. $spins = intval($config['spins']);
  1127. $props = $config['props'];
  1128. oo::commonOprModel('member')->optProperty($uid,['money'=>$coins,'spins'=>$spins],'+',16,'领取签到进度奖励:'.$curUserSignInProgress['signInDay']);
  1129. foreach ($props as $key=>&$row){
  1130. $this->sendReward($uid,$row['propsId'],$row['num'],16,'领取签到进度奖励:'.$curUserSignInProgress['signInDay'],[],$row);
  1131. }
  1132. $props[] = ['propsId'=>14,"num"=>$coins,"value"=>$coins];
  1133. $props[] = ['propsId'=>15,"num"=>$spins,"value"=>$spins];
  1134. return oo::response(1,$props);
  1135. }
  1136. return oo::response(-4,[],'system error');
  1137. }
  1138. /**
  1139. * 获取用户所在签到等级配置区间
  1140. * @param $uid
  1141. * @return int
  1142. * Created by: Hss
  1143. * Created on: 2020/5/25 11:11
  1144. */
  1145. public function getSignInSectionId($uid){
  1146. $userLevel = $this->getUserLevel($uid);
  1147. $levelId = $userLevel['levelId'];
  1148. $config = oo::commonOprModel('config')->signinSection();
  1149. $section_id = 1;
  1150. foreach($config as $k => $v){
  1151. if($levelId >= $v['start_level'] && $levelId < $v['end_level']){
  1152. $section_id = $v['section_id'];
  1153. }
  1154. }
  1155. return $section_id;
  1156. }
  1157. //=================================================
  1158. /**
  1159. * Notes:新手引导
  1160. * User: wsc
  1161. * Time: 2020/6/9 14:35
  1162. * @param $param
  1163. * @return false|string
  1164. */
  1165. public function endGuide($param){
  1166. $dump = oo::functions()->escape($param['dump']);
  1167. $uid = oo::functions()->uint($param['uid']);
  1168. $sid = oo::functions()->uint($param['sid']);
  1169. if($dump == "SUPERANT"){
  1170. $data['code'] = 1;
  1171. oo::commonOprRedis('common')->hDel(okeys::beginGuide(),$uid);
  1172. $tb = otable::gh_gameserver($uid);
  1173. $sql = "UPDATE {$tb} SET beginGuide = 19 WHERE mid = {$uid} LIMIT 1";
  1174. oo::commonOprDb('ghgames')->query($sql);
  1175. /**
  1176. * 结束新手引导人数
  1177. */
  1178. oo::commonOprRedis('common')->sAdd(okeys::getGuideCount($sid),$uid);
  1179. return json_encode($data,JSON_NUMERIC_CHECK);
  1180. }
  1181. $stage = oo::commonOprRedis('common')->hGet(okeys::beginGuide(),$uid);
  1182. $data = ['code'=>-1];
  1183. if($stage !== false && $stage!=18){
  1184. return json_encode($data,JSON_NUMERIC_CHECK);
  1185. }
  1186. // 判断当前玩家的类型
  1187. $userInfo = oo::commonOprModel('member')->getUserInfo($uid);
  1188. //查询是否属于FB
  1189. $infoArr = oo::commonOprModel('member')->getAccount($userInfo['siteuid']);
  1190. if (!empty($infoArr) && $infoArr['uid'] == $uid) {
  1191. $spinType = 'fbLoginSpin';
  1192. $coinType = 'fbLoginCoin';
  1193. } else {
  1194. $spinType = 'guestLoginSpin';
  1195. $coinType = 'guestLoginCoin';
  1196. }
  1197. $spins = oo::commonOprModel('readconfig')->getCon('BeginnerReward',$spinType);
  1198. $coins = oo::commonOprModel('readconfig')->getCon('BeginnerReward',$coinType);
  1199. $tb = otable::gh_gameserver($uid);
  1200. $sql = "SELECT * FROM {$tb} WHERE mid = {$uid} LIMIT 1";
  1201. $ret = oo::commonOprDb('ghgames')->getOne($sql,MYSQLI_ASSOC);
  1202. $userAssets = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1203. if(empty($ret)){
  1204. return json_encode($data,JSON_NUMERIC_CHECK);
  1205. }else if($ret['beginGuide'] == 19){
  1206. $data['data']['spins'] = $userAssets['spins'];
  1207. $data['data']['coins'] = $userAssets['money'];
  1208. $data['code'] = 1;
  1209. return json_encode($data,JSON_NUMERIC_CHECK);
  1210. }
  1211. oo::commonOprModel('member')->optProperty($uid,['spins'=>$spins],'+',101,"结束新手引导");
  1212. oo::commonOprModel('member')->optProperty($uid,['money'=>$coins],'+',101,"结束新手引导");
  1213. $userAssets['spins'] += $spins; //不取redis,直接更新内存数据
  1214. $userAssets['money'] += $coins; //不取redis,直接更新内存数据
  1215. $data['code'] = 1;
  1216. $data['data']['spins'] = $userAssets['spins'];
  1217. $data['data']['coins'] = $userAssets['money'];
  1218. if($userAssets['shield'] == 0){
  1219. oo::commonOprModel('member')->optProperty($uid,['shield'=>1],'+',101,"结束新手引导");
  1220. }
  1221. if($userAssets['star'] == 0){
  1222. oo::commonOprModel('member')->optProperty($uid,['star'=>1],'+',101,"结束新手引导");
  1223. }
  1224. $userLevel = oo::commonOprModel('member')->getUserLevel($uid);
  1225. $element = $userLevel['element'];
  1226. if($element[0]['level'] == 0){
  1227. $element[0]['level'] = 1;
  1228. oo::commonOprModel('member')->setUserLevel($uid,$userLevel['levelId'],$element);
  1229. }
  1230. oo::commonOprRedis('common')->hDel(okeys::beginGuide(),$uid);
  1231. $tb = otable::gh_gameserver($uid);
  1232. $sql = "UPDATE {$tb} SET beginGuide = 19 WHERE mid = {$uid} LIMIT 1";
  1233. oo::commonOprDb('ghgames')->query($sql);
  1234. /**
  1235. * 结束新手引导人数
  1236. */
  1237. oo::commonOprRedis('common')->sAdd(okeys::getGuideCount($sid),$uid);
  1238. return json_encode($data,JSON_NUMERIC_CHECK);
  1239. }
  1240. /**
  1241. * Notes:新新手引导
  1242. * User: wsc
  1243. * Time: 2020/6/9 14:35
  1244. * @param $uid
  1245. * @param $build
  1246. * @param $dump
  1247. * @return string
  1248. */
  1249. public function endGuide2($uid,$build, $dump){
  1250. if($dump == "SUPERANT"){
  1251. oo::commonOprRedis('common')->hDel(okeys::beginGuide(),$uid);
  1252. $tb = otable::gh_gameserver($uid);
  1253. $sql = "UPDATE {$tb} SET beginGuide = 19 WHERE mid = {$uid} LIMIT 1";
  1254. oo::commonOprDb('ghgames')->query($sql);
  1255. /**
  1256. * 结束新手引导人数
  1257. */
  1258. $userPlat = oo::commonOprModel('user')->getUserLoginPlat($uid);
  1259. oo::commonOprRedis('common')->sAdd(okeys::getGuideCount($userPlat),$uid);
  1260. return oo::response(1);
  1261. }
  1262. $tb = otable::gh_gameserver($uid);
  1263. $ret = oo::commonOprDb('ghgames')->getOne("SELECT * FROM {$tb} WHERE mid = {$uid} LIMIT 1",MYSQLI_ASSOC);
  1264. if(empty($ret)){
  1265. return oo::response(-2);
  1266. }else if($ret['beginGuide'] == 19){
  1267. $userAssets = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1268. $data['spins'] = $userAssets['spins'];
  1269. $data['coins'] = $userAssets['money'];
  1270. $data = 1;
  1271. return oo::response(1,$data);
  1272. }else{
  1273. $ret = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1274. }
  1275. /**
  1276. * 同步数据
  1277. */
  1278. $config = oo::commonOprModel('config')->getBeginGuideConfig(true);
  1279. oo::commonOprModel('member')->optProperty($uid,['spins'=>$ret['spins']],'-',101,"同步新手引导");
  1280. oo::commonOprModel('member')->optProperty($uid,['money'=>$config['coins']],'+',101,"同步新手引导");
  1281. $build = json_decode($build,true);
  1282. $userLevel = oo::commonOprModel('member')->getUserLevel($uid);
  1283. $element = $userLevel['element'];
  1284. $elementConfig = json_decode(oo::commonOprModel('level')->getCoinConfig($userLevel['levelId']),true);
  1285. $spendCoin = 0;
  1286. $start = 0;
  1287. foreach ($build as $row){
  1288. $start = $start + $row['level'];
  1289. $buildId = $row['id'] - 1;
  1290. $buildCoins = $elementConfig[$buildId];
  1291. for ($i=0;$i<$row['level'];$i++){
  1292. if($i == 1){
  1293. $start--;
  1294. continue;
  1295. }
  1296. $spendCoin += $buildCoins[$i];
  1297. }
  1298. $element[$buildId]['level'] = $row['level'];
  1299. $element[$buildId]['maxLevel'] = min($row['level'],5);
  1300. }
  1301. $userAssets = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1302. if($spendCoin != 0 && $spendCoin <= $userAssets['money']){
  1303. oo::commonOprModel('member')->optProperty($uid,['money'=>$spendCoin],'-',101,"同步新手引导");
  1304. oo::commonOprModel('member')->setUserLevel($uid,$userLevel['levelId'],$element);
  1305. oo::commonOprModel('member')->optProperty($uid,['star'=>min($start,10)],'+',101,"同步新手引导");
  1306. }
  1307. $userInfo = oo::commonOprModel('member')->getUserInfo($uid);
  1308. if(empty($userInfo['inviteuid'])){
  1309. $inviteUid = oo::commonOprModel('member')->actionAdjustInvite($uid);
  1310. if($inviteUid > 0){
  1311. $userInfo['inviteuid'] = $inviteUid;
  1312. }
  1313. }
  1314. //邀请活动完成模式2
  1315. if($userInfo['inviteuid']){
  1316. $fromid = $userInfo['inviteuid'];
  1317. if($userInfo['isFb']&&$fromid){
  1318. $aid = oo::commonOprModel('activitynew')->activityLock($fromid,'time_limit_invite');
  1319. // oo::logs()->commlog(['uid'=>$uid,'fid'=>$fromid,'aid'=>$aid],'time_limit_invite');
  1320. if($aid){
  1321. oo::commonOprModel('activitynew')->setInviteLog($aid,$fromid,$uid,0);
  1322. oo::commonOprModel('activitynew')->tryFinishIntivityAct($aid,$fromid,$uid,2);
  1323. }
  1324. }
  1325. }
  1326. if ($userInfo['isFb'] == 1) {
  1327. $spinType = 'fbLoginSpin';
  1328. $coinType = 'fbLoginCoin';
  1329. } else {
  1330. $spinType = 'guestLoginSpin';
  1331. $coinType = 'guestLoginCoin';
  1332. }
  1333. $spins = oo::commonOprModel('readconfig')->getCon('BeginnerReward',$spinType);
  1334. $coins = oo::commonOprModel('readconfig')->getCon('BeginnerReward',$coinType);
  1335. $isReward = oo::commonOprModel('readconfig')->getCon('Game',"isGuestReward") ?? 1;
  1336. if($userInfo['isFb'] == 1 || $isReward){
  1337. oo::commonOprModel('member')->optProperty($uid,['spins'=>$spins],'+',101,"结束新手引导");
  1338. oo::commonOprModel('member')->optProperty($uid,['money'=>$coins],'+',101,"结束新手引导");
  1339. }
  1340. $userAssets = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1341. $data['spins'] = $userAssets['spins'];
  1342. $data['coins'] = $userAssets['money'];
  1343. if($userAssets['shield'] == 0){
  1344. oo::commonOprModel('member')->optProperty($uid,['shield'=>1],'+',101,"结束新手引导");
  1345. }
  1346. oo::commonOprRedis('common')->hDel(okeys::beginGuide(),$uid);
  1347. $tb = otable::gh_gameserver($uid);
  1348. oo::commonOprDb('ghgames')->query("UPDATE {$tb} SET beginGuide = 19 WHERE mid = {$uid} LIMIT 1");
  1349. $userPlat = oo::commonOprModel('user')->getUserLoginPlat($uid);
  1350. /**
  1351. * 结束新手引导人数
  1352. */
  1353. oo::commonOprRedis('common')->sAdd(okeys::getGuideCount($userPlat),$uid);
  1354. return oo::response(1,$data);
  1355. }
  1356. //===============流水,日志,统计相关配置=============
  1357. public function moneyAddType(){
  1358. return [
  1359. 'stealAttack' =>'偷打活动',
  1360. 'rankActivity' =>'排行榜活动',
  1361. 'festival' =>'节日礼包',
  1362. 'holidayCollect'=>'节日收集',
  1363. 'goldEgg' =>'金蛋进度',
  1364. 'Architect' =>'建筑大师',
  1365. 'server' =>'后台修改',
  1366. 'slot' =>'摇奖奖励',
  1367. 'friendGift' =>'好友赠送',
  1368. 'mining' =>'矿岛收益',
  1369. 'shop' =>'商城购买',
  1370. 'card' =>'卡组收集满',
  1371. 'cardProgress' =>'卡组进度',
  1372. 'wheel' =>'大转盘',
  1373. 'chat' =>'聊天礼物',
  1374. 'firstPay' =>'首冲获取',
  1375. 'specialOffer' =>'限时特惠',
  1376. 'GiftPackage' =>'优惠礼包',
  1377. 'attackShield' =>'摧毁盾牌',
  1378. 'attack' =>'摧毁建筑',
  1379. 'attackStatus' =>'损毁建筑',
  1380. 'task' =>'每日任务',
  1381. 'ach' =>'领取成就',
  1382. 'level' =>'通过关卡',
  1383. 'balloon' =>'气球奖励',
  1384. 'ad' =>'广告获得',
  1385. 'newplayer' =>'新手引导',
  1386. 'exchange' =>'兑换码',
  1387. // 'betSteal' =>'倍率偷取',
  1388. 'recall' =>'回归',
  1389. 'invite' =>'邀请奖励',
  1390. 'speaker' =>'购买喇叭',
  1391. 'signIn' =>'签到奖励',
  1392. 'share' =>'分享奖励',
  1393. 'sysCom' =>'系统补偿',
  1394. 'versionGift' =>'更新礼包',
  1395. 'robot' =>'机器人补发',
  1396. 'recallCoin' =>'贈送召回',
  1397. 'luckyDraw' =>'夺宝抽奖',
  1398. // 'petGain' =>'宠物加成',
  1399. 'JackPot' =>'JackPot',
  1400. 'MiningGame' =>'矿工游戏',
  1401. 'VipWeek' =>'VIP每周奖励',
  1402. 'signProgress' =>'签到进度',
  1403. "systemPay" =>"系统补发",
  1404. "fbBind" =>"fb绑定",
  1405. ];
  1406. }
  1407. public function moneyLowType(){
  1408. return [
  1409. 'uplevel' =>'升级建筑',
  1410. 'relevel' =>'修复建筑',
  1411. 'upminig' =>'升级矿工',
  1412. 'bugChest' =>'购买宝箱',
  1413. 'miningGame'=>'矿工小游戏',
  1414. ];
  1415. }
  1416. public function sipnAddType(){
  1417. return [
  1418. 'stealAttack' =>'偷打活动',
  1419. 'rankActivity' =>'排行榜活动',
  1420. 'festival' =>'节日礼包',
  1421. 'holidayCollect'=>'节日收集',
  1422. 'goldEgg' =>'金蛋进度',
  1423. 'Architect' =>'建筑大师',
  1424. 'time' =>'自动恢复',
  1425. 'server' =>'后台修改',
  1426. 'slot' =>'摇奖奖励',
  1427. 'friendGift' =>'好友赠送',
  1428. 'shop' =>'商城购买',
  1429. 'newplayer' =>'新手引导',
  1430. 'slotShield' =>'盾牌转能量',
  1431. 'invite' =>'邀请奖励',
  1432. 'wheel' =>'大转盘',
  1433. 'chat' =>'聊天礼物',
  1434. 'recall' =>'回归',
  1435. 'card' =>'卡组收集满',
  1436. 'cardProgress'=>'卡组进度',
  1437. 'exchange' =>'兑换码',
  1438. 'task' =>'每日任务',
  1439. 'taskProgress'=>'每日任务进度',
  1440. 'ach' =>'领取成就',
  1441. 'level' =>'通过关卡',
  1442. 'balloon' =>'气球奖励',
  1443. 'ad' =>'广告获得',
  1444. 'firstPay' =>'首冲获取',
  1445. 'specialOffer'=>'限时特惠',
  1446. 'GiftPackage' =>'优惠礼包',
  1447. 'signIn' =>'签到奖励',
  1448. 'share' =>'分享奖励',
  1449. 'sysCom' =>'系统补偿',
  1450. 'versionGift' =>'更新礼包',
  1451. 'monthly' =>'体力月卡',
  1452. 'luckyDraw' =>'夺宝抽奖',
  1453. 'MiningGame' =>'矿工游戏',
  1454. 'VipWeek' =>'VIP每周奖励',
  1455. 'signProgress'=>'签到进度',
  1456. "fbBind" =>"fb绑定",
  1457. ];
  1458. }
  1459. public function sipnLowType(){
  1460. return [
  1461. 'slot' =>'摇奖扣除能量',
  1462. ];
  1463. }
  1464. /**
  1465. * 获取玩家等级id,简化部分接口获取多余的信息
  1466. * @param int $uid
  1467. * @return int
  1468. */
  1469. public function getUserLevelId($uid) {
  1470. $key = okeys::UserBuildLevel($uid);
  1471. $levelId = oo::commonOprRedis('common')->hGet($key, 'levelId');
  1472. if(!empty($levelId)){
  1473. return $levelId;
  1474. }
  1475. $info = $this->getUserLevel($uid);
  1476. return empty($info['levelId']) ? 1 : $info['levelId'];
  1477. }
  1478. //=========================用户等级相关========================
  1479. /**
  1480. * 获取玩家当前岛的建筑情况
  1481. * @param $uid
  1482. * @return array|bool
  1483. * Created by: Owen
  1484. * Created on: 2020/6/9 15:11
  1485. */
  1486. public function getUserLevel($uid) {
  1487. if (empty($uid)) {
  1488. return false;
  1489. }
  1490. $key = okeys::UserBuildLevel($uid);
  1491. $cache = oo::commonOprRedis('common')->hGetAll($key);
  1492. if(!$cache['levelId']){
  1493. $tb = otable::userlevel($uid);
  1494. $sql0 = "SELECT max(levelId) as levelId FROM {$tb} WHERE uid={$uid}";
  1495. $lv = oo::commonOprDb('userlevel')->getOne($sql0,1);
  1496. if(empty($lv)||!isset($lv['levelId'])){
  1497. $this->setUserNewLevel($uid,1);
  1498. $lv['levelId'] =1;
  1499. }
  1500. $sql = "SELECT * FROM {$tb} WHERE levelId={$lv['levelId']} AND uid={$uid} limit 1";
  1501. $cache = oo::commonOprDb('userlevel')->getOne($sql,1);
  1502. oo::commonOprRedis('common')->delete($key);
  1503. if(!empty($cache)&&is_array($cache)){
  1504. $temp = [
  1505. 'levelId' => $cache['levelId'],
  1506. 'element' => $cache['element'],
  1507. 'is_reward' => $cache['is_reward'],
  1508. ];
  1509. oo::commonOprRedis('common')->hMset($key,$temp);
  1510. oo::commonOprRedis('common')->expire($key,oo::redisRandomExpire(86400));
  1511. }
  1512. }
  1513. $cache = !empty($cache)?funs::getArrayFromOne($cache):[];
  1514. return $cache;
  1515. }
  1516. /**
  1517. * Notes:获取用户orig信息
  1518. * User: wsc
  1519. * Time: 2020/3/30 19:54
  1520. * @param $uid
  1521. * @param bool $db
  1522. * @return array
  1523. */
  1524. public function getUserLevel_orig($uid,$db=false){
  1525. $cache = [];
  1526. $key = okeys::userLevelOrig($uid);
  1527. if(!$db){
  1528. $cache = oo::commonOprRedis('common')->hGetAll($key);
  1529. }
  1530. if(empty($cache)){
  1531. $tb = otable::userlevel();
  1532. $sql = "SELECT * FROM {$tb} WHERE uid={$uid} LIMIT 1";
  1533. $cache = oo::commonOprDb('userlevel')->getOne($sql,1);
  1534. if(!empty($cache)){
  1535. oo::commonOprRedis('common')->hMset($key,$cache);
  1536. $time = timeFuns::today()[1];
  1537. oo::commonOprRedis('common')->expireAt($key,oo::redisRandomExpire($time));
  1538. }
  1539. }
  1540. return $cache;
  1541. }
  1542. /**
  1543. * 更新用户orig信息
  1544. * @param $uid
  1545. * @param array $updateInfo
  1546. * @return mixed
  1547. * Created by: Owen
  1548. * Created on: 2020/6/5 15:28
  1549. */
  1550. public function setUserLevel_orig($uid,$updateInfo = []){
  1551. self::getUserLevel_orig($uid); // 初始化
  1552. $tb = otable::userlevel();
  1553. $cacheKey = okeys::userLevelOrig($uid);
  1554. $sql = "";
  1555. foreach ($updateInfo as $key=>$row){
  1556. if($row['add']){
  1557. $sql.= "`{$key}`+='{$row['data']}',";
  1558. oo::commonOprRedis('user')->hIncrBy($cacheKey,$key,$row['data']);
  1559. }else{
  1560. $sql.= "`{$key}`='{$row['data']}',";
  1561. oo::commonOprRedis('user')->hSet($cacheKey,$key,$row['data']);
  1562. }
  1563. }
  1564. if(empty($sql)){
  1565. return false;
  1566. }
  1567. $sql = trim($sql,",");
  1568. $sql = "UPDATE {$tb} SET {$sql} WHERE uid={$uid}";
  1569. oo::commonOprDb('ghgames')->query($sql,false);
  1570. }
  1571. /**
  1572. * Notes:获取用户当前最小可建建筑的钱及位置
  1573. * User: wsc
  1574. * Time: 2020/4/17 16:38
  1575. * @param $uid
  1576. * @return array|int
  1577. */
  1578. public function getThisConstMinMoney($uid){
  1579. if(!$uid){
  1580. return 0;
  1581. }
  1582. $minArr = [];
  1583. $levelInfo = $this->getUserLevel($uid);
  1584. $levelCfg = oo::commonOprModel('level')->getLevelConf($levelInfo['levelId']);
  1585. $levelCfg = funs::getArrayFromOne($levelCfg);
  1586. foreach ($levelInfo['element'] as $k=>$v){
  1587. if($v['level']==5){
  1588. continue;
  1589. }
  1590. $minArr[$k] = $levelCfg['coinConfig'][$k][$v['level']];
  1591. }
  1592. $min['money'] = min($minArr);
  1593. $min['place_k'] = array_search($min['money'],$minArr)+1;
  1594. $min['place_v'] = array_search($min['money'],$levelCfg['coinConfig'][$min['place_k']])+1;
  1595. return $min;
  1596. }
  1597. /**
  1598. * 设置新等级
  1599. * @param $uid
  1600. * @param $level
  1601. * @return int
  1602. * Created by: Owen
  1603. * Created on: 2019/8/13 14:57
  1604. * Description:
  1605. */
  1606. public function setUserNewLevel($uid,$level) {
  1607. $str_level = '[{\"id\":1,\"level\":0,\"maxLevel\":0,\"status\":0},{\"id\":2,\"level\":0,\"maxLevel\":0,\"status\":0},{\"id\":3,\"level\":0,\"maxLevel\":0,\"status\":0},{\"id\":4,\"level\":0,\"maxLevel\":0,\"status\":0},{\"id\":5,\"level\":0,\"maxLevel\":0,\"status\":0}]';
  1608. if($level == 1){
  1609. $tb = otable::userlevel($uid);
  1610. $time = time();
  1611. oo::commonOprDb('common')->query("INSERT INTO {$tb} (`uid`,`levelId`,`element`,`createTime`) VALUES ({$uid},{$level}, '$str_level','{$time}')");
  1612. return true;
  1613. }
  1614. $info = $this->getUserAssetsInfo($uid);
  1615. oo::commonOprModel('steal')->outAllQueue($uid,$level-1);
  1616. oo::commonOprModel('steal')->toJoinQueue($uid,$level,$info['money']);
  1617. self::updateUserLevel($uid,[
  1618. 'levelId' => $level,
  1619. 'element' => json_decode(stripslashes($str_level),true),
  1620. 'is_reward'=> 0,
  1621. ]);
  1622. // oo::commonOprRedis('common')->hIncrBy(okeys::todayDataRank('level'),$uid,1);
  1623. if($level == 2){
  1624. oo::commonOprRedis('common')->delete(okeys::newcomerSpinNum($uid));
  1625. }
  1626. return true;
  1627. }
  1628. /**
  1629. * 更新建筑用户信息
  1630. * @param $uid
  1631. * @param array $updateInfo
  1632. * @return false
  1633. * Created by: Owen
  1634. * Created on: 2020/6/8 11:08
  1635. */
  1636. public function updateUserLevel($uid,$updateInfo = []){
  1637. if(empty($updateInfo)){
  1638. return false;
  1639. }
  1640. $taUpdateInfo = [];
  1641. if(!empty($updateInfo['element'])){
  1642. $total = array_sum(array_column($updateInfo['element'],'level'));
  1643. $updateInfo['element'] = json_encode($updateInfo['element']);
  1644. oo::commonOprRedis('common')->setex(okeys::UserBuildTotal($uid),$total,oo::redisRandomExpire(86400*10));
  1645. self::updateUserLevelTotal($uid,$total);
  1646. $taUpdateInfo["current_building_level"] = $total;
  1647. }
  1648. if(!empty($updateInfo['levelId'])){
  1649. $taUpdateInfo["current_level"] = $updateInfo['levelId'];
  1650. }
  1651. /**
  1652. * ta 公共属性
  1653. */
  1654. if(!empty($taUpdateInfo)){
  1655. oo::commonOprModel('ta')->setCommonEventProperty($uid,'common',$taUpdateInfo);
  1656. }
  1657. $updateInfo['isLanding'] = 1;
  1658. $key = okeys::UserBuildLevel($uid);
  1659. oo::commonOprRedis('common')->hMset($key,$updateInfo);
  1660. oo::commonOprRedis('common')->expire($key,oo::redisRandomExpire(86400));
  1661. return oo::commonOprRedis('common')->zAdd(okeys::Landing("BUILDING", $uid),time(),$uid) !== false;
  1662. }
  1663. /**
  1664. * 更新建筑总等级
  1665. * @param $uid
  1666. * @param $updateInfo
  1667. * @return mixed
  1668. * Created by: Owen
  1669. * Created on: 2019/11/5 12:25
  1670. */
  1671. public function updateLevelTotal($uid,$updateInfo = []){
  1672. if(empty($updateInfo)){
  1673. return false;
  1674. }
  1675. if(isset($updateInfo['total'])){
  1676. oo::commonOprRedis('common')->setex(okeys::UserBuildTotal($uid),$updateInfo['total']['data'],oo::redisRandomExpire(86400*10));
  1677. self::updateUserLevelTotal($uid,$updateInfo['total']['data']);
  1678. }
  1679. }
  1680. /**
  1681. * 更新建筑数据 -- 兼容版本
  1682. * @param $uid
  1683. * @param $level
  1684. * @param $userElement
  1685. * @return mixed
  1686. * Created by: Owen
  1687. * Created on: 2019/8/13 14:59
  1688. * Description:
  1689. */
  1690. public function setUserLevel($uid,$level,$userElement){
  1691. return self::updateUserLevel($uid,[
  1692. 'levelId' => $level,
  1693. 'element' => $userElement,
  1694. ]);
  1695. }
  1696. /** --------------------------打逻辑重构--------------------------- */
  1697. //====================打相关============================
  1698. /**
  1699. * Notes:获取当前默认敌人信息
  1700. * User: owen
  1701. * Time: 2020/3/31 20:05
  1702. * @param $uid
  1703. * @return mixed
  1704. */
  1705. public function getEnemyData($uid){
  1706. $toUid = $this->getEnemyListByType($uid,1);
  1707. if(empty($toUid)||$toUid==false){
  1708. return false;
  1709. }
  1710. $info = $this->checkBuildDamaged($toUid);
  1711. if($info){
  1712. return [
  1713. 'toUid' => $toUid,
  1714. 'levelId'=> $info['levelId'],
  1715. 'element'=> $info['element']
  1716. ];
  1717. }else{
  1718. $this->delFromAttackProtectList($toUid);
  1719. }
  1720. return false;
  1721. }
  1722. /**
  1723. * 获取攻击列表
  1724. * @param $uid
  1725. * @param int $first 1=>老虎机,2=>攻击列表
  1726. * @return mixed
  1727. * Created by: Owen
  1728. * Created on: 2020/6/22 16:27
  1729. */
  1730. public function getEnemyListByType($uid,$first=1){
  1731. $cacheKey = okeys::DefaultEnemy($uid);
  1732. $cache = oo::commonOprRedis('User')->get($cacheKey);
  1733. if(!$cache){
  1734. $firstOne = self::getFriendEnemyList($uid);
  1735. if(!empty($firstOne)){
  1736. $firstOne = $firstOne[0];
  1737. // 攻击好友之后当天不能再被攻击
  1738. if(oo::commonOprModel('friend')->isFriend($uid,$firstOne)){
  1739. oo::commonOprRedis('User')->sAdd(okeys::TodayFriendAttackLog($uid),$firstOne);
  1740. oo::commonOprRedis('User')->expire(okeys::TodayFriendAttackLog($uid),oo::todayDeadline());
  1741. }
  1742. self::outputAttackList($firstOne);
  1743. }else{
  1744. $firstOne = self::getFromAttackWaitList($uid);
  1745. }
  1746. $firstOne && oo::commonOprRedis('User')->setex($cacheKey,$firstOne,5*60);
  1747. }else{
  1748. $firstOne = $cache;
  1749. }
  1750. if($first == 1){
  1751. return $firstOne;
  1752. }
  1753. $actionList = [$firstOne];
  1754. // $actionList[] = self::getFromAttackWaitList($uid,$actionList); // 20210104 默认攻击对象减为1个
  1755. $enemy = self::getMyEnemyList($uid);
  1756. foreach ($enemy as $uid){
  1757. if(!in_array($uid,$actionList) && self::isFromAttackWaitList($uid)){
  1758. $actionList[] = $uid;
  1759. if(count($actionList) >= 10){
  1760. break;
  1761. }
  1762. }
  1763. }
  1764. return $actionList;
  1765. }
  1766. /**
  1767. * Notes:验证list是否满足条件
  1768. * User: wsc
  1769. * Time: 2020/4/1 10:28
  1770. * @param $list
  1771. * @return array 返回满足条件的 [uid1,uid2,uid3...]
  1772. */
  1773. public function verifyIsPass($uid,$type,$list){
  1774. $cfg = oo::cfg('stealattack')['attack'];
  1775. if(!empty($list)&&is_array($list)){
  1776. foreach ($list as $k=>$v){
  1777. if($v==$uid){
  1778. unset($list[$k]);
  1779. }
  1780. $ttl = oo::commonOprRedis('Userinfo')->ttl(okeys::AttackLock($v));//保护时间
  1781. $auid = oo::commonOprRedis('Userinfo')->get(okeys::beAttactLock($v));
  1782. $levelInfo = $this->getUserLevel_orig($v);
  1783. $res1 = $levelInfo['attackedNum']>=$cfg['maxLimit']?true:false;//次数
  1784. $res2 = $levelInfo['total']>0?false:true;//是否有建筑
  1785. $res3 = !empty($auid)?($auid==$uid?false:true):false;//是否有被锁定
  1786. $res4 = $levelInfo['levelId']<=$cfg['minLv']?true:false;//是否满足等级条件
  1787. if($ttl>0||$res1||$res2||$res3||$res4){//排除被保护的,排除被打大于maxLimit次的
  1788. unset($list[$k]);
  1789. if($type==3){
  1790. $dLKey = okeys::defaultAttactList($uid);
  1791. oo::commonOprRedis('Userinfo')->hDel($dLKey,$v);
  1792. }
  1793. }
  1794. }
  1795. }
  1796. return $list;
  1797. }
  1798. /**
  1799. * Notes:获取默认估计列表uidList
  1800. * User: wsc
  1801. * Time: 2020/4/26 12:23
  1802. * @param $uid
  1803. * @return array
  1804. */
  1805. // public function getDefaultAttactList($uid){
  1806. // $cfg = oo::cfg('stealattack')['attack'];
  1807. // $list = [];
  1808. // $inStr ='';
  1809. // $order = '';
  1810. // $enemyList = oo::commonOprRedis('common')->hGetAll(okeys::EnemyID($uid));//历史仇人列表
  1811. // $friends = oo::commonOprModel('friend')->getUserAllFriend($uid);//好友列表
  1812. // $w = " 1=1 ";
  1813. // if(!empty($friends)){
  1814. // $inStr .= implode(',',$friends);
  1815. // }
  1816. // if(!empty($enemyList)){
  1817. // $enemylist = array_keys($enemyList);
  1818. // $inStr .= implode(',',$enemylist);
  1819. // }
  1820. // if(!empty($inStr)){
  1821. // $w .= " AND uid IN ({$inStr}) ";
  1822. // $order .= " FIELD(`uid`,{$inStr}), ";
  1823. // }
  1824. // $w .= " AND levelId>{$cfg['minLv']}";
  1825. // $w .= " AND attackedNum<{$cfg['maxLimit']}";
  1826. // $w .= " AND total>0 ";
  1827. // $w .=" AND total<25";
  1828. // $order .= " total DESC,levelId DESC, logintime DESC ";
  1829. // $tb = otable::userlevel();
  1830. // $sql = "SELECT uid,attackedNum,logintime,total FROM {$tb} WHERE {$w} ORDER BY $order LIMIT 50";
  1831. // $data = oo::commonOprDb('userlevel')->getAll($sql,1);
  1832. // $list = array_column($data,'uid');
  1833. //
  1834. // $randList = $this->getRandEnemyListFromDB($uid);//随机用户
  1835. // $ruidList =!empty($randList)?array_column($randList,'uid'):[];
  1836. // $list = array_unique(array_merge($list,$ruidList));
  1837. // return $list;
  1838. // }
  1839. /**
  1840. * Notes:获取我的仇人满足条件的列表
  1841. * User: wsc
  1842. * Time: 2020/4/1 10:20
  1843. * @param $uid
  1844. * @return array [uid1,uid2,uid3...]
  1845. */
  1846. public function getMyEnemyList($uid){
  1847. return array_keys(array_reverse(oo::commonOprRedis('common')->hGetAll(okeys::EnemyID($uid)),true));
  1848. }
  1849. /**
  1850. * Notes:获取满足条件的好友
  1851. * User: wsc
  1852. * Time: 2020/4/1 10:16
  1853. * @param $uid
  1854. * @param $num
  1855. * @return array [uid1,uid2,uid3...]
  1856. */
  1857. public function getFriendEnemyList($uid , $num = 1){
  1858. $list = [];
  1859. $enemy = self::getMyEnemyList($uid);
  1860. $friends = oo::commonOprModel('friend')->getUserAllFriend($uid);
  1861. $enemyFriends = array_intersect($enemy,$friends);
  1862. $actions= [];
  1863. $todayAttackLog = oo::commonOprRedis('User')->sMembers(okeys::TodayFriendAttackLog($uid));
  1864. foreach ($enemyFriends as $row){
  1865. if(in_array($row,$todayAttackLog)){
  1866. continue;
  1867. }
  1868. $actions[] = $row;
  1869. }
  1870. foreach ($enemy as $row){
  1871. if(in_array($row,$todayAttackLog)){
  1872. continue;
  1873. }
  1874. !in_array($row,$actions) && $actions[] = $row;
  1875. }
  1876. foreach ($friends as $row){
  1877. if(in_array($row,$todayAttackLog)){
  1878. continue;
  1879. }
  1880. !in_array($row,$actions) && $actions[] = $row;
  1881. }
  1882. $i = 0;
  1883. foreach ($actions as $row){
  1884. if(self::isFromAttackWaitList($row)){
  1885. $list[] = $row;
  1886. $i++;
  1887. if($num == $i){
  1888. break;
  1889. }
  1890. }
  1891. }
  1892. return $list;
  1893. }
  1894. /**
  1895. * Notes:从DB中随机被打玩家缓存
  1896. * User: wsc
  1897. * Time: 2020/3/31 9:53
  1898. * @param $uid
  1899. * @param bool $db
  1900. * @return array [uid1,uid2,uid3...]
  1901. */
  1902. // public function getRandEnemyListFromDB($uid,$db=false){
  1903. // $cfg = oo::cfg('stealattack')['attack'];
  1904. // $list = $cache = [];
  1905. // $eListkey = okeys::EnemyListCache($uid);
  1906. // if(!$db){
  1907. // $cache = oo::commonOprRedis('common')->hGetAll($eListkey);
  1908. // $list = funs::getArrFromJsonArr($cache);
  1909. //// $list = $this->verifyIsPass($list);
  1910. // }
  1911. // if(empty($cache)){
  1912. // $tb = otable::userlevel();
  1913. // $stime =0;
  1914. //// if(!IS_DEBUF){//获取近期活跃
  1915. //// $stime = time()-86400*5;
  1916. //// }
  1917. // $w = "";
  1918. // $w .= " levelId>{$cfg['minLv']} ";
  1919. // $w .=" AND attackedNum<{$cfg['maxLimit']}";
  1920. // $w .=" AND total>0";
  1921. // $w .= " AND logintime>{$stime} ";
  1922. // $sql = "SELECT uid,attackedNum,logintime,total FROM {$tb} WHERE {$w} ORDER BY RAND() LIMIT 50";
  1923. // $ulist = oo::commonOprDb('userlevel')->getAll($sql,MYSQLI_ASSOC);
  1924. // oo::commonOprRedis('common')->delete($eListkey);
  1925. // if(!empty($ulist)){
  1926. // array_multisort(array_column($ulist,'total'),SORT_DESC,$ulist);
  1927. // foreach ($ulist as $k=>$v){
  1928. // $cache[$v['uid']] = json_encode($v,true);
  1929. // }
  1930. // oo::commonOprRedis('common')->hMset($eListkey,$cache);
  1931. // oo::commonOprRedis('common')->expire($eListkey,600);
  1932. // $list = array_column($ulist,null,'uid');
  1933. // }
  1934. // }
  1935. // !empty($list)?array_multisort(array_column($list,'total'),SORT_DESC,array_column($list,'logintime'),SORT_DESC,$list):$list=[];
  1936. //
  1937. // return $list;
  1938. // }
  1939. /**
  1940. * 获取用户岛建筑总值
  1941. * @param $uid
  1942. * @return int
  1943. * Created by: Owen
  1944. * Created on: 2020/6/20 17:49
  1945. */
  1946. public function getUserCurLevelTotal($uid){
  1947. $cacheKey = okeys::UserBuildTotal($uid);
  1948. $total = oo::commonOprRedis('User')->get($cacheKey);
  1949. if($total === false){
  1950. $userLevelData = self::getUserLevel($uid);
  1951. $element = $userLevelData['element'];
  1952. $total = 0;
  1953. foreach ($element as $row){
  1954. $total += max($row['level'],0);
  1955. }
  1956. oo::commonOprRedis('User')->setex($cacheKey,$total,oo::redisRandomExpire(86400*10));
  1957. }
  1958. return (int)$total;
  1959. }
  1960. /**
  1961. * 更新用户岛建筑总值(20210728-wsc-弃用)
  1962. * @param $uid
  1963. * @param $total
  1964. * Created by: Owen
  1965. * Created on: 2020/6/20 17:48
  1966. */
  1967. public function updateUserLevelTotal($uid,$total){
  1968. return true;
  1969. $total = max(0,$total);
  1970. if($total){
  1971. if(!self::getFromAttackProtectList($uid)){
  1972. self::addToAttackWaitList($uid);
  1973. }
  1974. }else{
  1975. self::delFromAttackWaitList($uid,true);
  1976. }
  1977. }
  1978. /**
  1979. * 获取用户每日被攻击次数
  1980. * @param $uid
  1981. * @return int
  1982. * Created by: Owen
  1983. * Created on: 2020/6/20 16:30
  1984. */
  1985. public function getUserDailyAttackedNum($uid){
  1986. return intval(oo::commonOprRedis('User')->hGet(okeys::UserDailyAttackedNum(),$uid));
  1987. }
  1988. /**
  1989. * 增加用户每日被攻击次数
  1990. * @param $uid
  1991. * @param $num
  1992. * @return int
  1993. * Created by: Owen
  1994. * Created on: 2020/6/20 16:30
  1995. */
  1996. public function addUserDailyAttackedNum($uid,$num = 1){
  1997. return oo::commonOprRedis('User')->hIncrBy(okeys::UserDailyAttackedNum(),$uid,$num);
  1998. }
  1999. /**
  2000. * 获取用户被攻击次数
  2001. * @param $uid
  2002. * @return int
  2003. * Created by: Owen
  2004. * Created on: 2021/2/20 17:26
  2005. */
  2006. public function getUserAttackedNum($uid){
  2007. return intval(oo::commonOprRedis('User')->get(okeys::UserAttackedNum($uid)));
  2008. }
  2009. /**
  2010. * 增加用户被攻击次数
  2011. * @param $uid
  2012. * @param int $num
  2013. * @return bool
  2014. * Created by: Owen
  2015. * Created on: 2021/2/20 17:24
  2016. */
  2017. public function addUserAttackedNum($uid,$num = 1){
  2018. $curNum = oo::commonOprRedis('User')->incrBy(okeys::UserAttackedNum($uid),$num);
  2019. if($curNum == $num){
  2020. oo::commonOprRedis('User')->expire(okeys::UserAttackedNum($uid),720*60);
  2021. }else if($curNum > 5){
  2022. $ttl = oo::commonOprRedis('User')->ttl(okeys::UserAttackedNum($uid));
  2023. if($ttl <= 0){
  2024. oo::commonOprRedis('User')->expire(okeys::UserAttackedNum($uid),720*60);
  2025. }
  2026. }
  2027. return $curNum;
  2028. }
  2029. /**
  2030. * 判断是否在保护期中
  2031. * @param $uid
  2032. * @return int
  2033. * Created by: Owen
  2034. * Created on: 2020/6/20 17:47
  2035. */
  2036. public function getFromAttackProtectList($uid){
  2037. return oo::commonOprRedis('common')->zScore(okeys::AttackProtectList(),$uid);
  2038. }
  2039. /**
  2040. * 加入保护期 -- 超过5次保护到今天结束
  2041. * @param $uid
  2042. * @param $from // 来源 1=>攻击,2=>支付,3=>好友攻击
  2043. * @param $time
  2044. * @return mixed
  2045. * Created by: Owen
  2046. * Created on: 2020/6/20 16:44
  2047. */
  2048. public function addToAttackProtectList($uid,$from,$time = 0){
  2049. $cfg = oo::cfg('stealattack')['attack']['proteCfg'];
  2050. if($from != 1 && $from != 2 && $from != 3){
  2051. return false;
  2052. }
  2053. if($from == 1){
  2054. $curAttackedNum = $this->getUserAttackedNum($uid);
  2055. $limit = $cfg['changeProteTimeLimit']?$cfg['changeProteTimeLimit']:5;
  2056. if($curAttackedNum >= $limit){
  2057. $time = $cfg['changeNotFriendProteTime']?$cfg['changeNotFriendProteTime']:720 * 60;
  2058. oo::commonOprRedis('User')->delete(okeys::UserAttackedNum($uid));
  2059. }else{
  2060. $time = $cfg['notFriendProteTime']?$cfg['notFriendProteTime']:60 * 60;
  2061. }
  2062. }
  2063. $curTime = intval(self::getFromAttackProtectList($uid));
  2064. self::delFromAttackWaitList($uid);
  2065. $userInfo = oo::commonOprModel('member')->getUserInfo($uid);//玩家基本信息
  2066. $longTimes = $cfg['longNoOnlineTime']?$cfg['longNoOnlineTime']:2880 * 60;
  2067. if(time() - $userInfo['lasttime'] > $longTimes){//超过两天不在线
  2068. $time = $cfg['longNoOnlineProteTime']?$cfg['longNoOnlineProteTime']:7*24*60*60;
  2069. }
  2070. $setTime = max($curTime,time() + $time);
  2071. self::addAttackProtectList($uid,$setTime);
  2072. oo::commonOprRedis('common')->setex(okeys::AttackLock($uid),1,$setTime - time());
  2073. }
  2074. /**
  2075. * 加入保护期 -- 超过5次保护到今天结束
  2076. * @param $uid
  2077. * @param $from // 来源 1=>攻击,2=>支付
  2078. * @param $time
  2079. * @return mixed
  2080. * Created by: Owen
  2081. * Created on: 2020/6/20 16:44
  2082. */
  2083. // public function addFromAttackProtectList_backup($uid,$from,$time = 0){
  2084. // if($from != 1 && $from != 2){
  2085. // return false;
  2086. // }
  2087. // if($from == 1){
  2088. // $cfg = oo::cfg('stealattack')['attack'];
  2089. // $curDailyAttackedNum = self::getUserDailyAttackedNum($uid);
  2090. // if($curDailyAttackedNum >= $cfg['maxLimit']){
  2091. // $time = oo::todayDeadline();
  2092. // }else{
  2093. // $cacheKey = okeys::UserDailyAttackedTime();
  2094. // $totalTime = intval(oo::commonOprRedis('User')->hGet($cacheKey,$uid));
  2095. // $totalTime = min($totalTime,300);
  2096. // if($totalTime >= 300){
  2097. // $time = 18000;
  2098. // }else{
  2099. // $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  2100. // if($userAssetsInfo['shield'] > 0){
  2101. // oo::commonOprRedis('User')->hIncrBy($cacheKey,$uid,3);
  2102. // $time = min($totalTime + 3,300) * 60;
  2103. // }else{
  2104. // $needTime = [1=>5,2=>5,3=>5,4=>10,5=>60];
  2105. // $total = self::getUserCurLevelTotal($uid);
  2106. // if($total > 20){
  2107. // $lv = 1;
  2108. // }else if($total>=16){
  2109. // $lv = 2;
  2110. // }else if($total>=11){
  2111. // $lv = 3;
  2112. // }else if($total>=5){
  2113. // $lv = 4;
  2114. // }else{
  2115. // $lv = 5;
  2116. // }
  2117. // $needTime = min($totalTime + $needTime[$lv],300);
  2118. // oo::commonOprRedis('User')->hSet($cacheKey,$uid,$needTime);
  2119. // $time = $needTime * 60;
  2120. // }
  2121. // }
  2122. // }
  2123. // }
  2124. // $curTime = intval(self::getFromAttackProtectList($uid));
  2125. // self::delFromAttackWaitList($uid);
  2126. // $setTime = max($curTime,time() + $time);
  2127. // self::addAttackProtectList($uid,$setTime);
  2128. // oo::commonOprRedis('common')->setex(okeys::AttackLock($uid),1,$setTime - time());
  2129. // }
  2130. /**
  2131. * 加入保护队列
  2132. * @param $uid
  2133. * @param $time
  2134. * @return bool
  2135. * Created by: Owen
  2136. * Created on: 2020/9/22 19:38
  2137. */
  2138. public function addAttackProtectList($uid,$time,$max = true){
  2139. if($max){
  2140. $time = max(intval(oo::commonOprRedis('common')->zScore(okeys::AttackProtectList(),$uid)),$time);
  2141. }
  2142. return oo::commonOprRedis('common')->zAdd(okeys::AttackProtectList(),$time,$uid);
  2143. }
  2144. /**
  2145. * 删除保护期中用户
  2146. * @param $uid
  2147. * @return bool
  2148. * Created by: Owen
  2149. * Created on: 2020/6/20 16:07
  2150. */
  2151. public function delFromAttackProtectList($uid){
  2152. return oo::commonOprRedis('User')->zDelete(okeys::AttackProtectList(),$uid);
  2153. }
  2154. /**
  2155. * 是否保护期中用户
  2156. * @param $uid
  2157. * @return bool
  2158. * Created by: Owen
  2159. * Created on: 2020/6/20 16:07
  2160. */
  2161. public function isFromAttackProtectList($uid){
  2162. return oo::commonOprRedis('User')->zScore(okeys::AttackProtectList(),$uid);
  2163. }
  2164. /**
  2165. * 获取随机攻击对象
  2166. * @param $uid
  2167. * @param $noUid
  2168. * @return int
  2169. * Created by: Owen
  2170. * Created on: 2020/6/20 17:47
  2171. */
  2172. public function getFromAttackWaitList($uid,$noUid = []){
  2173. $noUid[] = $uid;
  2174. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  2175. $actionLevel = oo::getActionLevel('attack',$userAssetsInfo['levelId']);
  2176. $curMaxLevel = oo::commonOprModel('config')->getCurMaxLevel();
  2177. $actionMaxLevel = $actionLevel['max'];
  2178. $trueMax = min($curMaxLevel,$actionMaxLevel);
  2179. $rand = rand(0,100);
  2180. if($rand < 40){
  2181. $max = $trueMax;
  2182. }else if($rand < 85){
  2183. $max = max(ceil($actionMaxLevel - $userAssetsInfo['levelId']/2),4);
  2184. }else{
  2185. $max = max($userAssetsInfo['levelId'] - 5,4);
  2186. }
  2187. $randUid = self::popFromAttackWaitList($max,$actionLevel['min'],$noUid);
  2188. if($max != $trueMax && !$randUid){
  2189. $randUid = self::popFromAttackWaitList($trueMax,$actionLevel['min'],$noUid);
  2190. }
  2191. return $randUid;
  2192. }
  2193. public function popFromAttackWaitList($max,$min = 3,$noUid = []){
  2194. $fromPro = rand(0,100);
  2195. for($i=$max;$i >= $min;$i--){
  2196. if($fromPro < 90){
  2197. $randUid = self::getFromAttackShieldList($i,$noUid);
  2198. if($randUid && !in_array($randUid,$noUid)){
  2199. return $randUid;
  2200. }
  2201. }
  2202. $size = oo::commonOprRedis('common')->sSize(okeys::AttackWaitList($i));
  2203. for($s=0;$s<$size;$s++){
  2204. $randUid = oo::commonOprRedis('common')->sPop(okeys::AttackWaitList($i));
  2205. self::outputAttackList($randUid,$i);
  2206. if($randUid && !in_array($randUid,$noUid)){
  2207. return $randUid;
  2208. }
  2209. }
  2210. }
  2211. return false;
  2212. }
  2213. /**
  2214. * 判断是否在待攻击中
  2215. * @param $uid
  2216. * @return int
  2217. * Created by: Owen
  2218. * Created on: 2020/6/20 17:47
  2219. */
  2220. public function isFromAttackWaitList($uid){
  2221. $cfg = oo::cfg('stealattack')['attack'];
  2222. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  2223. return $userAssetsInfo['levelId'] > $cfg['minLv'] && oo::commonOprRedis('common')->sContains(okeys::AttackWaitList($userAssetsInfo['levelId']),$uid);
  2224. }
  2225. /**
  2226. * 加入待攻击列表
  2227. * @param $uid
  2228. * @return bool
  2229. * Created by: Owen
  2230. * Created on: 2020/6/20 16:16
  2231. */
  2232. public function addToAttackWaitList($uid){
  2233. $total = self::getUserCurLevelTotal($uid);
  2234. if($total > 0){
  2235. if(self::checkBuildDamaged($uid)){
  2236. $cfg = oo::cfg('stealattack')['attack'];
  2237. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  2238. return $userAssetsInfo['levelId'] > $cfg['minLv'] && oo::commonOprRedis('User')->sAdd(okeys::AttackWaitList($userAssetsInfo['levelId']),$uid);
  2239. }
  2240. }
  2241. return false;
  2242. }
  2243. /**
  2244. * 删除待攻击列表
  2245. * @param $uid
  2246. * @param $check
  2247. * @return bool
  2248. * Created by: Owen
  2249. * Created on: 2020/6/20 16:08
  2250. */
  2251. public function delFromAttackWaitList($uid,$check = false){
  2252. if($check){
  2253. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  2254. $bool = oo::commonOprRedis('User')->sRemove(okeys::AttackWaitList($userAssetsInfo['levelId']),$uid);
  2255. !$bool && self::checkDelFromAttackWaitList($uid);
  2256. self::delFromAttackShieldList($userAssetsInfo['levelId'],$uid);
  2257. }else{
  2258. $bool = self::outputAttackList($uid);
  2259. }
  2260. return $bool;
  2261. }
  2262. /**
  2263. * 加入攻击锁定状态
  2264. * @param $uid
  2265. * @return mixed
  2266. * Created by: Owen
  2267. * Created on: 2020/6/30 16:08
  2268. */
  2269. public function addToAttackLockList($uid){
  2270. $ret = oo::commonOprRedis('common')->zAdd(okeys::AttackLockList(),time() + 3*60 ,$uid);
  2271. return $ret !== false ? true : false;
  2272. }
  2273. /**
  2274. * 删除攻击锁定
  2275. * @param $uid
  2276. * @return bool
  2277. * Created by: Owen
  2278. * Created on: 2020/6/30 17:55
  2279. */
  2280. public function delFromAttackLockList($uid){
  2281. return oo::commonOprRedis('User')->zDelete(okeys::AttackLockList(),$uid);
  2282. }
  2283. /**
  2284. * 将结束保护期的用户刷入待攻击列表(20210728-wsc-弃用)
  2285. * Created by: Owen
  2286. * Created on: 2020/6/20 17:13
  2287. */
  2288. public function refreshIntoAttackWaitList(){
  2289. return false;
  2290. $ret = oo::commonOprRedis('common')->zRangeByScore(okeys::AttackProtectList(),0,time(),['withscores'=>true]);
  2291. foreach ($ret as $uid=>$row){
  2292. self::addToAttackWaitList($uid) && self::checkAttackShieldByUid($uid);
  2293. self::delFromAttackProtectList($uid);
  2294. }
  2295. }
  2296. /**
  2297. * 检测建筑
  2298. * @param $uid
  2299. * @return array
  2300. * Created by: Owen
  2301. * Created on: 2020/6/30 21:23
  2302. */
  2303. public function checkElementTotal($uid){
  2304. $list = self::getEnemyListByType($uid,2);
  2305. $trueList = [];
  2306. foreach ($list as $row){
  2307. $userLevelInfo = self::getUserLevel($row);
  2308. $element = (array)$userLevelInfo['element'];
  2309. $total = 0;
  2310. foreach ($element as $e){
  2311. $total = $total + max($e['level'],0);
  2312. }
  2313. if($total > 0){
  2314. $trueList[] = $row;
  2315. }else{
  2316. self::updateUserLevelTotal($row,0);
  2317. }
  2318. }
  2319. $count = count($trueList);
  2320. //如果仇人列表只有1个且为自己好友时,也添加一个随机对象
  2321. if($count < 1||($count == 1 && oo::commonOprModel('friend')->isFriend($uid, $trueList[0]))){
  2322. $trueList[] = self::getFromAttackWaitList($uid, [$trueList[0]]);
  2323. }
  2324. return $trueList;
  2325. }
  2326. /**
  2327. * 检测出队
  2328. * @param $uid
  2329. * @return bool
  2330. * Created by: Owen
  2331. * Created on: 2020/7/1 15:50
  2332. */
  2333. public function checkDelFromAttackWaitList($uid){
  2334. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  2335. $maxWorldLevel = intval(oo::commonOprModel('readconfig')->getCon('basic','curMaxLevel'))??60;//当前世界最大等级
  2336. $level = min($maxWorldLevel,$userAssetsInfo['levelId'] + 5);
  2337. for ($i=4;$i<$level;$i++){
  2338. $bool = oo::commonOprRedis('User')->sRemove(okeys::AttackWaitList($i),$uid);
  2339. if($bool){
  2340. return true;
  2341. }
  2342. }
  2343. return true;
  2344. }
  2345. /**
  2346. * 从可被攻击盾牌池子获取可被攻击对象
  2347. * @@param $noUid
  2348. * @return mixed
  2349. * Created by: Owen
  2350. * Created on: 2020/8/21 16:33
  2351. */
  2352. public function getFromAttackShieldList($lv,$noUid = []){
  2353. $cacheKey = okeys::AttackShieldList($lv);
  2354. $zSize = oo::commonOprRedis('User')->zSize($cacheKey);
  2355. for($i=0;$i<$zSize;$i++){
  2356. $ret = oo::commonOprRedis('User')->zRevRange($cacheKey,$i,$i,true);
  2357. $randUid = array_keys($ret)[0];
  2358. if(!in_array($randUid,$noUid)){
  2359. self::outputAttackList($randUid,$lv);
  2360. return $randUid;
  2361. }
  2362. }
  2363. return false;
  2364. }
  2365. /**
  2366. * 攻击出队
  2367. * @param $uid
  2368. * @param $lv
  2369. * @return bool
  2370. * Created by: Owen
  2371. * Created on: 2020/9/27 16:31
  2372. */
  2373. public function outputAttackList($uid,$lv = 0){
  2374. if($lv == 0){
  2375. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  2376. $lv = $userAssetsInfo['levelId'];
  2377. }
  2378. oo::commonOprRedis('User')->zDelete(okeys::AttackShieldList($lv),$uid);
  2379. oo::commonOprRedis('User')->sRemove(okeys::AttackWaitList($lv),$uid);
  2380. return self::addAttackProtectList($uid,time() + 15);
  2381. }
  2382. /**
  2383. * 监测用户盾牌攻击池子
  2384. * @param $uid
  2385. * @param $checkInProtectPool
  2386. * @return mixed
  2387. * Created by: Owen
  2388. * Created on: 2020/8/21 16:48
  2389. */
  2390. public function checkAttackShieldByUid($uid,$checkInProtectPool = false){
  2391. if($checkInProtectPool){
  2392. if(self::isFromAttackProtectList($uid)){
  2393. return false;
  2394. }
  2395. }
  2396. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  2397. if($userAssetsInfo['levelId'] > 3){
  2398. if($userAssetsInfo['shield'] > 0){
  2399. $total = self::getUserCurLevelTotal($uid);
  2400. $total && self::addAttackShieldList($userAssetsInfo['levelId'],$uid,$userAssetsInfo['shield']);
  2401. }else{
  2402. self::delFromAttackShieldList($userAssetsInfo['levelId'],$uid);
  2403. }
  2404. }
  2405. }
  2406. /**
  2407. * 加入可被攻击盾牌池子
  2408. * @param $lv
  2409. * @param $uid
  2410. * @param $num
  2411. * Created by: Owen
  2412. * Created on: 2020/8/21 16:39
  2413. */
  2414. public function addAttackShieldList($lv,$uid,$num){
  2415. $cacheKey = okeys::AttackShieldList($lv);
  2416. oo::commonOprRedis('User')->zAdd($cacheKey,$num,$uid);
  2417. }
  2418. /**
  2419. * 移出可被攻击盾牌池子
  2420. * @param $lv
  2421. * @param $uid
  2422. * @return bool
  2423. * Created by: Owen
  2424. * Created on: 2020/8/21 16:38
  2425. */
  2426. public function delFromAttackShieldList($lv,$uid){
  2427. $cacheKey = okeys::AttackShieldList($lv);
  2428. $bool = oo::commonOprRedis('User')->zDelete($cacheKey,$uid);
  2429. if(!$bool){
  2430. for($i=$lv;$i>=4;$i--){
  2431. $tBool = oo::commonOprRedis('User')->zDelete($cacheKey,$uid);
  2432. if($tBool){
  2433. return true;
  2434. }
  2435. }
  2436. }
  2437. return $bool;
  2438. }
  2439. /**
  2440. * 建筑检测--1级破损不进行攻击
  2441. * @param $uid
  2442. * @return bool
  2443. * Created by: Owen
  2444. * Created on: 2020/9/21 15:04
  2445. */
  2446. public function checkBuildDamaged($uid){
  2447. $userLevelData = self::getUserLevel($uid);
  2448. $levelId = $userLevelData['levelId'];
  2449. $maxLevel = intval(oo::commonOprModel('readconfig')->getCon('basic',"curMaxLevel"));
  2450. $element = $userLevelData['element'];
  2451. if($levelId == $maxLevel){
  2452. if(array_sum(array_column($element,'level')) == 25){
  2453. return false;
  2454. }
  2455. }
  2456. if(empty($element)){ //没有岛,不进行攻击
  2457. oo::logs()->debug3(['uid' => $uid, 'userLevelData' => $userLevelData],'checkbuilddmg_err');//写日志
  2458. return false;
  2459. }
  2460. foreach ($element as $row){
  2461. if($row['level'] > 1 || ($row['level'] == 1 && $row['status'] == 0)){
  2462. return $userLevelData;
  2463. }
  2464. }
  2465. return false;
  2466. }
  2467. /**
  2468. * 若玩家被打后,已经超过2880分钟不在线,会拥有永久被打保护时间,玩家上线后,永久被打保护时间会变为30分钟被打保护时间
  2469. * @param $uid
  2470. * Created by: Owen
  2471. * Created on: 2021/2/20 18:35
  2472. */
  2473. public function reLoginAddIntoProtectList($uid){
  2474. $protectTime = intval($this->getFromAttackProtectList($uid));
  2475. if($protectTime - time() > 24 * 60 * 60){
  2476. if($this->checkBuildDamaged($uid)){
  2477. $this->addAttackProtectList($uid,time() + 30 * 60,false);
  2478. }
  2479. }
  2480. }
  2481. /** --------------------------打逻辑重构--------------------------- */
  2482. /**
  2483. * 获取用户动态数据
  2484. * @param $uid
  2485. * @return array|false|mixed
  2486. * Created by: Owen
  2487. * Created on: 2020/7/23 14:37
  2488. */
  2489. public function getUserDynamicsData($uid){
  2490. $cacheKey = okeys::UserDynamicsData($uid);
  2491. $cache = oo::commonOprRedis('User')->get($cacheKey);
  2492. if(empty($cache)){
  2493. $tb = otable::UserDynamicsData();
  2494. $cache= oo::commonOprDb('userinfo')->getOne("SELECT * FROM {$tb} WHERE uid={$uid} LIMIT 1",MYSQLI_ASSOC);
  2495. if(!empty($cache['userCache'])){
  2496. $cache['userCache'] = (array)json_decode($cache['userCache'], true);
  2497. }
  2498. if(empty($cache)){ //创建一条表记录
  2499. // oo::commonOprDb('userinfo')->query("INSERT INTO {$tb} (`uid`,`userCache`) VALUES ({$uid},'[]')");
  2500. $cache = oo::commonOprDb('userinfo')->getOne("SELECT * FROM {$tb} WHERE uid={$uid} LIMIT 1",MYSQLI_ASSOC);
  2501. }
  2502. //有无数据都要写入缓存
  2503. oo::commonOprRedis('User')->setex($cacheKey,json_encode($cache),oo::redisRandomExpire(7*24*60*60));
  2504. }else{
  2505. $cache = json_decode($cache,true);
  2506. if(empty($cache['userCache'])){
  2507. $cache['userCache'] = [];
  2508. }
  2509. if(!is_array($cache['userCache'])){
  2510. $cache['userCache'] = (array)json_decode($cache['userCache'], true);
  2511. }
  2512. }
  2513. return $cache;
  2514. }
  2515. /**
  2516. * 更新用户动态数据
  2517. * @param $uid
  2518. * @param $updateInfo
  2519. * @return mixed
  2520. * Created by: Owen
  2521. * Created on: 2020/7/23 14:38
  2522. */
  2523. public function updateUserDynamicsData($uid,$updateInfo){
  2524. if(empty($updateInfo)){
  2525. return false;
  2526. }
  2527. $userDynamicsData = self::getUserDynamicsData($uid);
  2528. foreach ($updateInfo as $key=>$row){
  2529. $userDynamicsData[$key] = $row;
  2530. }
  2531. return self::setUserDynamicsData($uid,$userDynamicsData);
  2532. }
  2533. /**
  2534. * 追加用户动态数据
  2535. * @param $uid
  2536. * @param $updateInfo
  2537. * @return bool
  2538. * Created by: Owen
  2539. * Created on: 2020/7/23 14:43
  2540. */
  2541. public function addUserDynamicsData($uid,$updateInfo){
  2542. if(empty($updateInfo)){
  2543. return false;
  2544. }
  2545. $userDynamicsData = self::getUserDynamicsData($uid);
  2546. foreach ($updateInfo as $key=>$row){
  2547. $userDynamicsData[$key] += $row;
  2548. }
  2549. return self::setUserDynamicsData($uid,$userDynamicsData);
  2550. }
  2551. /**
  2552. * 设定用户动态数据
  2553. * @param $uid
  2554. * @param $dynamicsData
  2555. * @return bool
  2556. * Created by: Owen
  2557. * Created on: 2020/7/23 14:54
  2558. */
  2559. public function setUserDynamicsData($uid,$dynamicsData){
  2560. $dynamicsData['isLanding'] = 1;
  2561. $cacheKey = okeys::UserDynamicsData($uid);
  2562. if(isset($dynamicsData['userCache']) && !is_array($dynamicsData['userCache'])){
  2563. $dynamicsData['userCache'] = (array)json_decode($dynamicsData['userCache'], true);
  2564. }
  2565. oo::commonOprRedis('User')->setex($cacheKey,json_encode($dynamicsData, 32),oo::redisRandomExpire(7*24*60*60));
  2566. // $ret = oo::commonOprRedis('Usercache')->zAdd(okeys::Landing("DYNAMICS", $uid),time(),$uid);
  2567. // if($ret !== false){
  2568. // return true;
  2569. // }
  2570. return false;
  2571. }
  2572. /**
  2573. * 领取短链奖励
  2574. * @param $uid
  2575. * @param $id
  2576. * @return string
  2577. * Created by: Owen
  2578. * Created on: 2020/8/5 11:32
  2579. */
  2580. public function getShareLinkReward($uid,$id){
  2581. $config = oo::commonOprModel('config')->getShareLinkConfig($id);
  2582. if(isset($config['expireTime']) && $config['expireTime'] < time()){
  2583. return oo::response(errorCode::SHARELINK_TIME_EXPIRED,[],'奖励已过期');
  2584. }
  2585. if(isset($config['userLimit']) && !empty($config['userLimit']) && strpos($config['userLimit'],"{$uid}") === false){
  2586. return oo::response(errorCode::SHARELINK_USER_LIMIT,[],'不在指定用户里');
  2587. }
  2588. if(in_array($config['action'],[1,4])){
  2589. if(oo::commonOprRedis('User')->hGet(okeys::ShareLinkReward($id),$uid)){
  2590. return oo::response(-2,[],'奖励已领取');
  2591. }
  2592. }
  2593. $curNum = oo::commonOprRedis('User')->hLen(okeys::ShareLinkReward($id));
  2594. if($curNum >= $config['num']){
  2595. return oo::response(-3,[],'奖励已超量');
  2596. }
  2597. if($config['action'] == 1){
  2598. $reward = $config['data'];
  2599. foreach ($reward['props'] as $row){
  2600. if($row['propsId'] == 14) {
  2601. $row['num'] = oo::commonOprModel('goods')->getGoodCoins($uid, oo::commonOprModel('config')->gidToCoins($row['gid'])) * $row['bet'];
  2602. }
  2603. self::sendReward($uid,$row['propsId'],$row['num'],4001,"点击链接:{$id}");
  2604. }
  2605. oo::commonOprRedis('User')->hSet(okeys::ShareLinkReward($id),$uid,1);
  2606. //oo::commonOprRedis('User')->expire(okeys::ShareLinkReward($id),86400*3);
  2607. return oo::response(1,$reward['props']);
  2608. }else if($config['action'] == 4){
  2609. if($config['data']['activityId'] == 102){
  2610. $this->sendReward($uid,27,intval($config['data']['time']),4001,'链接发放');
  2611. }else if($config['data']['activityId'] == 103){
  2612. $this->sendReward($uid,25,intval($config['data']['time']),4001,'链接发放');
  2613. }
  2614. oo::commonOprRedis('User')->hSet(okeys::ShareLinkReward($id),$uid,1);
  2615. }
  2616. return oo::response(1);
  2617. }
  2618. /**
  2619. * 获取用户firstName
  2620. * @param $nick
  2621. * @return mixed
  2622. * Created by: Owen
  2623. * Created on: 2020/8/17 19:55
  2624. */
  2625. public function getUserFirstName($nick){
  2626. $nick = explode(' ',$nick);
  2627. return $nick[0];
  2628. }
  2629. /**
  2630. * 获取上限限配置
  2631. * @param $levelId
  2632. * @param $from
  2633. * @return int|mixed
  2634. * Created by: Owen
  2635. * Created on: 2020/8/20 18:43
  2636. */
  2637. public function getLevelUpLimit($levelId,$from){
  2638. $config = oo::commonOprModel('config')->getUpLimitConfig($from);
  2639. $minNum = 0;
  2640. foreach ($config as $c){
  2641. if($levelId <= $c['levelId']){
  2642. return $c['upLimit'];
  2643. }else{
  2644. $minNum = $c['upLimit'];
  2645. }
  2646. }
  2647. return $minNum;
  2648. }
  2649. /**
  2650. * 获取用户最大值
  2651. * @param $uid
  2652. * @param $from
  2653. * @return mixed
  2654. * Created by: Owen
  2655. * Created on: 2020/8/21 10:39
  2656. */
  2657. public function getUserLevelUpLimit($uid,$from){
  2658. $userAssetsInfo = self::getUserAssetsInfo($uid);
  2659. $levelId = $userAssetsInfo['levelId'];
  2660. if($from == 'shield'){
  2661. $levelMaxShield = self::getLevelUpLimit($levelId,$from);
  2662. $vipShield = 3;
  2663. if(oo::commonOprModel('newvip')->checkNewVip($uid)) {
  2664. $config = oo::commonOprModel('newvip')->getUserVipLv($uid,true,false,155);
  2665. $vipShield += intval($config['shieldGroove']);
  2666. }
  2667. return max($vipShield,$levelMaxShield,3);
  2668. }else if($from == 'recovery'){
  2669. $levelSpins = self::getLevelUpLimit($levelId,'recovery'); // 恢复多少
  2670. $checkVip = oo::commonOprModel('newvip')->checkNewVip($uid);
  2671. $setSpins = oo::commonOprModel('readconfig')->getCon('basic','restoreSpins');; // 恢复多少
  2672. if($checkVip){
  2673. $config = oo::commonOprModel('newvip')->getUserVipLv($uid,true,false,155);
  2674. $setSpins += intval($config['spinsRestore']);
  2675. }
  2676. return max($levelSpins,$setSpins,5);
  2677. }
  2678. }
  2679. /**
  2680. * 用户推送开关
  2681. * @param $uid
  2682. * @return array
  2683. * Created by: Owen
  2684. * Created on: 2020/8/28 19:43
  2685. */
  2686. public function getUserSettingLock($uid){
  2687. $userDynamicsData = self::getUserDynamicsData($uid);
  2688. return explode(',',$userDynamicsData['pushLock']);
  2689. }
  2690. /**
  2691. * 发送下一次攻击对象等级
  2692. * @param $uid
  2693. * Created by: Owen
  2694. * Created on: 2020/9/12 18:56
  2695. */
  2696. public function sendNextAttackObject($uid){
  2697. $toUid = self::getEnemyListByType($uid,1);
  2698. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($toUid);
  2699. oo::commonOprModel('Workerman')->push($uid,ocmd::$send['Slot_AttackObject'],['levelId'=>$userAssetsInfo['levelId']]);
  2700. }
  2701. /**
  2702. * 是否是推金币进来的用户
  2703. * @param $uid
  2704. * @return false|int
  2705. * Created by: Owen
  2706. * Created on: 2020/11/25 14:50
  2707. */
  2708. public function isPushCoinsUser($uid){
  2709. return 0;
  2710. $cacheKey = okeys::isPushCoinsUser($uid);
  2711. $cache = oo::commonOprRedis('User')->get($cacheKey);
  2712. if($cache === false){
  2713. $isPush = 0;
  2714. $tb = otable::AdJustSta($uid);
  2715. $ret = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE uid={$uid} LIMIT 1",MYSQLI_ASSOC);
  2716. $tb = otable::AdJustData();
  2717. if(!empty($ret['android']) || !empty($ret['ios'])) {
  2718. $agps = trim($ret['android'], '"');
  2719. if(!empty($agps)){$where = "gps_adid='{$agps}'";}
  2720. $igps = trim($ret['ios'], '"');
  2721. if(!empty($igps)){$where = "idfa='{$igps}'";}
  2722. $ret = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE {$where} LIMIT 1", MYSQLI_ASSOC);
  2723. if(!empty($ret) && strpos($ret['campaign_name'],'PUSH') !== false){
  2724. $isPush = 1;
  2725. }
  2726. }
  2727. oo::commonOprRedis('User')->setex($cacheKey,$isPush,oo::redisRandomExpire(3*24*60*60));
  2728. }else{
  2729. $isPush = $cache;
  2730. }
  2731. return intval($isPush);
  2732. }
  2733. /**
  2734. * 获取adjust渠道名称(google, facebook, ironsource, ironsource)
  2735. * @param string $network
  2736. * @return string
  2737. */
  2738. public function getAdjustChannel($network = '') {
  2739. if(strpos($network, 'Facebook') !== false) {
  2740. return "facebook";
  2741. }
  2742. if(strpos($network, 'Google') !== false) {
  2743. return "google";
  2744. }
  2745. if(strpos($network, 'unity') !== false) {
  2746. return "unity";
  2747. }
  2748. if(strpos($network, 'ironSource') !== false) {
  2749. return "ironsource";
  2750. }
  2751. return "";
  2752. }
  2753. /**
  2754. * 获取adjust(creative_name,adgroup_name,campaign_name)等对应的id
  2755. */
  2756. public function getAdjustId($name = '') {
  2757. if(substr($name, -1) != ')' || strpos($name, '(') == false){
  2758. return '';
  2759. }
  2760. return substr($name, (int)strrpos($name, '(')+1, -2);
  2761. }
  2762. /**
  2763. * 检测adjust 邀请
  2764. * @param $uid
  2765. * @return bool
  2766. * Created by: Owen
  2767. * Created on: 2021/3/11 18:31
  2768. */
  2769. public function actionAdjustInvite($uid){
  2770. $cacheKey = okeys::AdjustInviteStatus($uid);
  2771. $status = oo::commonOprRedis('User')->get($cacheKey);
  2772. if($status){
  2773. $deviceID = $this->getAdjustDeviceIDByUid($uid);
  2774. if(!empty($deviceID)){
  2775. $ret = $this->getDataFromAdjust($deviceID);
  2776. $taData = [];
  2777. if(!empty($ret)){
  2778. if(strpos($ret['campaign_name'],'UAC2.0') !== false){
  2779. $group = 'UAC2.0';
  2780. }else if(strpos($ret['campaign_name'],'UAC2.5') !== false){
  2781. $group = 'UAC2.5';
  2782. }else if(strpos($ret['campaign_name'],'AEO') !== false){
  2783. $group = 'AEO';
  2784. }else if(strpos($ret['campaign_name'],'VO') !== false){
  2785. $group = 'VO';
  2786. }else if(strpos($ret['campaign_name'],'Recall') !== false){
  2787. $group = 'Recall';
  2788. }
  2789. $taData = [
  2790. //Google
  2791. "network_name" => $ret['network_name'],
  2792. "campaign_name" => $ret['campaign_name'],
  2793. "adgroup_name" => $ret['adgroup_name'],
  2794. "creative_name" => $ret['creative_name'],
  2795. "network_id" => $this->getAdjustChannel($ret['network_name']),
  2796. "campaign_id" => $this->getAdjustId($ret['campaign_name']),
  2797. "adgroup_id" => $this->getAdjustId($ret['adgroup_name']),
  2798. "creative_id" => $this->getAdjustId($ret['creative_name']),
  2799. ];
  2800. !empty($group) && $taData["user_source"] = 2;
  2801. }
  2802. $labelUid = intval(base64_decode($ret['label']));
  2803. if($labelUid > 0 || (IS_DEBUF && $labelUid != 0)){
  2804. oo::commonOprModel('invite')->inviteSuccess(abs($labelUid),$uid,3);
  2805. $this->updateInviteeAdjustData($deviceID,$ret);
  2806. $taData["user_source"] = 1;
  2807. }
  2808. !empty($taData) && oo::commonOprModel('ta')->setEventData($uid,'user_set',$taData);
  2809. oo::commonOprRedis('User')->delete($cacheKey);
  2810. return $labelUid;
  2811. }
  2812. $newStatus = $status - 1;
  2813. if($newStatus > 0){
  2814. oo::commonOprRedis('User')->setex($cacheKey,$newStatus,3*24*60*60);
  2815. }else{
  2816. oo::commonOprRedis('User')->delete($cacheKey);
  2817. }
  2818. }
  2819. }
  2820. /**
  2821. * 检测adjust离开7天以上(再归因深链)或客户端上报玩家邀请
  2822. * @param int $uid
  2823. * @param int $fid
  2824. */
  2825. public function actionCallbackAdjustInvite($uid, $fid = 0){
  2826. $cacheKey = okeys::AdjustBackInviteStatus($uid);
  2827. $status = oo::commonOprRedis('User')->get($cacheKey);
  2828. if(empty($status)){
  2829. return false;
  2830. }
  2831. if(!empty($fid)){ //客户端直接上报
  2832. if($uid == $fid){
  2833. return false;
  2834. }
  2835. $info = oo::commonOprModel('member')->getUserInfo($fid);
  2836. if(empty($info)){
  2837. return false;
  2838. }
  2839. oo::commonOprModel('invite')->inviteSuccess(abs($fid),$uid,3);
  2840. oo::commonOprRedis('User')->delete($cacheKey);
  2841. return true;
  2842. }
  2843. $deviceID = $this->getAdjustDeviceIDByUid($uid);
  2844. if(!empty($deviceID)){
  2845. $ret = $this->adjustDataFromCallbacks($deviceID);
  2846. $labelUid = intval(base64_decode($ret['label']));
  2847. if($labelUid > 0 || (IS_DEBUF && $labelUid != 0)){
  2848. oo::commonOprModel('invite')->inviteSuccess(abs($labelUid),$uid,3);
  2849. $this->updateInviteAdjustCalback($deviceID,$ret);
  2850. }
  2851. oo::commonOprRedis('User')->delete($cacheKey);
  2852. return $labelUid;
  2853. }
  2854. $newStatus = $status - 1;
  2855. if($newStatus > 0){
  2856. oo::commonOprRedis('User')->setex($cacheKey,$newStatus,3*24*60*60);
  2857. }else{
  2858. oo::commonOprRedis('User')->delete($cacheKey);
  2859. }
  2860. return false;
  2861. }
  2862. /**
  2863. * 更新邀请label
  2864. * @param $deviceID
  2865. * @param $ret
  2866. * Created by: Owen
  2867. * Created on: 2021/3/25 16:18
  2868. */
  2869. public function updateInviteeAdjustData($deviceID,$ret){
  2870. $labelUid = intval(base64_decode($ret['label']));
  2871. $labelUid = -abs($labelUid);
  2872. $newLabel = base64_encode($labelUid);
  2873. $tb = otable::AdJustData();
  2874. oo::commonOprDb('common')->query("UPDATE {$tb} SET label='{$newLabel}' WHERE created_at='{$ret['created_at']}' AND (gps_adid='{$deviceID}' OR idfa='{$deviceID}') ORDER BY created_at LIMIT 1");
  2875. oo::commonOprRedis('User')->delete(okeys::AdjustData($deviceID));
  2876. }
  2877. /**
  2878. * 更新7天回归邀请label(再归因深链)
  2879. * @param $deviceID
  2880. * @param $ret
  2881. * Created by: Owen
  2882. * Created on: 2021/3/25 16:18
  2883. */
  2884. public function updateInviteAdjustCalback($deviceID,$ret){
  2885. $labelUid = intval(base64_decode($ret['label']));
  2886. $labelUid = -abs($labelUid);
  2887. $newLabel = base64_encode($labelUid);
  2888. $tb = otable::AdjustBackData();
  2889. oo::commonOprDb('common')->query("UPDATE {$tb} SET label='{$newLabel}' WHERE created_at='{$ret['created_at']}' AND (gps_adid='{$deviceID}' OR idfa='{$deviceID}') ORDER BY created_at LIMIT 1");
  2890. oo::commonOprRedis('User')->delete(okeys::AdjustBackData($deviceID));
  2891. }
  2892. /**
  2893. * adjust 数据
  2894. * @param $deviceID
  2895. * @return array|mixed
  2896. * Created by: Owen
  2897. * Created on: 2021/3/11 18:12
  2898. */
  2899. public function getDataFromAdjust($deviceID){
  2900. $cacheKey = okeys::AdjustData($deviceID);
  2901. $cache = oo::commonOprRedis('User')->get($cacheKey);
  2902. if(empty($cache)){
  2903. $tb = otable::AdJustData();
  2904. $data = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE gps_adid='{$deviceID}' OR idfa='{$deviceID}' ORDER BY created_at LIMIT 1", MYSQLI_ASSOC);
  2905. oo::commonOprRedis('User')->setex($cacheKey,json_encode($data),oo::redisRandomExpire(3*24*60*60));
  2906. }else{
  2907. $data = json_decode($cache,true);
  2908. }
  2909. return $data;
  2910. }
  2911. /**
  2912. * adjust7天回归数据
  2913. * @param string $deviceID
  2914. * @return array
  2915. */
  2916. public function adjustDataFromCallbacks($deviceID) {
  2917. $cacheKey = okeys::AdjustBackData($deviceID);
  2918. $cache = oo::commonOprRedis('User')->get($cacheKey);
  2919. if(empty($cache)){
  2920. $tb = otable::AdjustBackData();
  2921. $data = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE gps_adid='{$deviceID}' OR idfa='{$deviceID}' ORDER BY created_at LIMIT 1", MYSQLI_ASSOC);
  2922. oo::commonOprRedis('User')->setex($cacheKey,json_encode($data),oo::redisRandomExpire(3*24*60*60));
  2923. }else{
  2924. $data = json_decode($cache,true);
  2925. }
  2926. return $data;
  2927. }
  2928. /**
  2929. * adjust 设备ID
  2930. * @param $uid
  2931. * @return false|string
  2932. * Created by: Owen
  2933. * Created on: 2021/3/11 18:07
  2934. */
  2935. public function getAdjustDeviceIDByUid($uid){
  2936. $cacheKey = okeys::AdjustDeviceID($uid);
  2937. $cache = oo::commonOprRedis('User')->get($cacheKey);
  2938. if(empty($cache)){
  2939. $tb = otable::AdJustSta($uid);
  2940. $ret = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE uid={$uid} LIMIT 1",MYSQLI_ASSOC);
  2941. if(!empty($ret)){
  2942. $actionID = "";
  2943. $agps = trim($ret['android'], '"');
  2944. if(!empty($agps)){
  2945. $actionID = $agps;
  2946. }
  2947. $igps = trim($ret['ios'], '"');
  2948. if(!empty($igps)){
  2949. $actionID = $igps;
  2950. }
  2951. oo::commonOprRedis('User')->setex($cacheKey,$actionID,oo::redisRandomExpire(24*60*60));
  2952. return $actionID;
  2953. }
  2954. $actionID = 0;
  2955. }else{
  2956. $actionID = $cache;
  2957. }
  2958. return $actionID;
  2959. }
  2960. /**
  2961. * 奖励列表
  2962. * @param $uid
  2963. * @param string $from
  2964. * @return array
  2965. * Created by: Owen
  2966. * Created on: 2020/12/2 19:24
  2967. */
  2968. public function getUserGiftList($uid,$from = ''){
  2969. $tb = otable::UserGiftList();
  2970. $expire = time();
  2971. $where = "WHERE uid={$uid} AND expired_at>='{$expire}' AND rewarded_at=0";
  2972. if($from){
  2973. $where .= " AND from={$from}";
  2974. }
  2975. $ret = oo::commonOprDb('userinfo')->getAll("SELECT * FROM {$tb} {$where}",MYSQLI_ASSOC);
  2976. $output = [];
  2977. foreach ($ret as $row) {
  2978. $reward = json_decode($row['reward'],true);
  2979. foreach ($reward['props'] as &$p){
  2980. $pConf = oo::commonOprModel('props')->getChestData($uid,$p['propsId']);
  2981. if($pConf){
  2982. $p['value'] = $pConf;
  2983. }
  2984. }
  2985. $output[] = [
  2986. 'id' => $row['id'],
  2987. 'uid' => $row['uid'],
  2988. 'from' => $row['from'],
  2989. 'reward'=> $reward
  2990. ];
  2991. }
  2992. return $output;
  2993. }
  2994. /**
  2995. * 领取奖励
  2996. * @param $uid
  2997. * @param $id
  2998. * @return string
  2999. * Created by: Owen
  3000. * Created on: 2020/12/2 19:40
  3001. */
  3002. public function rewardUserGift($uid,$id){
  3003. $tb = otable::UserGiftList();
  3004. $ret = oo::commonOprDb('userinfo')->getOne("SELECT * FROM {$tb} WHERE id={$id}",MYSQLI_ASSOC);
  3005. if(empty($ret)){
  3006. return oo::response(errorCode::GIFT_EMPTY_ERROR);
  3007. }
  3008. if($ret['uid'] != $uid){
  3009. return oo::response(errorCode::GIFT_UID_ERROR);
  3010. }
  3011. if($ret['rewarded_at']){
  3012. return oo::response(errorCode::GIFT_REWARD_ERROR);
  3013. }
  3014. $reward = json_decode($ret['reward'],true);
  3015. $reward = $reward['props'];
  3016. foreach ($reward as $k=>&$row){
  3017. $this->sendReward($uid,$row['propsId'],$row['num'],452,"用户礼包:".$id,[],$row);
  3018. }
  3019. $time = time();
  3020. oo::commonOprDb('userinfo')->query("UPDATE {$tb} SET `rewarded_at`='{$time}' WHERE id={$id} LIMIT 1");
  3021. return oo::response(errorCode::SUCCESS,$reward);
  3022. }
  3023. /**
  3024. * 用户注册版本
  3025. * @param $uid
  3026. * @return false
  3027. * Created by: Owen
  3028. * Created on: 2021/2/25 17:40
  3029. */
  3030. public function getUserRegVersion($uid){
  3031. $cacheKey = okeys::UserRegVersion($uid);
  3032. $cache = oo::commonOprRedis('User')->get($cacheKey);
  3033. if($cache){
  3034. return $cache;
  3035. }
  3036. $tb = otable::versionGitfLog($uid);
  3037. $ret = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE uid ='{$uid}' ORDER BY id LIMIT 1",MYSQLI_ASSOC);
  3038. $version = $ret['version'] ?? "1.8.0";
  3039. oo::commonOprRedis('User')->setex($cacheKey,$version,7*24*60*60);
  3040. return $version;
  3041. }
  3042. /**
  3043. * 获取玩家语言
  3044. * @param int $uid
  3045. * @return string
  3046. */
  3047. public function getUserLang($uid) {
  3048. $lang = oo::getDefinedLang($uid);
  3049. if(!empty($lang)){
  3050. return strtoupper($lang);
  3051. }
  3052. $tb = otable::xg_push($uid);
  3053. $sql = "SELECT lang FROM {$tb} WHERE uid = {$uid}";
  3054. $info = oo::commonOprDb('common')->getOne($sql, 1);
  3055. $lang = empty($info['lang']) ? 'EN' : $info['lang'];
  3056. return strtoupper($lang);
  3057. }
  3058. /**
  3059. * Notes:注册分群 数数
  3060. * User: hss
  3061. * Time: 2021/09/16 10:55
  3062. * @param $uid
  3063. * @return boolean
  3064. */
  3065. public function regSSgroup($uid = 0){
  3066. if(empty($uid)){
  3067. return false;
  3068. }
  3069. //190 lastnumber1 id尾号为1
  3070. //191 lastnumber0 id尾号为0
  3071. //192 lastnumber89 id尾号8&9
  3072. //193 lastnumber67 id尾号6&7
  3073. //194 lastnumber45 id尾号4&5
  3074. //195 lastnumber23 id尾号2&3
  3075. //196 lastnumber01 id尾号0&1
  3076. $end = $uid % 10;
  3077. $groupId = [];
  3078. switch ($end){
  3079. case 0:
  3080. $groupId = [191,196];
  3081. break;
  3082. case 1:
  3083. $groupId = [190,196];
  3084. break;
  3085. case 2:
  3086. case 3:
  3087. $groupId = [195];
  3088. break;
  3089. case 4:
  3090. case 5:
  3091. $groupId = [194];
  3092. break;
  3093. case 6:
  3094. case 7:
  3095. $groupId = [193];
  3096. break;
  3097. case 8:
  3098. case 9:
  3099. $groupId = [192];
  3100. break;
  3101. }
  3102. if($groupId){
  3103. $groupStr = implode(",",$groupId);
  3104. return oo::commonOprModel('member')->updateUserDynamicsData($uid,["groupId3"=>$groupStr]);
  3105. }
  3106. }
  3107. }