202 lines
7.2 KiB
PHP
202 lines
7.2 KiB
PHP
<?php
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\BaseController;
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
use app\common\service\ApprovalRecordsService;
|
|
use app\common\model\SysDictItem;
|
|
use support\Request;
|
|
|
|
class ApprovalRecordsController extends BaseController
|
|
{
|
|
use CrudControllerTrait;
|
|
|
|
protected $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new ApprovalRecordsService();
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function indexFormat($data)
|
|
{
|
|
if (isset($data['records']) && count($data['records']) > 0) {
|
|
foreach ($data['records'] as $key => &$record) {
|
|
$result = [
|
|
'id' => $record['id'],
|
|
'flows_name' => $record['instance']['flows']['name'],
|
|
|
|
'instance_id' => $record['instance_id'],
|
|
|
|
'biz_id' => $record['instance']['biz_id'],
|
|
'biz_desc' => '备货单【'.$record['instance']['bizInfo']['order_no'].'】',
|
|
'biz_type' => $record['instance']['biz_type'],
|
|
|
|
'initiator_name' => $record['instance']['initiator']['name'],
|
|
'initiator_avatar' => $record['instance']['initiator']['avatar'],
|
|
|
|
'approver_name' => $record['approver']['name'],
|
|
'approver_avatar' => $record['approver']['avatar'],
|
|
|
|
'step_index' => $record['step_index'],
|
|
'action' => $record['action'],
|
|
'action_desc' => SysDictItem::where('item_value', $record['action'])->where('status', 1)->value('item_label'),
|
|
'status' => $record['status'],
|
|
'status_desc' => SysDictItem::where('item_value', $record['status'])->where('status', 1)->value('item_label'),
|
|
'comment' => $record['comment'],
|
|
'approved_at' => $record['approved_at'],
|
|
|
|
'finished_at' => $record['instance']['finished_at'],
|
|
'deadline_at' => $record['instance']['deadline_at'],
|
|
|
|
'created_at' => $record['created_at']
|
|
];
|
|
$record = $result;
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
|
|
public function approve(Request $request)
|
|
{
|
|
try {
|
|
$res = $this->service->serviceApprove($request);
|
|
return $this->success([], $res['msg']);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
public function logs(Request $request)
|
|
{
|
|
try {
|
|
$instanceId = $request->get('instance_id');
|
|
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
|
$res = $appro->getSimpleTimeline($instanceId, 'name', 'prepend');
|
|
return $this->success($res);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
public function todo(Request $request)
|
|
{
|
|
try {
|
|
$raw = $this->service->serviceList($request, 'todo');
|
|
$data = $this->transformData($raw, method_exists($this, 'todoFormat')
|
|
? [$this, 'todoFormat']
|
|
: null);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
protected function todoFormat($data)
|
|
{
|
|
if (isset($data['records']) && count($data['records']) > 0) {
|
|
foreach ($data['records'] as $key => &$record) {
|
|
$result = [
|
|
'id' => $record['id'],
|
|
'flows_name' => $record['instance']['flows']['name'],
|
|
|
|
'instance_id' => $record['instance_id'],
|
|
|
|
'biz_id' => $record['instance']['biz_id'],
|
|
'biz_desc' => '业务单号【'.$record['instance']['bizInfo']['order_no'].'】',
|
|
'biz_type' => $record['instance']['biz_type'],
|
|
'flow_type' => $record['instance']['flow_type'],
|
|
|
|
'initiator_name' => $record['instance']['initiator']['name'],
|
|
'initiator_avatar' => $record['instance']['initiator']['avatar'],
|
|
|
|
'approver_name' => $record['approver']['name'],
|
|
'approver_avatar' => $record['approver']['avatar'],
|
|
|
|
'step_index' => $record['step_index'],
|
|
'action' => $record['action'],
|
|
'action_desc' => SysDictItem::where('item_value', $record['action'])->where('status', 1)->value('item_label'),
|
|
'status' => $record['status'],
|
|
'status_desc' => SysDictItem::where('item_value', $record['status'])->where('status', 1)->value('item_label'),
|
|
'comment' => $record['comment'],
|
|
'approved_at' => $record['approved_at'],
|
|
|
|
'finished_at' => $record['instance']['finished_at'],
|
|
'deadline_at' => $record['instance']['deadline_at'],
|
|
|
|
'created_at' => $record['created_at']
|
|
];
|
|
$record = $result;
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
|
|
|
|
public function businessOrder(Request $request)
|
|
{
|
|
try {
|
|
$raw = $this->service->serviceBusinessOrder($request, $request->all());
|
|
$data = $this->transformData($raw, method_exists($this, 'borderFormat')
|
|
? [$this, 'borderFormat']
|
|
: null);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
public function transferApproval(Request $request)
|
|
{
|
|
try {
|
|
$raw = $this->service->transferApproval($request, $request->all());
|
|
$data = $this->transformData($raw, method_exists($this, 'transferFormat')
|
|
? [$this, 'transferFormat']
|
|
: null);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
public function approvalTimeline(Request $request)
|
|
{
|
|
try {
|
|
$raw = $this->service->serviceApprovalTimeline($request, $request->all());
|
|
$data = $this->transformData($raw, method_exists($this, 'timelineFormat')
|
|
? [$this, 'timelineFormat']
|
|
: null);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
protected function timelineFormat($data)
|
|
{
|
|
$result = [];
|
|
foreach ($data as $record) {
|
|
$result[] = [
|
|
'id' => $record['id'],
|
|
'name' => $record['approver']['name'],
|
|
'comment' => $record['comment'] ?? '无',
|
|
'time' => $record['updated_at'],
|
|
'status_desc' => SysDictItem::where('item_value', $record['status'])->where('status', 1)->value('item_label'),
|
|
];
|
|
}
|
|
return $result;
|
|
}
|
|
} |