Merge branch 'feature/inv' into develop
This commit is contained in:
@@ -95,6 +95,6 @@ class InvRequisitionService
|
||||
//requisition_id:申请id
|
||||
//action:审批动作:1通过 2驳回
|
||||
//comment:审批意见
|
||||
return $appro->approve($param['requisition_id'], $param['approve_id'], $request->user->uid, $param['action'], $param['comment']);
|
||||
return $appro->approve($param['requisition_id'], $param['approve_id'], $request->user->uid, $param['action'], $param['comment'], $param['attachment']);
|
||||
}
|
||||
}
|
||||
@@ -99,12 +99,19 @@ class InvRequisitionItemReturnController extends BaseController
|
||||
if (isset($data['return_at']))
|
||||
$data['return_at'] = date('Y-m-d H:i:s', $data['return_at']);
|
||||
if (isset($data['id'])){
|
||||
//归还附件
|
||||
$data['return_attachment'] = InvRequisitionItemReturnAttachment::where('return_id', $data['id'])->get();
|
||||
$ossservice = new OssService();
|
||||
foreach ($data['return_attachment'] as $item){
|
||||
$item['file_path_pull'] = $ossservice->generatePrivateUrl($item['file_path']);
|
||||
|
||||
}
|
||||
|
||||
//归还审核附件
|
||||
$data['return_approve_attachment'] = InvRequisitionItemReturnAttachment::where('return_id', $data['id'])->get();
|
||||
foreach ($data['return_approve_attachment'] as $item){
|
||||
$item['file_path_pull'] = $ossservice->generatePrivateUrl($item['file_path']);
|
||||
}
|
||||
}
|
||||
/*if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class InvRequisitionApproveAttachment extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'inv_requisition_approve_attachment';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'requisition_id', 'approve_id', 'file_name', 'file_path', 'file_size', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class InvRequisitionReturnApproveAttachment extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'inv_requisition_return_approve_attachment';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = [];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -93,13 +93,13 @@ class InvRequisitionApproveService
|
||||
}
|
||||
|
||||
/** 执行审批 */
|
||||
public function approve(int $requisitionId, int $approverId, int $uid, string $action, string $comment = '')
|
||||
public function approve(int $requisitionId, int $approverId, int $uid, string $action, string $comment = '', array $attachment = [])
|
||||
{
|
||||
if (!in_array($action, ['1','2'], true)) { //审批动作:1通过 2驳回
|
||||
throw new BusinessException("无效的审批操作");
|
||||
}
|
||||
|
||||
return Db::transaction(function () use ($requisitionId, $approverId, $uid, $action, $comment) {
|
||||
return Db::transaction(function () use ($requisitionId, $approverId, $uid, $action, $comment, $attachment) {
|
||||
// $instance = Db::table('approval_instances')->where('id', $instanceId)->lockForUpdate()->first();
|
||||
$requisition = Db::table('inv_requisition')->where('id', $requisitionId)->lockForUpdate()->first();
|
||||
if (!$requisition) throw new BusinessException("审批实例未找到");
|
||||
@@ -151,6 +151,16 @@ class InvRequisitionApproveService
|
||||
'action_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
foreach ($attachment as $attac) {
|
||||
Db::table('inv_requisition_approve_attachment')->insertGetId([
|
||||
'requisition_id' => $requisitionId,
|
||||
'approve_id' => $approverId,
|
||||
'file_name' => $attac['original_name'],
|
||||
'file_path' => $attac['file_path'],
|
||||
'created_at' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
// 2) 已通过步骤与总步数相等则结束审核流程
|
||||
$pass = Db::table('inv_requisition_approve')
|
||||
|
||||
@@ -386,8 +386,10 @@ class InvRequisitionItemReturnService
|
||||
public function serviceReturnConfirm(Request $request, array $data, string $scene = 'returnConfirm')
|
||||
{
|
||||
try {
|
||||
$attachment = $request->post('attachment');
|
||||
unset($data['attachment']);
|
||||
// 归还确认是业务顶层方法,这里统一使用事务
|
||||
return Db::transaction(function () use ($request, $data, $scene) {
|
||||
return Db::transaction(function () use ($request, $data, $scene, $attachment) {
|
||||
|
||||
// 1. 当前操作人信息
|
||||
$userInfo = (new UserService())->getUserInfo($request->user->uid, '');
|
||||
@@ -430,7 +432,16 @@ class InvRequisitionItemReturnService
|
||||
// 4. 更新归还记录(状态 + 审核人 + 备注等)
|
||||
$updateResult = $this->logicUpdateBy($config, $data);
|
||||
$resultItem = $this->logicShow($config);
|
||||
InvRequisitionReturn::where('id',$resultItem['status'])->update(['status' => $data['status']]);
|
||||
InvRequisitionReturn::where('id',$resultItem['return_id'])->update(['status' => $data['status']]);
|
||||
foreach ($attachment as $attac) {
|
||||
Db::table('inv_requisition_return_approve_attachment')->insertGetId([
|
||||
'requisition_id' => $resultItem['requisition_id'],
|
||||
'return_id' => $resultItem['return_id'],
|
||||
'file_name' => $attac['original_name'],
|
||||
'file_path' => $attac['file_path'],
|
||||
'created_at' => time(),
|
||||
]);
|
||||
}
|
||||
if ($updateResult === 0) {
|
||||
throw new BusinessException('更新归还申请失败,可能记录不存在或已被处理');
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use app\common\controller\BaseController;
|
||||
use app\common\model\Corp;
|
||||
use app\common\model\InvItem;
|
||||
use app\common\model\InvRequisitionApprove;
|
||||
use app\common\model\InvRequisitionApproveAttachment;
|
||||
use app\common\model\InvRequisitionAttachment;
|
||||
use app\common\model\InvRequisitionItem;
|
||||
use app\common\service\OssService;
|
||||
@@ -117,8 +118,17 @@ class InvRequisitionController extends BaseController
|
||||
*/
|
||||
protected function showFormat($data)
|
||||
{
|
||||
$oss = new OssService();
|
||||
if (isset($data['id'])){
|
||||
$data['approve'] = InvRequisitionApprove::where('requisition_id', $data['id'])->get()->toArray();
|
||||
foreach ($data['approve'] as $key => $item){
|
||||
$attachment = InvRequisitionApproveAttachment::where('approve_id', $item['id'])->get();
|
||||
foreach ($attachment as $k => $v){
|
||||
$attachment[$k] = $v->toArray();
|
||||
$attachment[$k]['file_path_pull'] = $oss->generatePrivateUrl($v['file_path']);
|
||||
}
|
||||
$data['approve'][$key]['attachment'] = $attachment;
|
||||
}
|
||||
$approve_id = !empty($data['approve'])?array_pop($data['approve'])['id']:null;
|
||||
$data['approve_id'] = $approve_id;
|
||||
}
|
||||
@@ -129,7 +139,6 @@ class InvRequisitionController extends BaseController
|
||||
if (isset($data['id'])){
|
||||
$data['item'] = InvRequisitionItem::where('requisition_id', $data['id'])->get();
|
||||
$data['attachment'] = InvRequisitionAttachment::where('requisition_id', $data['id'])->get();
|
||||
$oss = new OssService();
|
||||
foreach ($data['attachment'] as $key => $value) {
|
||||
$data['attachment'][$key]['file_path_pull'] = $oss->generatePrivateUrl($value['file_path']);
|
||||
}
|
||||
|
||||
@@ -106,6 +106,12 @@ class InvRequisitionItemReturnController extends BaseController
|
||||
$item['file_path_pull'] = $ossservice->generatePrivateUrl($item['file_path']);
|
||||
|
||||
}
|
||||
|
||||
//归还审核附件
|
||||
$data['return_approve_attachment'] = InvRequisitionItemReturnAttachment::where('return_id', $data['id'])->get();
|
||||
foreach ($data['return_approve_attachment'] as $item){
|
||||
$item['file_path_pull'] = $ossservice->generatePrivateUrl($item['file_path']);
|
||||
}
|
||||
}
|
||||
/*if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
@@ -144,7 +150,6 @@ class InvRequisitionItemReturnController extends BaseController
|
||||
try {
|
||||
// 验证申请数据
|
||||
$data = $this->validate($this->service->getValidator(), $request->post(), 'returnConfirm');
|
||||
|
||||
// 处理申请逻辑
|
||||
$result = $this->service->serviceReturnConfirm($request, $data, 'returnConfirm');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user