123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace Act\Lib;
- use Dever;
- class Num
- {
- # 获取我在这个小刊中的本数
- public function get($id, $uid)
- {
- $where['uid'] = $uid;
- $where['journal_id'] = $id;
- $where['state'] = 1;
- $data = Dever::db('act/journal_num')->one($where);
- if ($data) {
- return $data['num'];
- } else {
- return 0;
- }
- }
-
- # 获取小刊的积分排行
- public function getList($id, $uid = false)
- {
- $key = 'journal_num_' . $id;
- $data = Dever::cache($key);
- if (!$data) {
- $where['journal_id'] = $id;
- if ($uid > 0) {
- $where['uid'] = $uid;
- }
- $data = Dever::db('act/journal_num')->getAll($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $user = Dever::load('passport/api')->info($v['uid']);
- $data[$k]['username'] = $user['username'];
- $data[$k]['avatar'] = $user['avatar'];
- $data[$k]['mobile'] = $user['mobile'];
- }
- Dever::cache($key, $data, 600);
- }
- }
-
- return $data;
- }
- public function submit($id, $uid = false, $num = false, $update = true)
- {
- $where['uid'] = $uid;
- $where['journal_id'] = $id;
- $table = 'act/journal_num';
- $db = Dever::db($table);
- $info = $db->one($where);
- if (!$info) {
- $where['num'] = $num;
- $db->insert($where);
- } else {
- if ($update) {
- $where['where_id'] = $info['id'];
- $where['num'] = $info['num'] + $num;
- $db->update($where);
- }
- }
- return true;
- }
- # 矫正数据用的,放到计划任务中
- public function cron()
- {
-
- return true;
- }
- /**
- * 导出成excel
- *
- * @return mixed
- */
- public function out_api()
- {
- $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['num'],
- );
- $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;
- }
- }
|