dever 6 年之前
父節點
當前提交
f2c8f5f982
共有 2 個文件被更改,包括 51 次插入0 次删除
  1. 4 0
      act/database/score.php
  2. 47 0
      act/lib/Score.php

+ 4 - 0
act/database/score.php

@@ -117,6 +117,10 @@ return array
 		'insert' => false,
 		'edit' => false,
 		'delete' => false,
+		'button' => array
+		(
+			'导出排行榜' => array('location', 'act/lib/score.out'),
+		),
 	),
 
 	# 更新表结构

+ 47 - 0
act/lib/Score.php

@@ -34,6 +34,7 @@ class Score
                 $user = Dever::load('passport/api')->info($v['uid']);
                 $data[$k]['username'] = $user['username'];
                 $data[$k]['avatar'] = $user['avatar'];
+                $data[$k]['mobile'] = $user['mobile'];
             }
         }
         return $data;
@@ -82,4 +83,50 @@ class Score
 
         return true;
     }
+
+    /**
+     * 导出成excel
+     *
+     * @return mixed
+     */
+    public function out()
+    {
+        $id = Dever::input('id');
+        $journal = Dever::db('journal/info')->one($id);
+
+        if (!$journal) {
+            return;
+        }
+
+        $score = $this->getList($id);
+        $header = $data = array();
+        $name = $journal['name'];
+        if ($score) {
+            $i = 0;
+            foreach ($score as $k => $v) {
+                $data[$i] = array
+                (
+                    $i+1,
+                    $v['username'],
+                    $v['mobile'],
+                    $v['score'],
+                );
+                $i++;
+            }
+        }
+
+        $header = array
+        (
+            '排序', '用户名', '手机号', '积分'
+        );
+
+        $file = $name . '_邀请积分排行榜';
+        if (Dever::input('test')) {
+            print_r($header);
+            print_r($data);die;
+        }
+        
+        Dever::excelExport($data, $header, $file, $sheet = 0, $sheetName = $name);
+        return;
+    }
 }