1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Services;
- use App\Models\CoachQualRecord;
- use Illuminate\Support\Facades\DB;
- use App\Models\TechnicianCertification;
- use Slowlyo\OwlAdmin\Services\AdminService;
- /**
- * 技师资质认证
- *
- * @method CoachQualRecord getModel()
- * @method CoachQualRecord|\Illuminate\Database\Query\Builder query()
- */
- class TechnicianService extends AdminService
- {
- protected string $modelName = CoachQualRecord::class;
- /**
- * 更新技师资质信息
- *
- * @param int $id 资质记录ID
- * @param array $data 更新的数据
- * @return bool
- * @throws \Exception
- */
- public function updateCertification(int $id, array $data): bool
- {
- DB::beginTransaction();
- try {
- // 获取资质记录
- $record = $this->getModel()::findOrFail($id);
- // 准备更新数据,确保不为 null
- $updateData = [];
- if (isset($data['qual_photo'])) {
- $updateData['qual_photo'] = json_encode($data['qual_photo']);
- }
- if (isset($data['business_license'])) {
- // 确保存储的值是有效的 JSON 格式
- $updateData['business_license'] = json_encode($data['business_license']);
- }
- if (isset($data['health_cert'])) {
- // 确保存储的值是有效的 JSON 格式
- $updateData['health_cert'] = json_encode($data['health_cert']);
- }
- // 确保更新数据不为空
- if (empty($updateData)) {
- throw new \Exception('没有提供有效的更新数据');
- }
- // 更新资质记录
- $record->update($updateData);
- DB::commit();
- return true;
- } catch (\Exception $e) {
- DB::rollBack();
- throw $e;
- }
- }
- }
|