diff --git a/extend/catcher/traits/db/BaseOptionsTrait.php b/extend/catcher/traits/db/BaseOptionsTrait.php index a36139e..d7e1af6 100644 --- a/extend/catcher/traits/db/BaseOptionsTrait.php +++ b/extend/catcher/traits/db/BaseOptionsTrait.php @@ -12,14 +12,12 @@ trait BaseOptionsTrait */ public function storeBy(array $data) { - if ($this->allowField($this->field)->save($data)) { - return $this->{$this->getPk()}; - } + $model = parent::create($data, $this->field, true); - return false; + return $model->{$this->getPk()}; } - /** + /**33 * * @time 2019年12月03日 * @param $id @@ -67,6 +65,35 @@ trait BaseOptionsTrait return static::destroy($id, $force); } + /** + * 批量插入 + * + * @time 2020年04月19日 + * @param array $data + * @return mixed + */ + public function insertAllBy(array $data) + { + $newData = []; + foreach ($data as $item) { + foreach ($item as $field => $value) { + if (!in_array($field, $this->field)) { + unset($item[$field]); + } + + if (in_array('created_at', $this->field)) { + $item['created_at'] = time(); + } + + if (in_array('updated_at', $this->field)) { + $item['updated_at'] = time(); + } + } + $newData[] = $item; + } + return $this->insertAll($newData); + } + /** * @time 2019年12月07日 * @param $id