This commit is contained in:
64
app/Repository/Company/CompanyModulesRepository.php
Normal file
64
app/Repository/Company/CompanyModulesRepository.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/7/10
|
||||
* Time: 下午9:10
|
||||
* Description:
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository\Company;
|
||||
|
||||
use App\Dao\Company\CompanyModulesDao;
|
||||
use App\Repository\AbstractRepository;
|
||||
|
||||
class CompanyModulesRepository extends AbstractRepository
|
||||
{
|
||||
public function __construct(CompanyModulesDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司功能模块列表.
|
||||
*/
|
||||
public function codeList(int $company_id): array
|
||||
{
|
||||
$query = $this->dao->builder()->where('company_id', '=', $company_id);
|
||||
$role_permission_code = [];
|
||||
$data_permission_code = [];
|
||||
if (!$query->exists()) {
|
||||
return compact('role_permission_code', 'data_permission_code');
|
||||
}
|
||||
$info = $query->first(['module_code', 'module_data_permissions'])->toArray();
|
||||
$role_permission_code = $info['module_code'];
|
||||
$data_permission_code = $info['module_data_permissions'];
|
||||
return compact('role_permission_code', 'data_permission_code');
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司功能模块分配.
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function addModule(array $data): array
|
||||
{
|
||||
$query = $this->dao->builder();
|
||||
|
||||
$params = [];
|
||||
$params['company_id'] = $data['company_id'];
|
||||
$params['module_code'] = $data['menu_permission'];
|
||||
$params['module_data_permissions'] = mergePermissions($data['data_permission'] ?? []);
|
||||
$query->updateOrCreate([
|
||||
'company_id' => $params['company_id'],
|
||||
], $params);
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ declare(strict_types=1);
|
||||
namespace App\Repository\Company;
|
||||
|
||||
use App\Dao\Company\FirstCompanyDao;
|
||||
use App\Exception\ApiException;
|
||||
use App\Repository\AbstractRepository;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
@ -99,13 +100,31 @@ class FirstCompanyRepository extends AbstractRepository
|
||||
/**
|
||||
* 根据公司全称获取公司信息.
|
||||
* @param string $fullName
|
||||
* @param bool $isVerify
|
||||
* @return array|null
|
||||
*/
|
||||
public function getCompanyByFullName(string $fullName): ?array
|
||||
public function getCompanyByFullName(string $fullName, bool $isVerify = true): ?array
|
||||
{
|
||||
return $this->dao->builder()
|
||||
->select($this->dao->getFields())
|
||||
->where('full_name', '=', $fullName)
|
||||
->first()?->toArray();
|
||||
$fields = $this->dao->getFields();
|
||||
$query = $this->dao->builder()->select($fields)->where('full_name', '=', $fullName);
|
||||
$company = $query->first();
|
||||
if (!$company && $isVerify) {
|
||||
throw new ApiException('公司不存在');
|
||||
}
|
||||
return $company?->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据公司ID查询公司信息.
|
||||
*/
|
||||
public function getCompanyById(int $companyId, bool $isVerify = true): array
|
||||
{
|
||||
$fields = $this->dao->getFields();
|
||||
$query = $this->dao->builder()->select($fields)->where('id', $companyId);
|
||||
$company = $query->first()?->toArray();
|
||||
if (!$company && $isVerify) {
|
||||
throw new ApiException('公司不存在');
|
||||
}
|
||||
return $company ?? [];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user