180 lines
6.1 KiB
PHP
180 lines
6.1 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 {
|
|
$applicant_id = $request->get('applicant_id');
|
|
$uid = $request->user->uid;
|
|
$raw = $this->service->serviceList($request);
|
|
$data = $this->formatindex($raw,$applicant_id,$uid);
|
|
// $data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
|
// ? [$this, 'indexFormat']
|
|
// : null);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function formatindex($p,$applicant_id,$uid){
|
|
$records = $p->getCollection()
|
|
->map(fn($item) => $this->indexFormat($item, $applicant_id,$uid))
|
|
->toArray();
|
|
|
|
return [
|
|
'records' => $records,
|
|
'total' => $p->total(),
|
|
'current' => $p->currentPage(),
|
|
'size' => $p->perPage(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function indexFormat($data, $applicant_id, $uid)
|
|
{
|
|
if (isset($data['id'])){
|
|
//$data['approve'] = InvRequisitionApprove::where('requisition_id', $data['id'])->get();
|
|
$data = $data->toArray();
|
|
}
|
|
if (isset($data['created_at'])){
|
|
$data['created_at'] = is_int($data['created_at'])?$data['created_at']:strtotime($data['created_at']);
|
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
|
}
|
|
if (isset($data['updated_at'])){
|
|
$data['updated_at'] = is_int($data['updated_at'])?$data['updated_at']:strtotime($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();
|
|
}
|
|
|
|
if($applicant_id != 'self' && isset($data['id'])){ //不是查询自己数据时查询是否已审核
|
|
$approve = InvRequisitionApprove::where('requisition_id', $data['id'])
|
|
->where('approver_id', $uid)
|
|
->first();
|
|
$data['action'] = $approve['action']??3;//查询人审核状态:0待审核 1通过 2驳回 3非审核人
|
|
}
|
|
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']);
|
|
}
|
|
$data['approve'][$key]['action_at'] = date('Y-m-d H:i:s', $data['approve'][$key]['action_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;
|
|
}
|
|
|
|
/**
|
|
* 管理员代领
|
|
*
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function proxyClaim(Request $request)
|
|
{
|
|
try {
|
|
$data = $this->service->proxyClaim($request, $request->post());
|
|
return $this->success($data, '代领成功');
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 扫码/代领记录查询
|
|
*
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function qrClaims(Request $request)
|
|
{
|
|
try {
|
|
$data = $this->service->qrClaimsList($request);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
} |