<?php

namespace app\extra\basic;

class Model extends \think\Model
{

    /**
     * 数据操作
     * @param array $data
     * @param string $id
     * @return bool|int
     */
    public function setAutoData(array $data = [],string $id = "id"): bool|int
    {
        try {
            if (isset($data[$id]) && $this->where($id,$data[$id])->count()) {
                $state = $this->where($id,$data[$id])->strict(false)->update($data);
            } else {
                $state = $this->strict(false)->insertGetId($data);
            }
        } catch (\Throwable $throwable) {
            echo $throwable->getMessage()."\n";
            return false;
        }
        return $state;
    }

}