45 lines
1.0 KiB
PHP
45 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Api\Suggest;
|
|
|
|
use App\Exception\ErrException;
|
|
use App\Model\Suggest;
|
|
use App\Service\Api\BaseService;
|
|
use App\Service\ServiceTrait\Common\OssTrait;
|
|
use Hyperf\DbConnection\Db;
|
|
|
|
class SubmissionService extends BaseService
|
|
{
|
|
use OssTrait;
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
Db::transaction(function () {
|
|
$insertModel = new Suggest();
|
|
|
|
$imageIds = $this->request->input('image_ids');
|
|
|
|
$insertModel->user_id = $this->userId;
|
|
$insertModel->content = $this->request->input('content');
|
|
if (!empty($imageIds)) {
|
|
$insertModel->image_ids = $imageIds;
|
|
$this->updateOssObjects(explode(',', $imageIds));
|
|
}
|
|
|
|
if (!$insertModel->save()) throw new ErrException('提交失败');
|
|
});
|
|
|
|
return $this->return->success();
|
|
}
|
|
} |