<?php namespace Model; use Lib\DbPool; /** * body * @author:dc * @time 2023/3/23 10:13 * Class bodySql * @package Model */ class bodySql { public static $table = 'bodies'; /** * * @param int $id * @return string * @author:dc * @time 2023/3/23 10:15 */ public static function first(int $id):string { return "select * from `".static::$table."` where `lists_id` = ".$id." limit 1"; } /** * has * @param int $id * @return string * @author:dc * @time 2023/3/23 10:15 */ public static function has(int $id){ return "select count(*) from `".static::$table."` where `lists_id` = ".$id." limit 1"; } /** * 插入或者更新 * @param DbPool $db * @param $data * @return int * @author:dc * @time 2023/4/10 17:30 */ public static function insertOrUpdate(DbPool $db,$data){ if($db->count(self::has($data['lists_id']))){ return $db->update(bodySql::$table,$data,dbWhere(['lists_id' => $data['lists_id']]),false); }else{ return $db->insert(bodySql::$table,$data,false); } } }