| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\api\model;
- use think\Model;
- class BaseModel extends Model
- {
- /**
- * @param $id
- * @param array $extend
- * @return array|bool|false|\PDOStatement|string|Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function findById($id, $extend = [])
- {
- $query = $this->where("id", $id);
- $keys = array_keys($extend);
- foreach ($keys as $key) {
- $query->where("$key", "=", $extend[$key]);
- }
- return $query->find();
- }
- public function findByIds(array $ids, $extend = [])
- {
- if (0 === count($ids))
- return [];
- $query = $this->where("id", "in", $ids);
- $keys = array_keys($extend);
- foreach ($keys as $key) {
- $query->where("$key", "=", $extend[$key]);
- }
- return $query->select();
- }
- }
|