PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/public/module/pay/qqgame_survey.php

https://github.com/karlom/gameadmin
PHP | 279 lines | 190 code | 57 blank | 32 comment | 12 complexity | 1d5e980ad8c89e099ac36ab7fe88d5b4 MD5 | raw file
  1. <?php
  2. /**
  3. * 游戏大厅单服概况
  4. * Author: libiao
  5. * 2013-10-09
  6. *
  7. */
  8. include_once "../../../protected/config/config.php";
  9. include_once SYSDIR_ADMIN_INCLUDE.'/global.php';
  10. global $lang;
  11. $this_day_time = GetTime_Today0();
  12. $cur_day_time = $this_day_time - 86400 ;
  13. $now = time();
  14. if (! isset($_REQUEST['dateStart'])) {
  15. // $dateStart = date('Y-m-d', strtotime("-13day")); //默认两周
  16. $dateStart = date('Y-m-d'); //默认两周
  17. } elseif ($_REQUEST['dateStart'] == 'ALL') {
  18. $dateStart = ONLINEDATE;
  19. } else {
  20. $dateStart = $_REQUEST['dateStart'];
  21. }
  22. if (! isset($_REQUEST['dateEnd'])) {
  23. $dateEnd = strftime("%Y-%m-%d", time());
  24. } elseif ($_REQUEST['dateEnd'] == 'ALL') {
  25. $dateEnd = strftime("%Y-%m-%d", time());
  26. } else {
  27. $dateEnd = strtotime($_REQUEST['dateEnd']) > time() ? strftime("%Y-%m-%d", time()) : $_REQUEST['dateEnd'];
  28. }
  29. $dateStartStamp = strtotime($dateStart . ' 0:0:0');
  30. $dateEndStamp = strtotime($dateEnd . ' 23:59:59');
  31. $dateStartStamp = intval($dateStartStamp) > 0 ? intval($dateStartStamp) : strtotime(ONLINEDATE);
  32. $dateEndStamp = intval($dateEndStamp) > 0 ? intval($dateEndStamp) : strtotime(ONLINEDATE);
  33. $openTimestamp = strtotime( ONLINEDATE );
  34. if($dateStartStamp < $openTimestamp)
  35. {
  36. $dateStartStamp = $openTimestamp;
  37. $dateStart = ONLINEDATE;
  38. }
  39. $dateStartStr = strftime("%Y-%m-%d", $dateStartStamp);
  40. $dateEndStr = strftime("%Y-%m-%d", $dateEndStamp);
  41. $dateStrPrev = strftime("%Y-%m-%d", $dateStartStamp - 86400);
  42. $dateStrToday = strftime("%Y-%m-%d");
  43. $dateStrNext = strftime("%Y-%m-%d", $dateStartStamp + 86400);
  44. $dateStartStamp = SS($dateStartStamp);
  45. $dateEndStamp = SS($dateEndStamp);
  46. //$sqlAccount = " SELECT COUNT(`account_name`) AS `total_account`, COUNT(`role_name`) AS `total_role` FROM ".T_LOG_REGISTER." ";
  47. //改成查创角色流失表来统计全服总帐号,总角色数
  48. $sqlAccount = " SELECT COUNT(distinct `account_name`) AS `total_account`,`step` FROM ".T_LOG_CREATE_LOSS." group by `step` ";
  49. $accountRs = GFetchRowSet($sqlAccount);
  50. foreach($accountRs as $v) {
  51. if($v['step']==0){
  52. $totalAccount = $v['total_account'];
  53. }
  54. if($v['step']==1){
  55. $totalRole = $v['total_account'];
  56. }
  57. }
  58. $sqlRole = " SELECT MAX(`level`) AS `max_level` FROM ".T_LOG_LEVEL_UP;
  59. $roleRs = GFetchRowOne($sqlRole);
  60. $roleMaxLevel = $roleRs['max_level'] ? $roleRs['max_level']:1;
  61. $sqlRoleName= " SELECT `role_name` FROM ".T_LOG_LEVEL_UP." WHERE `level`=".$roleMaxLevel . " group by `uuid`";
  62. $roleNameRs = GFetchRowSet($sqlRoleName);
  63. //print_r($roleNameRs);
  64. $roleNameStr = "";
  65. foreach ( $roleNameRs as $k => $v ) {
  66. $roleNameStr .= $v['role_name'].",";
  67. }
  68. //付费人数
  69. $sqlPayAccountCnt = " SELECT COUNT( DISTINCT(`uuid`) ) AS `pay_account_cnt`
  70. FROM ".T_LOG_BUY_GOODS .
  71. // " WHERE `ts` BETWEEN {$dateStartStamp} AND {$dateEndStamp} " .
  72. "";
  73. $payAccountCntRs = GFetchRowOne($sqlPayAccountCnt);
  74. $payAccountCnt = intval( $payAccountCntRs['pay_account_cnt'] ) ;
  75. //总消耗Q点
  76. $sqlAllTotalCost = "select round(sum(total_cost + pubacct + amt/10)) as totalCost from " . T_LOG_BUY_GOODS . " ";
  77. $sqlAllTotalCostResult = GFetchRowOne($sqlAllTotalCost);
  78. $allPayCount = $sqlAllTotalCostResult['totalCost'] ? $sqlAllTotalCostResult['totalCost'] : 0;
  79. //付费率(付费人数/注册人数)
  80. $allPayRate = $totalRole ? round($payAccountCnt/$totalRole,4)*100 : 0;
  81. //APRU值(元宝/付费人数/10)
  82. $allArpu = $payAccountCnt? round($allPayCount/$payAccountCnt/10, 2) : 0 ;
  83. //二次付费人数
  84. $sqlAllSecPayRoleCount = "select count(*) as secPayCount from (select uuid,account_name,role_name,count(*) as cnt from " . T_LOG_BUY_GOODS . " group by uuid having cnt>=2 ) t1 ";
  85. $sqlAllSecPayRoleCountResult = GFetchRowOne($sqlAllSecPayRoleCount);
  86. $allSecondPayCount = $sqlAllSecPayRoleCountResult['secPayCount'] ? $sqlAllSecPayRoleCountResult['secPayCount'] : 0;
  87. //二次付费率(二次付费人数/付费人数)
  88. $allSecondPayRate = $payAccountCnt ? round($allSecondPayCount/$payAccountCnt, 4)*100 : 0 ;
  89. //仙石使用数
  90. $sqlAllXsCostCount = "select sum(gold) as xsCostCount from " . T_LOG_GOLD . " WHERE gold < 0 AND type <> 20019 ";
  91. $sqlAllXsCostCountResult = GFetchRowOne($sqlAllXsCostCount);
  92. $allXsCostCount = $sqlAllXsCostCountResult ? $sqlAllXsCostCountResult['xsCostCount'] : 0;
  93. //消费的数据都是负数的,获取出来显示正数
  94. $allXsCostCount = $sqlAllXsCostCountResult['xsCostCount'] ? -$sqlAllXsCostCountResult['xsCostCount'] : 0 ;
  95. //单日最高充值(消耗Q点)
  96. $sqlAllMaxPay = "select year,month,day,mtime, sum(total_cost + pubacct + amt/10) as totalCost from " . T_LOG_BUY_GOODS . " group by year,month,day order by totalCost desc limit 1";
  97. $sqlAllMaxPayResult = GFetchRowOne($sqlAllMaxPay);
  98. $allMaxPay = array(
  99. 'allMaxPay' => $sqlAllMaxPayResult ? $sqlAllMaxPayResult['totalCost'] : 0,
  100. 'allMaxPayDate' => $sqlAllMaxPayResult ? date("Y-m-d", $sqlAllMaxPayResult['mtime'] ) : "-",
  101. );
  102. //单日最高在线
  103. $sqlAllMaxOnline = "select year,month,day,mtime, max(online) as online from " . T_LOG_ONLINE . " group by year,month,day order by online desc limit 1";
  104. $sqlAllMaxOnlineResult = GFetchRowOne($sqlAllMaxOnline);
  105. $allMaxOnline = array(
  106. 'allMaxOnline' => $sqlAllMaxOnlineResult ? $sqlAllMaxOnlineResult['online'] : 0,
  107. 'allMaxOnlineDate' => $sqlAllMaxOnlineResult ? date("Y-m-d", $sqlAllMaxOnlineResult['mtime'] ) : "-",
  108. );
  109. // ***** 选择时间内 start *****
  110. //登陆人数
  111. $sqlLoginCount = "select count(distinct uuid) as loginCount from " . T_LOG_LOGIN . " WHERE `mtime` BETWEEN {$dateStartStamp} AND {$dateEndStamp} and pf='qqgame' ";
  112. $sqlLoginCountResult = GFetchRowOne($sqlLoginCount);
  113. //创建角色数
  114. $sqlRegisterCount = "select count(distinct uuid) as createRoleCount from " . T_LOG_REGISTER . " WHERE `mtime` BETWEEN {$dateStartStamp} AND {$dateEndStamp} and pf='qqgame' ";
  115. $sqlRegisterCountResult = GFetchRowOne($sqlRegisterCount);
  116. //创建角色并付费人数
  117. $sqlRegister = "select distinct uuid from " . T_LOG_REGISTER . " WHERE `mtime` BETWEEN {$dateStartStamp} AND {$dateEndStamp} and pf='qqgame' ";
  118. $sqlPay = "select distinct uuid from " . T_LOG_BUY_GOODS . " WHERE `mtime` BETWEEN {$dateStartStamp} AND {$dateEndStamp} ";
  119. $sqlRegisterAndPay = "select count(*) as newPayCount from ({$sqlRegister}) t1, ({$sqlPay}) t2 where t1.uuid=t2.uuid ";
  120. $sqlRegisterAndPayResult = GFetchRowOne($sqlRegisterAndPay);
  121. //总消耗Q点
  122. $sqlTotalCost = "select round(sum(t1.total_cost + t1.pubacct + t1.amt/10)) as totalCost " .
  123. "from (select * from t_log_buy_goods WHERE `mtime` BETWEEN {$dateStartStamp} AND {$dateEndStamp} ) t1, (select distinct uuid from t_log_register where pf='qqgame' ) t2 " .
  124. " where t1.uuid=t2.uuid ";
  125. $sqlTotalCostResult = GFetchRowOne($sqlTotalCost);
  126. //付费人数
  127. $sqlPayRoleCount = "select count(distinct t1.uuid) as payRoleCount " .
  128. " from (select * from t_log_buy_goods WHERE `mtime` BETWEEN {$dateStartStamp} AND {$dateEndStamp} ) t1, (select distinct uuid from t_log_register where pf='qqgame' ) t2 " .
  129. " where t1.uuid=t2.uuid ";
  130. $sqlPayRoleCountResult = GFetchRowOne($sqlPayRoleCount);
  131. //次日留存率
  132. //创建角色数
  133. $dayend = $dateStartStamp+86400;
  134. $sql = "select count(distinct uuid) as registerCount from " . T_LOG_REGISTER . " WHERE `mtime` BETWEEN {$dateStartStamp} AND {$dayend} and pf='qqgame' ";
  135. $ret = GFetchRowOne($sql);
  136. $registerCount = $ret ? $ret['registerCount'] : 0 ;
  137. //次日登录数
  138. $secdaystart = $dateStartStamp+86400;
  139. $secdayend = $secdaystart+86400;
  140. $sql = "select count(distinct t2.uuid ) as loginCount " .
  141. " from (select distinct uuid from t_log_register where `mtime` BETWEEN {$dateStartStamp} AND {$dayend} and pf='qqgame' ) t1," .
  142. " (select distinct uuid from t_log_login where `mtime` BETWEEN {$secdaystart} AND {$secdayend} and pf='qqgame' )t2" .
  143. " where t1.uuid=t2.uuid ";
  144. $ret = GFetchRowOne($sql);
  145. $secLoginCount = $ret ? $ret['loginCount'] : 0 ;
  146. $secStayRate = $registerCount? round($secLoginCount/$registerCount,4)*100 : 0;
  147. $viewData = array(
  148. 'loginCount' => $sqlLoginCountResult['loginCount'],
  149. 'createRoleCount' => $sqlRegisterCountResult['createRoleCount'],
  150. 'maxOnline' => $sqlMaxOnlineResult['maxOnline'],
  151. 'payRoleCount' => $sqlPayRoleCountResult['payRoleCount'],
  152. 'payRate' => $sqlLoginCountResult['loginCount'] ? round($sqlPayRoleCountResult['payRoleCount']/$sqlLoginCountResult['loginCount'], 4)*100 :0 , //付费率(付费人数/注册人数)
  153. 'newPayCount' => $sqlRegisterAndPayResult['newPayCount'],
  154. 'newPayRate' => $sqlRegisterCountResult['createRoleCount'] ? round($sqlRegisterAndPayResult['newPayCount']/$sqlRegisterCountResult['createRoleCount'],4)*100 : 0,
  155. 'secPayCount' => $sqlSecPayRoleCountResult['secPayCount'],
  156. 'secPayRate' => $sqlPayRoleCountResult['payRoleCount'] ? round($sqlSecPayRoleCountResult['secPayCount']/$sqlPayRoleCountResult['payRoleCount'] ,4)*100 :0, //二次付费率(二次付费人数/付费人数)
  157. 'arup' => $sqlPayRoleCountResult['payRoleCount'] ? round($sqlTotalCostResult['totalCost']/($sqlPayRoleCountResult['payRoleCount']*10),2) :0,
  158. 'totalCost' => $sqlTotalCostResult['totalCost'],
  159. 'xsCostCount' => -$sqlXsCostCountResult['xsCostCount'],
  160. 'registerCount' => $registerCount,
  161. 'secLoginCount' => $secLoginCount,
  162. 'secStayRate' => $secStayRate,
  163. );
  164. // ***** 选择时间内 end *****
  165. $version = getVersion();
  166. $data = array(
  167. 'lang' => $lang,
  168. 'agent' => PROXY,
  169. 'agentId' => PROXYID,
  170. 'areaName'=> $_SESSION['gameAdminServer'],
  171. 'serverOnlineDay' => ONLINEDATE,
  172. 'hasOnlineDay' => intval( ( time()-strtotime(ONLINEDATE) ) / 86400 ) ,
  173. 'version' => $version,
  174. 'totalAccount' => $totalAccount,
  175. 'totalRole' => $totalRole,
  176. 'roleMaxLevel' => $roleMaxLevel,
  177. 'maxLevelRoleNames' => $roleNameStr,
  178. 'allArpu' => $allArpu,
  179. 'payAccountCnt' => $payAccountCnt,
  180. 'allPayRate' => $allPayRate,
  181. 'allPayCount' => $allPayCount,
  182. 'allSecondPayCount' => $allSecondPayCount,
  183. 'allSecondPayRate' => $allSecondPayRate,
  184. 'allXsCostCount' => $allXsCostCount,
  185. 'allMaxPay' => $allMaxPay,
  186. 'allMaxOnline' => $allMaxOnline,
  187. 'maxOnline' => $maxOnline,
  188. 'maxPay' => round($maxPay,1),
  189. 'maxPayMoney' => round($maxPay/10,1),
  190. // 'allTotalPay'=>round($allTotalPay,1),
  191. 'dateStart' => $dateStartStr,
  192. 'dateEnd' => $dateEndStr,
  193. 'dateStrPrev' => $dateStrPrev,
  194. 'dateStrNext' => $dateStrNext,
  195. 'dateStrToday' => $dateStrToday,
  196. 'diffDay'=>$diffDay,
  197. 'payOnline' => $payOnline,
  198. 'currentOnline' => $currentOnline,
  199. 'payUserOnline' => $payUserOnline,
  200. );
  201. $smarty->assign($data);
  202. $smarty->assign('viewData', $viewData);
  203. $smarty->display("module/pay/qqgame_survey.tpl");
  204. exit;
  205. function getVersion(){
  206. global $serverList;
  207. $serverId = isset($_SESSION['gameAdminServer']) ? ltrim($_SESSION['gameAdminServer'], "s") : -1;
  208. if($entranceUrl = $serverList[$_SESSION['gameAdminServer']]['url']){
  209. $timestamp = time();
  210. $key = urlencode(md5($timestamp.ADMIN_GAME_AUTH_KEY));
  211. $params = "timestamp={$timestamp}&key={$key}";
  212. $apiUrl = $entranceUrl."api/getClientVars.php";
  213. $clientVars = curlPost($apiUrl, $params);
  214. $clientVars = json_decode($clientVars, true);
  215. if($clientVars['result'] && $clientVars['data']){
  216. return $clientVars['data']['version'];
  217. }else{
  218. return -1;
  219. }
  220. }
  221. return 0;
  222. }