<?php

namespace app\admin\model;

use app\BaseModel;
use think\facade\Db;

class UserView extends BaseModel
{

    public static function addData($url,$user_id)
    {
        $website_id = Website::where('url', $url)->value('id');
        if (!$website_id) {
            $res = Website::create([
                'url'=>$url,
                'num' => 1,
            ]);
            $website_id = $res->id;
        } else {
            Website::where('id', $website_id)->update([
                'num' => Db::raw('num + 1'),
            ]);
        }
        self::create([
            'website_id' => $website_id,
            'user_id' => $user_id,
            'created_at' => date('Y-m-d H:i:s'),
        ]);
        return true;
    }
}