1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- declare (strict_types = 1);
- namespace app\common\model;
- /**
- * 计量单位模型
- * Class Unit
- * @package app\common\model
- */
- class Unit extends BaseModel
- {
- // 定义表名
- protected $name = 'unit';
- // 定义主键
- protected $pk = 'id';
- /**
- * 获取全部记录
- * @param array $param
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getAll($param = [])
- {
- // 检索查询条件
- $filter = $this->getFilter($param);
- // 查询列表数据
- return $this->where($filter)->order(['sort', $this->getPk()])->select();
- }
- /**
- * 获取列表
- * @param array $param
- * @return \think\Paginator
- * @throws \think\db\exception\DbException
- */
- public function getList($param = [])
- {
- // 检索查询调价你
- $filter = $this->getFilter($param);
- // 查询列表数据
- return $this->where($filter)->order(['sort', 'id'])->paginate(15);
- }
- /**
- * 检索查询条件
- * @param array $param
- * @return array
- */
- private function getFilter($param = [])
- {
- // 默认查询条件
- $params = $this->setQueryDefaultValue($param, ['name' => '']);
- // 检索查询条件
- $filter = [];
- !empty($params['name']) && $filter[] = ['name', 'like', "%{$params['name']}%"];
- return $filter;
- }
- /**
- * 详情
- * @param int $providerId
- * @return null|static
- */
- public static function detail(int $providerId)
- {
- return self::get($providerId);
- }
- /**
- * 添加新记录
- * @param $data
- * @return false|int
- */
- public function add($data)
- {
- return $this->save($data);
- }
- /**
- * 编辑记录
- * @param $data
- * @return mixed
- */
- public function edit($data)
- {
- return $this->save($data) !== false;
- }
- }
|