card.php 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. <?php
  2. defined( 'IN_WEB') or die( 'Include Error!');
  3. class ModelCard{
  4. CONST MAX_ACCEPT_TIME = 5; //每日接受卡片最大上限
  5. CONST CARD_LIMIT = 5;
  6. /**
  7. * @param $uid
  8. * @return Array
  9. * Created by: Cassie Lee
  10. * Created on: 2019/5/15 21:40
  11. * Description:获取卡片信息
  12. */
  13. public function getInfo($uid){
  14. $res = [];
  15. $cards = $this->getCardInfo();
  16. foreach ($cards as $items){
  17. $card[$items['ciid']] = $items['cgposition'];//ciid->位置
  18. }
  19. foreach ($cards as $items){
  20. $group[$items['ciid']] = $items['cgid'];//ciid->卡组id
  21. }
  22. $userCardInfo = self::getUserCardInfo($uid);
  23. if(!empty($userCardInfo)) {
  24. $cardNumData = $userCardInfo['ciid'];
  25. $groupTemp = [];
  26. foreach ($card as $ciid => $pos) {
  27. foreach ($group as $ci => $cgid) {
  28. if(!in_array($cgid,$groupTemp)){
  29. $res[$cgid][1] = -1;
  30. $groupTemp[] = $cgid;
  31. }
  32. if($ciid == $ci) {
  33. if (key_exists($ciid, $cardNumData)) {
  34. $res[$cgid][$card[$ciid]] = intval($cardNumData[$ciid]);
  35. }
  36. }
  37. }
  38. }
  39. foreach ($res as $key => $row) {
  40. foreach ($row as $x => $y) {
  41. if($y == -1){
  42. unset($res[$key][$x]);
  43. if(empty($res[$key])){
  44. unset($res[$key]);
  45. }
  46. }
  47. }
  48. }
  49. return $res;
  50. }else{
  51. return [];
  52. }
  53. }
  54. /**
  55. * 根据Ciid 获取卡片信息
  56. * @param $ciid
  57. * @return mixed|void
  58. * Created by: Owen
  59. * Created on: 2021/3/9 17:55
  60. */
  61. public function getCardInfoByCiid($ciid){
  62. $arrJson = oo::commonOprRedis('config')->hGet(okeys::CardConfig(),$ciid);
  63. if(!empty($arrJson)){
  64. return json_decode($arrJson,true);
  65. }
  66. $tb = otable::cardinfo_config();
  67. $ret = oo::commonOprDb('cardinfo')->getOne("SELECT * FROM {$tb} WHERE ciid={$ciid} LIMIT 1", MYSQLI_ASSOC);
  68. return $ret;
  69. }
  70. /**
  71. * @param $cgid
  72. * @param $pos
  73. * @return mixed
  74. * Created by: Cassie Lee
  75. * Created on: 2019/5/15 21:41
  76. * Description:根据卡片位置及卡组信息返回卡片id ciid
  77. */
  78. private function getCardId($cgid, $pos){
  79. $cardInfo = otable::cardinfo_config();
  80. $sql = "SELECT ciid FROM {$cardInfo} WHERE cgid = {$cgid} AND cgposition = {$pos}";
  81. $list = oo::commonOprDb('cardinfo')->getOne($sql, MYSQLI_ASSOC);
  82. $ciid = $list['ciid'];
  83. return $ciid;
  84. }
  85. /**
  86. * @param $uid 用户uid
  87. * @param $cgid 卡片组id
  88. * @param $pos 组id
  89. * @param $sendToUid 对方uid
  90. * @param $num 数量
  91. * @return array
  92. * Created by: Cassie Lee
  93. * Created on: 2019/5/14 10:52
  94. * Description:赠送卡片
  95. */
  96. public function sendTo($uid, $cgid, $pos , $sendToUid, $num)
  97. {
  98. $ciid = $this->getCardId($cgid,$pos);
  99. //获取自己的卡片信息
  100. $cardInfoList = $this->getInfo($uid);
  101. //获取卡片数量
  102. $totalCardNum = intval($cardInfoList[$cgid][$pos]) - 1; //自己必须保留一张
  103. if($totalCardNum < 1){
  104. return array("code"=> -1,"msg"=>"您的卡片数量不足",'data'=>[]);
  105. }
  106. //1 获取已赠送卡片数量
  107. $sendNum = $this->getSendNumber($uid,$ciid,$sendToUid);
  108. if($sendNum && ($sendNum > self::CARD_LIMIT || $sendNum == self::CARD_LIMIT ))
  109. {
  110. return array("code"=> -1,"msg"=>"只能赠送".self::CARD_LIMIT."张卡片");
  111. }
  112. //我向好友赠送礼物 添加到队列里面去 领取了就prop
  113. $key = okeys::userGiftList($sendToUid);
  114. //要记录 谁送的 时间 赠送卡组 赠送卡片 数量 {"fromId":327,"time":1558076971,"pos":6,"cgid":8,"num":1}
  115. $recordData = json_encode(['fromId'=>$uid,'time'=>time(),'pos'=>intval($ciid),'cgid'=>intval($cgid),'num'=>1]);
  116. $res = $this->updateOwnCardQuantity($uid,$ciid,$num,$sendToUid);
  117. //添加成功后在扣用户的卡
  118. if($res['code'] < 0)
  119. {
  120. return array("code"=> $res['code'],"msg"=>$res['msg']);
  121. }
  122. oo::commonOprRedis('common')->lPush($key, $recordData);
  123. $cardInfo = $this->getInfo($uid);
  124. ////赠送卡片排行榜,取消该统计
  125. //oo::commonOprModel('statistics')->giveCardSta($ciid);
  126. return array("code"=>1,"msg"=>1,"data"=>['card'=>$cardInfo]);
  127. }
  128. /**
  129. * @param $uid
  130. * @param $ciid
  131. * @param $sendToUid
  132. * @return int
  133. * Created by: Cassie Lee
  134. * Created on: 2019/5/14 12:11
  135. * Description:获取赠送卡片的数量
  136. */
  137. public function getSendNumber($uid, $ciid, $sendToUid)
  138. {
  139. $cardInfo = self::getUserCardInfo($uid);
  140. if(!empty($cardInfo)){
  141. if(!empty($cardInfo['send_card'])){
  142. $sendcard = $cardInfo['send_card'];
  143. return $sendcard[$sendToUid][$ciid]??0;
  144. }else{
  145. return 0;
  146. }
  147. }else{
  148. return 0;
  149. }
  150. }
  151. /**
  152. * @param $uid
  153. * @param $ciid
  154. * @param $askForUid
  155. * @param $num
  156. * @return array
  157. * Created by: Cassie Lee
  158. * Created on: 2019/5/14 11:41
  159. * Description:索要卡片
  160. */
  161. public function askFor($uid, $ciid, $askForUid, $num)
  162. {
  163. $flag = $this->validateCard($ciid,$uid);
  164. if(!$flag)
  165. {
  166. return array("code"=> -1,"msg"=>"不符合索要条件");
  167. }
  168. $res = $this->sendMessageTo($uid,$askForUid,5);
  169. if($res)
  170. {
  171. return array('code'=> 1,'msg'=>"success");
  172. }
  173. return array('code'=> -1,'msg'=>"failed");
  174. }
  175. /**
  176. * @param $uid
  177. * @param $toUid
  178. * @param $type
  179. * @return mixed
  180. * Created by: Cassie Lee
  181. * Created on: 2019/5/14 11:37
  182. * Description:$uid 当前用户uid $toUid 被索要用户uid $type 所属类型 1被偷钱 2防御成功 3损坏建筑 4摧毁建筑 5索要卡片
  183. */
  184. public function sendMessageTo($uid, $toUid, $type){
  185. $uidInfo = oo::commonOprModel('member')->getUserInfo($uid);
  186. $is_read = 0;//是否已读
  187. //****** 存入数据库提供查询 ******
  188. $toTable = otable::messageLog($toUid);
  189. $start_time = time();
  190. $end_time = strtotime('+30day');
  191. $nick = $uidInfo['nick'];
  192. $s_picture = $uidInfo['s_picture'];
  193. $sql = " INSERT INTO $toTable VALUES($toUid,$uid,'$nick','$s_picture', 0,$type,$is_read , $start_time,$end_time,0)";
  194. $res = oo::commonOprDb('message_log')->query($sql);
  195. return $res;
  196. }
  197. /**
  198. * 更新卡片赠送者的卡片数量
  199. * @param $uid
  200. * @param $ciid
  201. * @param $num
  202. * @param $sendToUid
  203. * @return array
  204. * Created by: Owen
  205. * Created on: 2020/3/25 16:46
  206. */
  207. public function updateOwnCardQuantity($uid, $ciid,$num,$sendToUid){
  208. $userCardInfo = self::getUserCardInfo($uid);
  209. $sendCard = $userCardInfo['send_card'];
  210. $obj = $userCardInfo['ciid'];
  211. if(intval($obj[$ciid]) >= (intval($num) + 1)) {
  212. $obj[$ciid] = intval($obj[$ciid]) - intval($num);//对应卡片数量 - num
  213. $sendCard[$sendToUid][$ciid] += $num;
  214. self::updateUserCardInfo($uid,['ciid'=>$obj,'send_card'=>$sendCard]);
  215. return array("code"=>1,"msg"=>"update success");
  216. }else {
  217. return array("code"=> -3,"msg"=>"卡片不足");
  218. }
  219. }
  220. /**
  221. * @param $uid
  222. * @param $ciid
  223. * @return array
  224. * Created by: Cassie Lee
  225. * Created on: 2019/5/13 11:44
  226. * Description:更新被赠送者卡片数量
  227. */
  228. public function updateFriendsCardQuantity($uid, $ciid,$num){
  229. $userCardInfo = self::getUserCardInfo($uid);
  230. $obj = $userCardInfo['ciid'];
  231. $obj[$ciid] = strval(intval($obj[$ciid]) + intval($num));//对应卡片数量+num
  232. $res = self::updateUserCardInfo($uid,['ciid'=>$obj]);
  233. // return array("code"=>$res['code'],"msg"=>"success");
  234. return array("code"=>$res?1:0,"msg"=>"success");
  235. }
  236. /**
  237. * @param $uid
  238. * @return array
  239. * Created by: Cassie Lee
  240. * Created on: 2019/5/10 14:44
  241. * Description:获取好友列表
  242. */
  243. public function getFriendList($uid)
  244. {
  245. $data = [];
  246. $friendList = [];
  247. oo::commonOprModel('friend')->getUserFriends($uid, $friendList);
  248. $Info = $this->getUserWatchmeInfoNew($friendList);
  249. foreach ($Info as $key => $value)
  250. {
  251. $data[] = $value;
  252. }
  253. if (!empty($friendList['game_list']) || !empty($friendList['poker'])) {
  254. $res = array('code' => 1,'msg'=>'success','data'=>$data);
  255. return $res;
  256. }else{
  257. $res = array('code' => -1,'msg'=>'failed','data'=>array());
  258. return $res;
  259. }
  260. }
  261. /**
  262. * 获取用户信息
  263. * @param $userWatchmeList
  264. * @return array
  265. * Created by: Owen
  266. * Created on: 2019/8/29 11:37
  267. * Description:
  268. */
  269. private function getUserWatchmeInfoNew($userWatchmeList)
  270. {
  271. $data = [];
  272. if(empty($userWatchmeList['game_list'])){
  273. return $data;
  274. }
  275. $userWatchme = explode(",",$userWatchmeList['game_list']);
  276. $userWatchme = array_filter($userWatchme);
  277. $arr = ['uid','nick','s_picture','u_flag','siteuid'];
  278. foreach ($userWatchme as $key => $value)
  279. {
  280. //玩家基本信息
  281. $memberInfo = oo::commonOprModel('member')->getUserInfo($value,$arr,false,NULL);
  282. //检测是否可以领取
  283. $accept = $this->checkAcceptAuth($memberInfo['uid']);
  284. //组成新的array
  285. $data[$memberInfo['uid']]['url'] = $memberInfo['s_picture'];
  286. $data[$memberInfo['uid']]['nick'] = $memberInfo['nick'];
  287. $data[$memberInfo['uid']]['isSended'] = $accept;
  288. $data[$memberInfo['uid']]['uid'] = intval($memberInfo['uid']);
  289. $data[$memberInfo['uid']]['flag'] = intval($memberInfo['u_flag']);
  290. $isVisitor = oo::commonOprModel('member')->isVistor($memberInfo['uid']);
  291. if($isVisitor != 1){
  292. $data[$memberInfo['uid']]['fbId'] = (string)$memberInfo['siteuid'];
  293. }
  294. }
  295. $poker = explode(",",$userWatchmeList['poker']);
  296. $poker = array_filter($poker);
  297. foreach ($poker as $key => $value)
  298. {
  299. //玩家基本信息
  300. $memberInfo = oo::commonOprModel('member')->getUserInfo($value,$arr,false,NULL);
  301. //检测是否可以领取
  302. $accept = $this->checkAcceptAuth($memberInfo['uid']);
  303. //组成新的array
  304. $data[$memberInfo['uid']]['url'] = $memberInfo['s_picture'];
  305. $data[$memberInfo['uid']]['nick'] = $memberInfo['nick'];
  306. $data[$memberInfo['uid']]['isSended'] = $accept;
  307. $data[$memberInfo['uid']]['uid'] = intval($memberInfo['uid']);
  308. $data[$memberInfo['uid']]['flag'] = intval($memberInfo['u_flag']);
  309. $isVisitor = oo::commonOprModel('member')->isVistor($memberInfo['uid']);
  310. if($isVisitor != 1){
  311. $data[$memberInfo['uid']]['fbId'] = (string)$memberInfo['siteuid'];
  312. }
  313. }
  314. return $data;
  315. }
  316. /**
  317. * @param $fuid
  318. * @return bool
  319. * Created by: Cassie Lee
  320. * Created on: 2019/5/10 15:20
  321. * Description:检测是否領過卡片
  322. */
  323. private function checkAcceptAuth($fuid)
  324. {
  325. $time = 0;//写死
  326. if($time <= self::MAX_ACCEPT_TIME)
  327. {
  328. return false;
  329. }
  330. return true;
  331. }
  332. /**
  333. * @param $uid
  334. * @return array
  335. * Created by: Cassie Lee
  336. * Created on: 2019/5/13 20:18
  337. * Description:卡片集满获取奖励
  338. */
  339. public function calCardReward($uid){
  340. $data = [];
  341. $result = [];
  342. $list = $this->getCardInfo(); //获取所有的卡片信息
  343. foreach ($list as $key => $value)
  344. {
  345. $data[intval($value['cgid'])][] = intval($value['ciid']); //根据卡组分组
  346. }
  347. //未领取奖励的卡组 $result[0,1,2,3]
  348. foreach ($data as $key => $value)
  349. {
  350. $tempKey = okeys::userCardReward($uid,$key);
  351. $flag = oo::commonOprRedis('common')->get($tempKey);
  352. if(!$flag)
  353. {
  354. $result[] = $key;
  355. }
  356. }
  357. //查询自己的卡片信息 看看是否满足条件
  358. $userCardInfo = $this->getInfo($uid); //当前用户的卡片信息
  359. $totalCoins = 0;
  360. $totalSpins = 0;
  361. foreach ($userCardInfo as $key => $value)
  362. {
  363. if(in_array($key,$result))//只有未领取奖励的卡组才能领取
  364. {
  365. if(count($value) == count($data[$key]))//卡片集满9张
  366. {
  367. //获取奖励配置
  368. $list = self::getCardGroupInfo($key);
  369. if(!empty($list))
  370. {
  371. //更新卡组进度
  372. $this->updateCardGroupTotal($uid);
  373. $coins = intval($list['cg_coin_reward']);
  374. $spins = intval($list['cg_spin_reward']);
  375. oo::commonOprModel('member')->optProperty($uid,array('money'=>$coins),'+',30,'卡组收集满奖励金币:卡组'.$key);
  376. oo::commonOprModel('member')->optProperty($uid,array('spins'=>$spins),'+',30,'卡组收集满奖励体力:'.$key);
  377. oo::commonOprRedis('common')->set(okeys::userCardReward($uid,$key),1);
  378. $totalCoins += $coins;
  379. $totalSpins += $spins;
  380. }
  381. }
  382. }
  383. }
  384. if($totalCoins != 0 || $totalSpins != 0){
  385. return ['cg_coin_reward'=>$totalCoins,'cg_spin_reward'=>$totalSpins];
  386. }
  387. return [];
  388. }
  389. /**
  390. * 卡组进度配置
  391. * @param bool $progress
  392. * @return mixed
  393. * Created by: Owen
  394. * Created on: 2020/3/25 20:03
  395. */
  396. public function getCardGroupRewardConfig($progress = false){
  397. $cacheKey = okeys::CardGroupProgressConfig();
  398. $arrJson = oo::commonOprRedis('config')->hGetAll($cacheKey);
  399. $arr = funs::getArrFromJsonArr($arrJson);
  400. if(empty($arr)||(!$progress&&empty($arr[$progress]))){
  401. $tb = otable::cardgroupreward_config();
  402. $sql = "SELECT * FROM {$tb}";
  403. $ret = oo::commonOprDb('config')->getAll($sql,1);
  404. if(!empty($ret)){
  405. foreach ($ret as $k=>$v){
  406. $arr[$v['progress']] = $v;
  407. $cache[$v['progress']] = json_encode($v);
  408. }
  409. oo::commonOprRedis('config')->hMset($cacheKey,$cache);
  410. oo::commonOprRedis('config')->expire($cacheKey,oo::redisRandomExpire(7*86400));
  411. }
  412. }
  413. $data = !$progress?$arr:$arr[$progress];
  414. return $data;
  415. }
  416. /**
  417. * @param $card
  418. * @param $rank
  419. * @return array
  420. * Created by: Cassie Lee
  421. * Created on: 2019/5/14 17:42
  422. * Description:返回已解锁卡组下等于 $rank 星级的卡片
  423. * 增加一个要过滤的卡片id参数,从解锁的卡池里去掉需要过滤的卡,卡包开卡去重
  424. */
  425. private function getCardRank($card, $rank, $filteredCards= []){
  426. if(IS_DEBUF)oo::logs()->debug2(['rank' => $rank], 'cardRank.log');
  427. $data = $noRepeatCards = $noRepeatRankCards = [];
  428. foreach ($card as $item){
  429. if(!in_array($item['ciid'], $filteredCards)){ #从已解锁的卡池获取全部未抽出的卡
  430. $noRepeatCards[] = $item;
  431. if(intval($item['ci_star_rank']) == $rank) { #从已解锁的卡池获取当前星级,未抽出的卡
  432. $noRepeatRankCards[] = $item;
  433. }
  434. }
  435. if(intval($item['ci_star_rank']) == $rank) { #从已解锁的卡池获取当前星级的卡
  436. $data[] = $item;
  437. }
  438. }
  439. if(count($noRepeatRankCards) > 0)return $noRepeatRankCards; #已解锁卡池,当前星级还有未抽出的卡,就返回未抽出的卡组
  440. if(count($noRepeatCards) > 0)return $noRepeatCards; #已解锁卡池还有未抽出的卡,就返回未抽出的卡组
  441. return $data; #否则返回当前星级卡组
  442. }
  443. /**
  444. * @param $card
  445. * @param $rank
  446. * @return array
  447. * Created by: Cassie Lee
  448. * Created on: 2019/5/14 17:43
  449. * Description:返回已解锁卡组下小于 $rank 星级的卡片
  450. */
  451. private function getCard($card, $rank){
  452. $woodenCard = [];
  453. foreach ($card as $item) {
  454. if(intval($item['ci_star_rank']) <= $rank) {
  455. $woodenCard[] = $item;
  456. }
  457. }
  458. return $woodenCard;
  459. }
  460. /**
  461. * @param $uid
  462. * @return array
  463. * Created by: Cassie Lee
  464. * Created on: 2019/5/14 15:35
  465. * Description:返回已解锁的卡组
  466. */
  467. public function getUnlockCardGroup($uid)
  468. {
  469. $group = [];
  470. $memberAssets = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  471. $levelId = $memberAssets['levelId'];
  472. $cardGroupInfo = $this->getCardGroupInfo();
  473. foreach ($cardGroupInfo as $key => $value) {
  474. if(intval($value['cg_lock_rank']) <= intval($levelId)) {
  475. $group[] = $value['cgid'];
  476. }
  477. }
  478. return $group;
  479. }
  480. /**
  481. * @param $uid
  482. * @return array
  483. * Created by: Cassie Lee
  484. * Created on: 2019/5/14 15:55
  485. * Description:返回已解锁的卡片
  486. */
  487. public function getUnlockCard($uid)
  488. {
  489. $group = self::getUnlockCardGroup($uid);
  490. $card = [];
  491. $cardInfo = $this->getCardInfo();
  492. foreach ($cardInfo as $key => $value) {
  493. if(in_array(intval($value['cgid']),$group)) {
  494. $card[] = $value;
  495. }
  496. }
  497. return $card;
  498. }
  499. public function cardReward($uid,$gid){
  500. $userCardInfo = self::getUserCardInfo($uid);
  501. $cgreward = $userCardInfo['cgreward'];
  502. $userCard = $userCardInfo['ciid'];
  503. if(in_array($gid,$cgreward)){
  504. return false;
  505. }
  506. $list = self::getCardInfo(); //获取所有的卡片信息
  507. $groupCard = [];
  508. foreach ($list as $key => $value) {
  509. if($value['cgid'] == $gid){
  510. $groupCard[] = $value['ciid'];
  511. }
  512. }
  513. foreach ($groupCard as $cardId){
  514. if($userCard[$cardId] < 1){
  515. return false;
  516. }
  517. }
  518. $reward = self::getCardGroupInfo($gid); //获取所有的卡片信息
  519. $coins = intval($reward['cg_coin_reward']);
  520. $spins = intval($reward['cg_spin_reward']);
  521. $feed = intval($reward['cg_petFeed_reward']);
  522. $exp = intval($reward['cg_petExp_reward']);
  523. $coins && oo::commonOprModel('member')->optProperty($uid,array('money' => $coins),'+',30,'卡组收集满奖励金币:卡组'.$gid);
  524. $spins && oo::commonOprModel('member')->optProperty($uid,array('spins' => $spins),'+',30,'卡组收集满奖励体力:卡组'.$gid);
  525. $feed && oo::commonOprModel('props')->addUserProps($uid,9,$feed,0,30);
  526. $exp && oo::commonOprModel('props')->addUserProps($uid,8,$exp,0,30);
  527. $groupCardNames=['TW'=> $reward['cg_name_tw'], 'ZH'=> $reward['cg_name_zh'], 'FR'=> $reward['cg_name_fr'], 'DE'=> $reward['cg_name_de'], 'EN'=> $reward['cg_name']];
  528. oo::async()->add('oo::commonOprModel("notice")->sendNoticeMsg',[$uid,"fulCardGroup",[$groupCardNames]]);//集齐卡组跑马灯消息
  529. //----领奖记录----
  530. $rewardProps=[
  531. ["propsId"=>14,"num"=>$coins],
  532. ["propsId"=>15,"num"=>$spins],
  533. ["propsId"=>8,"num"=>$exp],
  534. ["propsId"=>9,"num"=>$feed],
  535. ];
  536. $dataLog = [
  537. "uid"=>$uid,
  538. "gid"=>$gid,
  539. "ts"=>time(),
  540. "reward"=>json_encode($rewardProps)
  541. ];
  542. oo::async()->add('oo::commonOprModel("card")->cardRewardLog',[$dataLog]);
  543. $bet = 0;
  544. //卡组活动额外奖励
  545. $aid = oo::commonOprModel('activitynew')->activityLock($uid,'crazy_card_group');
  546. if($aid){
  547. $bet = intval(oo::commonOprModel('activitynew')->getCrazyCardGroupBet($uid,$aid)['rate'])*0.01;
  548. $bcoin = intval($bet*$coins);$coins += $bcoin;
  549. $bspins = intval($bet*$spins);$spins += $bspins;
  550. $bfeed = intval($bet*$feed);$feed += $bfeed;
  551. $bexp = intval($bet*$exp);$exp += $bexp;
  552. oo::commonOprModel('member')->optProperty($uid,array('money'=>$bcoin),'+',216,'疯狂卡组:'.$aid);
  553. oo::commonOprModel('member')->optProperty($uid,array('spins'=>$bspins),'+',216,'疯狂卡组:'.$aid);
  554. intval($bet*$feed) && oo::commonOprModel('props')->addUserProps($uid,9, $bfeed,0,216);
  555. intval($bet*$exp) && oo::commonOprModel('props')->addUserProps($uid,8,$bexp,0,216);
  556. }
  557. $cgreward[] = intval($gid);
  558. $cgreward = array_unique($cgreward);
  559. $taCgId = [];
  560. foreach ($cgreward as $gid){
  561. $taCgId[] = "".$gid;
  562. }
  563. self::updateUserCardInfo($uid,['ciid'=>$userCard,'cgreward'=>$cgreward]);
  564. oo::commonOprModel('ta')->setEventData($uid,'user_set',['cardset_complete_num'=>count($cgreward),"cardset_complete_list"=>$taCgId]);
  565. /**
  566. * ta 事件--卡组完成
  567. */
  568. oo::commonOprModel('ta')->setEventData($uid,"cardset_complate",[
  569. "cardset_id" =>$gid,
  570. "cardset_activity_ratio" =>$bet,
  571. "cardset_reward_spin" =>$spins,
  572. "cardset_reward_coin" =>$coins,
  573. "cardset_reward_petfood" =>$feed,
  574. "cardset_reward_petexp" =>$exp,
  575. ]);
  576. return ['coins'=>$coins,'spins'=>$spins,'petfeed'=>$feed,'petexp'=>$exp];
  577. }
  578. public function cardRewardLog($data){
  579. $tb = otable::cardRewardLog();
  580. oo::logs()->commlog($data,"cardlog");
  581. $sql = funs::db_insertSQL($tb,$data);
  582. $res = oo::commonOprDb("log")->query($sql,1);
  583. }
  584. /**
  585. * 卡组进度奖励
  586. * @param $uid
  587. * @return array|bool
  588. * Created by: Owen
  589. * Created on: 2019/11/4 17:15
  590. */
  591. public function progressReward($uid){
  592. $total = count(self::getCardProgress($uid));
  593. $list = self::getCardGroupRewardConfig();
  594. foreach ($list as $row){
  595. $progress = $row['progress'];
  596. if($progress <= $total){
  597. $tempKey = okeys::userCardGroupReward($uid,$progress);
  598. if(!oo::commonOprRedis('common')->get($tempKey)) {
  599. $coins = intval($row['coin_reward']);
  600. $spins = intval($row['spin_reward']);
  601. //查询到当前卡组进度奖励
  602. $add = ['money'=>$coins,'spins'=>$spins];
  603. oo::commonOprRedis('common')->set($tempKey, 1);
  604. $userCard = self::getUserCardInfo($uid);
  605. $cpreward = $userCard['cpreward'];
  606. $cpreward[] = intval($progress);
  607. self::updateUserCardInfo($uid,['cpreward'=>array_unique($cpreward)]);
  608. oo::commonOprModel('member')->optProperty($uid,$add,'+',31,'卡组进度奖励:'.$progress);
  609. $add['coins'] = $coins;
  610. return $add;
  611. }
  612. }else{
  613. return false;
  614. }
  615. }
  616. return false;
  617. }
  618. /**
  619. * 已经领取过的卡组
  620. * @param $uid
  621. * @return mixed
  622. * Created by: Owen
  623. * Created on: 2020/3/25 20:07
  624. */
  625. public function getCardProgress($uid){
  626. $ret = self::getUserCardInfo($uid);
  627. return $ret['cgreward'];
  628. }
  629. /**
  630. * 已经领取到的卡组进度
  631. * @param $uid
  632. * @return int
  633. * Created by: Owen
  634. * Created on: 2020/3/25 20:08
  635. */
  636. public function getRewardProgress($uid){
  637. $ret = self::getUserCardInfo($uid);
  638. $cpreward = count($ret['cpreward']);
  639. return ($cpreward == 0)? -1 :$cpreward;
  640. }
  641. /**
  642. * 获得限定卡片信息
  643. * @param $uid
  644. * @return array
  645. * Created by: Owen
  646. * Created on: 2019/11/20 17:06
  647. */
  648. public function getExclusiveInfo($uid){
  649. $res = [];
  650. $cards = $this->getExclusiveCardInfo();
  651. foreach ($cards as $items)
  652. {
  653. $card[$items['ciid']] = $items['cgposition'];//ciid->位置
  654. }
  655. foreach ($cards as $items)
  656. {
  657. $group[$items['ciid']] = $items['cgid'];//ciid->卡组id
  658. }
  659. $userCardInfo = self::getUserCardInfo($uid);
  660. if(!empty($userCardInfo)) {
  661. $cardNumData = $userCardInfo['csid'];//ciid->数量
  662. if(empty($cardNumData)){
  663. return [];
  664. }
  665. $groupTemp = [];
  666. foreach ($card as $ciid => $pos) {
  667. foreach ($group as $ci => $cgid) {
  668. if(!in_array($cgid,$groupTemp)){
  669. $res[$cgid][1] = 0;
  670. $groupTemp[] = $cgid;
  671. }
  672. if($ciid == $ci) {
  673. if (key_exists($ciid, $cardNumData)) {
  674. $res[$cgid][$card[$ciid]] = intval($cardNumData[$ciid]);
  675. }
  676. }
  677. }
  678. }
  679. foreach ($res as $key=>$row){
  680. $res[$key] = array_filter($row);
  681. }
  682. $res = array_filter($res);
  683. return $res;
  684. }else{
  685. return [];
  686. }
  687. }
  688. /**
  689. * 领取限定卡片
  690. * @param $uid
  691. * @param $scardId
  692. * Created by: Owen
  693. * Created on: 2019/11/22 11:12
  694. */
  695. public function rewardExclusiveCard($uid,$scardId){
  696. $userCardInfo = self::getUserCardInfo($uid);
  697. $cardNumData = $userCardInfo['csid'];
  698. $cardNumData[$scardId] += 1;
  699. self::updateUserCardInfo($uid,['csid'=>$cardNumData]);
  700. }
  701. /**
  702. * 获得限定卡片信息
  703. * @param bool $gid
  704. * @return mixed
  705. * Created by: Owen
  706. * Created on: 2019/11/22 11:10
  707. */
  708. public function getExclusiveCardInfo($gid = false){
  709. $cacheKey = okeys::SpecialCardConfig();
  710. $arrJson = oo::commonOprRedis('config')->hGetAll($cacheKey);
  711. $arr = funs::getArrFromJsonArr($arrJson);
  712. if(empty($arr)||(!$gid&&empty($arr[$gid]))){
  713. $tb = otable::specialCardInfoConfig();
  714. $sql = "SELECT * FROM {$tb}";
  715. $ret = oo::commonOprDb('config')->getAll($sql,1);
  716. if(!empty($ret)){
  717. foreach ($ret as $k=>$v){
  718. $arr[$v['ciid']] = $v;
  719. $cache[$v['ciid']] = json_encode($v);
  720. }
  721. oo::commonOprRedis('config')->hMset($cacheKey,$cache);
  722. oo::commonOprRedis('config')->expire($cacheKey,oo::redisRandomExpire(7*86400));
  723. }
  724. }
  725. $data = !$gid?$arr:$arr[$gid];
  726. return $data;
  727. }
  728. /**
  729. * 根据ID获得限定卡片
  730. * @param $id
  731. * @return mixed
  732. * Created by: Owen
  733. * Created on: 2019/11/22 17:58
  734. */
  735. public function getExclusiveCardInfoById($id){
  736. $ret = self::getExclusiveCardInfo();
  737. foreach ($ret as $row){
  738. if($row['ciid'] == $id){
  739. return $row;
  740. }
  741. }
  742. return false;
  743. }
  744. /**
  745. * 限定卡组信息
  746. * @param bool $gid
  747. * @return mixed
  748. * Created by: Owen
  749. * Created on: 2020/3/25 19:46
  750. */
  751. public function getExclusiveCardGroupInfo($gid = false){
  752. $cacheKey = okeys::SpecialCardGroupConfig();
  753. $arrJson = oo::commonOprRedis('config')->hGetAll($cacheKey);
  754. $arr = funs::getArrFromJsonArr($arrJson);
  755. if(empty($arr)||($gid!==false&&empty($arr[$gid]))){
  756. $tb = otable::specialCardgroup_config();
  757. $sql = "SELECT * FROM {$tb}";
  758. $ret = oo::commonOprDb('config')->getAll($sql,1);
  759. if(!empty($ret)){
  760. foreach ($ret as $k=>$v){
  761. $arr[$v['cgid']] = $v;
  762. $cache[$v['cgid']] = json_encode($v);
  763. }
  764. oo::commonOprRedis('config')->hMset($cacheKey,$cache);
  765. oo::commonOprRedis('config')->expire($cacheKey,oo::redisRandomExpire(7*86400));
  766. }
  767. }
  768. $data = $gid===false?$arr:$arr[$gid];
  769. return $data;
  770. }
  771. /**
  772. * 领取限定卡片奖励--头像框
  773. * @param $uid
  774. * @param $sGroupId
  775. * @return bool
  776. * Created by: Owen
  777. * Created on: 2019/11/22 11:07
  778. */
  779. public function rewardExclusiveGroup($uid,$sGroupId){
  780. $userCardInfo = self::getUserCardInfo($uid);
  781. $cardNumData = $userCardInfo['csid'];
  782. $cardNumData = array_keys($cardNumData);
  783. $cardList = self::getExclusiveCardInfo($sGroupId);
  784. if(!in_array($cardList['ciid'],$cardNumData)){
  785. return false;
  786. }
  787. $ret = self::getExclusiveCardGroupInfo($sGroupId);
  788. if(!empty($ret)){
  789. return oo::commonOprModel('user')->rewardAvatarBox($uid,$ret['cg_avatar']);
  790. }
  791. }
  792. /**
  793. * 获得已领取的卡片组
  794. * @param $uid
  795. * @return array
  796. * Created by: Owen
  797. * Created on: 2019/11/22 11:18
  798. */
  799. public function getExclusiveGroupEd($uid){
  800. $userAvatarData = oo::commonOprModel('user')->getAvatar($uid);
  801. $avatarBox = $userAvatarData['avatarBox'];
  802. if(empty($avatarBox)){
  803. return [];
  804. }
  805. $ret = self::getExclusiveCardGroupInfo();
  806. $list= [];
  807. foreach ($ret as $row){
  808. if(in_array($row['cg_avatar'],$avatarBox)){
  809. $list[] = $row;
  810. }
  811. }
  812. return array_column($list,'cgid');
  813. }
  814. /**
  815. * 卡祝福
  816. * @param $uid
  817. * @param $gid
  818. * @return bool
  819. * Created by: Owen
  820. * Created on: 2019/12/20 17:53
  821. */
  822. public function getCardBless($uid,$bless){
  823. $gid = self::blessTurnToGid($bless);
  824. $flag = oo::commonOprRedis('usercache')->get(okeys::cardBless($uid,$gid));
  825. if($flag === 0){
  826. return false;
  827. }else if(!empty($flag)){
  828. return json_decode($flag,true);
  829. }
  830. $tb = otable::payment($uid);
  831. $sql = " SELECT * FROM {$tb} WHERE uid = {$uid} AND gid={$gid} AND use_time is null AND status = 2 LIMIT 1";
  832. $ret = oo::commonOprDb('payment')->getOne($sql,MYSQLI_ASSOC);
  833. if(empty($ret)){
  834. oo::commonOprRedis('usercache')->setex(okeys::cardBless($uid,$gid),0,oo::redisRandomExpire(3*24*60*60));
  835. return false;
  836. }else{
  837. $buff = json_decode($ret['buff'],true);
  838. oo::commonOprRedis('usercache')->setex(okeys::cardBless($uid,$gid),json_encode($buff),oo::redisRandomExpire(3*24*60*60));
  839. return $buff;
  840. }
  841. }
  842. /**
  843. * 祝福列表
  844. * @param $uid
  845. * @return array
  846. * Created by: Owen
  847. * Created on: 2019/12/26 16:15
  848. */
  849. public function getCardBlessList($uid){
  850. $tb = otable::payment($uid);
  851. $sql = " SELECT * FROM {$tb} WHERE uid = {$uid} AND gid IN (1101,1102) AND use_time is null AND status = 2";
  852. $ret = oo::commonOprDb('payment')->getAll($sql,MYSQLI_ASSOC);
  853. if(empty($ret)){
  854. return [];
  855. }else{
  856. foreach ($ret as $key=>$row){
  857. $buff = json_decode($row['buff'],true);
  858. $ret[$key] = [
  859. 'chestId' => $buff['id'],
  860. 'blessTo' => $buff['blessTo'],
  861. 'blessType'=> $buff['bless'],
  862. ];
  863. }
  864. return $ret;
  865. }
  866. }
  867. /**
  868. * 使用祝福
  869. * @param $uid
  870. * @param $gid
  871. * Created by: Owen
  872. * Created on: 2019/12/20 17:56
  873. */
  874. public function useCardBless($uid,$id,$bless){
  875. $gid = self::blessTurnToGid($bless);
  876. $time = time();
  877. $tb = otable::payment($uid);
  878. $like = '\'%"id":'.$id.',"bless":'.$bless.'%\'';
  879. $sql = " UPDATE {$tb} SET use_time='{$time}' WHERE uid='{$uid}' AND gid='{$gid}' AND status=2 AND use_time is null AND buff LIKE {$like} LIMIT 1";
  880. oo::commonOprDb('payment')->query($sql);
  881. oo::commonOprRedis('usercache')->delete(okeys::cardBless($uid,$gid));
  882. }
  883. public function blessTurnToGid($bless){
  884. $data =[
  885. 1=>1101,
  886. 2=>1102,
  887. ];
  888. return $data[$bless]??0;
  889. }
  890. //---------------------------------------------------- 1.3.7 改版---------------------------------------------------//
  891. /**
  892. * 卡片信息 -- 1.3.7 改版
  893. * @param $uid
  894. * @param $interface
  895. * @return mixed
  896. * Created by: Owen
  897. * Created on: 2020/3/24 19:56
  898. */
  899. public function info($uid,$interface = true){
  900. $userCardInfo = self::getUserCardInfo($uid);
  901. $userBasic = (array)$userCardInfo['ciid'];
  902. $userExclusive = (array)$userCardInfo['csid'];
  903. $cards = [];
  904. foreach ($userBasic as $key=>$row){
  905. $cards[$key] = $row;
  906. }
  907. foreach ($userExclusive as $key=>$row){
  908. $cards[$key + 100000] = $row;
  909. }
  910. $jokerTime = max(oo::commonOprRedis('User')->ttl(okeys::JokerCard($uid)),0);
  911. $data = [
  912. 'cardList' => $cards,
  913. 'cardRewardRecord' => [
  914. 'basic' => ($userCardInfo['cgreward'] == 'null' || empty($userCardInfo['cgreward'])) ? [] : $userCardInfo['cgreward'],
  915. 'exclusive'=> self::getExclusiveGroupEd($uid)
  916. ],
  917. 'taskRewardRecord' => [
  918. 'basic' => ($userCardInfo['cpreward'] == 'null' || empty($userCardInfo['cpreward'])) ? 0 : count($userCardInfo['cpreward']),
  919. 'exclusive'=> 0
  920. ],
  921. 'joker' => $jokerTime > 0 ? $jokerTime + time() : 0
  922. ];
  923. if($interface){
  924. return oo::response(1,$data,"",true);
  925. }else{
  926. return $data;
  927. }
  928. }
  929. /**
  930. * 获取卡组信息
  931. * @param bool $gid
  932. * @return mixed
  933. * Created by: Owen
  934. * Created on: 2020/3/25 17:45
  935. */
  936. public function getCardGroupInfo($gid = false){
  937. $cacheKey = okeys::CardGroupConfig();
  938. $arrJson = oo::commonOprRedis('config')->hGetAll($cacheKey);
  939. $arr = funs::getArrFromJsonArr($arrJson);
  940. if(empty($arr)||($gid!==false&&empty($arr[$gid]))){
  941. $tb = otable::cardgroup_config();
  942. $sql = "SELECT * FROM {$tb}";
  943. $ret = oo::commonOprDb('config')->getAll($sql,1);
  944. if(!empty($ret)){
  945. foreach ($ret as $k=>$v){
  946. $arr[$v['cgid']] = $v;
  947. $cache[$v['cgid']] = json_encode($v);
  948. }
  949. oo::commonOprRedis('config')->hMset($cacheKey,$cache);
  950. oo::commonOprRedis('config')->expire($cacheKey,oo::redisRandomExpire(7*86400));
  951. }
  952. }
  953. $data = $gid===false?$arr:$arr[$gid];
  954. return $data;
  955. }
  956. /**
  957. * 获取卡片信息
  958. * @return array
  959. * Created by: Owen
  960. * Created on: 2020/3/25 11:33
  961. */
  962. public function getCardInfo($ciid=false){
  963. $arrJson = oo::commonOprRedis('config')->hGetAll(okeys::CardConfig());
  964. $arr = funs::getArrFromJsonArr($arrJson);
  965. if(empty($arr)||($ciid!==false&&empty($arr[$ciid]))){
  966. $tb = otable::cardinfo_config();
  967. $sql = "SELECT * FROM {$tb}";
  968. $ret = oo::commonOprDb('config')->getAll($sql,1);
  969. if(!empty($ret)){
  970. foreach ($ret as $k=>$v){
  971. $arr[$v['ciid']] = $v;
  972. $cache[$v['ciid']] = json_encode($v);
  973. }
  974. }
  975. }
  976. if($ciid===false){
  977. array_multisort(array_column($arr,'ciid'),SORT_ASC,$arr);
  978. $data = $arr;
  979. }else{
  980. $data = $arr[$ciid];
  981. }
  982. return $data;
  983. }
  984. /**
  985. * 根据等级Id获取解锁的卡组
  986. * @param $levelId
  987. * @return array
  988. * Created by: Owen
  989. * Created on: 2020/3/25 11:33
  990. */
  991. public function getUnlockCardGroupByLevelId($levelId){
  992. $group = [];
  993. $cardGroupInfo = $this->getCardGroupInfo();
  994. foreach ($cardGroupInfo as $key => $value) {
  995. if(intval($value['cg_lock_rank']) <= intval($levelId)) {
  996. $group[] = $value['cgid'];
  997. }
  998. }
  999. return $group;
  1000. }
  1001. /**
  1002. * 根据等级Id获取解锁的卡片
  1003. * @param $levelId
  1004. * @return array
  1005. * Created by: Owen
  1006. * Created on: 2020/3/25 11:34
  1007. */
  1008. public function getUnlockCardByLevelId($levelId){
  1009. $group = self::getUnlockCardGroupByLevelId($levelId);
  1010. $card = [];
  1011. $cardInfo = self::getCardInfo();
  1012. foreach ($cardInfo as $key => $value) {
  1013. if(in_array($value['cgid'],$group) && $value['ci_lockRank'] <= $levelId) {
  1014. $card[] = $value;
  1015. }
  1016. }
  1017. return $card;
  1018. }
  1019. /**
  1020. * 随机生成星级卡片
  1021. * @param $card
  1022. * @param $num
  1023. * @param $type
  1024. * @return array
  1025. * Created by: Owen
  1026. * Created on: 2019/12/20 19:19
  1027. */
  1028. public function generateCard($userCard,$card, $num, $type,$skin = 0, $levelId = 0){
  1029. $userCardCiid = array_keys($userCard);
  1030. $array = [];
  1031. $config = [];
  1032. if($skin){
  1033. $temp = oo::commonOprModel('config')->getChestSkinStarProConfig($skin);
  1034. if(!empty($temp)){
  1035. $config = $temp["pro"];
  1036. $goldNum = $temp["maxGoldCard"];
  1037. }
  1038. }
  1039. if(empty($config)){
  1040. $config = self::getCardTypeProConfig($type);
  1041. $goldNum = self::getMaxGoldCardByType($type);
  1042. }
  1043. if($levelId <= 7) $goldNum = min($goldNum, 1); #7级以下,每次最多一张金卡
  1044. $coConfig= oo::commonOprModel('config')->cardCoefficient();
  1045. $curGoldNum = 0;
  1046. $log =[];
  1047. $ce =1;
  1048. $delGoldCard = false;
  1049. $whiteCards = [];
  1050. for($i = 0; $i < $num; ++$i) {
  1051. $data = self::getCardRank($card,oo::commonOprModel('slot')->get_rand($config), $whiteCards);
  1052. if($delGoldCard || $curGoldNum >= $goldNum){ #需要剔除金卡 或者 金卡已到上限
  1053. foreach ($data as $k => $v){
  1054. if($v['grade'] == 2) unset($data[$k]);
  1055. }
  1056. }
  1057. #剔除卡组中,当前已经重复的卡
  1058. $countCards = array_count_values($whiteCards);
  1059. $this->changeCardWeights($coConfig,$userCard,$data);
  1060. if(count($data) > 0){
  1061. $total = array_sum(array_column($data,'weights'));
  1062. if($total > 0){
  1063. $random = rand(0,$total);
  1064. $addAction = false;
  1065. foreach ($data as $row){
  1066. $ce =pow(1/5,intval($log[$row['ciid']]));//修正系数随卡片出现次数变更
  1067. $random -= intval($row['weights']);//降低已出现的卡片出现权重
  1068. if(!($goldNum != -1 && $goldNum <= $curGoldNum && $row['grade'] == 2) && ($random <= 0)){
  1069. $whiteCards[] = $row['ciid'];
  1070. $log[$row['ciid']]++;//记录 卡组id_卡片id 出现次数
  1071. $array[] = $row;
  1072. $userCard[$row['ciid']] += 1;
  1073. $row['grade'] == 2 && $curGoldNum += 1;
  1074. $addAction = true;
  1075. break;
  1076. }
  1077. }
  1078. if(!$addAction){
  1079. $data = self::getCardRank($card,rand(1,3), $whiteCards);
  1080. $randCard = $data[array_rand($data,1)];
  1081. $whiteCards[] = $randCard['ciid'];
  1082. $userCard[$randCard['ciid']] += 1;
  1083. $array[] = $randCard;
  1084. }
  1085. }else{
  1086. $randCard = $data[array_rand($data,1)];
  1087. $whiteCards[] = $randCard['ciid'];
  1088. $userCard[$randCard['ciid']] += 1;
  1089. $array[] = $randCard;
  1090. }
  1091. }else{
  1092. $userWhiteCards = [];
  1093. foreach ($card as $item){
  1094. if(
  1095. $item['grade'] == 1 #白卡
  1096. && in_array($item['ciid'], $userCardCiid) #用户已拥有
  1097. && $countCards[$item['ciid']] < 2 #当前未重复
  1098. ){
  1099. $userWhiteCards[] = $item;
  1100. }
  1101. }
  1102. if(!empty($userWhiteCards))
  1103. $array[] = $userWhiteCardsTemp = $userWhiteCards[array_rand($userWhiteCards,1)];
  1104. else
  1105. $array[] = $userWhiteCardsTemp = self::getCardInfo()[0];
  1106. $whiteCards[] = $userWhiteCardsTemp['ciid'];
  1107. }
  1108. // oo::logs()->debug3(["ts"=>date("H:i:s"), "whiteCards"=>$whiteCards,"countData"=>count($data),"random"=>$random],'cardLoop.log');
  1109. }
  1110. // oo::logs()->debug3(["ts"=>date("H:i:s"), "whiteCards"=>array_values(array_unique($whiteCards)),"countData"=>count($data),"type"=>$type,"skin"=>$skin],'cardLoop.log');
  1111. return $array;
  1112. }
  1113. /**
  1114. * @param $type
  1115. * @return array
  1116. * Created by: Cassie Lee
  1117. * Created on: 2019/5/15 17:16
  1118. * Description:获取卡片概率配置
  1119. */
  1120. public function getCardTypeProConfig($type){
  1121. $cacheKey = okeys::CardTypePro($type);
  1122. $cache = oo::commonOprRedis('config')->hGetAll($cacheKey);
  1123. if($cache){
  1124. return $cache;
  1125. }
  1126. $tb = otable::cardPro_Config();
  1127. $sql = "select * from {$tb} where type ={$type} limit 1";
  1128. $data = oo::commonOprDb('config')->getOne($sql, MYSQLI_ASSOC);
  1129. $config = json_decode($data['star_pro'],true);
  1130. $arr = [];
  1131. foreach ($config as $key => $val) {
  1132. $arr[$val['star']] = intval($val['v']);
  1133. }
  1134. oo::commonOprRedis('config')->hMset($cacheKey,$arr);
  1135. oo::commonOprRedis('config')->expire($cacheKey,oo::redisRandomExpire(7*24*60*60));
  1136. return $arr;
  1137. }
  1138. /**
  1139. * 最大金卡数量
  1140. * @param $type
  1141. * @return false
  1142. * Created by: Owen
  1143. * Created on: 2020/9/1 17:42
  1144. */
  1145. public function getMaxGoldCardByType($type){
  1146. $cacheKey = okeys::MaxGoldCard($type);
  1147. $cache = oo::commonOprRedis('config')->get($cacheKey);
  1148. if(empty($cache)){
  1149. $tb = otable::cardPro_Config();
  1150. $sql = "select * from {$tb} where type ={$type} limit 1";
  1151. $data = oo::commonOprDb('config')->getOne($sql, MYSQLI_ASSOC);
  1152. $cache = $data['maxGoldCard'];
  1153. oo::commonOprRedis('config')->setex($cacheKey,$cache,oo::redisRandomExpire(7*86400));
  1154. }
  1155. return $cache;
  1156. }
  1157. /**
  1158. * 获取卡片信息 -- 兼容旧代码
  1159. * @param $uid
  1160. * @return array
  1161. * Created by: Owen
  1162. * Created on: 2020/3/24 19:49
  1163. */
  1164. public function getUserCardInfo($uid){
  1165. // $cacheKey = okeys::UserCardInfo($uid);
  1166. // $cache = oo::commonOprRedis('common')->get($cacheKey);
  1167. $cardList = oo::commonOprRedis('common')->hGetAll(okeys::userCardList($uid));
  1168. if($cardList){
  1169. $ret['ciid'] = $cardList;
  1170. $cgreward = oo::commonOprRedis('common')->get(okeys::cardGroupRevLog($uid,1));
  1171. $ret['cgreward'] = json_decode($cgreward,true);
  1172. return $ret;
  1173. }
  1174. // if($cache){
  1175. // $ret = json_decode($cache,true);
  1176. // $ret['ciid'] = (array)$ret['ciid'];
  1177. // $ret['send_card'] = (array)$ret['send_card'];
  1178. // $ret['csid'] = (array)$ret['csid'];
  1179. // $ret['cgreward'] = (array)$ret['cgreward'];
  1180. // $ret['cpreward'] = (array)$ret['cpreward'];
  1181. // $ret['sended_card'] = (array)$ret['sended_card'];
  1182. // return $ret;
  1183. // }
  1184. $tb = otable::usercard_config($uid);
  1185. $sql = "SELECT * FROM {$tb} WHERE uid={$uid} ";
  1186. $ret = oo::commonOprDb('cardinfo')->getOne($sql, MYSQLI_ASSOC);
  1187. if(!empty($ret)){
  1188. $ret['ciid'] = json_decode($ret['ciid'],true)??[];
  1189. $ret['send_card'] = json_decode($ret['send_card'],true)??[];
  1190. $ret['csid'] = json_decode($ret['csid'],true)??[];
  1191. $ret['cgreward'] = json_decode($ret['cgreward'],true)??[];
  1192. $ret['cpreward'] = json_decode($ret['cpreward'],true)??[];
  1193. $ret['sended_card'] = json_decode($ret['sended_card'],true)??[];
  1194. // oo::commonOprRedis('common')->setex($cacheKey,json_encode($ret),oo::redisRandomExpire(7*24*60*60));
  1195. }else{
  1196. oo::commonOprDb('cardinfo')->query("INSERT INTO {$tb} (`uid`,`cgid`,`ciid`,`reward_type`,`reward_amount`,`gtime`,`gchannel`,`gid`,`expire`,`receive_time`) VALUES ({$uid},'', '{}', '0', '0', '0', '0', '0', '0', '0');");
  1197. $ret = oo::commonOprDb('cardinfo')->getOne("SELECT * FROM {$tb} WHERE uid={$uid} ", MYSQLI_ASSOC);
  1198. if(!empty($ret)){
  1199. $ret['ciid'] = json_decode($ret['ciid'],true)??[];
  1200. $ret['send_card'] = json_decode($ret['send_card'],true)??[];
  1201. $ret['csid'] = json_decode($ret['csid'],true)??[];
  1202. $ret['cgreward'] = json_decode($ret['cgreward'],true)??[];
  1203. $ret['cpreward'] = json_decode($ret['cpreward'],true)??[];
  1204. $ret['sended_card'] = json_decode($ret['sended_card'],true)??[];
  1205. // oo::commonOprRedis('common')->setex($cacheKey,json_encode($ret),oo::redisRandomExpire(7*24*60*60));
  1206. }else{
  1207. return [];
  1208. }
  1209. }
  1210. return $ret;
  1211. }
  1212. /**
  1213. * 更新用户卡片信息
  1214. * @param $uid
  1215. * @param $info
  1216. * @return bool
  1217. * Created by: Owen
  1218. * Created on: 2020/3/25 16:28
  1219. */
  1220. public function updateUserCardInfo($uid,$info){
  1221. // $cacheKey = okeys::UserCardInfo($uid);
  1222. // $userCardInfo = self::getUserCardInfo($uid);
  1223. // foreach ($info as $key=>$row){
  1224. // $userCardInfo[$key] = $row;
  1225. // }
  1226. // oo::commonOprRedis('common')->setex($cacheKey,json_encode($userCardInfo),oo::redisRandomExpire(7*24*60*60));
  1227. /** 数据落地标识 */
  1228. // oo::commonOprRedis('common')->zAdd(okeys::Landing("CARD", $uid),time(),$uid);
  1229. return true;
  1230. }
  1231. /**
  1232. * 获得卡片
  1233. * @param $uid
  1234. * @param $type 1木质宝箱 2白银宝箱 3黄金宝箱 4魔法宝箱 5 挖矿【挖到金币为0才有机会触发】,6任务奖励, 7活动奖励 10绿宝箱11蓝宝箱12红宝箱
  1235. * @param int $setNum 强制设定宝箱数量
  1236. * @param int $skin 强制设定宝箱数量
  1237. * @return array|bool
  1238. * Created by: Owen
  1239. * Created on: 2019/12/20 18:13
  1240. */
  1241. public function getCardByType($uid, $type,$setNum = 0,$getCardArray = [],$skin = 0){
  1242. $assetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1243. $card = self::getUnlockCardByLevelId($assetsInfo['levelId']);
  1244. $cardNum = $setNum != 0 ? $setNum : [1=>2,2=>4,3=>8,4=>10,7=>1][$type] ?? 1;
  1245. oo::commonOprModel('statistics')->cardSourceSta($type,$cardNum);//卡片来源统计
  1246. $userCardInfo = self::getUserCardInfo($uid);
  1247. if($type == 5){
  1248. $temp = [20,15,25,10,30];
  1249. $starRank = oo::commonOprModel('slot')->get_rand($temp);
  1250. if($temp[$starRank] == $temp[0]){
  1251. $array = self::generateCard($userCardInfo['ciid'],$card,$cardNum,$type, 0, $assetsInfo['levelId']);
  1252. }else{
  1253. return [];
  1254. }
  1255. }else if($type == 7){
  1256. foreach ($getCardArray as $ciid){
  1257. $array[] = self::getCardInfoByCiid($ciid);
  1258. }
  1259. }else{
  1260. if(oo::commonOprModel('activitynew')->activityLock($uid,'card')){
  1261. $cardNum = ceil($cardNum*1.5);
  1262. }
  1263. $array = self::generateCard($userCardInfo['ciid'],$card,$cardNum,$type,$skin, $assetsInfo['levelId']);
  1264. }
  1265. if(!empty($array)){
  1266. $userCardData = $userCardInfo['ciid'];
  1267. $userCard = array_keys($userCardData);
  1268. $newCardStar = 0;
  1269. $newCard = [];
  1270. $cardLog = [];
  1271. foreach ($array as $key=>$item){
  1272. $flag = true;
  1273. if(in_array($item['ciid'],$userCard)){
  1274. $flag = false;
  1275. $userCardData[$item['ciid']] += 1;
  1276. }else{
  1277. $userCardData[$item['ciid']] = 1;
  1278. if(!in_array($item['ciid'],$newCard)){
  1279. $newCardStar+= $item['ci_star_rank'];
  1280. $newCard[] = $item['ciid'];
  1281. }
  1282. }
  1283. $cardLog[] = $item['ciid'];
  1284. $cardInfo['card'][] = [
  1285. 'id' => $item['ciid'],
  1286. 'isNew' => $flag,
  1287. ];
  1288. }
  1289. self::updateUserCardInfo($uid,['ciid'=>$userCardData]);
  1290. $newCardStar > 0 && oo::commonOprModel('member')->optProperty($uid,array('star'=>$newCardStar),'+',32,'获取新卡片星星:'.implode(',',array_unique($newCard)));
  1291. $propsName = [5=>"偷取获得",6=>"任务获得",7=>"活动获得"][$type] ?? oo::commonOprModel('props')->getPropsConfig()[$type]['name'];
  1292. oo::commonOprModel('currency')->log($uid,"card","+",count($array),count($userCardData),3001,"{$propsName}:".implode(',',$cardLog));
  1293. oo::commonOprModel('currency')->setUserDayData($uid,'obtain_card',count($cardInfo['card']));//用户每日数据-卡片数获得
  1294. return $cardInfo;
  1295. }else{
  1296. return [];
  1297. }
  1298. }
  1299. // ------------------------------------------1.5.0 改版 -----------------------------------------------------//
  1300. /**
  1301. * 赠送卡片
  1302. * @param $uid
  1303. * @param $toUid
  1304. * @param $cids
  1305. * @param int $num
  1306. * @return mixed
  1307. * Created by: Owen
  1308. * Created on: 2020/3/28 14:20
  1309. */
  1310. public function sendCardToFriend($uid,$toUid,$cids,$num = 1){
  1311. $todayCacheKey = okeys::SendCardTodayTotal($uid);
  1312. $todayTimer = intval(oo::commonOprRedis('User')->get($todayCacheKey));
  1313. $dayLimit = oo::commonOprModel('readconfig')->getCon('Game','sendCardTotalLimit');
  1314. if($todayTimer >= $dayLimit){
  1315. return oo::response(-3,[],"当天次数不足");
  1316. }
  1317. $singlePersonLimit = oo::commonOprModel('readconfig')->getCon('Game','sendCardPlayerLimit');
  1318. $todayPersonCacheKey = okeys::SendCardTodayPerson($uid,$toUid);
  1319. $todayPersonTimer = intval(oo::commonOprRedis('User')->get($todayPersonCacheKey));
  1320. if($todayPersonTimer >= $singlePersonLimit){
  1321. return oo::response(-3,[],"当天次数不足");
  1322. }
  1323. $userCardInfo = self::getUserCardInfo($uid);
  1324. $userCurCard = $userCardInfo['ciid'];
  1325. $userSendCard = $userCardInfo['send_card'];
  1326. $toUserCardInfo = self::getUserCardInfo($toUid);
  1327. $toUserSendedCard = $toUserCardInfo['sended_card'];
  1328. $cardNum = 0;
  1329. $actionCard = [];
  1330. foreach ($cids as $cid){
  1331. if(intval($userCurCard[$cid]) < 2){
  1332. return oo::response(-2,[],"卡片不足");
  1333. }
  1334. // 扣除赠送方卡片
  1335. $userCurCard[$cid] -= 1;
  1336. $userSendCard[$toUid][$cid] += 1;
  1337. // 追加待领取卡片
  1338. $toUserSendedCard[$uid][$cid] += 1;
  1339. $cardNum += 1;
  1340. $actionCard[] = $cid;
  1341. }
  1342. oo::commonOprRedis('User')->setex($todayCacheKey,$todayTimer+$cardNum,oo::todayDeadline());
  1343. oo::commonOprRedis('User')->setex($todayPersonCacheKey,$todayPersonTimer+$cardNum,oo::todayDeadline());
  1344. self::updateUserCardInfo($uid,['ciid'=>$userCurCard,'send_card'=>$userSendCard]);
  1345. self::updateUserCardInfo($toUid,['sended_card'=>$toUserSendedCard]);
  1346. oo::commonOprModel('currency')->log($uid,"card","-",count($actionCard),array_sum($userCurCard),3001,"赠送好友 {$toUid}卡片:".implode(',',$actionCard));
  1347. oo::commonOprModel('currency')->setUserDayData($uid,'cost_card',count($actionCard));//用户每日数据-卡片数消耗
  1348. //赠送卡片
  1349. oo::commonOprModel('callback')->doTask($uid, 11, 1);
  1350. oo::commonOprModel('Workerman')->push($toUid,ocmd::$redPoint,['type'=>5]);
  1351. //卡片赠送游戏推送
  1352. $version = oo::commonOprModel('user')->getUserVersion($uid);
  1353. if(oo::compareVersion($version,'1.14.1') && oo::commonOprRedis('User')->setex(okeys::cardSendlog($uid,$toUid),1,60)){
  1354. $userInfo = oo::commonOprModel('member')->getUserBasic($uid);
  1355. $sendData = [
  1356. 'nick'=>$userInfo['nick'],
  1357. 's_picture'=>$userInfo['s_picture'],
  1358. 'sex'=>$userInfo['sex'],
  1359. 'signature'=>$userInfo['signature'],
  1360. 'u_flag'=>$userInfo['u_flag'],
  1361. 'uid'=>$userInfo['uid'],
  1362. ];
  1363. oo::commonOprModel('Workerman')->push($toUid,ocmd::$send['SendCard'],['userinfo'=>$sendData]);
  1364. //离线推送
  1365. oo::commonOprModel('push')->pushNews($toUid, 'push.title.shareCard', 'push.content.shareCard', [$userInfo['nick']],'shareCard');
  1366. }
  1367. //// 赠送卡片排行榜,取消该统计
  1368. //foreach ($cids as $cid){
  1369. // oo::commonOprModel('statistics')->giveCardSta($cid);
  1370. //}
  1371. oo::commonOprModel('ta')->setEventData($uid,"card_send",["card_list"=>$cids,"card_send_object_user"=>$toUid]);
  1372. return oo::response(1);
  1373. }
  1374. /**
  1375. * 领取卡片
  1376. * @param $uid
  1377. * @param $toUid
  1378. * @param bool $all
  1379. * @param int $rcid
  1380. * @return string
  1381. * Created by: Owen
  1382. * Created on: 2020/3/28 15:38
  1383. */
  1384. public function receiveCardFromFriend($uid,$toUid,$all = false,$rcid=0){
  1385. $userCardInfo = self::getUserCardInfo($uid);
  1386. $userCurCard = $userCardInfo['ciid'];
  1387. $userSendedCard = $userCardInfo['sended_card'];
  1388. if(empty($userSendedCard[$toUid])){
  1389. return oo::response(-2,[],'卡片已领取');
  1390. }
  1391. $receiveCard = [];
  1392. $newCard = [];
  1393. if($all && $rcid==0){
  1394. foreach ($userSendedCard[$toUid] as $cid=>$num){
  1395. if(empty($userCurCard[$cid])){
  1396. $newCard[] = $cid;
  1397. }
  1398. $userCurCard[$cid] += $num;
  1399. $receiveCard[$cid] = $num;
  1400. }
  1401. unset($userSendedCard[$toUid]);
  1402. }else{
  1403. foreach ($userSendedCard[$toUid] as $cid=>$num){
  1404. if($rcid != 0 && $cid != $rcid){
  1405. continue;
  1406. }
  1407. if(empty($userCurCard[$cid])){
  1408. $newCard[] = $cid;
  1409. }
  1410. $userCurCard[$cid] += 1;
  1411. $receiveCard[$cid] = 1;
  1412. if($userSendedCard[$toUid][$cid] == 1){
  1413. unset($userSendedCard[$toUid][$cid]);
  1414. }else{
  1415. $userSendedCard[$toUid][$cid] -= 1;
  1416. }
  1417. break;
  1418. }
  1419. }
  1420. $newCardStar = 0;
  1421. $cardList = self::getCardInfo();
  1422. foreach ($cardList as $row){
  1423. if(in_array($row['ciid'],$newCard)){
  1424. $newCardStar+= $row['ci_star_rank'];
  1425. }
  1426. }
  1427. if($newCardStar != 0){
  1428. oo::commonOprModel('member')->optProperty($uid,array('star'=>$newCardStar),'+',32,'获取新卡片星星:'.implode(',',array_unique($newCard)));
  1429. }
  1430. self::updateUserCardInfo($uid,['ciid'=>$userCurCard ,'sended_card'=>$userSendedCard]);
  1431. $out = [];
  1432. $actionCard = [];
  1433. foreach($receiveCard as $cid=>$row){
  1434. $first = true;
  1435. for ($i=0;$i<$row;$i++){
  1436. $actionCard[] = $cid;
  1437. $isNew = in_array($cid,$newCard) && $first;
  1438. $first = false;
  1439. $out[] = [
  1440. "id" => $cid,
  1441. "isNew" => $isNew
  1442. ];
  1443. oo::commonOprModel('ta')->setEventData($uid,"card_accept",["card_id"=>$cid,"card_accept_from_user"=>$toUid]);
  1444. }
  1445. }
  1446. oo::commonOprModel('currency')->setUserDayData($uid,'obtain_card',count($out));//用户每日数据-卡片数获得
  1447. oo::commonOprModel('currency')->log($uid,"card","+",count($actionCard),array_sum($userCurCard),3001,"领取好友 {$toUid}卡片:".implode(',',$actionCard));
  1448. return oo::response(1,['card'=>$out]);
  1449. }
  1450. /**
  1451. * 星星兑换
  1452. * @param $uid
  1453. * @param $propsId
  1454. * @param $cards
  1455. * @return string
  1456. * Created by: Owen
  1457. * Created on: 2020/6/10 15:46
  1458. */
  1459. public function starExchange($uid,$propsId,$cards){
  1460. $cards = json_decode(base64_decode($cards),true);
  1461. if(empty($cards)){
  1462. return oo::response(-2,"","兑换数据异常");
  1463. }
  1464. $refreshTimeCacheKey = okeys::StarExchange($uid,$propsId);
  1465. if(oo::commonOprRedis('User')->ttl($refreshTimeCacheKey) > 0){
  1466. return oo::response(-3);
  1467. }
  1468. $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1469. $config = oo::commonOprModel('config')->getStarExchange($propsId);
  1470. if(empty($config)){
  1471. return oo::response(-4,"","配置异常");
  1472. }
  1473. if($userAssetsInfo['levelId'] < $config['lockLevel']){
  1474. return oo::response(-5,"","等级不足");
  1475. }
  1476. $totalStar = 0;
  1477. $cardsInfo = array_column(self::getCardInfo(),NULL,'ciid');
  1478. $userCardInfo = self::getUserCardInfo($uid);
  1479. $userCardInfo = $userCardInfo['ciid'];
  1480. foreach ($cards as $cid=>$row){
  1481. $cardInfo = $cardsInfo[$cid];
  1482. $totalStar+= $cardInfo['ci_star_rank'] * $row;
  1483. if($userCardInfo[$cid] - $row >= 1){
  1484. $userCardInfo[$cid] -= $row;
  1485. }else{
  1486. return oo::response(-6,"","卡片数据异常");
  1487. }
  1488. }
  1489. if($totalStar < $config['starNum']){
  1490. return oo::response(-7,"","卡片星星不足");
  1491. }
  1492. self::updateUserCardInfo($uid,['ciid'=>$userCardInfo]);
  1493. oo::commonOprRedis('User')->setex($refreshTimeCacheKey,1,$config['refreshTime']);
  1494. oo::commonOprModel('currency')->log($uid,"card","-",count($cards),count($userCardInfo),3002,"星星兑换".json_encode($cards));
  1495. oo::commonOprModel('currency')->setUserDayData($uid,'cost_card',count($cards));//用户每日数据-卡片数消耗
  1496. $data = oo::commonOprModel('props')->rewardChest($uid,19,"星星兑换",33,$propsId);
  1497. return oo::response(1,$data);
  1498. }
  1499. /**
  1500. * joker卡兑换
  1501. * @param $uid
  1502. * @param $cid
  1503. * @return string
  1504. * Created by: Owen
  1505. * Created on: 2020/6/11 18:04
  1506. */
  1507. public function jokerExchange($uid,$cid){
  1508. $cacheKey = okeys::JokerCard($uid);
  1509. $ttl = intval(oo::commonOprRedis('User')->ttl($cacheKey));
  1510. if($ttl <= 0){
  1511. return oo::response(-2,[],'无小丑卡');
  1512. }
  1513. $unLockCard = array_column(self::getUnlockCard($uid),NULL,'ciid');
  1514. if(empty($unLockCard[$cid])){
  1515. return oo::response(-2,[],'卡片未解锁');
  1516. }
  1517. $userCardInfo = self::getUserCardInfo($uid)['ciid'];
  1518. $userCardInfo[$cid] += 1;
  1519. self::updateUserCardInfo($uid,['ciid'=>$userCardInfo]);
  1520. //小丑卡兑换流水
  1521. oo::commonOprModel('currency')->log($uid,"card","+",1,count($userCardInfo),3003,"小丑卡兌換:".$cid);
  1522. oo::commonOprModel('currency')->setUserDayData($uid,'obtain_card',1);//用户每日数据-卡片数获得
  1523. $deleteFlag = true;
  1524. $expireTime = time();
  1525. if(oo::compareVersion(oo::commonOprModel('user')->getUserVersion($uid),'1.8.1')){
  1526. $expire = (ceil($ttl/86400) - 1) * 86400;
  1527. if($expire > 0){
  1528. $deleteFlag = false;
  1529. $expireTime += $expire ;
  1530. oo::commonOprRedis('User')->setex($cacheKey,1,$expire);
  1531. }
  1532. }
  1533. $deleteFlag && oo::commonOprRedis('User')->delete($cacheKey);
  1534. return oo::response(1,['expireTime'=>$expireTime]);
  1535. }
  1536. /**
  1537. * 根据卡组获取卡片
  1538. * @param $gid
  1539. * @return array
  1540. * Created by: Owen
  1541. * Created on: 2020/9/17 17:33
  1542. */
  1543. public function getCardByGroup($gid){
  1544. $cards = self::getCardInfo();
  1545. $output = [];
  1546. foreach ($cards as $card){
  1547. if($card['cgid'] == $gid){
  1548. $output[] = $card;
  1549. }
  1550. }
  1551. return $output;
  1552. }
  1553. /**
  1554. * 卡组是否收集满
  1555. * @param $uid
  1556. * @param $gid
  1557. * @return bool
  1558. * Created by: Owen
  1559. * Created on: 2020/9/17 17:20
  1560. */
  1561. public function isGetAllCardByGroup($uid,$gid){
  1562. $userCardInfo = self::getUserCardInfo($uid);
  1563. $userCardGroup= $userCardInfo['cgreward'];
  1564. if(!in_array($gid,$userCardGroup)){
  1565. return false;
  1566. }
  1567. return true;
  1568. }
  1569. /**
  1570. * Notes:获取随机金卡
  1571. * User: wsc
  1572. * Time: 2021/9/9 11:02
  1573. * @param $uid
  1574. * @return array
  1575. */
  1576. public function getRandomCard($uid){
  1577. $data=$card=[];
  1578. $levelId = oo::commonOprModel('member')->getUserLevelId($uid);
  1579. //获取已解锁的卡组
  1580. $openCardGroupIdList = $this->getUnlockCardGroupByLevelId($levelId);
  1581. //获取所有已解锁的卡组及金卡
  1582. $cardInfo =$this->getCardInfo();
  1583. foreach ($cardInfo as $key => $value) {
  1584. if(in_array($value['cgid'],$openCardGroupIdList) && $value['ci_lockRank'] <= $levelId&&$value['grade']==2) {
  1585. $card[$value['cgid']][] = $value;
  1586. }
  1587. }
  1588. //用户已拥有卡片id list
  1589. $userCardInfo = oo::commonOprModel('card')->getUserCardInfo($uid);
  1590. $userCardTemp = array_keys($userCardInfo['ciid']);
  1591. //排除已获得的金卡
  1592. $lockCardGroupWeight = $allUnlockCard=$lockCardNum=[];
  1593. foreach ($card as $cgid=>$val){
  1594. foreach ($val as $k=>$v){
  1595. if(!in_array($v["ciid"],$userCardTemp)){
  1596. $lockCardGroupWeight[$cgid][$v["ciid"]]= $v["weights"];
  1597. $lockCardNum[$cgid]++;
  1598. }
  1599. $allUnlockCardWeight[$v["ciid"]] = $v["weights"];
  1600. }
  1601. }
  1602. $randCards=[];
  1603. if(!empty($lockCardGroupWeight)){
  1604. arsort($lockCardNum);
  1605. foreach ($lockCardNum as $cgid=>$num){
  1606. $randCards = $lockCardGroupWeight[$cgid];
  1607. break;
  1608. }
  1609. $isNew =1;
  1610. }else{
  1611. $randCards = $allUnlockCardWeight;
  1612. $isNew=0;
  1613. }
  1614. $data['id'] = oo::commonOprModel('slot')->get_rand($randCards);
  1615. $data['isNew'] = $isNew;
  1616. return $data;
  1617. }
  1618. /**
  1619. * 获取随机金卡
  1620. * @param $type 1普通卡 2金卡
  1621. * @return array
  1622. * Created by: Hss
  1623. * Created on: 2020/9/17 17:33
  1624. */
  1625. public function getRandomCard_old($uid,$num = 1,$type = 2){
  1626. $type = $type != 2 ?1:$type;
  1627. $assetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1628. $unlockCard = self::getUnlockCardByLevelId($assetsInfo['levelId']);
  1629. $userCardInfo = oo::commonOprModel('card')->getUserCardInfo($uid);
  1630. $userCardTemp = array_keys($userCardInfo['ciid']);
  1631. $out = $randCards = [];
  1632. $treasureCardConfig = oo::commonOprModel('config')->treasureCardConfig();
  1633. $ce=1;$notHaveCard=0;
  1634. $activateCfg = oo::commonOprModel('config')->cardCoefficient()['activate'];
  1635. foreach($unlockCard as $key => $row){
  1636. if($row['grade'] == $type){
  1637. if(!in_array($row['ciid'],$userCardTemp)){//未激活的金卡
  1638. $notHaveCard++;//未拥有的未激活的金卡数
  1639. }
  1640. }
  1641. }
  1642. foreach($unlockCard as $key => $row){
  1643. if($row['grade'] == $type){
  1644. $ce =1;
  1645. if(in_array($row['ciid'],$userCardTemp)) {//未激活的金卡
  1646. // $ce = $this->getHaveCardWeightCe($userCardInfo['ciid'][$row['ciid']]);//已经激活金卡权重修正系数
  1647. $ce = $userCardInfo['ciid'][$row['ciid']]==0?1:0.001;
  1648. }
  1649. // if(!in_array($row['ciid'],$userCardTemp)) {//未激活的金卡
  1650. // $ce = $activateCfg[$notHaveCard][1] ? $activateCfg[$notHaveCard][1] : 1;//未激活金卡权重修正系数
  1651. // }
  1652. $randCards[$row['ciid']] = $treasureCardConfig[$row['ciid']]*$ce*10000;//设置权重
  1653. }
  1654. }
  1655. $i = $num;
  1656. while($i--){
  1657. $temp = [];
  1658. $temp['id'] = oo::commonOprModel('slot')->get_rand($randCards);
  1659. $temp['isNew'] = in_array($temp['ciid'],$userCardTemp);
  1660. $out[] = $temp;
  1661. }
  1662. if($num == 1){
  1663. return $out[0];
  1664. }else{
  1665. return $out;
  1666. }
  1667. }
  1668. public function getHaveCardWeightCe($num){
  1669. if ($num==0){
  1670. return 1;
  1671. }
  1672. $arr=[1=>0.4,2=>0.3,3=>0.2,4=>0.1,5=>0.05,6=>0.02];
  1673. if( isset($arr[$num])&&$arr[$num]!=0){
  1674. return $arr[$num];
  1675. }
  1676. return 0.01;
  1677. }
  1678. /**
  1679. * 根据用户调整卡片权重
  1680. * @param $uid
  1681. * @param $card
  1682. * @return mixed
  1683. * Created by: Owen
  1684. * Created on: 2020/10/24 14:30 -- 20210121 弃用
  1685. */
  1686. public function changeCardWeightsByUserId($uid,$card){
  1687. $oddNum = $uid % 2 == 1 ? true : false;
  1688. $n = 0.6;
  1689. $m = 0.6;
  1690. foreach ($card as $key=>$row){
  1691. if($row['cgid'] < 3 || $row['ci_star_rank'] >= 5){
  1692. continue;
  1693. }
  1694. if($oddNum){ // 奇数
  1695. ($row['cgid'] % 2 ==1 ) ? $card[$key]['weights'] = ceil($row['weights'] * (1+$m)) : $card[$key]['weights'] = ceil($row['weights'] * (1-$n));
  1696. }else{ // 偶数
  1697. ($row['cgid'] % 2 ==1 ) ? $card[$key]['weights'] = ceil($row['weights'] * (1-$n)) : $card[$key]['weights'] = ceil($row['weights'] * (1+$m));
  1698. }
  1699. }
  1700. return $card;
  1701. }
  1702. /**
  1703. * 卡组格式
  1704. * @param $cardArr
  1705. * @return array
  1706. * Created by: Owen
  1707. * Created on: 2021/1/21 20:34
  1708. */
  1709. public function userCardGroupFormat($cardArr){
  1710. $format = [];
  1711. foreach ($cardArr as $cid=>$num){
  1712. if(!$cid&&$cid!==0){
  1713. continue;
  1714. }
  1715. $gid = intval(($cid - 1) / 9);
  1716. $pid = intval(($cid - 1) % 9);
  1717. $format[$gid][$pid] = $num;
  1718. }
  1719. return $format;
  1720. }
  1721. /**
  1722. * 根据用户调整卡片权重
  1723. * @param $config
  1724. * @param $userCard
  1725. * @param $data
  1726. * Created by: Owen
  1727. * Created on: 2021/1/21 20:34
  1728. */
  1729. public function changeCardWeights($config,&$userCard,&$data){
  1730. $formatArr = $this->userCardGroupFormat($userCard);
  1731. $numCoArr = [0 => 1, 1 => 0.5, 2 => 0.4, 3 => 0.3, 4 => 0.2, 5 => 0.1];
  1732. $activateCoArr = [
  1733. 0 => [1,0 ],
  1734. 1 => [1,0.1],
  1735. 2 => [1,0.6],
  1736. 3 => [1,0.5],
  1737. 4 => [1,0.4],
  1738. 5 => [1,0.5],
  1739. 6 => [1,1 ],
  1740. 7 => [0,1 ],
  1741. 8 => [0,1 ],
  1742. 9 => [0,1 ]];
  1743. if(!empty($config['num'])){
  1744. $numCoArr = $config['num'];
  1745. }
  1746. if(!empty($config['activate'])){
  1747. $activateCoArr = $config['activate'];
  1748. }
  1749. foreach ($data as $key=>$row){
  1750. $cardNum = min(intval($userCard[$row['ciid']]),max(count($numCoArr) - 1,0));
  1751. $groupNum = empty($formatArr[$row['cgid']]) ? 9 : max(9 - count($formatArr[$row['cgid']]),0);
  1752. $activateCo = $activateCoArr[$groupNum];
  1753. $isActivate = isset($userCard[$row['ciid']]) ? 0 : 1;
  1754. $data[$key]['weights'] = $row['weights'] * $numCoArr[$cardNum] * $activateCo[$isActivate];
  1755. }
  1756. }
  1757. /**
  1758. * 设置小丑卡
  1759. * @param $uid
  1760. * @return int
  1761. * Created by: Owen
  1762. * Created on: 2021/2/20 11:47
  1763. */
  1764. public function setJokerCard($uid){
  1765. $cacheKey = okeys::JokerCard($uid);
  1766. $ttl = oo::commonOprRedis('User')->ttl($cacheKey);
  1767. $default = 86400;
  1768. if($ttl > 0){
  1769. $default = $default + $ttl;
  1770. }
  1771. oo::commonOprRedis('User')->setex($cacheKey,1,$default);
  1772. oo::async()->add('oo::commonOprModel("notice")->sendNoticeMsg',[$uid,"getCard"]);//获得小丑卡跑马灯消息
  1773. return time() + $default;
  1774. }
  1775. }