TechnicianService.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Services;
  3. use App\Models\CoachQualRecord;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Models\TechnicianCertification;
  6. use Slowlyo\OwlAdmin\Services\AdminService;
  7. /**
  8. * 技师资质认证
  9. *
  10. * @method CoachQualRecord getModel()
  11. * @method CoachQualRecord|\Illuminate\Database\Query\Builder query()
  12. */
  13. class TechnicianService extends AdminService
  14. {
  15. protected string $modelName = CoachQualRecord::class;
  16. /**
  17. * 更新技师资质信息
  18. *
  19. * @param int $id 资质记录ID
  20. * @param array $data 更新的数据
  21. * @return bool
  22. * @throws \Exception
  23. */
  24. public function updateCertification(int $id, array $data): bool
  25. {
  26. DB::beginTransaction();
  27. try {
  28. // 获取资质记录
  29. $record = $this->getModel()::findOrFail($id);
  30. // 准备更新数据,确保不为 null
  31. $updateData = [];
  32. if (isset($data['qual_photo'])) {
  33. $updateData['qual_photo'] = json_encode($data['qual_photo']);
  34. }
  35. if (isset($data['business_license'])) {
  36. // 确保存储的值是有效的 JSON 格式
  37. $updateData['business_license'] = json_encode($data['business_license']);
  38. }
  39. if (isset($data['health_cert'])) {
  40. // 确保存储的值是有效的 JSON 格式
  41. $updateData['health_cert'] = json_encode($data['health_cert']);
  42. }
  43. // 确保更新数据不为空
  44. if (empty($updateData)) {
  45. throw new \Exception('没有提供有效的更新数据');
  46. }
  47. // 更新资质记录
  48. $record->update($updateData);
  49. DB::commit();
  50. return true;
  51. } catch (\Exception $e) {
  52. DB::rollBack();
  53. throw $e;
  54. }
  55. }
  56. }