物品领用
This commit is contained in:
@@ -48,8 +48,20 @@ class InvRequisitionService
|
|||||||
if(isset($p['status']) && $p['status']){
|
if(isset($p['status']) && $p['status']){
|
||||||
$config['where']['status'] = $p['status'];
|
$config['where']['status'] = $p['status'];
|
||||||
}
|
}
|
||||||
if(isset($p['applicant_id']) && $p['applicant_id']){
|
if (isset($p['applicant_id']) && $p['applicant_id'] == 'self') { //自己的领用申请
|
||||||
|
$config['where']['applicant_id'] = $request->user->uid;
|
||||||
|
} elseif (isset($p['applicant_id']) && $p['applicant_id']) { //指定人员的申请
|
||||||
$config['where']['applicant_id'] = $p['applicant_id'];
|
$config['where']['applicant_id'] = $p['applicant_id'];
|
||||||
|
} else { //审批人对应的记录
|
||||||
|
$config['where']['approval.approver_id'] = $request->user->uid;
|
||||||
|
$config['where']['approval.action'] = 0;
|
||||||
|
}
|
||||||
|
if(isset($p['phase']) && $p['phase'] == 'approve'){//借用审批中
|
||||||
|
$config['where']['status'] = ['in',[10,11,13]];
|
||||||
|
}elseif(isset($p['phase']) && $p['phase'] == 'repaid'){//已全部归还
|
||||||
|
$config['where']['status'] = 17;
|
||||||
|
}elseif(isset($p['phase']) && $p['phase'] == 'unreturned'){ //未归还
|
||||||
|
$config['where']['status'] = ['in',[12,14,15,16,18]];
|
||||||
}
|
}
|
||||||
$config['order']['id'] = 'desc';
|
$config['order']['id'] = 'desc';
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,8 +2,14 @@
|
|||||||
namespace app\common\controller;
|
namespace app\common\controller;
|
||||||
|
|
||||||
use app\common\controller\BaseController;
|
use app\common\controller\BaseController;
|
||||||
|
use app\common\model\InvItem;
|
||||||
|
use app\common\model\InvRequisitionItem;
|
||||||
|
use app\common\model\InvRequisitionItemReturn;
|
||||||
|
use app\common\model\InvRequisitionItemReturnAttachment;
|
||||||
|
use app\common\service\OssService;
|
||||||
use app\common\traits\crud\CrudControllerTrait;
|
use app\common\traits\crud\CrudControllerTrait;
|
||||||
use app\common\service\InvRequisitionItemReturnService;
|
use app\common\service\InvRequisitionItemReturnService;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
class InvRequisitionItemReturnController extends BaseController
|
class InvRequisitionItemReturnController extends BaseController
|
||||||
{
|
{
|
||||||
@@ -16,18 +22,134 @@ class InvRequisitionItemReturnController extends BaseController
|
|||||||
$this->service = new InvRequisitionItemReturnService();
|
$this->service = new InvRequisitionItemReturnService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取列表
|
||||||
|
*
|
||||||
|
* @param Request $request 请求对象
|
||||||
|
* @return mixed 返回分页数据及总数
|
||||||
|
*/
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
//$request->setGet('$request');
|
||||||
|
$raw = $this->service->serviceList($request);
|
||||||
|
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||||
|
? [$this, 'indexFormat']
|
||||||
|
: null);
|
||||||
|
return $this->success($data);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表页数据格式化
|
* 列表页数据格式化
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
// protected function indexFormat($data)
|
protected function indexFormat($data)
|
||||||
// {
|
{
|
||||||
// if (isset($data['created_at']))
|
if(isset($data['id'])){
|
||||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
$data['return_item'] = InvRequisitionItemReturn::where('return_id', $data['id'])->get();
|
||||||
// if (isset($data['updated_at']))
|
foreach ($data['return_item'] as $key => $value) {
|
||||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['return_item'][$key]['item'] = InvItem::where('id', $value['item_id'])->get();
|
||||||
// return $data;
|
}
|
||||||
// }
|
}
|
||||||
|
if (isset($data['return_at']))
|
||||||
|
$data['return_at'] = date('Y-m-d H:i:s', $data['return_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']);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表页数据格式化
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function showFormat($data)
|
||||||
|
{
|
||||||
|
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['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']);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*
|
||||||
|
* @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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物品归还确认
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function returnConfirm(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// 验证申请数据
|
||||||
|
$data = $this->validate($this->service->getValidator(), $request->post(), 'returnConfirm');
|
||||||
|
|
||||||
|
// 处理申请逻辑
|
||||||
|
$result = $this->service->serviceReturnConfirm($request, $data, 'returnConfirm');
|
||||||
|
|
||||||
|
return $this->success($result, '申请提交成功');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -429,6 +429,8 @@ class InvRequisitionItemReturnService
|
|||||||
|
|
||||||
// 4. 更新归还记录(状态 + 审核人 + 备注等)
|
// 4. 更新归还记录(状态 + 审核人 + 备注等)
|
||||||
$updateResult = $this->logicUpdateBy($config, $data);
|
$updateResult = $this->logicUpdateBy($config, $data);
|
||||||
|
$resultItem = $this->logicShow($config);
|
||||||
|
InvRequisitionReturn::where('id',$resultItem['status'])->update(['status' => $data['status']]);
|
||||||
if ($updateResult === 0) {
|
if ($updateResult === 0) {
|
||||||
throw new BusinessException('更新归还申请失败,可能记录不存在或已被处理');
|
throw new BusinessException('更新归还申请失败,可能记录不存在或已被处理');
|
||||||
}
|
}
|
||||||
@@ -543,6 +545,11 @@ class InvRequisitionItemReturnService
|
|||||||
if(isset($p['status'])){
|
if(isset($p['status'])){
|
||||||
$config['where']['status'] = $p['status'];
|
$config['where']['status'] = $p['status'];
|
||||||
}
|
}
|
||||||
|
if(isset($p['handler_id']) && $p['handler_id']=='self'){
|
||||||
|
$config['where']['applicant_id'] = $request->user->uid;
|
||||||
|
}else{
|
||||||
|
$config['where']['handler_id'] = $request->user->uid;
|
||||||
|
}
|
||||||
$config['order']['id'] = 'desc';
|
$config['order']['id'] = 'desc';
|
||||||
break;
|
break;
|
||||||
case 'show':
|
case 'show':
|
||||||
@@ -572,8 +579,8 @@ class InvRequisitionItemReturnService
|
|||||||
public function serviceShow(Request $request, string $scene = 'show')
|
public function serviceShow(Request $request, string $scene = 'show')
|
||||||
{
|
{
|
||||||
$id = $request->get('id');
|
$id = $request->get('id');
|
||||||
$return = InvRequisitionReturn::where('id', $id)->first()->toArray();
|
$return = InvRequisitionReturn::where('id', $id)->first();
|
||||||
$return['item_return'] = InvRequisitionItemReturn::where('return_id', $return['id'])->orderBy('id', 'desc')->get()->toArray();
|
$return['item_return'] = InvRequisitionItemReturn::where('return_id', $return['id'])->orderBy('id', 'desc')->get();
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class InvRequisitionService
|
|||||||
$config['where']['applicant_id'] = $p['applicant_id'];
|
$config['where']['applicant_id'] = $p['applicant_id'];
|
||||||
} else { //审批人对应的记录
|
} else { //审批人对应的记录
|
||||||
$config['where']['approval.approver_id'] = $request->user->uid;
|
$config['where']['approval.approver_id'] = $request->user->uid;
|
||||||
|
$config['where']['approval.action'] = 0;
|
||||||
}
|
}
|
||||||
if(isset($p['phase']) && $p['phase'] == 'approve'){//借用审批中
|
if(isset($p['phase']) && $p['phase'] == 'approve'){//借用审批中
|
||||||
$config['where']['status'] = ['in',[10,11,13]];
|
$config['where']['status'] = ['in',[10,11,13]];
|
||||||
|
|||||||
@@ -54,22 +54,37 @@ class InvRequisitionController extends BaseController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$raw = $this->service->serviceList($request);
|
$raw = $this->service->serviceList($request);
|
||||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
$uid = $request->user->uid;
|
||||||
? [$this, 'indexFormat']
|
$data = $this->formatindex($raw,$uid);
|
||||||
: null);
|
// $data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||||
|
// ? [$this, 'indexFormat']
|
||||||
|
// : null);
|
||||||
return $this->success($data);
|
return $this->success($data);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function formatindex($p,$uid){
|
||||||
|
$records = $p->getCollection()
|
||||||
|
->map(fn($item) => $this->indexFormat($item, $uid))
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'records' => $records,
|
||||||
|
'total' => $p->total(),
|
||||||
|
'current' => $p->currentPage(),
|
||||||
|
'size' => $p->perPage(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表页数据格式化
|
* 列表页数据格式化
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function indexFormat($data)
|
protected function indexFormat($data, $uid)
|
||||||
{
|
{
|
||||||
if (isset($data['created_at']))
|
if (isset($data['created_at']))
|
||||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||||
@@ -80,6 +95,8 @@ class InvRequisitionController extends BaseController
|
|||||||
foreach ($data['item'] as $key => $item){
|
foreach ($data['item'] as $key => $item){
|
||||||
$corpId = InvItem::where('id', $item->item_id)->value('company_id');
|
$corpId = InvItem::where('id', $item->item_id)->value('company_id');
|
||||||
$item['company_name'] = Corp::where('id', $corpId)->value('name');
|
$item['company_name'] = Corp::where('id', $corpId)->value('name');
|
||||||
|
$aprove = InvRequisitionApprove::where('requisition_id', $data['id'])->where('approver_id', $uid)->orderBy('id','desc')->first();
|
||||||
|
$item['approval_action'] = $aprove?$aprove['action']:3; //查询人审核状态:0待审核 1通过 2驳回 3非审核人
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class InvRequisitionItemReturnController extends BaseController
|
|||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
//$request->setGet('$request');
|
||||||
$raw = $this->service->serviceList($request);
|
$raw = $this->service->serviceList($request);
|
||||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||||
? [$this, 'indexFormat']
|
? [$this, 'indexFormat']
|
||||||
|
|||||||
+8
-2
@@ -520,9 +520,15 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/show', [app\admin\controller\InvRequisitionController::class, 'show']);
|
Route::any('/show', [app\admin\controller\InvRequisitionController::class, 'show']);
|
||||||
Route::any('/approve', [app\admin\controller\InvRequisitionController::class, 'approve']);
|
Route::any('/approve', [app\admin\controller\InvRequisitionController::class, 'approve']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 物品归还
|
// 物品归还
|
||||||
Route::any('/requisition/return', [app\admin\controller\InvRequisitionReturnController::class, 'store']);
|
Route::group('/requisition/return', function () {
|
||||||
// Route::any('/requisition/return', [app\admin\controller\InvRequisitionReturnController::class, 'returnConfirm']);
|
Route::any('/store', [app\common\controller\InvRequisitionItemReturnController::class, 'store']);
|
||||||
|
Route::any('/update', [app\common\controller\InvRequisitionItemReturnController::class, 'update']);
|
||||||
|
Route::any('/list', [app\common\controller\InvRequisitionItemReturnController::class, 'index']);
|
||||||
|
Route::any('/show', [app\common\controller\InvRequisitionItemReturnController::class, 'show']);
|
||||||
|
Route::any('/confirm', [app\common\controller\InvRequisitionItemReturnController::class, 'returnConfirm']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user