feat : suggest
This commit is contained in:
45
app/Service/Api/Suggest/SubmissionService.php
Normal file
45
app/Service/Api/Suggest/SubmissionService.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user