// +---------------------------------------------------------------------- namespace app\dao\driver\express; use crmeb\basic\BaseDao; use app\model\driver\express\ExpressDriver; /** * 电子面单驱动数据访问层 * Class ExpressDriverDao * @package app\dao\driver\express */ class ExpressDriverDao extends BaseDao { /** * @return string */ protected function setModel(): string { return ExpressDriver::class; } /** * 获取列表 * @param array $where * @param array|string[] $field * @param int $page * @param int $limit * @param null $sort * @param array $with * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getList(array $where = [], array $field = ['*'], int $page = 0, int $limit = 0, $sort = null, array $with = []) { return $this->search($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) { $query->page($page, $limit); })->when($sort, function ($query) use ($sort) { if (is_array($sort)) { foreach ($sort as $v => $k) { if (is_numeric($v)) { $query->order($k, 'desc'); } else { $query->order($v, $k); } } } else { $query->order($sort); } })->with($with)->select()->toArray(); } /** * 根据 driver_key 获取驱动信息 * @param string $driverKey * @return array|\think\Model|null * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getByDriverKey(string $driverKey) { return $this->search(['driver_key' => $driverKey])->find(); } /** * 获取所有启用的驱动 * @return array * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getEnabledDrivers() { return $this->search(['status' => 1])->order('sort', 'desc')->select()->toArray(); } }