90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
|
namespace app\mobile\controller;
|
|
|
|
use app\common\controller\BaseController;
|
|
use app\common\model\Corp;
|
|
use app\common\model\InvItem;
|
|
use app\common\model\InvRequisitionAttachment;
|
|
use app\common\model\InvRequisitionItem;
|
|
use app\common\service\OssService;
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
use app\common\service\InvRequisitionService;
|
|
use support\Request;
|
|
|
|
class InvRequisitionController extends BaseController
|
|
{
|
|
use CrudControllerTrait;
|
|
|
|
protected $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new InvRequisitionService();
|
|
}
|
|
|
|
/**
|
|
* 提交物品申请
|
|
*
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function apply(Request $request)
|
|
{
|
|
try {
|
|
// 验证申请数据
|
|
$data = $this->validate($this->service->getValidator(), $request->post(), 'apply');
|
|
|
|
// 处理申请逻辑
|
|
$result = $this->service->serviceStore($request, $data, 'apply');
|
|
|
|
return $this->success($result, '申请提交成功');
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function indexFormat($data)
|
|
{
|
|
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();
|
|
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');
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 详情页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function showFormat($data)
|
|
{
|
|
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;
|
|
}
|
|
} |