123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Log;
- use App\Service\ImportService;
- use App\Service\MaterialService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Validation\Rule;
- class MaterialController extends Controller
- {
- /**
- * 上传素材
- * */
- public function upload(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'type' => ['required', Rule::in([1, 2, 3, 4])],
- 'need_media_id' => ['nullable', Rule::in([0, 1])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $file = $request->file('material_file');
- $corpid = $request->input('corpid');
- $type = $request->input('type');
- $needMediaId = $request->input('need_media_id');
- $uploadToOss = $request->input('upload_to_oss', 1);
- $data = [];
- $errno = MaterialService::uploadMaterial($corpid, $type, $file, $needMediaId, $uploadToOss, $data);
- return self::returnValue($data, $errno);
- }
- /**
- * 导入excel
- * @param Request $request
- * @return mixed
- */
- public function importExcel(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'file' => 'required|file',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $file = $request->file('file');
- $corpid = $request->input('corpid');
- $importType = $request->input('import_type', 1);
- list($res, $code) = ImportService::importExcel($file, $corpid, $importType);
- return self::returnValue($res, $code);
- }
- public function uploadFileToOss(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'type' => ['required', Rule::in([1, 2, 3, 4])],
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $file = $request->file('file');
- $corpid = $request->input('corpid');
- $type = $request->input('type');
- $isMaterial = $request->input('is_material', 1);
- $data = [];
- $errno = MaterialService::uploadFileToOss($corpid, $type, $file, $isMaterial, $data);
- return self::returnValue($data, $errno);
- }
- public function uploadFileByUrl(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'corpid' => 'required|string',
- 'img_url' => 'required|string',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $corpid = $request->input('corpid');
- $imgUrl = $request->input('img_url');
- $ossUrl = '';
- $errno = MaterialService::uploadFileByUrl($corpid, $imgUrl, $ossUrl);
- return self::returnValue(['oss_url' => $ossUrl], $errno);
- }
- }
|