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) { $where = ' 1=1 '; foreach ($keyCol as $key => $col) { $where .= " and " . $col[0] . " = '" . $col[1] . "'"; } // echo "select count(*) from $this->table where $where "; list($cnt) = DB::fields( "select count(*) from $this->table where $where " ); if ($cnt == 0) { foreach ($keyCol as $key => $col) { $data[$col[0]] = $col[1]; } self::create($data); } else { self::update($keyCol, $data); } } public function delete(array $keyCol, array $data) { $where = ' 1=1 '; foreach ($keyCol as $key => $col) { $where .= " and " . $col[0] . " = '" . $col[1] . "'"; } // echo "delete from $this->table where $where "; DB::query( "delete from $this->table where $where " ); } 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]; } $where = ' 1=1 '; foreach ($keyCol as $key => $col) { $where .= " and " . $col[0] . " = '" . $col[1] . "'"; } DB::update_table($this->table, $_data, $where); } /** * 获取记录 * * @param array $cond * @return void */ public function get(array $cond) { return []; } }