You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
<?php
|
|
class Model
|
|
{
|
|
protected $table = '';
|
|
protected $fillable = [];
|
|
/**
|
|
* 创建记录
|
|
*
|
|
* @param array $data
|
|
* @return void
|
|
*/
|
|
public function create(array $data)
|
|
{
|
|
$_data = [];
|
|
foreach ($this->fillable as $col) {
|
|
$_data[$col] = empty($data[$col]) ? '' : $data[$col];
|
|
}
|
|
DB::insert_table($this->table, $_data);
|
|
}
|
|
/**
|
|
* 创建或更新
|
|
*
|
|
* @return void
|
|
*/
|
|
public function createOrUpdate(array $keyCol, array $data)
|
|
{
|
|
list($cnt) = DB::fields(
|
|
"select count(*) from $this->table where " . $keyCol[0] . " = '" . $keyCol[1] . "'"
|
|
);
|
|
if ($cnt == 0) {
|
|
self::create(array_merge($data, $keyCol));
|
|
}
|
|
}
|
|
|
|
public function update(array $keyCol, array $data)
|
|
{
|
|
$_data = [];
|
|
foreach ($this->fillable as $col) {
|
|
if (in_array($col, array_keys($data))) $_data[$col] = empty($data[$col]) ? '' : $data[$col];
|
|
}
|
|
DB::update_table($this->table, $_data, $keyCol[0] . '=\'' . $keyCol[1] . '\'');
|
|
}
|
|
/**
|
|
* 获取记录
|
|
*
|
|
* @param array $cond
|
|
* @return void
|
|
*/
|
|
public function get(array $cond)
|
|
{
|
|
return [];
|
|
}
|
|
}
|
|
|