104 lines
2.6 KiB
PHP
104 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: zn
|
|
* Date: 2017/6/2
|
|
* Time: 13:30
|
|
*/
|
|
|
|
namespace common\models;
|
|
|
|
|
|
use common\services\ClientMessageServices;
|
|
use common\utils\EnumUtil;
|
|
use yii\behaviors\TimestampBehavior;
|
|
use yii\db\ActiveRecord;
|
|
|
|
/**
|
|
* 用户日志
|
|
* Class UserLog
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property int $be_user_id
|
|
* @property int $be_user_nickname
|
|
* @property int $type <p>操作类型</p>
|
|
* @property int $item_id
|
|
* @property int $num
|
|
* @property int $delete <p>是否删除,1:删除</p>
|
|
* @property int $created_at
|
|
* @property int $updated_at
|
|
*/
|
|
class UserLog extends ActiveRecord
|
|
{
|
|
|
|
public function behaviors()
|
|
{
|
|
return [
|
|
TimestampBehavior::className(),
|
|
];
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
['user_id', 'required'],
|
|
['user_id', 'exist', 'targetClass' => '\common\models\User', 'targetAttribute' => 'id'],
|
|
|
|
['be_user_id', 'default', 'value' => 0],
|
|
|
|
['be_user_nickname', 'string', 'max' => 255],
|
|
|
|
['type', 'default', 'value' => 0],
|
|
['type', 'in', 'range' => EnumUtil::USER_LOG_TYPE_LIST],
|
|
|
|
['item_id', 'default', 'value' => 0],
|
|
|
|
['num', 'default', 'value' => 0],
|
|
|
|
['delete', 'default', 'value' => EnumUtil::DELETE_NOT],
|
|
['delete', 'in', 'range' => EnumUtil::DELETE_LIST],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param $userID
|
|
* @param $offset
|
|
* @param $count
|
|
* @param $totalCount
|
|
* @return array|UserLog[]
|
|
*/
|
|
public static function findAllByUserID($userID, $offset, $count, &$totalCount)
|
|
{
|
|
$find = UserLog::find()->where(['user_id' => $userID, 'delete' => EnumUtil::DELETE_NOT])->orderBy(['updated_at' => SORT_DESC]);
|
|
$totalCount = $find->count();
|
|
|
|
return $find->offset($offset)->limit($count)->all();
|
|
}
|
|
|
|
public static function findByID($id)
|
|
{
|
|
return self::findOne(['id' => $id, 'delete' => EnumUtil::DELETE_NOT]);
|
|
}
|
|
/**
|
|
* 删除用户日志
|
|
* @param $userID
|
|
*/
|
|
public static function deleteByUserID($userID)
|
|
{
|
|
if (!$userID) return;
|
|
UserLog::updateAll(['delete' => EnumUtil::DELETE], ['user_id' => $userID, 'delete' => EnumUtil::DELETE_NOT]);
|
|
}
|
|
|
|
public function genClientData()
|
|
{
|
|
return [
|
|
'user_id' => $this->user_id,
|
|
'be_user_id' => $this->be_user_id,
|
|
'be_user_nickname' => $this->be_user_nickname,
|
|
'type' => $this->type,
|
|
'item_id' => $this->item_id,
|
|
'num' => $this->num,
|
|
'time' => $this->created_at,
|
|
];
|
|
}
|
|
} |