编辑工作台
This commit is contained in:
81
application/common/UserActLog.php
Normal file
81
application/common/UserActLog.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace app\common;
|
||||
use think\Db;
|
||||
class UserActLog
|
||||
{
|
||||
|
||||
private $aField = ['article_id','user_id','act_p_id','act_id','type','content','is_view'];
|
||||
/**
|
||||
* 添加用户操作日志
|
||||
*/
|
||||
public function addLog($aParam = []){
|
||||
//获取参数
|
||||
$aParam = empty($aParam) ? [] : $aParam;
|
||||
//获取表字段
|
||||
$aField = $this->aField;
|
||||
|
||||
$aInsert = [];
|
||||
foreach ($aField as $key => $value) {
|
||||
if(empty($aParam[$value])){
|
||||
continue;
|
||||
}
|
||||
$aInsert[$value] = $aParam[$value];
|
||||
}
|
||||
//必填参数验证
|
||||
if(empty($aInsert['article_id']) || empty($aInsert['type']) || empty($aInsert['act_id'])){
|
||||
return ['status' => 2, 'msg' => '非法操作'];
|
||||
}
|
||||
$aInsert['create_time'] = time();
|
||||
$result = Db::name('user_act_log')->insertGetId($aInsert);
|
||||
if(empty($result)){
|
||||
return ['status' => 3, 'msg' => '数据插入失败'.Db::getLastSql()."\n数据内容:",'data' => $aParam];
|
||||
}
|
||||
return ['status' => 1, 'msg' => '日志插入成功'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日志
|
||||
*/
|
||||
public function getLog($aParam = []){
|
||||
//获取参数
|
||||
$aParam = empty($aParam) ? [] : $aParam;
|
||||
//必填参数验证
|
||||
if(empty($aParam['article_id']) || empty($aParam['type']) || empty($aParam['act_id'])){
|
||||
return ['status' => 2, 'msg' => '非法操作'];
|
||||
}
|
||||
$aLog = Db::name('user_act_log')->where($aParam)->find();
|
||||
return ['status' => 1, 'msg' => '获取数据成功','data' => $aLog];
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户操作日志
|
||||
*/
|
||||
public function updateLog($aParam = []){
|
||||
//获取参数
|
||||
$aParam = empty($aParam) ? [] : $aParam;
|
||||
//必填参数验证
|
||||
if(empty($aParam['log_id'])){
|
||||
return ['status' => 2, 'msg' => '非法操作'];
|
||||
}
|
||||
//获取表字段
|
||||
$aField = $this->aField;
|
||||
$aUpdate = [];
|
||||
foreach ($aField as $key => $value) {
|
||||
if(empty($aParam[$value])){
|
||||
continue;
|
||||
}
|
||||
$aUpdate[$value] = $aParam[$value];
|
||||
}
|
||||
if(empty($aUpdate)){
|
||||
return ['status' => 2, 'msg' => '更新数据为空'];
|
||||
}
|
||||
|
||||
$aUpdate['update_time'] = time();
|
||||
$aWhere = ['log_id' => $aParam['log_id']];
|
||||
$result = Db::name('user_act_log')->where($aWhere)->limit(1)->update($aInsert);
|
||||
if($result === false){
|
||||
return ['status' => 3, 'msg' => '数据插入更新失败'.Db::getLastSql()."\n数据内容:",'data' => $aParam];
|
||||
}
|
||||
return ['status' => 1, 'msg' => '日志更新成功'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user