119 lines
4.0 KiB
PHP
119 lines
4.0 KiB
PHP
<?php
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\BaseController;
|
|
use app\common\model\InvRequisitionApprove;
|
|
use app\common\model\InvRequisitionAttachment;
|
|
use app\common\model\InvRequisitionItem;
|
|
use app\common\service\OssService;
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
use app\admin\service\InvRequisitionService;
|
|
use support\Request;
|
|
|
|
class InvRequisitionController extends BaseController
|
|
{
|
|
use CrudControllerTrait;
|
|
|
|
protected $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new InvRequisitionService();
|
|
}
|
|
|
|
/**
|
|
* 审核
|
|
*
|
|
* @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());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取列表
|
|
*
|
|
* @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;
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function showFormat($data)
|
|
{
|
|
if (isset($data['id'])){
|
|
$data['approve'] = InvRequisitionApprove::where('requisition_id', $data['id'])->orderBy('id')->get()->toArray();
|
|
|
|
$approve_id = 0;
|
|
foreach ($data['approve'] as $key => $value) {
|
|
if (isset($value['created_at'])){
|
|
$value['created_at'] = is_int($value['created_at'])?$value['created_at']:strtotime($value['created_at']);
|
|
$data['approve'][$key]['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
|
|
}
|
|
if (isset($value['updated_at'])){
|
|
$value['updated_at'] = is_int($value['updated_at'])?$value['updated_at']:strtotime($value['updated_at']);
|
|
$data['approve'][$key]['updated_at'] = date('Y-m-d H:i:s', $value['updated_at']);
|
|
}
|
|
$approve_id = $value['id'];
|
|
}
|
|
$data['approve_id'] = $approve_id;
|
|
}
|
|
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;
|
|
}
|
|
} |