12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace Act\Lib;
- use Dever;
- class Score
- {
- # 获取我在这个小刊中的积分
- public function get($id, $uid, $type = 4)
- {
- $where['uid'] = $uid;
- $where['type'] = $type;
- $where['data_id'] = $id;
- $where['state'] = 1;
- $data = Dever::db('act/score')->one($where);
- if ($data) {
- return $data['score'];
- } else {
- return 0;
- }
- }
-
- # 获取小刊的积分排行
- public function getList($id, $type = 4)
- {
- $where['type'] = $type;
- $where['data_id'] = $id;
- $data = Dever::db('act/score')->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'];
- }
- }
- return $data;
- }
- public function submit()
- {
- $user_log_id = Dever::input('user_log_id');
- $type = Dever::input('type', 4);
- $id = Dever::input('id');
- $method = Dever::input('method');
- $user_log = Dever::db('score/user_log')->one($user_log_id);
- if ($user_log) {
- if ($method == 'share' || $method == 'pay' || $method == 'code') {
- # 活动结束后,无法增加当前小刊积分
- if ($type == 4) {
- $journal = Dever::db('journal/active')->one(array('info_id' => $id, 'state' => 1));
- if (!$journal) {
- return;
- }
- if ($journal && $journal['status'] == 2) {
- return;
- }
- if ($journal && time() > $journal['end']) {
- return;
- }
- }
- }
- //$where['user_log_id'] = $user_log_id;
- $where['uid'] = $user_log['uid'];
- $where['data_id'] = $id;
- $where['type'] = $type;
- $table = 'act/score';
- $info = Dever::db($table)->one($where);
- if (!$info) {
- $where['score'] = $user_log['num'];
- Dever::db($table)->insert($where);
- } else {
- $where['where_id'] = $info['id'];
- $where['score'] = $info['score'] + $user_log['num'];
- Dever::db($table)->update($where);
- }
- }
- return true;
- }
- }
|