recall.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. define('RECALL_SECRET', 'ab*&()[cae!@+?>#5981~.,-zm');
  3. class ModelRecall {
  4. /**
  5. * 老玩家召回应用外推送
  6. * @param int $uid
  7. */
  8. public function firebasePush($uid = 0){
  9. if($uid){
  10. $reward = $this->getRecallReward($uid);
  11. if(empty($reward)){
  12. return;
  13. }
  14. oo::commonOprModel('push')->pushNews($uid, 'push.title.recall', 'push.content.recall', $reward);
  15. }else{
  16. $config = oo::commonOprModel('config')->recallConfig();
  17. $tb = otable::userinfo();
  18. $stime = time() - 16 * 24 * 3600;
  19. $etime = time() - 3 * 24 * 3600;
  20. $sql = "SELECT uid, lasttime FROM {$tb} WHERE lasttime >= {$stime} AND lasttime < $etime";
  21. $arr = oo::commonOprDb('userinfo')->getAll($sql, 1);
  22. foreach($arr as $val){
  23. $reward = $this->getRecallReward($val['uid'], $val['lasttime'], $config);
  24. if(empty($reward)){
  25. continue;
  26. }
  27. oo::commonOprModel('push')->pushNews($val['uid'], 'push.title.recall', 'push.content.recall', $reward);
  28. }
  29. }
  30. }
  31. public function getRecallReward($uid, $lasttime = 0, array $config = [], $level = 0) {
  32. if(empty($config)){
  33. $config = oo::commonOprModel('config')->recallConfig();
  34. }
  35. if(empty($lasttime)){
  36. $info = oo::commonOprModel('member')->getUserInfo($uid);
  37. $lasttime = empty($info['lasttime']) ? time() : $info['lasttime'];
  38. }
  39. $money = $spins = 0;
  40. $time = time();
  41. if(empty($level)){
  42. $level = oo::commonOprModel('member')->getUserLevelId($uid);
  43. }
  44. foreach ($config as $row){
  45. if(($lasttime + $row['day']*24*60*60) > $time){
  46. continue;
  47. }
  48. if(!empty($row['reward']['coins'])&&!empty($row['reward']['coins']['coins'])){
  49. $coins = oo::commonOprModel('goods')->getGoodCoinsByLevelId($level,$row['reward']['coins']['coins']);
  50. $bet = empty($row['reward']['coins']['bet']) ? 1 : $row['reward']['coins']['bet'];
  51. $money += $coins * $bet;
  52. }
  53. if(!empty($row['reward']['spins'])){
  54. $spins += $row['reward']['spins'];
  55. }
  56. }
  57. if(empty($money) && empty($spins)){
  58. return [];
  59. }
  60. return [intval($money), $spins];
  61. }
  62. }