lose.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * 流失相关
  4. */
  5. defined('IN_WEB') or die('Include Error!');
  6. class ModelLose
  7. {
  8. private $moneyLevel = [
  9. [0, 1000],[1001, 40000], [40001,150000],[150001, 600000],[600001, 2000000],[2000001, 10000000],[10000001, 100000000]
  10. ];
  11. /**
  12. * 获取昨天流失玩家统计
  13. * @return bool
  14. */
  15. public function getYesterdayLoseUser()
  16. {
  17. set_time_limit(0);
  18. $key = okeys::robotUidList();
  19. $lastDay = date('Ymd', strtotime('-1 day'));
  20. $last2Day = date('Ymd', strtotime('-2 days'));
  21. $stime = strtotime("-2 days 00:00:00");
  22. $etime = strtotime("-2 days 23:59:59");
  23. $lastDayPlayer = $this->getAllPlayer($lastDay, 2);
  24. $last2DayPlayer = $this->getAllPlayer($last2Day, 2);
  25. $lostPlayer = array_diff($last2DayPlayer, $lastDayPlayer);//前天在玩,昨天不在。则为流失玩家
  26. $lostList = [];//昨天的玩家
  27. if(!empty($lostPlayer)) {
  28. foreach ($lostPlayer as $uid) {
  29. //判断是否是机器人
  30. if ($isRobot = oo::commonOprRedis('robot')->sContains($key, $uid)) {
  31. continue;
  32. }
  33. $info = oo::commonOprModel('member')->getUserInfo($uid);
  34. if (empty($info)) {
  35. continue;
  36. }
  37. $isVisitor = oo::commonOprModel('member')->isVistor($uid);
  38. $account = ($isVisitor == 1) ? 'V' : 'F';
  39. $divice = in_array($info['login_plat'], array(1, 11)) ? 'A' : 'I';
  40. $userInfo = oo::commonOprModel('member')->getUserLevel($uid);
  41. $level = $userInfo['levelId'];
  42. $checkBought = oo::commonOprModel('payment')->checkBought($uid);
  43. $bought = $checkBought ? 'pay' : 'notpay';//付费 非付费
  44. $lostList['level'][$level] += 1;
  45. $lostList['bought'][$bought] += 1;
  46. $lostList['deviceAccount'][$divice.$account] += 1;
  47. $lostList['total'] += 1;
  48. }
  49. //统计两天前总人数、付费人数、LIAFB、LIAV、LIIFB、LIIV
  50. $loginPlayer = otable::sta_lp();
  51. $sql = "SELECT * FROM {$loginPlayer} WHERE ordertime >= {$stime} AND ordertime <= {$etime} AND sid=999 LIMIT 1";
  52. $ret = oo::commonOprDb('common')->getOne($sql, 1);
  53. $lostList['dau'] = $ret['total'] ?? 0;
  54. $lostList['login_af'] = $ret['login_af'] ?? 0;
  55. $lostList['login_av'] = $ret['login_av'] ?? 0;
  56. $lostList['login_if'] = $ret['login_if'] ?? 0;
  57. $lostList['login_iv'] = $ret['login_iv'] ?? 0;
  58. $slTable = otable::summarylist();
  59. $sql2 = "SELECT DISTINCT sl_uid FROM {$slTable} WHERE sl_status = 2 ";
  60. $ret2 = oo::commonOprDb('common')->getAll($sql2, 1);
  61. $allPayUid = [];
  62. foreach ($ret2 as $value) {
  63. array_push($allPayUid, $value['sl_uid']);
  64. }
  65. $payNum = array_intersect($last2DayPlayer, $allPayUid);//前天登录的充值玩家
  66. $lostList['payNum'] = count($payNum);
  67. }
  68. $key = okeys::losestatistics($lastDay);
  69. oo::commonOprRedis('statistics')->set($key, serialize($lostList));
  70. oo::commonOprRedis('statistics')->expireAt($key, strtotime('+7 days 23:59:59'));
  71. return true;
  72. }
  73. /**
  74. * 获取7天流失玩家统计
  75. * @return bool
  76. */
  77. public function getSevendayLoseUser()
  78. {
  79. set_time_limit(0);
  80. //机器人id
  81. $key = okeys::robotUidList();
  82. $lastDay = date('Ymd', strtotime('-1 day'));
  83. $last2Day = date('Ymd', strtotime('-7 days'));
  84. $stime = strtotime("-7 days 00:00:00");
  85. $etime = strtotime("-7 days 23:59:59");
  86. $moneyLevel = $this->moneyLevel;
  87. $lastDayPlayer = $this->getAllPlayer($lastDay, 2);
  88. $last2DayPlayer = $this->getAllPlayer($last2Day, 2);
  89. $lostPlayer = array_diff($last2DayPlayer, $lastDayPlayer);//前天在玩,昨天不在。则为流失玩家
  90. $lostList = [];//昨天的玩家
  91. if(!empty($lostPlayer)) {
  92. foreach ($lostPlayer as $uid) {
  93. //判断是否是机器人
  94. if ($isRobot = oo::commonOprRedis('robot')->sContains($key, $uid)) {
  95. continue;
  96. }
  97. $props = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  98. $money = $props['money'];
  99. if ($money == 0) {//记录到机器人中
  100. continue;
  101. }
  102. $info = oo::commonOprModel('member')->getUserInfo($uid);
  103. if (empty($info)) {
  104. continue;
  105. }
  106. //记录
  107. // $version = $info['version'];
  108. $isVisitor = oo::commonOprModel('member')->isVistor($uid);
  109. $account = ($isVisitor == 1) ? 'V' : 'F';
  110. $divice = in_array($info['login_plat'], array(1, 11)) ? 'A' : 'I';
  111. $userInfo = oo::commonOprModel('member')->getUserLevel($uid);
  112. $level = $userInfo['levelId'];
  113. // $total = $wintimes + $losetimes;
  114. $checkBought = oo::commonOprModel('payment')->checkBought($uid);
  115. $bought = $checkBought ? 'pay' : 'notpay';//付费 非付费
  116. $lostList['level'][$level] += 1;
  117. // $lostList['version'][$version] += 1;
  118. $lostList['bought'][$bought] += 1;
  119. $lostList['deviceAccount'][$divice.$account] += 1;
  120. // $lostList['device'][$divice] += 1;
  121. $lostList['total'] += 1;
  122. //判断筹码的区间
  123. $maxLength = count($moneyLevel);
  124. foreach ($moneyLevel as $k => $moneyBetween) {
  125. $moneyBegin = $moneyBetween[0];
  126. $moneyEnd = $moneyBetween[1];
  127. if ($money >= $moneyBegin && $money <= $moneyEnd) {
  128. $lostList['money'][$moneyBegin] += 1;
  129. break;
  130. } elseif ($k == $maxLength - 1) {
  131. $lostList['money'][$moneyEnd] += 1;
  132. }
  133. }
  134. // oo::logs()->debug3("uid:".$uid, 'Lose.php');
  135. }
  136. //统计七天前总人数、付费人数、LIAFB、LIAV、LIIFB、LIIV
  137. $loginPlayer = otable::sta_lp();
  138. $sql = "SELECT * FROM {$loginPlayer} WHERE ordertime >= {$stime} AND ordertime <= {$etime} AND sid=999 LIMIT 1";
  139. $ret = oo::commonOprDb('common')->getOne($sql, 1);
  140. $lostList['dau'] = $ret['total'] ?? 0;
  141. $lostList['login_af'] = $ret['login_af'] ?? 0;
  142. $lostList['login_av'] = $ret['login_av'] ?? 0;
  143. $lostList['login_if'] = $ret['login_if'] ?? 0;
  144. $lostList['login_iv'] = $ret['login_iv'] ?? 0;
  145. $slTable = otable::summarylist();
  146. $sql2 = "SELECT DISTINCT sl_uid FROM {$slTable} WHERE sl_status = 2 ";
  147. $ret2 = oo::commonOprDb('common')->getAll($sql2, 1);
  148. $allPayUid = [];
  149. foreach ($ret2 as $value) {
  150. array_push($allPayUid, $value['sl_uid']);
  151. }
  152. $payNum = array_intersect($last2DayPlayer, $allPayUid);//前天登录的充值玩家
  153. $lostList['payNum'] = count($payNum);
  154. }
  155. $key = okeys::losestatisticsseven($lastDay);
  156. oo::commonOprRedis('statistics')->set($key, serialize($lostList));
  157. oo::commonOprRedis('statistics')->expireAt($key, strtotime('+7 days 23:59:59'));
  158. return true;
  159. }
  160. /**
  161. * 计算所有玩家
  162. * type 1 新注册 其他登陆
  163. */
  164. public function getAllPlayer($date, $type)
  165. {
  166. $total = oo::commonOprModel('statistics')->getAllPlayer($date, $type);
  167. return $total;
  168. }
  169. }