物品领用审核
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\InvRequisitionApproveService;
|
||||
|
||||
class InvRequisitionApproveController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new InvRequisitionApproveService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\InvRequisitionReturnService;
|
||||
|
||||
class InvRequisitionReturnController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new InvRequisitionReturnService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\InvRequisitionApprove;
|
||||
|
||||
class InvRequisitionApproveLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = InvRequisitionApprove::class;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\traits\crud\CrudLogicTrait;
|
||||
use app\common\model\InvRequisitionReturn;
|
||||
|
||||
class InvRequisitionReturnLogic
|
||||
{
|
||||
use CrudLogicTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = InvRequisitionReturn::class;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class InvRequisitionApprove 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';
|
||||
|
||||
/**
|
||||
* 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', 'node_type', 'approver_id', 'approver_name', 'action', 'comment', 'action_at', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class InvRequisitionReturn 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';
|
||||
|
||||
/**
|
||||
* 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', 'order_no', 'requisition_id', 'applicant_id', 'applicant_name', 'apply_remark', 'handler_id', 'handler_name', 'status', 'handle_remark', 'return_at', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\validate\InvRequisitionApproveValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\InvRequisitionApprove;
|
||||
|
||||
class InvRequisitionApproveService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = InvRequisitionApprove::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = InvRequisitionApproveValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace app\common\service;
|
||||
|
||||
use app\common\model\InvRequisition;
|
||||
use app\common\model\InvRequisitionItem;
|
||||
use app\common\model\InvRequisitionReturn;
|
||||
use app\common\validate\InvRequisitionItemReturnValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\InvRequisitionItemReturn;
|
||||
@@ -13,6 +14,7 @@ use support\exception\BusinessException;
|
||||
use app\common\service\UserService;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use app\common\model\InvRequisitionItemReturnAttachment;
|
||||
use function Symfony\Component\String\u;
|
||||
|
||||
class InvRequisitionItemReturnService
|
||||
{
|
||||
@@ -91,7 +93,7 @@ class InvRequisitionItemReturnService
|
||||
// ];
|
||||
|
||||
// 获取所有申请项ID
|
||||
$reqItemIds = array_column($data, 'requisition_item_id');
|
||||
$reqItemIds = array_column($data['items'], 'requisition_item_id');
|
||||
|
||||
// 参数校验
|
||||
if (empty($reqItemIds)) {
|
||||
@@ -99,7 +101,9 @@ class InvRequisitionItemReturnService
|
||||
}
|
||||
|
||||
// 将申请项按 ID 重组为关联数组
|
||||
$newReqItems = $this->groupArrayByKey($data, 'requisition_item_id');
|
||||
$newReqItems = $this->groupArrayByKey($data['items'], 'requisition_item_id');
|
||||
|
||||
$data['return_at'] = is_int($data['return_at']) ? $data['return_at']: strtotime($data['return_at']);
|
||||
|
||||
// 获取申请项明细
|
||||
$reqItemsArr = InvRequisitionItem::whereIn('id', $reqItemIds)->get()->toArray();
|
||||
@@ -112,10 +116,12 @@ class InvRequisitionItemReturnService
|
||||
// 获取用户信息
|
||||
$userService = new UserService();
|
||||
$user = $userService->getUserInfo($request->user->uid, '');
|
||||
$data['applicant_id'] = $user['user']['id'];
|
||||
$data['applicant_name'] = $user['user']['name'];
|
||||
|
||||
$reqItemId = $data['requisition_id'];
|
||||
$arr = [];
|
||||
foreach ($reqItemsArr as $reqItem) {
|
||||
$reqItemId = $reqItem['id'];
|
||||
|
||||
// 检查是否有对应的新申请项数据
|
||||
if (!isset($newReqItems[$reqItemId])) {
|
||||
@@ -123,19 +129,21 @@ class InvRequisitionItemReturnService
|
||||
}
|
||||
|
||||
$arr[] = [
|
||||
'requisition_id' => $reqItem['requisition_id'],
|
||||
'requisition_item_id' => $reqItemId,
|
||||
'requisition_id' => $data['requisition_id'],
|
||||
'requisition_item_id' => $reqItem['id'],
|
||||
'item_id' => $reqItem['item_id'],
|
||||
'apply_user_id' => $user['user']['id'],
|
||||
'apply_user_name' => $user['user']['name'],
|
||||
'return_qty' => $newReqItems[$reqItemId]['return_qty'],
|
||||
'return_qty' => $newReqItems[$reqItemId]['return_qty'] ?: '1',
|
||||
'apply_remark' => $newReqItems[$reqItemId]['apply_remark'] ?? '',
|
||||
'attachment' => $newReqItems[$reqItemId]['attachment'],
|
||||
'return_at' => time()
|
||||
//'attachment' => $newReqItems[$reqItemId]['attachment'],
|
||||
//'return_at' => time(),
|
||||
'return_at' => $data['return_at'],
|
||||
];
|
||||
}
|
||||
$data['items'] =$arr;
|
||||
|
||||
return $arr;
|
||||
return $data;
|
||||
} catch (BusinessException $e) {
|
||||
throw $e;
|
||||
} catch (\Throwable $th) {
|
||||
@@ -156,15 +164,24 @@ class InvRequisitionItemReturnService
|
||||
// 关联表增加事务处理
|
||||
return Db::transaction(function () use ($request, $data) {
|
||||
$data = $this->preProcess('Store', $data, $request);
|
||||
$dl = $this->getDataLimitFromRequest($request);
|
||||
foreach ($data as $item) {
|
||||
$created = $this->logicCreate($item, $dl);
|
||||
$this->processRequisitionItemReturnAttachment($created, $item['attachment']);
|
||||
//$dl = $this->getDataLimitFromRequest($request);
|
||||
|
||||
$items = $data['items'];
|
||||
$attachment = $data['attachment'];
|
||||
unset($data['items']);
|
||||
unset($data['attachment']);
|
||||
$data['order_no'] = $this->generateOrderNo();
|
||||
$res = InvRequisitionReturn::create($data);
|
||||
$created = [];
|
||||
foreach ($items as $item) {
|
||||
//$created = $this->logicCreate($item, $dl);
|
||||
$created = $this->logicCreate($item);
|
||||
}
|
||||
$this->processRequisitionItemReturnAttachment($res, $attachment);
|
||||
return $this->postProcess('Store', $created);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException("创建物品申请失败:" . $e->getMessage());
|
||||
throw new BusinessException("创建物品申请失败:" . $e->getMessage().$e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,4 +463,14 @@ class InvRequisitionItemReturnService
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成申请单号
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateOrderNo(): string
|
||||
{
|
||||
return 'RR' . date('Ymd') . strtoupper(substr(uniqid(), -6));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\validate\InvRequisitionReturnValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\InvRequisitionReturn;
|
||||
|
||||
class InvRequisitionReturnService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = InvRequisitionReturn::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = InvRequisitionReturnValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\InvItem;
|
||||
use app\common\validate\InvRequisitionValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\InvRequisition;
|
||||
@@ -91,6 +92,18 @@ class InvRequisitionService
|
||||
$data['leader_id'] = $user['user']['report_to'];
|
||||
$data['status'] = InvRequisition::STATUS_LEADER;
|
||||
|
||||
//查询物品管理人是否是一个
|
||||
if(count($data['items'])>=2){
|
||||
$manage_user = [];
|
||||
foreach ($data['items'] as $item) {
|
||||
$manage_user[] = InvItem::where('id',$item['item_id'])->value('manage_user_id');
|
||||
}
|
||||
$manage_user = array_unique($manage_user);
|
||||
if(count($manage_user)>1){
|
||||
throw new BusinessException("审批实例未找到");
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -113,13 +126,36 @@ class InvRequisitionService
|
||||
$this->processRequisitionItems($created, $data['items']);
|
||||
// 处理物品申请附件
|
||||
$this->processRequisitionAttachmentItems($created, $data['attachment']);
|
||||
return $this->postProcess('Store', $created);
|
||||
$res = $this->postProcess('Store', $created);
|
||||
|
||||
$manage_user_id = InvItem::where('id',$data['items']['item_id'])->value('manage_user_id');
|
||||
$approval = [
|
||||
'id' => $res['id'], //申请单id
|
||||
'applicant_id' => $res['applicant_id'], //申请人id
|
||||
'manage_user_id' => $manage_user_id,
|
||||
];
|
||||
$this->startApproval($approval);
|
||||
|
||||
return $res;
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException("创建物品申请失败:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动审批
|
||||
*/
|
||||
public function startApproval($requisition)
|
||||
{
|
||||
// 启动审批
|
||||
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||
$formData = [
|
||||
'manage_user_id' => $requisition['manage_user_id'],
|
||||
];
|
||||
$appro->start('inv_requisition', 'inv_requisition', $requisition['id'], $formData, $requisition['applicant_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新物品申请
|
||||
*
|
||||
|
||||
@@ -7,10 +7,10 @@ use support\Log;
|
||||
|
||||
class ApprovalFlowService
|
||||
{
|
||||
use traits\ApprovalEngineTrait;
|
||||
use traits\ApprovalQueryTrait;
|
||||
use traits\ApprovalResolverTrait;
|
||||
use traits\ApprovalNotificationTrait;
|
||||
use traits\ApprovalDiscussionTrait;
|
||||
use traits\ApprovalTransferTrait;
|
||||
use \app\common\utils\approval\traits\ApprovalEngineTrait;
|
||||
use \app\common\utils\approval\traits\ApprovalQueryTrait;
|
||||
use \app\common\utils\approval\traits\ApprovalResolverTrait;
|
||||
use \app\common\utils\approval\traits\ApprovalNotificationTrait;
|
||||
use \app\common\utils\approval\traits\ApprovalDiscussionTrait;
|
||||
use \app\common\utils\approval\traits\ApprovalTransferTrait;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\common\utils\approval\service\traits;
|
||||
namespace app\common\utils\approval\traits;
|
||||
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\common\utils\approval\service\traits;
|
||||
namespace app\common\utils\approval\traits;
|
||||
|
||||
use support\Db;
|
||||
use support\Log;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\common\utils\approval\service\traits;
|
||||
namespace app\common\utils\approval\traits;
|
||||
|
||||
use support\Db;
|
||||
use support\Log;
|
||||
@@ -62,6 +62,15 @@ trait ApprovalNotificationTrait
|
||||
case 'purchase_order':
|
||||
// 采购单
|
||||
break;
|
||||
case 'inv_requisition':
|
||||
// 备货单
|
||||
$invRequisition = \app\common\model\InvRequisition::find($instance->biz_id);
|
||||
if ($invRequisition) {
|
||||
$title = $prefix."物品借用:{$invRequisition->order_no}";
|
||||
$flowTxt = $approvalType[$instance->flow_type] ?? $instance->flow_type;
|
||||
$content = "{$prefix}你有一条审批 {$text}:类型 {$flowTxt},业务单号 {$invRequisition->order_no}";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 附加说明(提交说明/申诉/讨论摘要)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\common\utils\approval\service\traits;
|
||||
namespace app\common\utils\approval\traits;
|
||||
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\common\utils\approval\service\traits;
|
||||
namespace app\common\utils\approval\traits;
|
||||
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\common\utils\approval\service\traits;
|
||||
namespace app\common\utils\approval\traits;
|
||||
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class InvRequisitionApproveValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class InvRequisitionReturnValidate extends Validate
|
||||
{
|
||||
// 规则
|
||||
protected $rule = [
|
||||
|
||||
];
|
||||
|
||||
// 提示
|
||||
protected $message = [
|
||||
|
||||
];
|
||||
|
||||
// 场景
|
||||
protected $scene = [
|
||||
'store' => [
|
||||
|
||||
],
|
||||
|
||||
'update' => [
|
||||
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -73,26 +73,26 @@ class IndexController
|
||||
{
|
||||
$options = [
|
||||
'controller' => [
|
||||
'module' => 'common',
|
||||
'name' => 'inv_requisition_item_return_attachment'
|
||||
'module' => 'mobile',
|
||||
'name' => 'inv_requisition_return'
|
||||
],
|
||||
'model' => [
|
||||
'module' => 'common',
|
||||
'name' => 'inv_requisition_item_return_attachment'
|
||||
'name' => 'inv_requisition_return'
|
||||
],
|
||||
'service' => [
|
||||
'module' => 'common',
|
||||
'name' => 'inv_requisition_item_return_attachment'
|
||||
'name' => 'inv_requisition_return'
|
||||
],
|
||||
'logic' => [
|
||||
'module' => 'common',
|
||||
'name' => 'inv_requisition_item_return_attachment'
|
||||
'name' => 'inv_requisition_return'
|
||||
],
|
||||
'validate' => [
|
||||
'module' => 'common',
|
||||
'name' => 'inv_requisition_item_return_attachment'
|
||||
'name' => 'inv_requisition_return'
|
||||
],
|
||||
'table' => 'inv_requisition_item_return_attachment'
|
||||
'table' => 'inv_requisition_return'
|
||||
];
|
||||
|
||||
$result = (new Generate($options))->doGenerate();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\InvRequisitionReturnService;
|
||||
|
||||
class InvRequisitionReturnController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new InvRequisitionReturnService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user