181 lines
5.8 KiB
PHP
181 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace app\common\service;
|
|
|
|
use app\common\validate\ApprovalRecordsValidate;
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
use app\common\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'] = [
|
|
'instance',
|
|
'approver',
|
|
'instance.flows',
|
|
'instance.initiator',
|
|
'instance.bizInfo'
|
|
];
|
|
|
|
// $config['dataLimit']['type'] = 'relation';
|
|
// $config['dataLimit']['userId'] = $request->user->uid;
|
|
// $config['dataLimit']['userField'] = 'approver_id';
|
|
break;
|
|
case 'todo':
|
|
|
|
if ($p['scene'] === 'todo') {
|
|
// if (!in_array(1, $request->user->role_ids)) {
|
|
// $config['where']['approver_id'] = $request->user->uid;
|
|
// }
|
|
$config['where']['status'] = 'pending';
|
|
$config['where']['instance.status'] = 'processing';
|
|
}
|
|
|
|
if ($p['scene'] === 'history') {
|
|
if (!in_array(1, $request->user->role_ids)) {
|
|
$config['where']['approver_id'] = $request->user->uid;
|
|
}
|
|
$config['where']['status'] = ['!=', 'pending'];
|
|
}
|
|
|
|
$config['order']['id'] = 'desc';
|
|
|
|
$config['with'] = [
|
|
'instance',
|
|
'approver',
|
|
'instance.flows',
|
|
'instance.initiator',
|
|
'instance.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;
|
|
case 'logs':
|
|
$config['where']['instance_id'] = $p['instance_id'];
|
|
$config['order']['id'] = 'desc';
|
|
break;
|
|
case 'border':
|
|
$config['where']['id'] = $p['id'];
|
|
$config['order']['id'] = 'desc';
|
|
$config['with'] = [
|
|
'instance',
|
|
'approver',
|
|
'instance.flows',
|
|
'instance.initiator',
|
|
'instance.bizInfo',
|
|
|
|
// 'instance.bizInfo.items',
|
|
// 'instance.bizInfo.items.options',
|
|
// 'instance.bizInfo.items.moneyValues',
|
|
// 'instance.bizInfo.accounts',
|
|
// 'instance.bizInfo.moneyValues',
|
|
// 'instance.bizInfo.salesperson',
|
|
];
|
|
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);
|
|
}
|
|
|
|
|
|
public function serviceBusinessOrder(Request $request, array $data = [])
|
|
{
|
|
$config = $this->buildQueryConfig($request, 'border');
|
|
$config = $this->borderConfig($config, $data['flow_type']);
|
|
$item = $this->logicShow($config);
|
|
$bizInfo = [];
|
|
$service = match ($data['flow_type']) {
|
|
'stock_orders' => new \app\common\service\StockOrdersService(),
|
|
'purchase_orders' => new \app\common\service\PurchaseOrdersService(),
|
|
default => new \app\common\service\StockOrdersService()
|
|
};
|
|
$bizInfo = $service->formatData($item->instance->bizInfo);
|
|
return $this->postProcess('Border', $bizInfo);
|
|
}
|
|
|
|
public function borderConfig($config, $type = 'stock_orders')
|
|
{
|
|
$with = match ($type) {
|
|
'stock_orders' => [
|
|
'instance.bizInfo.items',
|
|
'instance.bizInfo.items.options',
|
|
'instance.bizInfo.items.moneyValues',
|
|
'instance.bizInfo.accounts',
|
|
'instance.bizInfo.moneyValues',
|
|
'instance.bizInfo.salesperson',
|
|
],
|
|
'purchase_orders' => [
|
|
'instance.bizInfo.items',
|
|
'instance.bizInfo.items.stockOrder',
|
|
'instance.bizInfo.items.stockOrderItems'
|
|
]
|
|
};
|
|
$config['with'] = array_merge($config['with'], $with);
|
|
return $config;
|
|
}
|
|
|
|
|
|
public function transferApproval(Request $request, array $data = [])
|
|
{
|
|
$service = new \app\common\utils\approval\service\ApprovalFlowService();
|
|
$result = $service->transferApproval($data['instance_id'], $data['step_index'], $request->user->uid, $data['to_uid'], $data['reason'], 'name');
|
|
return $result;
|
|
}
|
|
} |