Public Function invitation ($appId, $type) {
$arr = db ("indicated")->field ("Id,superior,avatar,nickname")
->where (' superior=0 ')
->select ();
foreach ($arr as $k = = $v) {
$where = Self::invitationtime ($type, $v);
$arr [$k] [' count '] = db ("indicated")
->where ($where)
->count ();
}
foreach ($arr as $key = = $val) {
if ($val [' count ']==0) {
Unset ($arr [$key]);
}else{
if ($val [' Avatar ']) {
$arr [$key] [' avatar '] = Cdnurl ($val [' Avatar '],true);
}
$sort [] = $val [' count '];
}
}
if (!empty ($arr)) {
Sort
Array_multisort ($sort, Sort_desc, $arr);
$list = Array_slice ($arr, 0,10);
}
return $list;
}
Common time method Public function Invitationtime ($type, $v) {if ($type ==1) {//Today $beginToday = Mktime (0,0,0,date (' m '), D Ate (' d '), date (' Y ')); $endToday = Mktime (0,0,0,date (' m '), date (' d ') +1,date (' Y '))-1; $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginToday." and ". $endToday.";} if ($type ==2) {//Yesterday $beginYesterday = Mktime (0,0,0,date (' m '), date (' d ') -1,date (' Y ')); $endYesterday = Mktime (0,0,0,date (' m '), date (' d '), date (' Y '))-1; $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginYesterday." and ". $endYesterday.";} if ($type ==3) {//this week $beginWeek =mktime (0,0,0,date (' m '), date (' d ')-date (' W ') +1,date (' Y ')); $endWeek =mktime (23,59,59,date (' m '), date (' d ')-date (' W ') +7,date (' Y ')); $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginWeek." and ". $endWeek.";} if ($type ==4) {//Last week $beginLastweek =mktime (0,0,0,date (' m '), date (' d ')-date (' W ') +1-7,date (' Y '));$endLastweek =mktime (23,59,59,date (' m '), date (' d ')-date (' W ') +7-7,date (' Y ')); $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginLastweek." and ". $endLastweek.";} if ($type ==5) {//this month $beginThismonth =mktime (0,0,0,date (' m '), 1,date (' Y ')); $endThismonth =mktime (23,59,59,date (' m '), date (' t '), date (' Y ')); $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginThismonth." and ". $endThismonth.";} if ($type ==6) {//Last month $beginLastmonth =strtotime (' y-m-01 00:00:00 ', Strtotime ('-1 month ')); $endLastmonth =strtotime (Date ("Y-m-d 23:59:59", Strtotime (-date (' d '). Day ')); $where = "Superior REGEXP ' ^{$v [' id ']}_ ' and createtime between '. $beginLastmonth." and ". $endLastmonth.";} return $where;}
Sort the PHP array and take the number of array bars