From d1f3c33a021abcb6d623709a22fd1d227f263bf2 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Tue, 1 Apr 2025 15:11:04 +0800 Subject: [PATCH] feat : check --- app/Controller/Api/SalesmanController.php | 3 +- app/Model/SalesmanTakePhoto.php | 33 +++++++++++++++++++ .../Api/Salesman/ForceTakePhotoService.php | 30 +++++++++++++++-- app/Service/Common/OssCallbackService.php | 2 ++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 app/Model/SalesmanTakePhoto.php diff --git a/app/Controller/Api/SalesmanController.php b/app/Controller/Api/SalesmanController.php index dc9fd93..415e42d 100644 --- a/app/Controller/Api/SalesmanController.php +++ b/app/Controller/Api/SalesmanController.php @@ -6,6 +6,7 @@ namespace App\Controller\Api; use App\Controller\AbstractController; use App\Middleware\Api\JwtAuthMiddleware; +use App\Service\Api\Salesman\ForceTakePhotoService; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Middlewares; use Hyperf\HttpServer\Annotation\RequestMapping; @@ -21,6 +22,6 @@ class SalesmanController extends AbstractController #[Scene(scene: 'take_photo')] public function forceTakePhoto() { - return $response->raw('Hello Hyperf!'); + return (new ForceTakePhotoService)->handle(); } } diff --git a/app/Model/SalesmanTakePhoto.php b/app/Model/SalesmanTakePhoto.php new file mode 100644 index 0000000..fdaf81b --- /dev/null +++ b/app/Model/SalesmanTakePhoto.php @@ -0,0 +1,33 @@ + 'integer', 'cycle_id' => 'integer', 'user_id' => 'integer', 'image_id' => 'integer']; +} diff --git a/app/Service/Api/Salesman/ForceTakePhotoService.php b/app/Service/Api/Salesman/ForceTakePhotoService.php index de7750e..9fe7797 100644 --- a/app/Service/Api/Salesman/ForceTakePhotoService.php +++ b/app/Service/Api/Salesman/ForceTakePhotoService.php @@ -10,10 +10,36 @@ 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 { - public function handle() + use OssTrait; + + /** + * @return array + * @throws ErrException + */ + public function handle(): array { - //todo Write logic + $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(); } } \ No newline at end of file diff --git a/app/Service/Common/OssCallbackService.php b/app/Service/Common/OssCallbackService.php index ce888fb..5a28772 100644 --- a/app/Service/Common/OssCallbackService.php +++ b/app/Service/Common/OssCallbackService.php @@ -109,6 +109,8 @@ class OssCallbackService 'site', 'category', 'sku', + 'salesman', + 'driver' ]; /**