jingcai-php/app/Http/Controllers/Api/Customer/UploadController.php

50 lines
1.2 KiB
PHP
Executable File

<?php
/**
* @createtime 2023/5/17
* @author wild
* @copyright PhpStorm
*/
namespace App\Http\Controllers\Api\Customer;
use App\Enums\MaterialScene;
use App\Enums\UserType;
use App\Service\MaterialService;
use App\Utils\ThrowException;
use Illuminate\Http\Request;
class UploadController extends BaseController
{
/**
* @api {POST} /api/customer/upload 上传文件
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {File} file 文件的name
* @apiParam {Int} type 3:反馈;
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "id": 2, // id
* "file_url": "http://localhost/uploads/lottery/aEZKWqAm7qXR896PIE1cNtHbGaTYCbuDsfijFHuT.jpg" // 地址
* }
* }
*
*/
public function index(Request $request, MaterialService $materialService) {
$file = $request->file('file');
$type = $request->input('type');
ThrowException::isTrue(!MaterialScene::hasValue($type, false), '类型不对');
$data = $materialService->upload($file, $this->customerId(), $type, UserType::CUSTOMER);
return $this->jsonSuccess($data);
}
}