2021-06-23 01:05:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Member;
|
|
|
|
|
2021-08-22 21:40:27 +02:00
|
|
|
use App\Activity;
|
|
|
|
use App\Confession;
|
|
|
|
use App\Group;
|
2022-05-01 21:00:15 +02:00
|
|
|
use App\Setting\NamiSettings;
|
2021-08-22 21:40:27 +02:00
|
|
|
use App\Subactivity;
|
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:00:15 +02:00
|
|
|
Member::withoutEvents(function () use ($response, $api, $member) {
|
|
|
|
$version = $api->member($member->group->nami_id, $response['id'])['version'];
|
|
|
|
$member->update(['version' => $version, 'nami_id' => $response['id']]);
|
2021-06-23 01:05:17 +02:00
|
|
|
});
|
2021-06-24 23:48:08 +02:00
|
|
|
|
2022-05-01 21:00:15 +02:00
|
|
|
$memberships = $member->getNamiMemberships($api);
|
2021-06-24 23:48:08 +02:00
|
|
|
foreach ($memberships as $membership) {
|
2022-05-01 21:00:15 +02:00
|
|
|
$member->memberships()->create([
|
2022-01-02 12:32:57 +01:00
|
|
|
'activity_id' => Activity::nami($membership['activity_id'])->id,
|
2021-08-22 21:40:27 +02:00
|
|
|
'subactivity_id' => $membership['subactivity_id']
|
|
|
|
? Subactivity::nami($membership['subactivity_id'])->id
|
2022-01-02 12:32:57 +01:00
|
|
|
: null,
|
2021-06-24 23:48:08 +02:00
|
|
|
'group_id' => Group::nami($membership['group_id'])->id,
|
|
|
|
'nami_id' => $membership['id'],
|
|
|
|
'created_at' => $membership['starts_at'],
|
|
|
|
]);
|
|
|
|
}
|
2021-06-23 01:05:17 +02:00
|
|
|
}
|
|
|
|
}
|