<?php
namespace app\model;

use think\Model;

class ClickCount extends Model
{
    protected $table = "jm_click_count";

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';


    public static function docClickCount($md5):bool
    {
        $docClickCount = ClickCount::where('md5' , $md5)->find();
        if($docClickCount) {
            $result = ClickCount::where('md5', $md5)->update(
                [
                    'click_count' => $docClickCount->click_count + 1
                ]
            );
        } else {
            $result = ClickCount::create(
                [
                    'md5' => $md5 ,
                ]
            );
        }

        if( ! $result) {
            return false;
        }
        return true;
    }

}