// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\services\message; use app\dao\message\SystemPrinterDao; use app\services\BaseServices; use app\services\store\StoreConfigServices; use think\exception\ValidateException; /** * 打印机 * Class SystemPrinterServices * @package app\services\message * @mixin SystemPrinterDao */ class SystemPrinterServices extends BaseServices { public $default = [ 'store_print_type' => '', 'store_terminal_number' => '', 'store_printing_client_id' => '', 'store_printing_api_key' => '', 'store_develop_id' => '', 'store_fey_user' => '', 'store_fey_ukey' => '', 'store_fey_sn' => '', ]; /** * SystemPrinterServices constructor. * @param SystemPrinterDao $dao */ public function __construct(SystemPrinterDao $dao) { $this->dao = $dao; } /** * 获取有效的打印机 * @param int $type * @param int $relation_id * @param string $field * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getValidPrinter(int $type = 0, int $relation_id = 0, int $print_event = 2, string $field = '*') { return $this->dao->getList(['type' => $type, 'relation_id' => $relation_id, 'status' => 1, 'print_event' => $print_event], $field); } /** * 获取打印机列表 * @param array $where * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function index(array $where = []) { $list = $this->dao->getList($where); $count = $this->dao->count($where); if ($list) { foreach ($list as &$item) { $item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : ''; } } return compact('count', 'list'); } /** * 获取单个打印机信息 * @param int $id * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getInfo(int $id) { $info = $this->dao->get($id); if (!$info) { throw new ValidateException('打印机信息不存在或已删除'); } $info = $info->toArray(); /** @var StoreConfigServices $service */ $service = app()->make(StoreConfigServices::class); $data = $service->getConfigAll([], (int)$info['type'], (int)$info['relation_id'], $id); $data = array_merge($this->default, array_intersect_key($data, $this->default)); return array_merge($info, $data); } }