归还详情与编辑
This commit is contained in:
@@ -55,4 +55,9 @@ class InvRequisition extends Model
|
||||
const STATUS_REJECTEDT = 40; // 已驳回
|
||||
const STATUS_CANCELED = 50; // 已取消
|
||||
|
||||
public function approval()
|
||||
{
|
||||
return $this->hasMany('app\common\model\InvRequisitionApprove',
|
||||
'requisition_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,10 @@ class InvRequisitionApprove extends Model
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
public function requisition()
|
||||
{
|
||||
return $this->belongsTo('app\common\model\InvRequisition',
|
||||
'requisition_id','id');
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class InvRequisitionItemReturn extends Model
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'requisition_id', 'requisition_item_id', 'item_id', 'apply_user_id', 'apply_user_name', 'return_qty', 'status', 'handler_id', 'handler_name', 'return_status', 'apply_remark', 'handle_remark', 'return_at', 'created_at', 'updated_at'];
|
||||
protected $fillable = ['id', 'return_id', 'requisition_id', 'requisition_item_id', 'item_id', 'apply_user_id', 'apply_user_name', 'return_qty', 'status', 'handler_id', 'handler_name', 'return_status', 'apply_remark', 'handle_remark', 'return_at', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
|
||||
@@ -99,7 +99,7 @@ class InvRequisitionApproveService
|
||||
throw new BusinessException("无效的审批操作");
|
||||
}
|
||||
|
||||
return Db::transaction(function () use ($requisitionId, $approverId, $action, $comment) {
|
||||
return Db::transaction(function () use ($requisitionId, $approverId, $uid, $action, $comment) {
|
||||
// $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("审批实例未找到");
|
||||
@@ -138,6 +138,10 @@ class InvRequisitionApproveService
|
||||
// return ['status' => 'noop', 'msg' => '非当前审批'];
|
||||
// }
|
||||
return ['status' => 'noop', 'msg' => '无待处理记录'];
|
||||
}else{
|
||||
if ($pendingRecord->approver_id == $uid) {
|
||||
return ['status' => 'noop', 'msg' => '无审核权限'];
|
||||
}
|
||||
}
|
||||
|
||||
$now = time();
|
||||
@@ -161,7 +165,7 @@ class InvRequisitionApproveService
|
||||
->where('requisition_id', $requisition->id)
|
||||
->where('is_consumable_snap', 0)
|
||||
->get();
|
||||
if(!$requisitionItem){
|
||||
if($requisitionItem){
|
||||
Db::table('inv_requisition')->where('id', $requisition->id)->update(['status'=>12]);
|
||||
}else{
|
||||
Db::table('inv_requisition')->where('id', $requisition->id)->update(['status'=>19]);
|
||||
|
||||
@@ -5,13 +5,13 @@ namespace app\common\service;
|
||||
use app\common\model\InvRequisition;
|
||||
use app\common\model\InvRequisitionItem;
|
||||
use app\common\model\InvRequisitionReturn;
|
||||
use app\common\service\UserService;
|
||||
use app\common\validate\InvRequisitionItemReturnValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\InvRequisitionItemReturn;
|
||||
use support\Request;
|
||||
use support\Db;
|
||||
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;
|
||||
@@ -175,7 +175,10 @@ class InvRequisitionItemReturnService
|
||||
$created = [];
|
||||
foreach ($items as $item) {
|
||||
//$created = $this->logicCreate($item, $dl);
|
||||
$item['return_id'] = $res->id;
|
||||
$item['requisition_id'] = $data['requisition_id'];
|
||||
$item['return_at'] = $data['return_at'];
|
||||
$item['apply_remark'] = $data['apply_remark'];
|
||||
$created = $this->logicCreate($item);
|
||||
}
|
||||
$this->processRequisitionItemReturnAttachment($res, $attachment);
|
||||
@@ -222,8 +225,71 @@ class InvRequisitionItemReturnService
|
||||
// ]
|
||||
// ];
|
||||
|
||||
$data['return_at'] = time();
|
||||
return $data;
|
||||
try {
|
||||
$approved = InvRequisitionItemReturn::where('return_id',$data['id'])
|
||||
->where('status','>',0)
|
||||
->count();
|
||||
if ($approved > 0) {
|
||||
throw new BusinessException('已审核禁止编辑');
|
||||
}
|
||||
|
||||
// 获取所有申请项ID
|
||||
$reqItemIds = array_column($data['items'], 'requisition_item_id');
|
||||
|
||||
// 参数校验
|
||||
if (empty($reqItemIds)) {
|
||||
throw new BusinessException('未提供有效的申请项ID');
|
||||
}
|
||||
|
||||
// 将申请项按 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();
|
||||
|
||||
// 检查是否获取到有效数据
|
||||
if (empty($reqItemsArr)) {
|
||||
throw new BusinessException('未找到对应的申请项');
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
$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])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$arr[] = [
|
||||
'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'] ?: '1',
|
||||
'apply_remark' => $data['apply_remark'] ?? '',
|
||||
//'attachment' => $newReqItems[$reqItemId]['attachment'],
|
||||
//'return_at' => time(),
|
||||
'return_at' => $data['return_at'],
|
||||
];
|
||||
}
|
||||
$data['items'] =$arr;
|
||||
|
||||
return $data;
|
||||
} catch (BusinessException $e) {
|
||||
throw $e;
|
||||
} catch (\Throwable $th) {
|
||||
throw new BusinessException('创建物品归还申请失败:' . $th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,20 +305,37 @@ class InvRequisitionItemReturnService
|
||||
// 关联表增加事务处理
|
||||
return Db::transaction(function () use ($request, $data) {
|
||||
$data = $this->preProcess('Update', $data, $request);
|
||||
$config = $this->buildQueryConfig($request, 'update');
|
||||
//$config = $this->buildQueryConfig($request, 'update');
|
||||
|
||||
$attachment = $data['attachment'];
|
||||
unset($data['attachment']);
|
||||
$items = $data['items'];
|
||||
unset($data['items']);
|
||||
|
||||
$this->logicUpdateBy($config, $data);
|
||||
|
||||
$config = [];
|
||||
$config['model'] = InvRequisitionReturn::class;
|
||||
$config['where']['id'] = $request->post('id');
|
||||
$returnService = new InvRequisitionReturnService();
|
||||
$returnService->logicUpdateBy($config, $data);
|
||||
|
||||
InvRequisitionItemReturn::where('return_id',$data['id'])->delete();
|
||||
foreach ($items as $item) {
|
||||
$item['return_id'] = $data['id'];
|
||||
$item['requisition_id'] = $data['requisition_id'];
|
||||
$item['return_at'] = $data['return_at'];
|
||||
$item['apply_remark'] = $data['apply_remark'];
|
||||
$created = $this->logicCreate($item);
|
||||
//$this->logicUpdateBy($config, $data);
|
||||
}
|
||||
// 获取更新后的完整记录
|
||||
$updated = $this->logicShow($config);
|
||||
$updated = $returnService->logicShow($config);
|
||||
// 处理附件更新
|
||||
$this->processRequisitionItemReturnAttachment($updated, $attachment, true);
|
||||
return $this->postProcess('Update', $updated);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException("更新物品归还申请失败:" . $e->getMessage());
|
||||
throw new BusinessException("更新物品归还申请失败:" . $e->getMessage().$e->getLine().$e->getFile().$e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,6 +433,8 @@ class InvRequisitionItemReturnService
|
||||
throw new BusinessException('更新归还申请失败,可能记录不存在或已被处理');
|
||||
}
|
||||
|
||||
//InvRequisitionReturn::where('return_id', $data['id'])->update(['status' => $status]);
|
||||
|
||||
// 5. 若是拒绝,直接返回(不改库存、不改已归还数量)
|
||||
if ($status === 2) {
|
||||
// 拒绝:这里你返回 true 或者返回更新后的记录都可以
|
||||
@@ -476,6 +561,15 @@ class InvRequisitionItemReturnService
|
||||
return $config;
|
||||
}
|
||||
|
||||
/** 查看单条 */
|
||||
public function serviceShow(Request $request, string $scene = 'show')
|
||||
{
|
||||
$id = $request->get('id');
|
||||
$return = InvRequisitionReturn::where('id', $id)->first()->toArray();
|
||||
$return['item_return'] = InvRequisitionItemReturn::where('return_id', $return['id'])->orderBy('id', 'desc')->get()->toArray();
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成申请单号
|
||||
*
|
||||
|
||||
@@ -55,11 +55,12 @@ class InvRequisitionService
|
||||
if(isset($p['status']) && $p['status']){
|
||||
$config['where']['status'] = $p['status'];
|
||||
}
|
||||
if(isset($p['applicant_id']) && $p['applicant_id'] == 'self'){
|
||||
if (isset($p['applicant_id']) && $p['applicant_id'] == 'self') { //自己的领用申请
|
||||
$config['where']['applicant_id'] = $request->user->uid;
|
||||
|
||||
}elseif(isset($p['applicant_id']) && $p['applicant_id']){
|
||||
} elseif (isset($p['applicant_id']) && $p['applicant_id']) { //指定人员的申请
|
||||
$config['where']['applicant_id'] = $p['applicant_id'];
|
||||
} else { //审批人对应的记录
|
||||
$config['where']['approval.approver_id'] = $request->user->uid;
|
||||
}
|
||||
if(isset($p['phase']) && $p['phase'] == 'approve'){//借用审批中
|
||||
$config['where']['status'] = ['in',[10,11,13]];
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace app\mobile\controller;
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Corp;
|
||||
use app\common\model\InvItem;
|
||||
use app\common\model\InvRequisitionItem;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\InvRequisitionItemReturnService;
|
||||
use support\Request;
|
||||
@@ -62,6 +63,26 @@ class InvRequisitionItemReturnController extends BaseController
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @param int|string $id 资源 ID
|
||||
* @return mixed 返回资源详情数据
|
||||
*/
|
||||
public function show(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceShow($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'showFormat')
|
||||
? [$this, 'showFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
@@ -70,23 +91,37 @@ class InvRequisitionItemReturnController extends BaseController
|
||||
*/
|
||||
protected function showFormat($data)
|
||||
{
|
||||
if (isset($data['item_id'])){
|
||||
$data['item'] = InvItem::where('id', $data['item_id'])->get();
|
||||
foreach ($data['item'] as $key => $item){
|
||||
$corpId = InvItem::where('id', $item->item_id)->value('company_id');
|
||||
$item['company_name'] = Corp::where('id', $corpId)->value('name');
|
||||
}
|
||||
foreach ($data['item_return'] as $key => $item){
|
||||
$data['item_return'][$key]['requisition_item'] = InvRequisitionItem::where('id', $item['requisition_item_id'])->first();
|
||||
}
|
||||
if (isset($data['return_at']))
|
||||
$data['return_at'] = date('Y-m-d H:i:s', $data['return_at']);
|
||||
if (isset($data['created_at']))
|
||||
/*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']);
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);*/
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回更新成功的数据或信息
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $this->validate($this->service->getValidator(), $request->post(), 'update');
|
||||
$res = $this->service->serviceUpdate($request, $data);
|
||||
return $this->success([], '更新成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 物品归还确认
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user