1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Services;
- use App\Models\CoachUser;
- use App\Models\CoachQualRecord;
- use Illuminate\Support\Facades\DB;
- use App\Enums\TechnicianAuthStatus;
- use Slowlyo\OwlAdmin\Services\AdminService;
- /**
- * 技师资质认证记录
- *
- * @method CoachQualRecord getModel()
- * @method CoachQualRecord|\Illuminate\Database\Query\Builder query()
- */
- class CoachQualRecordService extends AdminService
- {
- protected string $modelName = CoachQualRecord::class;
- /**
- * 审核技师资质认证
- *
- * @param int $id 认证记录ID
- * @param int $state 审核状态 2:通过 3:驳回
- * @param string $remark 审核意见
- * @param int $adminId 审核人ID
- * @return bool
- * @throws \Exception
- */
- public function audit(int $id, int $state, string $remark = '', int $adminId = 0): bool
- {
- DB::beginTransaction();
- try {
- // 获取认证记录
- $record = $this->getModel()::findOrFail($id);
- // 检查状态
- if ((int)$record->state != TechnicianAuthStatus::AUDITING->value) {
- throw new \Exception('该认证已审核');
- }
- // 更新认证记录
- $record->update([
- 'state' => $state,
- 'audit_remark' => $remark,
- 'auditor' => $adminId,
- 'audit_time' => now(),
- ]);
- // 如果审核通过,更新技师状态
- if ($state == TechnicianAuthStatus::PASSED->value) {
- CoachUser::where('id', $record->coach_id)->update([
- 'qualification_record_id' => $record->id
- ]);
- }
- DB::commit();
- return true;
- } catch (\Exception $e) {
- DB::rollBack();
- throw $e;
- }
- }
- }
|