作者 王智

统计调试

@@ -64,21 +64,11 @@ class SportA extends Backend @@ -64,21 +64,11 @@ class SportA extends Backend
64 } 64 }
65 65
66 $result = array("total" => $list->total(), "rows" => $list->items()); 66 $result = array("total" => $list->total(), "rows" => $list->items());
67 - dump($result);  
68 - die;  
69 return json($result); 67 return json($result);
70 } 68 }
71 return $this->view->fetch(); 69 return $this->view->fetch();
72 } 70 }
73 71
74 72
75 - public function sport($person)  
76 - {  
77 - $newArr = array();  
78 - foreach ($person as $key => $v) {  
79 - $newArr[$key]['num'] = $v['num'];  
80 - }  
81 - array_multisort($newArr, SORT_DESC, $person);//SORT_DESC为降序,SORT_ASC为升序  
82 - return $person;  
83 - } 73 +
84 } 74 }
@@ -338,6 +338,15 @@ class Common extends Api @@ -338,6 +338,15 @@ class Common extends Api
338 echo $end_time; 338 echo $end_time;
339 } 339 }
340 340
  341 + public function sport($person)
  342 + {
  343 + $newArr = array();
  344 + foreach ($person as $key => $v) {
  345 + $newArr[$key]['num'] = $v['num'];
  346 + }
  347 + array_multisort($newArr, SORT_DESC, $person);//SORT_DESC为降序,SORT_ASC为升序
  348 + return $person;
  349 + }
341 350
342 /*排序定时任务A 根据篇数排序*/ 351 /*排序定时任务A 根据篇数排序*/
343 public function SportA() 352 public function SportA()
@@ -347,9 +356,14 @@ class Common extends Api @@ -347,9 +356,14 @@ class Common extends Api
347 $Array = Db::name('user')->select(); 356 $Array = Db::name('user')->select();
348 foreach ($Array as $k => $v) { 357 foreach ($Array as $k => $v) {
349 $DiaryCount = Db::name('diary')->where('user_id', $v['id'])->select(); 358 $DiaryCount = Db::name('diary')->where('user_id', $v['id'])->select();
  359 + $List[$k]['user_id'] = $v['id'];
  360 + $List[$k]['num'] = count($DiaryCount);
  361 + }
  362 + $Sport_List = $this->sport($List);
  363 + foreach ($Sport_List as $k => $v) {
350 $data = [ 364 $data = [
351 - 'user_id' => $v['id'],  
352 - 'num' => count($DiaryCount), 365 + 'user_id' => $v['user_id'],
  366 + 'num' => $v['num'],
353 'createtime' => time() 367 'createtime' => time()
354 ]; 368 ];
355 Db::name('sport_a')->insert($data); 369 Db::name('sport_a')->insert($data);
@@ -364,9 +378,14 @@ class Common extends Api @@ -364,9 +378,14 @@ class Common extends Api
364 $Array = Db::name('user')->select(); 378 $Array = Db::name('user')->select();
365 foreach ($Array as $k => $v) { 379 foreach ($Array as $k => $v) {
366 $DiaryCount = Db::name('diary')->where('user_id', $v['id'])->select(); 380 $DiaryCount = Db::name('diary')->where('user_id', $v['id'])->select();
  381 + $List[$k]['user_id'] = $v['id'];
  382 + $List[$k]['num'] = count($this->second_array_unique_bykey($DiaryCount, 'createtime'));
  383 + }
  384 + $Sport_List = $this->sport($List);
  385 + foreach ($Sport_List as $k => $v) {
367 $data = [ 386 $data = [
368 - 'user_id' => $v['id'],  
369 - 'num' => count($this->second_array_unique_bykey($DiaryCount, 'createtime')), 387 + 'user_id' => $v['user_id'],
  388 + 'num' => $v['num'],
370 'createtime' => time() 389 'createtime' => time()
371 ]; 390 ];
372 Db::name('sport_b')->insert($data); 391 Db::name('sport_b')->insert($data);