PageRenderTime 26ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/web/admin/module/analysis/sum_enhance_log.php

https://gitlab.com/xusasuke6/Slg_php
PHP | 297 lines | 252 code | 33 blank | 12 comment | 37 complexity | d3e048d31c22368c62383cd3f107c841 MD5 | raw file
  1. <?php
  2. define('IN_DATANG_SYSTEM', true);
  3. include "../../../config/config.php";
  4. include SYSDIR_ADMIN."/include/global.php";
  5. global $smarty, $db;
  6. $sum_common = array(
  7. '1' => '精炼',
  8. '2' => '装备打孔',
  9. '3' => '宝石镶嵌',
  10. '4' => '灵石合成',
  11. '5' => '装备刻印',
  12. '6' => '装备升级',
  13. '7' => '正常拆卸宝石',
  14. 1043=>' 装备洗练',
  15. 1046=>' 装备回炉',
  16. );
  17. $act_type_option = array(
  18. '0' => $buf_lang['new']['select'],
  19. '1' => $buf_lang['left']['arena'],
  20. );
  21. if ( isset($_REQUEST['dStartDate'])){
  22. $date_start1 = explode("-",$_REQUEST['dStartDate']);
  23. $date_start1[1] = (strlen($date_start1[1]) >= 2) ? $date_start1[1] : '0'.$date_start1[1];
  24. $date_start1[2] = (strlen($date_start1[2]) >= 2) ? $date_start1[2] : '0'.$date_start1[2];
  25. $date_start_temp = $date_start1[0].'-'.$date_start1[1].'-'.$date_start1[2];
  26. $dateStart = $date_start1[0].$date_start1[1].$date_start1[2];
  27. }
  28. else
  29. {
  30. $date_start_temp = strftime ("%Y-%m-%d", time()-(60*60*24)*3 );
  31. $dateStart = str_replace('-','',$date_start_temp);
  32. }
  33. if ( isset($_REQUEST['dEndDate']))
  34. {
  35. $date_end1 = explode("-",$_REQUEST['dEndDate']);
  36. $date_end1[1] = (strlen($date_end1[1]) >= 2) ? $date_end1[1] : '0'.$date_end1[1];
  37. $date_end1[2] = (strlen($date_end1[2]) >= 2) ? $date_end1[2] : '0'.$date_end1[2];
  38. $date_end_temp = $date_end1[0].'-'.$date_end1[1].'-'.$date_end1[2];
  39. $dateEnd = $date_end1[0].$date_end1[1].$date_end1[2];
  40. }
  41. else
  42. {
  43. $date_end_temp= strftime ("%Y-%m-%d",time()-(60*60*24));
  44. $dateEnd = str_replace('-','',$date_end_temp);
  45. }
  46. $u_date_start = strtotime($date_start_temp);
  47. $u_end_start = strtotime($date_end_temp);
  48. $act_type = isset($_REQUEST['act_type']) ? $_REQUEST['act_type'] : 0;
  49. if (isset($act_type))
  50. {
  51. if($act_type == '0')
  52. {
  53. $match_sql = "SELECT * " .
  54. " FROM `t_sum_enhance` " .
  55. " WHERE mtime>='{$dateStart}' AND mtime<='{$dateEnd}' " .
  56. " ORDER BY mtime desc";
  57. $match_data = GFetchRowSet($match_sql);
  58. }
  59. else
  60. {
  61. $match_sql = "SELECT * " .
  62. " FROM `t_sum_enhance` " .
  63. " WHERE do_type='{$act_type}' AND mtime>='{$dateStart}' AND mtime<='{$dateEnd}' " .
  64. " ORDER BY mtime desc";
  65. $match_data = GFetchRowSet($match_sql);
  66. }
  67. }
  68. //exit($dateStart.'--'.$dateEnd);
  69. //exit(print_r($match_data));
  70. $ttype = isset($_REQUEST['ttype']) ? $_REQUEST['ttype'] :1;
  71. $date_arr = array();
  72. $date_arr = getFormatDate($date_start_temp,$date_end_temp,$ttype);
  73. //if($ttype == 2){exit(print_r($date_arr));}
  74. if(isset($match_data))
  75. {
  76. if(isset($date_arr['format']))
  77. {
  78. foreach($date_arr['format'] as $k => $v)
  79. {
  80. $data_per[$k] = array();
  81. $v['start'] = isset($v['start']) ? str_replace('-','',$v['start']) : '';
  82. $v['end'] = isset($v['end']) ? str_replace('-','',$v['end']) : '';
  83. $v['date'] = isset($v['date']) ? str_replace('-','',$v['date']) : '';
  84. if($v['date'] != '')
  85. {
  86. $start1 = $v['date'];
  87. $end1 = $v['date'];
  88. }
  89. else
  90. {
  91. $start1 = $v['start'];
  92. $end1 = $v['end'];
  93. }
  94. foreach($match_data as $data)
  95. {
  96. if($data['mtime'] >= $start1 && $data['mtime'] <= $end1 )
  97. {
  98. $data_per[$k][] = $data;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. //if($ttype == 1){exit(print_r($data_per));}
  105. $data10 = array();
  106. $rid_arr = array();
  107. foreach($data_per as $v)
  108. {
  109. if(is_array($v) && !empty($v))
  110. {
  111. foreach($v as $v1)
  112. {
  113. if($ttype != 1)
  114. {
  115. if(!isset($rid_arr[$v1['do_type']]))
  116. {
  117. $rid_arr[$v1['do_type']] = $v1;
  118. }
  119. else
  120. {
  121. $rid_arr[$v1['do_type']]['mtime'] = $v1['mtime'];
  122. $rid_arr[$v1['do_type']]['do_type'] = $v1['do_type'];
  123. $rid_arr[$v1['do_type']]['players'] = $rid_arr[$v1['do_type']]['players'] + $v1['players'];
  124. $rid_arr[$v1['do_type']]['do_times'] = $rid_arr[$v1['do_type']]['do_times'] + $v1['do_times'];
  125. $rid_arr[$v1['do_type']]['succ_n'] = $rid_arr[$v1['do_type']]['succ_n'] + $v1['succ_n'];
  126. }
  127. }
  128. else
  129. {
  130. $rid_arr = $v;
  131. }
  132. //if($ttype == 2){print_r($rid_arr[$v1['do_type']]);echo "<br>";}
  133. }
  134. $v = NULL;
  135. $v = $rid_arr;
  136. }
  137. $data10[] = $v;
  138. }
  139. //if($ttype == 1){exit(print_r($data10));}
  140. $output = output_data($data10,$u_date_start,$sum_common,$ttype,$date_arr);
  141. $smarty->assign("ctype_desc", $sum_common);
  142. $smarty->assign("output", $output);
  143. $smarty->assign("allAgentName", $AGENT_NAME);
  144. $smarty->assign("search_keyword1", $date_start_temp);
  145. $smarty->assign("search_keyword2", $date_end_temp);
  146. $smarty->assign("act_type_option", $act_type_option);
  147. $smarty->assign("act_type", $act_type);
  148. $smarty->display("module/analysis/sum_enhance_log.html");
  149. function output_data($data,$u_date_start,$ctype_desc,$t_type,$date) {
  150. if(empty($data)) return FALSE;
  151. $html = '';
  152. $flag = array(1=>'<font color="red"><b>↓</b></font>',2=>'<font color="green"><b>↑</b></font>');
  153. $table = '<td width="310" valign="top" ><table cellspacing="1" cellpadding="0" border="1" bgcolor="#bbe5e5" width="310" valign="top">';
  154. $thead = '<tr align="center"><td><b>强化类型</b></td><td><b>参加人数</b></td><td><b>参加次数</b></td><td><b>成功次数</b></td></tr>';
  155. //exit(print_r($data[-1]));
  156. for($i = 0; $i < count($data);$i++) {
  157. if($t_type == 1)
  158. {
  159. $info = $date['format'][$i]['date'].' 强化类型统计';
  160. }
  161. elseif($t_type == 2)
  162. {
  163. $info = '第'.$date['format'][$i]['yearweek'].'周'.$date['format'][$i]['start'].'~'.$date['format'][$i]['end'].'强化类型统计';
  164. }
  165. else
  166. {
  167. $info = '第'.$date['format'][$i]['yearmonth'].'月'.$date['format'][$i]['start'].'~'.$date['format'][$i]['end'].'强化类型统计';
  168. }
  169. $head = "<tr align='center'><td colspan='5'><b>$info</b></td></tr>";
  170. $tr = '';
  171. foreach($data[$i] as $k1=>$v1) {
  172. $before_suc = 0;
  173. $before_players = 0;
  174. $before_do_times = 0;
  175. if($i >= 0 && $i < count($data) && isset($data[$i+1]))
  176. {
  177. foreach($data[$i+1] as $before)
  178. {
  179. if($before['do_type'] == $v1['do_type'])
  180. {
  181. $before_players = $before['players'];
  182. $before_do_times = $before['do_times'];
  183. $before_suc = $before['succ_n'];
  184. }
  185. }
  186. //echo $v1['r_id'].'--'.$v1['players'].'-'.$v1['do_times'].'-+++'.$before_id.'-'.$before_players.'---'.$before_do_times.'<br>';
  187. $is_players = (($v1['players'] - $before_players)>=0)? $flag[2] : $flag[1];
  188. $is_do_times = (($v1['do_times'] - $before_do_times)>=0)? $flag[2] : $flag[1];
  189. $is_suc = (($v1['succ_n'] - $before_suc)>=0)? $flag[2] : $flag[1];
  190. $tr .= '<tr><td>'.$ctype_desc[$v1['do_type']].'</td><td>'.$v1['players'].$is_players.'</td><td>'.$v1['do_times'].$is_do_times.'</td><td>'.$v1['succ_n'].$is_suc.'</td></tr>';
  191. }
  192. else
  193. {
  194. $tr .= '<tr><td>'.$ctype_desc[$v1['do_type']].'</td><td>'.$v1['players'].'</td><td>'.$v1['do_times'].'</td><td>'.$v1['succ_n'].'</td></tr>';
  195. }
  196. }
  197. $tbody .=$tr;
  198. $html .=$table.$head.$thead.$tbody.'</table></td>';
  199. $tbody='';
  200. }
  201. return $html;
  202. }
  203. function getFormatDate($start,$end,$flag=1) {
  204. if($flag == 2) {
  205. //生成某一天所在星期的星期一的日期
  206. $weekday = date('N',strtotime($start));
  207. $startday = date('Y-m-d',strtotime($start)-($weekday-1)*60*60*24);
  208. $rt['start'] = $startday;
  209. //生成某一天所在星期的星期天的日期
  210. $weekday= date('N',strtotime($end));
  211. $endday = date('Y-m-d',strtotime($end)+(7-$weekday)*60*60*24);
  212. $rt['end'] = $endday;
  213. $stamp = strtotime($startday);
  214. $etamp = strtotime($endday);
  215. for($i=0,$t=$stamp;$t<$etamp;$t += 60*60*24,$i++) {
  216. $rt_date[$i]['yearweek'] = date('Y-W',$t);
  217. $rt_date[$i]['week'] = date('W',$t);
  218. $rt_date[$i]['start'] = date('Y-m-d',$t);
  219. $t += 6*24*60*60;
  220. $rt_date[$i]['end'] =date('Y-m-d',$t);
  221. }
  222. $rt_date['format'] = array_reverse($rt_date);
  223. } else if($flag == 3) {
  224. //生成某一天所在月份的第一天的日期
  225. $date_arr= getdate(strtotime($start));
  226. $day = $date_arr['year'].'-'.$date_arr['mon'].'-1';
  227. $startday =date('Y-m-d',strtotime($day));
  228. $rt['start'] = $startday;
  229. print_r($data_arr);
  230. //生成某一天所在月份的最后一天的日期
  231. $date_arr = getdate(strtotime($end));
  232. $day = $date_arr['year'].'-'.($date_arr['mon']+1).'-1';
  233. $endday =date('Y-m-d',strtotime($day)-1);
  234. $rt['end'] = $endday;
  235. $stamp = strtotime($startday);
  236. $etamp = strtotime($endday);
  237. for($i=0,$t=$stamp; $t<$etamp; $t += 60*60*24,$i++) {
  238. $rt_date[$i]['yearmonth'] = date('Y-n',$t);
  239. $rt_date[$i]['start'] = date('Y-m-d',$t);
  240. $date_arr = getdate($t);
  241. $rt_date[$i]['month'] = $date_arr['mon'];
  242. if($date_arr['mon']<12)
  243. $day = $date_arr['year'].'-'.($date_arr['mon']+1).'-1';
  244. else $day = ($date_arr['year']+1).'-1-1';
  245. $rt_date[$i]['end'] = date('Y-m-d',strtotime($day)-1);
  246. $t = strtotime($rt_date[$i]['end']);
  247. }
  248. $rt_date['format'] = array_reverse($rt_date);
  249. } else {
  250. $rt['start'] = $start;
  251. $rt['end'] = $end;
  252. $strtime1 = strtotime($end)+60*60*24;
  253. $strtime2 = strtotime($start);
  254. for($t=$strtime1-1,$i=0; $t>=$strtime2; ) {
  255. $rt_date['format'][$i]['date'] = date('Y-m-d',$t);
  256. $rt_date['format'][$i]['weekday'] = date('l',$t);
  257. $t -= 60*60*24;
  258. $i++;
  259. }
  260. }
  261. $rt_date['start'] = $rt['start']; //str_replace('-','',$rt['start']);
  262. $rt_date['end'] = $rt['end']; //str_replace('-','',$rt['end']);
  263. return $rt_date;
  264. }