adrema/app/Member/CreateJob.php

74 lines
2.5 KiB
PHP
Raw Normal View History

2021-06-23 01:05:17 +02:00
<?php
namespace App\Member;
2022-05-01 21:30:14 +02:00
use App\Actions\MemberPullAction;
2021-08-22 21:40:27 +02:00
use App\Confession;
2022-05-01 21:00:15 +02:00
use App\Setting\NamiSettings;
2021-06-23 01:05:17 +02:00
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class CreateJob implements ShouldQueue
{
2022-03-11 20:19:17 +01:00
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
2021-06-23 01:05:17 +02:00
2022-02-12 15:35:58 +01:00
public int $memberId;
2021-06-23 01:05:17 +02:00
2022-02-19 18:06:07 +01:00
public function __construct(Member $member)
2021-06-23 01:05:17 +02:00
{
$this->memberId = $member->id;
}
/**
* Execute the job.
*
* @return void
*/
2022-05-01 21:00:15 +02:00
public function handle(NamiSettings $settings)
2021-06-23 01:05:17 +02:00
{
2022-05-01 21:00:15 +02:00
$member = Member::findOrFail($this->memberId);
if ($member->hasNami) {
2022-01-02 12:32:57 +01:00
return;
2021-06-23 01:05:17 +02:00
}
2022-05-01 21:00:15 +02:00
$api = $settings->login();
$response = $api->putMember([
'firstname' => $member->firstname,
'lastname' => $member->lastname,
'joined_at' => $member->joined_at,
'birthday' => $member->birthday,
'send_newspaper' => $member->send_newspaper,
'address' => $member->address,
'zip' => $member->zip,
'location' => $member->location,
'nickname' => $member->nickname,
'other_country' => $member->other_country,
'further_address' => $member->further_address,
'main_phone' => $member->main_phone,
'mobile_phone' => $member->mobile_phone,
'work_phone' => $member->work_phone,
'fax' => $member->fax,
'email' => $member->email,
'email_parents' => $member->email_parents,
'gender_id' => optional($member->gender)->nami_id,
'confession_id' => $member->confession ? $member->confession->nami_id : Confession::firstWhere('is_null', true)->id,
'region_id' => optional($member->region)->nami_id,
'country_id' => $member->country->nami_id,
'fee_id' => $member->getNamiFeeId(),
'nationality_id' => $member->nationality->nami_id,
'group_id' => $member->group->nami_id,
'first_activity_id' => $member->firstActivity->nami_id,
'first_subactivity_id' => $member->firstSubactivity->nami_id,
2021-06-23 01:05:17 +02:00
]);
2022-05-01 21:30:14 +02:00
Member::withoutEvents(function () use ($response, $member, $api) {
$member->update(['nami_id' => $response['id']]);
2022-05-02 09:58:42 +02:00
app(MemberPullAction::class)->api($api)->member($member->group->nami_id, $member->nami_id)->execute();
2021-06-23 01:05:17 +02:00
});
}
}