* add score auth

This commit is contained in:
滔哥
2017-10-31 10:03:54 +08:00
parent 2dc822ca73
commit 3d0dff1420
15 changed files with 143 additions and 110 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ ALTER TABLE `zt_team` DROP PRIMARY KEY;
ALTER TABLE `zt_team` ADD PRIMARY KEY (`project`, `task`, `account`);
ALTER TABLE `zt_user` ADD `score` DECIMAL(12,1) NOT NULL DEFAULT '0' AFTER `deleted`;
ALTER TABLE `zt_user` ADD `score_level` DECIMAL(12,1) NOT NULL DEFAULT '0' AFTER `score`;
ALTER TABLE `zt_user` ADD `scoreLevel` DECIMAL(12,1) NOT NULL DEFAULT '0' AFTER `score`;
CREATE TABLE `zt_score` (
`id` bigint(12) unsigned NOT NULL AUTO_INCREMENT,
+1 -1
View File
@@ -175,7 +175,7 @@ $lang->my->menu->dynamic = 'Dynamic|my|dynamic|';
$lang->my->menu->profile = array('link' => 'Profile|my|profile', 'alias' => 'editprofile');
$lang->my->menu->changePassword = 'Password|my|changepassword';
$lang->my->menu->manageContacts = 'Contact|my|managecontacts';
$lang->my->menu->score = array('link' => 'Score|score|browse', 'subModule' => 'score');
$lang->my->menu->score = 'Score|score|browse';
$lang->todo = new stdclass();
$lang->todo->menu = $lang->my->menu;
+1 -1
View File
@@ -175,7 +175,7 @@ $lang->my->menu->dynamic = '动态|my|dynamic|';
$lang->my->menu->profile = array('link' => '档案|my|profile', 'alias' => 'editprofile');
$lang->my->menu->changePassword = '密码|my|changepassword';
$lang->my->menu->manageContacts = '联系人|my|managecontacts';
$lang->my->menu->score = array('link' => '积分|score|browse', 'subModule' => 'score');
$lang->my->menu->score = '积分|my|score';
$lang->todo = new stdclass();
$lang->todo->menu = $lang->my->menu;
+1 -1
View File
@@ -175,7 +175,7 @@ $lang->my->menu->dynamic = '動態|my|dynamic|';
$lang->my->menu->profile = array('link' => '檔案|my|profile', 'alias' => 'editprofile');
$lang->my->menu->changePassword = '密碼|my|changepassword';
$lang->my->menu->manageContacts = '聯繫人|my|managecontacts';
$lang->my->menu->score = array('link' => '積分|score|browse', 'subModule' => 'score');
$lang->my->menu->score = '積分|my|score';
$lang->todo = new stdclass();
$lang->todo->menu = $lang->my->menu;
+2 -2
View File
@@ -1162,8 +1162,8 @@ class commonModel extends model
global $app;
if(!empty($app->user->admin)) return true;
if($module = 'todo' and ($method == 'create' or $method == 'batchcreate')) return true;
if($module = 'effort' and ($method == 'createforobject' or $method == 'batchcreate')) return true;
if($module == 'todo' and ($method == 'create' or $method == 'batchcreate')) return true;
if($module == 'effort' and ($method == 'createforobject' or $method == 'batchcreate')) return true;
// limited project
$limitedProject = false;
+3 -1
View File
@@ -85,6 +85,7 @@ $lang->resource->my->unbind = 'unbind';
$lang->resource->my->manageContacts = 'manageContacts';
$lang->resource->my->deleteContacts = 'deleteContacts';
$lang->resource->my->limited = 'limited';
$lang->resource->my->score = 'score';
$lang->my->methodOrder[0] = 'index';
$lang->my->methodOrder[5] = 'todo';
@@ -101,7 +102,8 @@ $lang->my->methodOrder[55] = 'changePassword';
$lang->my->methodOrder[60] = 'unbind';
$lang->my->methodOrder[65] = 'manageContacts';
$lang->my->methodOrder[75] = 'deleteContacts';
$lang->my->methodOrder[80] = 'limited';
$lang->my->methodOrder[80] = 'score';
$lang->my->methodOrder[85] = 'limited';
/* Todo. */
$lang->resource->todo = new stdclass();
+24
View File
@@ -37,6 +37,30 @@ class my extends control
$this->display();
}
/**
* Get score list
*
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
*
* @access public
* @return mixed
*/
public function score($recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$scores = $this->loadModel('score')->getScores($pager);
$this->view->title = $this->lang->score->common;
$this->view->user = $this->loadModel('user')->getById($this->app->user->account);
$this->view->pager = $pager;
$this->view->scores = $scores;
$this->display();
}
/**
* My todos.
*
+1
View File
@@ -18,6 +18,7 @@ $lang->my->unbind = 'Unbind Ranger';
$lang->my->manageContacts = 'Maintain Contact';
$lang->my->deleteContacts = 'Delete Contact';
$lang->my->limited = 'Restricted operation (editing only content related to itself)';
$lang->my->score = 'Score';
$lang->my->taskMenu = new stdclass();
$lang->my->taskMenu->assignedToMe = 'Assigned to Me';
+1
View File
@@ -18,6 +18,7 @@ $lang->my->unbind = '解除然之绑定';
$lang->my->manageContacts = '维护联系人';
$lang->my->deleteContacts = '删除联系人';
$lang->my->limited = '受限操作(只能编辑与自己相关的内容)';
$lang->my->score = '积分';
$lang->my->taskMenu = new stdclass();
$lang->my->taskMenu->assignedToMe = '指派给我';
+1
View File
@@ -18,6 +18,7 @@ $lang->my->unbind = '解除然之綁定';
$lang->my->manageContacts = '維護聯繫人';
$lang->my->deleteContacts = '刪除聯繫人';
$lang->my->limited = '受限操作(只能編輯與自己相關的內容)';
$lang->my->score = '積分';
$lang->my->taskMenu = new stdclass();
$lang->my->taskMenu->assignedToMe = '指派給我';
+14 -39
View File
@@ -9,44 +9,6 @@
*/
class score extends control
{
/**
* score constructor.
*
* @param string $module
* @param string $method
*
* @access public
* @return mixed
*/
public function __construct($module = '', $method = '')
{
parent::__construct($module, $method);
$this->loadModel('my')->setMenu();
}
/**
* Get score list
*
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
*
* @access public
* @return mixed
*/
public function browse($recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$scores = $this->score->getScores($pager);
$this->view->title = $this->lang->score->common;
$this->view->user = $this->loadModel('user')->getById($this->app->user->account);
$this->view->pager = $pager;
$this->view->scores = $scores;
$this->display();
}
/**
* Ajax action score
*
@@ -78,8 +40,21 @@ class score extends control
$this->display();
}
public function refresh()
public function refresh($lastID = 0)
{
if(helper::isAjaxRequest())
{
$result = $this->score->refresh($lastID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
if($result['status'] == 'finish')
{
$this->send(array('result' => 'finished', 'message' => $this->lang->score->refreshFinish));
}
else
{
$this->send(array('result' => 'unfinished', 'message' => $this->lang->score->refreshLoading, 'lastID' => $result['lastID']));
}
}
$this->display();
}
}
+28 -10
View File
@@ -48,7 +48,7 @@ class scoreModel extends model
switch($model)
{
case 'user':
if($method == 'login') $desc = $this->lang->score->methods[$model][$method] . 'IP:' . helper::getRemoteIp();
if($method == 'login') $desc = $this->lang->score->methods[$model][$method];
if($method == 'changePassword')
{
if(!empty($rule['ext'][$param])) $rule['score'] = $rule['score'] + $rule['ext'][$param];
@@ -87,7 +87,7 @@ class scoreModel extends model
}
break;
case 'bug':
$desc .= 'ID:' . $param;
if(is_numeric($param)) $desc .= 'ID:' . $param;
if($method == 'createFormCase')
{
$desc = $this->lang->score->models['testcase'] . 'ID:' . $param;
@@ -125,14 +125,14 @@ class scoreModel extends model
$objectID = $param->id;
if(!empty($param->PM))
{
$rule['score'] = $param->end > date('Y-m-d') ? $rule['ext']['manager'][0] + $rule['ext']['manager'][1] : $rule['ext']['manager'][0];
$rule['score'] = $param->end > date('Y-m-d', $time) ? $rule['ext']['manager'][0] + $rule['ext']['manager'][1] : $rule['ext']['manager'][0];
$this->saveScore($param->PM, $rule, $model, $method, $desc, $objectID, $time);
}
$teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($param->id)->fetchGroup('account');
if(!empty($teams))
{
$users = array_keys($teams);
$rule['score'] = $param->end > date('Y-m-d') ? $rule['ext']['member'][0] + $rule['ext']['member'][1] : $rule['ext']['member'][0];
$rule['score'] = $param->end > date('Y-m-d', $time) ? $rule['ext']['member'][0] + $rule['ext']['member'][1] : $rule['ext']['member'][0];
foreach($users as $user)
{
if($user != $param->PM) $this->saveScore($user, $rule, $model, $method, $desc, $objectID, $time);
@@ -208,7 +208,7 @@ class scoreModel extends model
$data->after = $user->score + $rule['score'];
$data->time = empty($time) ? helper::now() : $time;
$this->dao->insert(TABLE_SCORE)->data($data)->exec();
$this->dao->query("UPDATE " . TABLE_USER . " SET `score`=`score` + " . $rule['score'] . ",`score_level`=`score_level` + " . $rule['score'] . " WHERE `account`='" . $account . "'");
$this->dao->query("UPDATE " . TABLE_USER . " SET `score`=`score` + " . $rule['score'] . ",`scoreLevel`=`scoreLevel` + " . $rule['score'] . " WHERE `account`='" . $account . "'");
$this->dao->commit();
}
catch(ErrorException $e)
@@ -218,14 +218,32 @@ class scoreModel extends model
}
/**
* reset all user score and level score
*
* refresh all user score and level score
*
* @param int $lastID
*
* @access public
* @return void
*/
public function resetScore()
public function refresh($lastID = 0)
{
if($lastID == 0)
{
$this->dao->query("DROP TABLE IF EXISTS `score_bak`");
$this->dao->query("RENAME TABLE " . TABLE_SCORE . ' TO score_bak');
$this->dao->query("CREATE TABLE " . TABLE_SCORE . ' LIKE score_bak');
$this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`scoreLevel`=0");
}
$actions = $this->dao->select('*')->from('score_bak')->where('id')->gt($lastID)->orderBy('id_asc')->limit(100)->fetchAll('id');
if(empty($actions)) return array('num' => 0, 'status' => 'finish');
foreach($actions as $action)
{
$param = $action->objectID;
if($action->model == 'project' && $action->method == 'close') $param = $this->dao->findById($action->objectID)->from(TABLE_PROJECT)->fetch();
if($action->model == 'bug' && ($action->method == 'confirmBug' || $action->method == 'resolve')) $param = $this->dao->findById($action->objectID)->from(TABLE_BUG)->fetch();
$this->score($action->model, $action->method, $param, $action->account, $action->time);
}
return array('status' => 'more', 'lastID' => max(array_keys($actions)));
}
/**
@@ -240,7 +258,7 @@ class scoreModel extends model
{
if($lastID == 0)
{
$this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`score_level`=0");
$this->dao->query("UPDATE " . TABLE_USER . " SET `score`=0,`scoreLevel`=0");
$this->dao->query("TRUNCATE TABLE " . TABLE_SCORE);
}
$actions = $this->dao->select('*')->from(TABLE_ACTION)->where('id')->gt($lastID)->orderBy('id_asc')->limit(100)->fetchAll('id');
-53
View File
@@ -1,53 +0,0 @@
<?php
/**
* The browse view file of score module of ZenTaoPMS.
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Memory <lvtao@cnezsoft.com>
* @package score
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php'; ?>
<div id='titlebar'>
<div class='heading'><?php echo html::icon($lang->icons['score']); ?><?php echo $lang->score->record; ?></div>
<div class='actions'>
<span class='btn disabled'><label><?php echo $lang->score->current; ?>:</label><?php echo $user->score; ?></span>
<span class='btn disabled hidden'><label><?php echo $lang->score->level; ?>:</label><?php echo $user->score_level; ?></span>
</div>
</div>
<table class='table tablesorter'>
<thead>
<tr class='colhead'>
<th class="w-200px"><?php echo $lang->score->time; ?></th>
<th class="w-150px"><?php echo $lang->score->model; ?></th>
<th class="w-150px"><?php echo $lang->score->method; ?></th>
<th class="w-100px"><?php echo $lang->score->before; ?></th>
<th class="w-100px"><?php echo $lang->score->score; ?></th>
<th class="w-100px"><?php echo $lang->score->after; ?></th>
<th><?php echo $lang->score->desc; ?></th>
</tr>
</thead>
<tbody>
<?php if(!empty($scores)) foreach($scores as $score): ?>
<tr class='text-center'>
<td><?php echo $score->time; ?></td>
<td><?php echo $lang->score->models[$score->model]; ?></td>
<td><?php echo $lang->score->methods[$score->model][$score->method]; ?></td>
<td><?php echo $score->before; ?></td>
<td><?php echo $score->score; ?></td>
<td><?php echo $score->after; ?></td>
<td><?php echo $score->desc; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<td colspan='7'>
<?php $pager->show(); ?>
</td>
</tr>
</tfoot>
</table>
<?php include '../../common/view/footer.html.php'; ?>
+1 -1
View File
@@ -55,7 +55,7 @@
}
else
{
$('#loading_content').html("<li class='text-success' style='color:#"+(Math.random()*0xffffff<<0).toString(16)+"'>" + response.message + "</li>");
$('#loading_content').html("<li class='text-success' style='color:#" + (Math.random() * 0xffffff << 0).toString(16) + "'>" + response.message + "</li>");
setTimeout(function(){score_init(response.lastID);}, 2000);
}
});
+64
View File
@@ -0,0 +1,64 @@
<?php
/**
* The init view file of score module of ZenTaoPMS.
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Memory <lvtao@cnezsoft.com>
* @package score
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php'; ?>
<div class="alert with-icon" id="refresh_start">
<i class="icon-inbox"></i>
<div class="content">
<h4><?php echo $lang->score->refresh; ?></h4>
<hr>
<p><?php echo $lang->score->refreshTips; ?></p>
<p>
<button class="btn btn-primary" id="refresh_init"><?php echo $lang->score->refreshStart; ?></button>
</p>
</div>
</div>
<div class="alert alert-info with-icon hidden" id="refresh_loading">
<i class="icon-info-sign"></i>
<h4><?php echo $lang->score->refreshLoading; ?></h4>
<hr/>
<p><?php echo $lang->score->refreshTips; ?></p>
<p id="loading_content"></p>
</div>
<div class="alert alert-success with-icon hidden" id="refresh_finish">
<i class="icon-ok-sign"></i>
<div class="content">
<strong><?php echo $lang->score->refreshFinish; ?></strong>
</div>
</div>
<script>
$("#refresh_init").on('click', function()
{
$("#refresh_start").addClass('hidden');
$("#refresh_loading").removeClass('hidden');
refresh_init(0);
});
function refresh_init(lastID)
{
$.getJSON(createLink('score', 'refresh', 'lastID=' + lastID), function(response)
{
if(response.result == 'finished')
{
$("#refresh_loading").addClass('hidden');
$("#refresh_finish").removeClass('hidden');
setTimeout(function(){parent.location.reload();}, 2000);
return false;
}
else
{
$('#loading_content').html("<li class='text-success' style='color:#" + (Math.random() * 0xffffff << 0).toString(16) + "'>" + response.message + "</li>");
setTimeout(function(){refresh_init(response.lastID);}, 2000);
}
});
}
</script>
<?php include '../../common/view/footer.html.php'; ?>