|
@@ -3,7 +3,8 @@
|
|
|
namespace app\admin\controller\user;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
-
|
|
|
+use think\Db;
|
|
|
+use app\common\library\ExcelCsv;
|
|
|
/**
|
|
|
* 用户管理
|
|
|
*
|
|
@@ -69,4 +70,68 @@ class User extends Backend
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 统计
|
|
|
+ */
|
|
|
+ public function tongji(){
|
|
|
+ $list_exam = Db::name('user_question_log')->alias('log')
|
|
|
+ ->field('log.user_id,count(log.id) as right_num,user.nickname,user.mobile,user.bind_jigou_id,vote_jigou.title')
|
|
|
+ ->join('user','log.user_id = user.id','LEFT')
|
|
|
+ ->join('vote_jigou','user.bind_jigou_id = vote_jigou.id','LEFT')
|
|
|
+ ->where('log.is_right',1)
|
|
|
+ ->group('log.user_id')->order('right_num desc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $list_vote = Db::name('vote_record')->field('user_id,sum(vote) as vote_num')->group('user_id')->order('vote_num desc')->select();
|
|
|
+
|
|
|
+ foreach($list_exam as $key => $val){
|
|
|
+ $val['num'] = $key + 1;
|
|
|
+ $val['vote_num'] = 0;
|
|
|
+ foreach($list_vote as $k => $v){
|
|
|
+ if($val['user_id'] == $v['user_id']){
|
|
|
+ $val['vote_num'] = $v['vote_num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $list_exam[$key] = $val;
|
|
|
+ }
|
|
|
+
|
|
|
+ //只要前300名,后面的砍掉
|
|
|
+ if(count($list_exam) > 300){
|
|
|
+ $list_exam = array_chunk($list_exam,300)[0];
|
|
|
+ }
|
|
|
+// dump($list_exam);
|
|
|
+// dump($list_vote);
|
|
|
+
|
|
|
+ //导出excel
|
|
|
+ $action = input('action','');
|
|
|
+ if($action == 'export'){
|
|
|
+ //表头
|
|
|
+ $excel_header = [
|
|
|
+ 'num' => '排名',
|
|
|
+ 'user_id' => '用户ID',
|
|
|
+ 'nickname' => '用户昵称',
|
|
|
+ 'mobile' => '用户手机',
|
|
|
+ 'right_num' => '答对次数',
|
|
|
+ 'title' => '绑定机构',
|
|
|
+ 'vote_num' => '投出票数',
|
|
|
+ ];
|
|
|
+
|
|
|
+ //内容
|
|
|
+ $excel_result = $list_exam;
|
|
|
+
|
|
|
+ //文件输出
|
|
|
+
|
|
|
+
|
|
|
+ $fileName = date('Y-m-d-H-i-s');
|
|
|
+ $ExcelCsv = new ExcelCsv($excel_header, $excel_result);
|
|
|
+ $data = $ExcelCsv->collection();
|
|
|
+ $ExcelCsv->download($fileName, $excel_header, $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->assign('lists',$list_exam);
|
|
|
+ $this->view->engine->layout(false);
|
|
|
+ return $this->view->fetch();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|