操作类型
* @property int $item_id * @property int $num * @property int $delete是否删除,1:删除
* @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, ]; } }