Files
hyperf_service/app/Service/Api/Salesman/ForceTakePhotoService.php
2025-04-01 15:11:04 +08:00

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\Salesman;
use App\Exception\ErrException;
use App\Model\SalesmanTakePhoto;
use App\Service\ServiceTrait\Common\OssTrait;
use Hyperf\DbConnection\Db;
class ForceTakePhotoService extends BaseSalesmanService
{
use OssTrait;
/**
* @return array
* @throws ErrException
*/
public function handle(): array
{
$imageId = (int)$this->request->input('image_id');
Db::transaction(function () use ($imageId) {
$insertModel = new SalesmanTakePhoto();
$insertModel->user_id = $this->userId;
$insertModel->cycle_id = $this->cycleId;
$insertModel->date = date('Y-m-d');
$insertModel->image_id = $imageId;
$this->updateOssObjects([$imageId]);
if (!$insertModel->save()) throw new ErrException('拍照失败');
});
return $this->return->success();
}
}