Merge branch 'feature/mzl_dev' into develop
# Conflicts: # app/admin/service/SysDictService.php
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\ApprovalInstancesValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\admin\model\ApprovalInstances;
|
||||
|
||||
class ApprovalInstancesService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalInstances::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = ApprovalInstancesValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\ApprovalRecordsValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\admin\model\ApprovalRecords;
|
||||
use support\Request;
|
||||
|
||||
class ApprovalRecordsService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalRecords::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = ApprovalRecordsValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
$config['with'] = [
|
||||
'approvalInstance',
|
||||
'approver',
|
||||
'approvalInstance.flows',
|
||||
'approvalInstance.initiator',
|
||||
'approvalInstance.bizInfo'
|
||||
];
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
public function serviceApprove(Request $request)
|
||||
{
|
||||
$param = $request->all();
|
||||
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||
return $appro->approve($param['instance_id'], $request->user->uid, $param['action'], $param['comment']);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ namespace app\admin\service;
|
||||
use app\admin\validate\SysDictValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysDict;
|
||||
use app\common\model\SysDictCategory;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use support\Request;
|
||||
@@ -151,4 +154,89 @@ class SysDictService
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
示例用法:
|
||||
|
||||
// 1) 获取分类为“车辆类型”的所有字典
|
||||
$list = $dictService->getDictsByCategoryName('车辆类型');
|
||||
// => [['dict_code' => 'SUV', 'dict_name' => '越野车'], …]
|
||||
|
||||
// 2) 获取某分类下某个 code 的名称
|
||||
$name = $dictService->getDictName('车辆类型', 'SUV');
|
||||
// => "越野车"
|
||||
|
||||
// 3) 获取某分类下拉选项
|
||||
$options = $dictService->getDictOptions('车辆类型');
|
||||
// => ['SUV' => '越野车', 'SEDAN' => '轿车', …]
|
||||
|
||||
// 4) 通过 code 直接拿名称(不管分类)
|
||||
$name = $dictService->getNameByCode('SUV');
|
||||
// => "越野车"
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 根据分类名获取字典列表
|
||||
*/
|
||||
public function getDictsByCategoryName(string $categoryName): array
|
||||
{
|
||||
$category = SysDictCategory::where('category_name', $categoryName)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
|
||||
if (!$category) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $category->dicts()->get(['dict_code', 'dict_name'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类名 + 字典code 获取字典项名称
|
||||
*/
|
||||
public function getDictName(string $categoryName, string $dictCode): ?string
|
||||
{
|
||||
$dict = SysDict::whereHas('category', function ($q) use ($categoryName) {
|
||||
$q->where('category_name', $categoryName)->where('status', 1);
|
||||
})
|
||||
->where('dict_code', $dictCode)
|
||||
->where('status', 1)
|
||||
->whereNull('deleted_at')
|
||||
->first();
|
||||
|
||||
return $dict?->dict_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类名获取下拉键值对
|
||||
* 返回格式:['code1' => '名称1', 'code2' => '名称2']
|
||||
*/
|
||||
public function getDictOptions(string $categoryName): array
|
||||
{
|
||||
$dicts = $this->getDictsByCategoryName($categoryName);
|
||||
|
||||
$options = [];
|
||||
foreach ($dicts as $item) {
|
||||
$options[$item['dict_code']] = $item['dict_name'];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典 code 获取对应的名称(不依赖分类)
|
||||
*/
|
||||
public function getNameByCode(string $dictCode): ?string
|
||||
{
|
||||
$dict = SysDict::where('dict_code', $dictCode)
|
||||
->where('status', 1)
|
||||
->whereNull('deleted_at')
|
||||
->first();
|
||||
|
||||
return $dict?->dict_name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user