协程版仓库后端项目
Some checks failed
Build Docker / build (push) Has been cancelled

This commit is contained in:
2025-07-08 14:59:47 +08:00
commit 0b2299c427
134 changed files with 19277 additions and 0 deletions

View File

@ -0,0 +1,72 @@
<?php
/**
* Author: ykxiao
* Date: 2024/12/24
* Time: 下午3:04
* 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);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Repository;
use App\Service\Trait\ColumnConfigTrait;
/**
* Author: ykxiao
* Date: 2024/12/24
* Time: 下午3:06
* Description: BaseRepository类用于提供一个基本的仓库模式实现。它包含一个DAO数据访问对象属性并允许通过魔术方法动态调用DAO上的方法。
*
* (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.
*/
class AbstractRepository
{
use ColumnConfigTrait;
/**
* 存储数据访问对象的属性。
* @var string
*/
protected mixed $dao;
/**
* 当尝试调用不存在的实例方法时,自动调用此方法。
* 允许通过对象的动态方法调用DAO上的相应方法。
* @param string $name 被调用的方法名
* @param array $arguments 被调用方法的参数数组
* @return mixed 返回DAO方法的执行结果
*/
public function __call(string $name, array $arguments)
{
// 动态调用DAO上的方法。
return call_user_func_array([$this->dao, $name], $arguments);
}
/**
* 设置DAO对象。
* 用于设置存储数据访问对象的属性。
* @param string $dao 数据访问对象的实例
*/
public function setDao(string $dao): void
{
$this->dao = $dao;
}
}

View File

@ -0,0 +1,87 @@
<?php
/**
* Author: ykxiao
* Date: 2025/6/5
* Time: 下午6:00
* 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\CompanyDao;
use App\Repository\AbstractRepository;
use Exception;
use function Hyperf\Collection\collect;
/**
* Author: ykxiao
* Date: 2025/6/5
* Time: 下午6:01
* Description: CompanyRepository类用于提供公司相关的数据访问和操作。它继承自AbstractRepository类并实现了CompanyDao接口。
*
* (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.
*/
class CompanyRepository extends AbstractRepository
{
public function __construct(CompanyDao $dao)
{
$this->dao = $dao;
}
/**
* 添加公司。
* @param array $data
* @return void
* @throws Exception
*/
public function add(array $data): void
{
$count = $this->dao->builder();
if (!empty($data['id'])) {
$count->where('id', '!=', $data['id']);
}
// 重复验证邮箱和手机号码
$make = $this->dao->make();
$verify = $make->verifyData(clone $count);
$collect = clone collect($verify->get());
$errors = [];
if ($collect->where('name', '=', $data['name'])->isNotEmpty()) {
$errors[] = '公司名称已存在';
}
if (!empty($errors)) {
throw new Exception(implode(',', $errors));
}
$this->dao->commonCreate($this->paramsData($data));
}
/**
* 处理参数数据。
* @param array $params
* @return array
*/
private function paramsData(array $params): array
{
if (empty($params['id'])) {
return $params;
}
return [
'id' => $params['id'],
'company_type' => $params['company_type'], // 公司类别1开证 2收货
'name' => $params['name'], // 公司名称
'status' => $params['status'] // 状态0禁用 1启用
];
}
}

View File

@ -0,0 +1,111 @@
<?php
/**
* Author: ykxiao
* Date: 2025/6/5
* Time: 下午9:25
* 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\FirstCompanyDao;
use App\Repository\AbstractRepository;
use Carbon\Carbon;
use Exception;
use function Hyperf\Collection\collect;
/**
* Author: ykxiao
* Date: 2025/6/5
* Time: 下午9:26
* 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.
*/
class FirstCompanyRepository extends AbstractRepository
{
public function __construct(FirstCompanyDao $dao)
{
$this->dao = $dao;
}
/**
* 新增公司.
* @throws Exception
*/
public function addCompany(array $data): void
{
$count = $this->dao->builder();
// 重复字段验证
$make = $this->dao->make();
$verify = $make->verifyData(clone $count, $data);
$collect = clone collect($verify->get());
$errors = [];
if ($collect->where('name', '=', $data['name'])->isNotEmpty()) {
$errors[] = '公司简称已存在';
}
if ($collect->where('full_name', '=', $data['full_name'])->isNotEmpty()) {
$errors[] = '公司全称已存在';
}
if ($collect->where('mobile', '=', $data['mobile'])->isNotEmpty()) {
$errors[] = '负责人手机已存在';
}
if (!empty($errors)) {
throw new Exception(implode(',', $errors));
}
$this->dao->commonCreate($this->paramsData($data));
}
/**
* 参数处理.
*/
private function paramsData(array $params): array
{
if (empty($params['id'])) {
return $params;
}
return [
'id' => $params['id'],
'domain' => $params['domain'],
'name' => $params['name'],
'full_name' => $params['full_name'],
'company_type' => $params['company_type'],
'address' => $params['address'] ?? '',
'logo' => $params['logo'] ?? '',
'owner' => $params['owner'] ?? '', // 公司负责人
'id_card' => $params['id_card'] ?? '', // 法人身份证
'mobile' => $params['mobile'],
'org_code' => $params['org_code'] ?? '',
'remark' => $params['remark'] ?? '',
'active_status' => $params['active_status'],
'activation_date' => Carbon::parse($params['activation_date'])->timestamp,
];
}
/**
* 根据公司全称获取公司信息.
* @param string $fullName
* @return array|null
*/
public function getCompanyByFullName(string $fullName): ?array
{
return $this->dao->builder()
->select($this->dao->getFields())
->where('full_name', '=', $fullName)
->first()?->toArray();
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Author: ykxiao
* Date: 2025/6/5
* Time: 下午5:31
* 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\Purchase;
use App\Dao\Purchase\PurchaseDao;
use App\Repository\AbstractRepository;
/**
* Author: ykxiao
* Date: 2025/6/5
* Time: 下午5:32
* Description: PurchaseRepository类用于提供采购相关的数据访问和操作。它继承自AbstractRepository类并实现了PurchaseDao接口。
*
* (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.
*/
class PurchaseRepository extends AbstractRepository
{
public function __construct(PurchaseDao $dao)
{
$this->dao = $dao;
}
public function addPurchase(array $data): void
{
}
}