2025-12-05 09:22:53 +00:00
|
|
|
<?php
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
|
|
use app\common\controller\BaseController;
|
2026-02-02 13:17:11 +08:00
|
|
|
use app\common\model\InvRequisitionApprove;
|
|
|
|
|
use app\common\model\InvRequisitionAttachment;
|
|
|
|
|
use app\common\model\InvRequisitionItem;
|
|
|
|
|
use app\common\service\OssService;
|
2025-12-05 09:22:53 +00:00
|
|
|
use app\common\traits\crud\CrudControllerTrait;
|
2026-01-30 10:46:54 +08:00
|
|
|
use app\admin\service\InvRequisitionService;
|
2026-02-02 13:17:11 +08:00
|
|
|
use support\Request;
|
2025-12-05 09:22:53 +00:00
|
|
|
|
|
|
|
|
class InvRequisitionController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
use CrudControllerTrait;
|
|
|
|
|
|
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->service = new InvRequisitionService();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 13:17:11 +08:00
|
|
|
/**
|
|
|
|
|
* 审核
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return \support\Response
|
|
|
|
|
*/
|
|
|
|
|
public function approve(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$data = $this->service->serviceApprove($request);
|
|
|
|
|
return $this->success($data);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return $this->error($e->getMessage().$e->getFile().$e->getLine().$e->getTraceAsString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取列表
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request 请求对象
|
|
|
|
|
* @return mixed 返回分页数据及总数
|
|
|
|
|
*/
|
|
|
|
|
public function index(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$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
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function indexFormat($data)
|
|
|
|
|
{
|
|
|
|
|
// if (isset($data['id'])){
|
|
|
|
|
// $data['approve'] = InvRequisitionApprove::where('requisition_id', $data['id'])->get();
|
|
|
|
|
// }
|
|
|
|
|
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']);
|
|
|
|
|
if (isset($data['id'])){
|
|
|
|
|
$data['item'] = InvRequisitionItem::where('requisition_id', $data['id'])->get();
|
|
|
|
|
}
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-05 09:22:53 +00:00
|
|
|
/**
|
|
|
|
|
* 列表页数据格式化
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2026-02-02 13:17:11 +08:00
|
|
|
protected function showFormat($data)
|
|
|
|
|
{
|
|
|
|
|
if (isset($data['id'])){
|
|
|
|
|
$data['approve'] = InvRequisitionApprove::where('requisition_id', $data['id'])->get();
|
|
|
|
|
}
|
|
|
|
|
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']);
|
|
|
|
|
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']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
2025-12-05 09:22:53 +00:00
|
|
|
}
|