123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /**
- * @Name
- * @Description
- * @Author 刘学玺
- * @Date 2024/8/27 10:52
- */
- namespace App\Http\Services\Backend\Server\System;
- use App\Http\Services\Service;
- use App\Models\System\Dept;
- use App\Models\System\DictData;
- use App\Models\System\DictType;
- use Symfony\Component\HttpFoundation\Response;
- class DeptService extends Service
- {
- protected array $simpleColumn = ['id', 'name', 'parent_id as parentId'];
- protected array $selectColumn = ['id', 'name', 'parent_id as parentId', 'sort', 'leader_user_id as leaderUserId', 'status'];
- protected array $selectAppendColumn = ['created_at as createTime'];
- public function getDeptSimpleList(): array
- {
- return Dept::query()->select($this->simpleColumn)->get()->all();
- }
- public function getDeptList($params)
- {
- $dept = Dept::query();
- isset($params['name']) && filled($params['name']) && $dept->whereLike('name', "%{$params['name']}%");
- isset($params['status']) && filled($params['status']) && $dept->where('status', $params['status']);
- $deptPage = $dept->paginate($params['pageSize'], [...$this->selectColumn, ...$this->selectAppendColumn], 'page', $params['pageNo']);
- return ['list' => $deptPage->items(), 'total' => $deptPage->total()];
- }
- public function createDictData($data)
- {
- // 校验字典类型有效
- // $this->validateDictTypeExists($data['dictType']);
- // // 校验字典数据的值的唯一性
- // $this->validateDictDataValueUnique($data['dictType'], $data['value']);
- //
- // // 插入字典类型
- // $dictData = self::toModel($data, DictData::class);
- // return $dictData->create($dictData->getAttributes())->id;
- }
- public function getDictData(int $id)
- {
- // return DictData::query()->select($this->selectColumn)->find($id);
- }
- public function updateDictData(array $data, int $id)
- {
- // 校验字典类型有效
- // $this->validateDictTypeExists($data['dictType']);
- //
- // // 校验字典数据的值的唯一性
- // $this->validateDictDataValueUnique($data['dictType'], $data['value'], $id);
- // // 修改字典数据
- // $dictData = self::toModel([...$data, 'id' => $id], DictData::class);
- // $dictData->update($dictData->getAttributes());
- }
- public function deleteDictData(int $id)
- {
- // $dictData = DictData::query()->find($id);
- // is_null($dictData) && self::error('DICT_DATA_NOT_EXISTS', Response::HTTP_UNPROCESSABLE_ENTITY);
- // return $dictData->delete();
- }
- protected function validateDictTypeExists($dictType)
- {
- $isExists = DictType::query()->where('type', $dictType)->exists();
- !$isExists && self::error('DICT_TYPE_NOT_EXISTS', Response::HTTP_UNPROCESSABLE_ENTITY);
- }
- protected function validateDictDataValueUnique(string $type, string $value, int $id = null)
- {
- $dictDataId = DictData::query()->where(['dict_type' => $type, 'value' => $value])->value('id');
- !empty($dictDataId) && $dictDataId !== $id && self::error('DICT_DATA_DUPLICATE', Response::HTTP_UNPROCESSABLE_ENTITY);
- }
- }
|