审查视图

model/bodySql.php 1.2 KB
1  
邓超 authored
1 2 3 4
<?php

namespace Model;
1  
邓超 authored
5 6
use Lib\DbPool;
1  
邓超 authored
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/**
 * 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 {
x  
邓超 authored
27
        return "select * from `".static::$table."` where `lists_id` = ".$id." limit 1";
1  
邓超 authored
28 29 30 31 32 33 34 35 36 37
    }

    /**
     * has
     * @param int $id
     * @return string
     * @author:dc
     * @time 2023/3/23 10:15
     */
    public static function has(int $id){
x  
邓超 authored
38
        return "select count(*) from `".static::$table."` where `lists_id` = ".$id." limit 1";
1  
邓超 authored
39 40 41
    }

1  
邓超 authored
42 43 44 45 46 47 48 49 50
    /**
     * 插入或者更新
     * @param DbPool $db
     * @param $data
     * @return int
     * @author:dc
     * @time 2023/4/10 17:30
     */
    public static function insertOrUpdate(DbPool $db,$data){
x  
邓超 authored
51 52

        if($db->count(self::has($data['lists_id']))){
1  
邓超 authored
53
            return $db->update(bodySql::$table,$data,dbWhere(['lists_id'    =>  $data['lists_id']]),false);
x  
邓超 authored
54 55
        }else{
            return $db->insert(bodySql::$table,$data,false);
1  
邓超 authored
56
        }
x  
邓超 authored
57
1  
邓超 authored
58 59
    }
1  
邓超 authored
60 61

}