12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Services;
- use App\Models\CoachUser;
- use App\Enums\TechnicianStatus;
- use App\Models\CoachInfoRecord;
- use Illuminate\Support\Facades\DB;
- use App\Enums\TechnicianAuthStatus;
- use Slowlyo\OwlAdmin\Services\AdminService;
- /**
- * 技师信息记录
- *
- * @method CoachInfoRecord getModel()
- * @method CoachInfoRecord|\Illuminate\Database\Query\Builder query()
- */
- class CoachInfoRecordService extends AdminService
- {
- protected string $modelName = CoachInfoRecord::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): bool
- {
- DB::beginTransaction();
- try {
- // 获取申请记录
- $record = $this->getModel()::findOrFail($id);
- // 检查状态
- if ($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([
- 'state' => TechnicianStatus::ACTIVE->value,
- 'info_record_id' => $record->id
- ]);
- }
- DB::commit();
- return true;
- } catch (\Exception $e) {
- DB::rollBack();
- throw $e;
- }
- }
- }
|