|
@@ -23,8 +23,8 @@ class Core
|
|
|
if (isset($action['id'])) {
|
|
|
$log_id = Dever::db('score/action_log')->insert(array('uid' => $uid, 'action_id' => $action['id'], 'callback' => $callback));
|
|
|
|
|
|
- //Dever::deamon('lib/core.oper?log_id='.$log_id, 'score');
|
|
|
- Dever::load('score/lib/core.oper?log_id='.$log_id);
|
|
|
+ Dever::daemon('lib/core.oper?log_id='.$log_id, 'score');
|
|
|
+ //Dever::load('score/lib/core.oper?log_id='.$log_id);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -83,6 +83,9 @@ class Core
|
|
|
|
|
|
Dever::db('score/user')->update($update);
|
|
|
|
|
|
+ # 提升等级
|
|
|
+ $this->setLevel($uid);
|
|
|
+
|
|
|
if ($log['callback']) {
|
|
|
if (strstr($log['callback'], '?')) {
|
|
|
Dever::load($log['callback'] . '&user_log_id=' . $user_log_id);
|
|
@@ -166,33 +169,54 @@ class Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function cron_api()
|
|
|
- {}
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 根据积分算等级
|
|
|
*
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function level()
|
|
|
+ public function setLevel($uid)
|
|
|
{
|
|
|
- $level = Dever::db('score/level')->state();
|
|
|
-
|
|
|
- foreach ($level as $k => $v) {
|
|
|
- $config = Dever::array_decode($v['score']);
|
|
|
- if ($config) {
|
|
|
- foreach ($config as $k1 => $v1) {
|
|
|
- $score = $v1['config'];
|
|
|
- $num = $v1['num'];
|
|
|
-
|
|
|
- $user = Dever::db('score/user')->state(array('config_id' => $score, 'score' => $num));
|
|
|
+ # 获取当前用户的等级
|
|
|
+ $where['uid'] = $uid;
|
|
|
+ $user_level = Dever::db('score/user_level')->one($where);
|
|
|
+ if ($user_level && $user_level['type'] == 2) {
|
|
|
+ return;
|
|
|
+ } elseif ($user_level && $user_level['type'] == 1) {
|
|
|
+ $config = Dever::db('score/level')->one($user_level['level_id']);
|
|
|
+ $level = $config['level'] + 1;
|
|
|
+ } else {
|
|
|
+ $level = 1;
|
|
|
+ }
|
|
|
|
|
|
- if ($user) {
|
|
|
+ $config = Dever::db('score/level')->one(array('level' => $level, 'state' => 1));
|
|
|
|
|
|
+ if ($config) {
|
|
|
+ # 是否能升级
|
|
|
+ $yes = false;
|
|
|
+ $rule = Dever::array_decode($config['score']);
|
|
|
+ if ($rule) {
|
|
|
+ $user_score = Dever::db('score/user')->getScoreByConfig($where);
|
|
|
+ if ($user_score) {
|
|
|
+ foreach ($rule as $k => $v) {
|
|
|
+ $score = $v['config'];
|
|
|
+ $num = $v['num'];
|
|
|
+ if (isset($user_score[$score]) && $user_score[$score]['score'] && $user_score[$score]['score'] >= $num) {
|
|
|
+ $yes = $config['id'];
|
|
|
+ } else {
|
|
|
+ $yes = false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if ($yes) {
|
|
|
+ # 可以升级
|
|
|
+ if ($user_level) {
|
|
|
+ Dever::db('score/user_level')->update(array('where_id' => $user_level['id'], 'level_id' => $yes));
|
|
|
+ } else {
|
|
|
+ Dever::db('score/user_level')->insert(array('uid' => $uid,'level_id' => $yes, 'type' => 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|