Merge branch 'develop'
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\ApprovalFlowsValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\admin\model\ApprovalFlows;
|
||||
use support\Request;
|
||||
|
||||
class ApprovalFlowsService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = ApprovalFlows::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = ApprovalFlowsValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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,91 @@
|
||||
<?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'
|
||||
];
|
||||
|
||||
// $config['dataLimit']['type'] = 'relation';
|
||||
// $config['dataLimit']['userId'] = $request->user->uid;
|
||||
// $config['dataLimit']['userField'] = 'approver_id';
|
||||
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;
|
||||
case 'logs':
|
||||
$config['where']['instance_id'] = $p['instance_id'];
|
||||
$config['order']['id'] = 'desc';
|
||||
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']);
|
||||
}
|
||||
|
||||
|
||||
public function serviceLogs(Request $request)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'logs');
|
||||
$item = $this->logicListAll($config);
|
||||
return $this->postProcess('Logs', $item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\BrandSeriesValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\BrandSeries;
|
||||
use support\Request;
|
||||
|
||||
class BrandSeriesService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = BrandSeries::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = BrandSeriesValidate::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']['sort'] = 'desc';
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
$config['where']['brand_id'] = $p['brand_id'];
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['series_code','series_name'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\BrandValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\Brand;
|
||||
use support\Request;
|
||||
|
||||
class BrandService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = Brand::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = BrandValidate::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']['sort'] = 'desc';
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['brand_code','brand_name'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\SysAccountValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysAccount;
|
||||
use support\Request;
|
||||
|
||||
class SysAccountService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysAccount::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysAccountValidate::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']['sort'] = 'desc';
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 状态
|
||||
if (isset($p['type']) && $p['type']) {
|
||||
$config['where']['type'] = $p['type'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['account_name','account_number','bank_name','bank_branch','description'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\SysCurrencyValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysCurrency;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use support\Request;
|
||||
|
||||
class SysCurrencyService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysCurrency::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysCurrencyValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造 CrudUtil 查询配置
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'default':
|
||||
$config['order']['id'] = 'desc';
|
||||
case 'index':
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public $translatFields = ['currency_name'];
|
||||
|
||||
public function afterServiceStore($res)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$data = $res->toArray();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'sys_currency',
|
||||
$res['id'],
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\logic\SysDictCategoryLogic;
|
||||
use app\admin\validate\SysDictCategoryValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysDictCategory;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
class SysDictCategoryService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysDictCategory::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysDictCategoryValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
/**
|
||||
* 获取系统list
|
||||
*/
|
||||
public function getList($params)
|
||||
{
|
||||
return (new SysDictCategoryLogic)->getList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\SysDictItemValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysDictItem;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use support\Request;
|
||||
|
||||
class SysDictItemService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysDictItem::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysDictItemValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
// ====== ====== 排序 ====== ======
|
||||
$config['order']['sort'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
|
||||
$config['where']['dict_id'] = $p['id'];
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['item_label','item_value','remark'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'update':
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public $translatFields = ['item_label','remark'];
|
||||
|
||||
public function afterServiceStore($res)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$data = $res->toArray();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'sys_dict_item',
|
||||
$res['id'],
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
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 support\Request;
|
||||
|
||||
class SysDictService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysDict::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysDictValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'index':
|
||||
// ====== ====== 排序 ====== ======
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 分类筛选
|
||||
if (isset($p['category_id']) && !empty($p['category_id'])) {
|
||||
$config['where']['category_id'] = $p['category_id'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['dict_name','dict_code','description'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
|
||||
// ====== ====== 关联 ====== ======
|
||||
$config['with']['sysDictItem'][] = 'item_label';
|
||||
$config['with']['sysDictItem'][] = 'item_value';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
// ====== ====== 关联 ====== ======
|
||||
$config['with']['sysDictItem'][] = 'item_label';
|
||||
$config['with']['sysDictItem'][] = 'item_value';
|
||||
break;
|
||||
case 'update':
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'scope':
|
||||
$config['order']['id'] = 'desc';
|
||||
// 决定查id还是code
|
||||
$scopeType = 0;
|
||||
if (isset($p['scope_type']) && $p['scope_type'] > 0) {
|
||||
$scopeType = 1;
|
||||
}
|
||||
if (isset($p['scope']) && !empty($p['scope'])) {
|
||||
if ($scopeType == 1) {
|
||||
$config['where']['dict_code'] = ['in', explode(',', $p['scope'])];
|
||||
} else {
|
||||
$config['where']['id'] = ['in', explode(',', $p['scope'])];
|
||||
}
|
||||
}
|
||||
$config['with']['sysDictItem'][] = 'dict_id';
|
||||
$config['with']['sysDictItem'][] = 'item_label';
|
||||
$config['with']['sysDictItem'][] = 'item_value';
|
||||
break;
|
||||
case 'group':
|
||||
$config['order']['id'] = 'desc';
|
||||
$config['where']['id'] = 1;
|
||||
$config['with']['sysDictItem'][] = 'dict_id';
|
||||
$config['with']['sysDictItem'][] = 'item_label';
|
||||
$config['with']['sysDictItem'][] = 'item_value';
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function group(Request $request)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'group');
|
||||
$result = $this->logicShow($config);
|
||||
return $this->postProcess('group', $result);
|
||||
}
|
||||
|
||||
|
||||
public function serviceListAllScope(Request $request)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'scope');
|
||||
$result = $this->logicListAll($config);
|
||||
return $this->postProcess('ListAllScope', $result);
|
||||
}
|
||||
|
||||
|
||||
public function afterServiceListAllScope($data)
|
||||
{
|
||||
|
||||
// $data->each(function (&$item) {
|
||||
|
||||
// });
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public $translatFields = ['dict_name', 'description'];
|
||||
|
||||
public function afterServiceStore($res)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$data = $res->toArray();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'sys_dict',
|
||||
$res['id'],
|
||||
$sourceLocale,
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\SysPortValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysPort;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use support\Request;
|
||||
|
||||
class SysPortService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = SysPort::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = SysPortValidate::class;
|
||||
|
||||
public $translatFields = ['port_name','description'];
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
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']['sort'] = 'desc';
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['port_code','port_name'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
// 场景
|
||||
if (isset($p['scene']) && $p['scene']) {
|
||||
if($p['country_id'] == 'domestic'){
|
||||
$config['where']['country_id'] = 45;
|
||||
}else{
|
||||
$config['where']['country_id'] = ['<>', 45];
|
||||
}
|
||||
}
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
if(empty($data['lat']))
|
||||
unset($data['lat']);
|
||||
if(empty($data['lng']))
|
||||
unset($data['lng']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function afterServiceStore($res)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$data = $res->toArray();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'sys_port_translation',
|
||||
$res['id'],
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceUpdate($data, Request $request)
|
||||
{
|
||||
if(empty($data['lat']))
|
||||
unset($data['lat']);
|
||||
if(empty($data['lng']))
|
||||
unset($data['lng']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,9 @@ class UserService
|
||||
if (isset($p['id']) && $p['id']) {
|
||||
$config['where']['id'] = $p['id'];
|
||||
}
|
||||
if (isset($p['corp_id']) && $p['corp_id']) {
|
||||
$config['where']['corp_id'] = $p['corp_id'];
|
||||
}
|
||||
|
||||
$config['fields'] = ['id','sn', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', 'report_to', 'status', 'created_at'];
|
||||
|
||||
@@ -113,6 +116,7 @@ class UserService
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'edit':
|
||||
case 'updateSign':
|
||||
$config['where']['id'] = $request->user->uid;
|
||||
break;
|
||||
}
|
||||
@@ -154,4 +158,13 @@ class UserService
|
||||
$user = $this->logicUpdateBy($config,$data);
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function serviceUpdateSign(Request $request, array $data)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'updateSign');
|
||||
$user = $this->logicUpdateBy($config,$data);
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\VehColorValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\VehColor;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use support\Request;
|
||||
|
||||
class VehColorService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = VehColor::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = VehColorValidate::class;
|
||||
|
||||
public $translatFields = ['color_text'];
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
public function afterServiceStore($res)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$data = $res->toArray();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'veh_color_translation',
|
||||
$res['id'],
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一的7位颜色编码
|
||||
* 格式:C + (O/I) + 5位字母数字组合
|
||||
*
|
||||
* @param int $type 类型:2=I,其他=O
|
||||
* @return string 7位唯一编码
|
||||
*/
|
||||
public function generateUniqueColorCode($type)
|
||||
{
|
||||
$secondChar = $type ==2 ? 'I' : 'O';
|
||||
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$maxAttempts = 10; // 防止无限循环
|
||||
|
||||
for ($attempt = 0; $attempt < $maxAttempts; $attempt++) {
|
||||
// 生成后5位随机字符
|
||||
$suffix = '';
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$suffix .= $chars[rand(0, strlen($chars) - 1)];
|
||||
}
|
||||
|
||||
$colorCode = 'C' . $secondChar . $suffix;
|
||||
|
||||
// 检查是否已存在
|
||||
$existing = VehColor::where('color_code', $colorCode)->first();
|
||||
if (!$existing) {
|
||||
return $colorCode;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果1000次尝试后仍然重复,使用时间戳确保唯一性
|
||||
$timestamp = substr(time(), -5);
|
||||
return 'C' . $secondChar . $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
$type = $data['type'] ?? 0;
|
||||
$data['color_code'] = $this->generateUniqueColorCode($type);
|
||||
$data['created_by'] = $request->user->uid;
|
||||
$data['updated_by'] = $request->user->uid;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceUpdate($data, Request $request)
|
||||
{
|
||||
$data['updated_by'] = $request->user->uid;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\admin\validate\VehModificationValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\VehModification;
|
||||
use support\Request;
|
||||
|
||||
class VehModificationService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = VehModification::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = VehModificationValidate::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']['sort'] = 'desc';
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
// ====== ====== 筛选 ====== ======
|
||||
// 状态
|
||||
if (isset($p['status']) && in_array($p['status'], [0,1])) {
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
// 状态
|
||||
if (isset($p['type']) && $p['type']) {
|
||||
$config['where']['type'] = $p['type'];
|
||||
}
|
||||
// 关键字
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$k = '%' . $p['keyword'] . '%';
|
||||
foreach (['code','name'] as $col) {
|
||||
$config['orWhere'][] = [$col, 'like', $k];
|
||||
}
|
||||
}
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
//$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一的7位颜色编码
|
||||
* 格式:C + (O/I) + 5位字母数字组合
|
||||
*
|
||||
* @param int $type 类型
|
||||
* @return string 7位唯一编码
|
||||
*/
|
||||
public function generateUniqueModificationCode($type)
|
||||
{
|
||||
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$maxAttempts = 10; // 防止无限循环
|
||||
|
||||
for ($attempt = 0; $attempt < $maxAttempts; $attempt++) {
|
||||
// 生成后5位随机字符
|
||||
$suffix = '';
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$suffix .= $chars[rand(0, strlen($chars) - 1)];
|
||||
}
|
||||
|
||||
$code = 'C' . $type . $suffix;
|
||||
|
||||
// 检查是否已存在
|
||||
$existing = VehModification::where('code', $code)->first();
|
||||
if (!$existing) {
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果1000次尝试后仍然重复,使用时间戳确保唯一性
|
||||
$timestamp = substr(time(), -5);
|
||||
return 'C' . $type . $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
$type = $data['type'] ?? 0;
|
||||
$data['code'] = $this->generateUniqueModificationCode($type);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user