74 lines
2.3 KiB
PHP
74 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: Administrator
|
|
* Date: 2017/8/31
|
|
* Time: 10:31
|
|
*/
|
|
|
|
namespace app\controllers;
|
|
|
|
|
|
use common\modules\systemlog\SystemLog;
|
|
use common\modules\systemlog\SystemLogUtil;
|
|
use common\services\BackMessageServices;
|
|
use common\services\ResultStatusServices;
|
|
use common\utils\CommUtil;
|
|
use Yii;
|
|
use yii\rest\Controller;
|
|
|
|
|
|
class SystemController extends Controller
|
|
{
|
|
public $enableCsrfValidation = false;
|
|
public function actionSystemList()
|
|
{
|
|
$startTime = Yii::$app->request->get('start_time');
|
|
$endTime = Yii::$app->request->get('end_time');
|
|
$user_id = (int)Yii::$app->request->get('user_id');
|
|
$type=Yii::$app->request->get('type');
|
|
$current_page = (int)Yii::$app->request->get('page');
|
|
$sort = Yii::$app->request->get('sort');
|
|
|
|
$find = SystemLog::find();
|
|
if (!empty($user_id)) $find->andWhere(['=', 'user_id', $user_id]);
|
|
if (!empty($type)) $find->andWhere(['=', 'type', $type]);
|
|
if (!empty($startTime)) $find->andWhere(['>=', 'created_at', date_create($startTime)->getTimestamp()+3600*24]);
|
|
if (!empty($endTime)) $find->andWhere(['<=', 'created_at', date_create($endTime)->getTimestamp()+3600*24]);
|
|
|
|
|
|
$total = $find->count();
|
|
|
|
$per_page = 12;
|
|
$last_page = ceil($total / $per_page);
|
|
|
|
$find->offset($per_page * ($current_page - 1))->limit($per_page);
|
|
|
|
if (!empty($sort)) {
|
|
list($field, $sortType) = explode("|", $sort);
|
|
if (!empty($field) && !empty($sortType)) {
|
|
$type = SORT_ASC;
|
|
if ($sortType == 'desc') $type = SORT_DESC;
|
|
$find->addOrderBy([$field => $type]);
|
|
}
|
|
}
|
|
$dbList = $find->all();
|
|
$list = [];
|
|
foreach ($dbList as $item) {
|
|
$itemData = $item->toArray();
|
|
$itemData['created_at'] = CommUtil::formatDate($item->created_at);
|
|
array_push($list, $itemData);
|
|
}
|
|
|
|
$returnData['data'] = $list;
|
|
$returnData['total'] = $total;
|
|
$returnData['per_page'] = $per_page;
|
|
$returnData['current_page'] = $current_page;
|
|
$returnData['last_page'] = $last_page;
|
|
return BackMessageServices::sendMessage(ResultStatusServices::RS_OPERATION_SUCCESS, $returnData);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
?>
|