2021-09-30 13:27:25 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2021-10-25 20:16:43 +09:00
|
|
|
use App\Http\Controllers\Controller, Session;
|
2021-10-15 10:37:47 +09:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2021-09-30 13:27:25 +09:00
|
|
|
use Illuminate\Http\Request;
|
2021-11-20 11:49:20 +09:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2021-10-15 10:37:47 +09:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-12-20 22:08:39 +09:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2021-10-28 17:12:12 +09:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2021-09-30 13:27:25 +09:00
|
|
|
|
|
|
|
use App\Models\Child;
|
|
|
|
use App\Models\FatherRelation;
|
|
|
|
use App\Models\MeetingApprovals;
|
2021-10-29 17:32:00 +09:00
|
|
|
use App\Models\TelActivation;
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-29 17:51:41 +09:00
|
|
|
use App\Notifications\SmsNotification;
|
2021-12-20 22:12:20 +09:00
|
|
|
use App\Mail\ChildrenMainRegistrationMail;
|
2021-10-29 17:51:41 +09:00
|
|
|
|
2021-09-30 13:27:25 +09:00
|
|
|
class ChildrenController extends Controller {
|
2021-10-25 20:16:43 +09:00
|
|
|
use AuthenticationTrait;
|
|
|
|
use AuthorizationTrait;
|
|
|
|
|
|
|
|
/* Traitで使うメソッド */
|
|
|
|
protected function getGuard () {
|
2021-10-30 23:13:12 +09:00
|
|
|
return 'children';
|
2021-10-25 20:16:43 +09:00
|
|
|
}
|
|
|
|
protected function getModel () {
|
2021-10-25 22:38:06 +09:00
|
|
|
return new \App\Models\Child();
|
2021-10-25 20:16:43 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
public function registerTemporary (Request $r) {
|
2021-11-10 11:42:07 +09:00
|
|
|
// 電話番号の文字数。
|
|
|
|
Validator::extend('tel_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->telsize($value);
|
2021-11-10 11:42:07 +09:00
|
|
|
});
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
$validate = Validator::make($r->all(), [
|
2021-11-10 11:42:07 +09:00
|
|
|
'tel' => 'required|unique:children|numeric|starts_with:0|tel_size'
|
2021-10-15 10:37:47 +09:00
|
|
|
]);
|
2021-11-10 11:42:07 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
if ($validate->fails()) {
|
|
|
|
// バリデーションエラー
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
2021-10-29 17:32:00 +09:00
|
|
|
if ($get = TelActivation::where('tel', $r->tel)->first()) {
|
2021-11-25 01:11:40 +09:00
|
|
|
if (time() > strtotime($get->ttl)) {
|
|
|
|
TelActivation::where('tel', $r->tel)->delete();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['既に使用されている電話番号です。']];
|
|
|
|
}
|
2021-10-15 10:37:47 +09:00
|
|
|
}
|
|
|
|
|
2021-11-22 21:48:48 +09:00
|
|
|
$token = bin2hex(random_bytes(24));
|
2021-11-28 16:27:04 +09:00
|
|
|
|
2021-10-29 17:51:41 +09:00
|
|
|
$create = [
|
|
|
|
'type' => 0,
|
|
|
|
'tel' => $r->tel,
|
|
|
|
'token' => $token,
|
2021-11-28 16:27:04 +09:00
|
|
|
'ttl' => date('Y-m-d H:i:s', strtotime("8 hour")),
|
2021-10-29 17:51:41 +09:00
|
|
|
];
|
2021-10-15 10:37:47 +09:00
|
|
|
|
2021-12-24 14:40:31 +09:00
|
|
|
if (isset($r->father_id) && $r->father_id > 0) {
|
|
|
|
$create['father_id'] = $r->father_id;
|
|
|
|
}
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
try {
|
2021-10-29 17:32:00 +09:00
|
|
|
// DBに入ります。
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
$telact = new TelActivation;
|
|
|
|
$telact->fill($create);
|
|
|
|
$telact->push();
|
2021-10-29 17:51:41 +09:00
|
|
|
|
|
|
|
// SMSを送ります。
|
2021-12-14 17:50:04 +09:00
|
|
|
$message = view('sms.children.register.temporary', ['token' => $token]);
|
2021-11-05 18:20:36 +09:00
|
|
|
\Notification::route('nexmo', '81'.substr($r->tel, 1))->notify(new SmsNotification($message));
|
2021-11-20 11:49:20 +09:00
|
|
|
|
|
|
|
DB::commit();
|
2021-10-15 10:37:47 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::rollback();
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['登録に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 仮登録に成功した場合
|
|
|
|
return ['status_code' => 200, 'params' => ['tel' => $r->tel]];
|
|
|
|
}
|
|
|
|
|
2021-12-18 16:51:43 +09:00
|
|
|
public function checkRegisterMain (Request $r) {
|
|
|
|
// トークンの確認
|
2021-12-24 02:30:56 +09:00
|
|
|
if (null === ($get = TelActivation::select('tel')->where('token', $r->token)->first())) {
|
2021-12-18 16:51:43 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['不正な登録トークン。']];
|
|
|
|
}
|
|
|
|
|
2021-12-24 02:30:56 +09:00
|
|
|
$get->tel .= rand(100,999);
|
|
|
|
|
2021-12-18 16:51:43 +09:00
|
|
|
// 本登録に成功
|
2021-12-23 18:28:22 +09:00
|
|
|
return ['status_code' => 200, 'params' => $get];
|
2021-12-18 16:51:43 +09:00
|
|
|
}
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
public function registerMain (Request $r) {
|
2021-11-22 20:45:19 +09:00
|
|
|
// トークンの確認
|
|
|
|
if (null === ($get = TelActivation::where('token', $r->token)->first())) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['仮登録の有効期限が切れました。改めて親にお問い合わせいただき、再登録の手続きを行ってください。']];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 有効期限が切れている場合
|
|
|
|
if (time() > strtotime($get->ttl)) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['仮登録の有効期限が切れました。改めて親にお問い合わせいただき、再登録の手続きを行ってください。']];
|
|
|
|
}
|
|
|
|
|
2021-11-28 17:10:40 +09:00
|
|
|
if (!is_null($r->image) && count(Storage::disk('private')->files('/')) >= 9999) {
|
|
|
|
Log::critical('ストレージの限界を超えています。9999個ファイルまで保存可能ですので、不要なファイルを削除して下さい。');
|
2021-12-20 22:08:39 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['登録に失敗しました。']];
|
2021-11-26 16:15:22 +09:00
|
|
|
}
|
|
|
|
|
2021-11-30 12:45:32 +09:00
|
|
|
// ファイルサイズは5MiB以内又はnull
|
2021-11-05 12:50:00 +09:00
|
|
|
Validator::extend('image_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagesizecannull($value);
|
2021-11-05 12:50:00 +09:00
|
|
|
});
|
2021-11-22 21:48:48 +09:00
|
|
|
|
2021-11-05 12:50:00 +09:00
|
|
|
// ミームタイプ
|
|
|
|
Validator::extend('image_meme', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagememecannull($value);
|
2021-11-05 12:50:00 +09:00
|
|
|
});
|
|
|
|
|
2021-12-30 14:06:21 +09:00
|
|
|
// 規約に同意する
|
|
|
|
Validator::extend('agreed', function ($attribute, $value, $params, $validator) {
|
|
|
|
return $value == 'true';
|
|
|
|
});
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
$validate = Validator::make($r->all(), [
|
2021-10-29 17:51:41 +09:00
|
|
|
'identity' => 'required|max:20|alpha_num',
|
2021-10-15 10:37:47 +09:00
|
|
|
'email' => 'required|unique:children|max:255|email',
|
2021-12-19 11:32:45 +09:00
|
|
|
'password' => ['required', 'min:8', 'max:72', 'confirmed', new \App\Rules\Hankaku],
|
2021-10-15 10:37:47 +09:00
|
|
|
'last_name' => 'required|max:100',
|
|
|
|
'first_name' => 'required|max:100',
|
2021-11-05 12:50:00 +09:00
|
|
|
'image' => 'image_size|image_meme',
|
2021-10-15 10:37:47 +09:00
|
|
|
'company' => 'max:100',
|
2021-12-30 14:06:21 +09:00
|
|
|
'terms' => 'agreed',
|
2021-10-15 10:37:47 +09:00
|
|
|
]);
|
2021-11-05 12:50:00 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
if ($validate->fails()) {
|
|
|
|
// バリデーションエラー
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
2021-11-28 22:06:46 +09:00
|
|
|
if ($r->image == 'null') {
|
|
|
|
$r->image = null;
|
|
|
|
}
|
|
|
|
|
2021-10-29 17:51:41 +09:00
|
|
|
$password = Hash::make($r->password);
|
2021-11-10 11:34:43 +09:00
|
|
|
|
2021-11-28 22:06:46 +09:00
|
|
|
if (!is_null($r->image)) {
|
2021-11-30 13:34:14 +09:00
|
|
|
$filename = $this->uuidv4().'.jpg';
|
2021-11-28 22:06:46 +09:00
|
|
|
}
|
2021-11-10 11:34:43 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
$insert = [
|
2021-10-29 17:51:41 +09:00
|
|
|
'identity' => $r->identity,
|
2021-10-15 10:37:47 +09:00
|
|
|
'email' => $r->email,
|
2021-11-05 18:20:36 +09:00
|
|
|
'tel' => $get->tel,
|
2021-10-15 10:37:47 +09:00
|
|
|
'password' => $password,
|
|
|
|
'last_name' => $r->last_name,
|
|
|
|
'first_name' => $r->first_name,
|
2021-11-28 22:06:46 +09:00
|
|
|
'image' => !is_null($r->image) ? '/files/'.$filename : '/assets/default/avatar.jpg',
|
2021-10-15 10:37:47 +09:00
|
|
|
'company' => $r->company,
|
|
|
|
];
|
|
|
|
|
|
|
|
try {
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::beginTransaction();
|
|
|
|
$child = new Child;
|
|
|
|
$telact = TelActivation::where('token', $r->token)->first();
|
|
|
|
|
2021-11-28 22:06:46 +09:00
|
|
|
if (!is_null($r->image)) {
|
|
|
|
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
|
|
|
|
Storage::disk('private')->put($filename, $image);
|
2021-12-01 13:40:37 +09:00
|
|
|
$this->fiximg($filename);
|
2021-11-28 22:06:46 +09:00
|
|
|
}
|
2021-11-23 11:36:07 +09:00
|
|
|
|
2021-11-20 11:49:20 +09:00
|
|
|
$child->fill($insert);
|
|
|
|
$child->push();
|
|
|
|
|
2021-12-24 14:40:31 +09:00
|
|
|
if (!is_null($telact->father_id)) {
|
|
|
|
$rel = new FatherRelation;
|
|
|
|
$add = [
|
|
|
|
'father_id' => $telact->father_id,
|
|
|
|
'child_id' => $child->id,
|
|
|
|
'hire_at' => date('Y-m-d H:i:s', time()),
|
|
|
|
];
|
|
|
|
|
|
|
|
$rel->fill($add);
|
|
|
|
$rel->push();
|
|
|
|
}
|
|
|
|
|
2021-12-18 16:51:43 +09:00
|
|
|
$telact->delete();
|
2021-11-20 11:49:20 +09:00
|
|
|
|
2021-12-20 18:56:18 +09:00
|
|
|
// メールを送ります。
|
|
|
|
Mail::to($r->email)->send(new ChildrenMainRegistrationMail());
|
2021-12-14 17:50:04 +09:00
|
|
|
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::commit();
|
2021-10-15 10:37:47 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::rollback();
|
2021-11-30 15:24:14 +09:00
|
|
|
if (!is_null($r->image)) Storage::disk('private')->delete($filename);
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['登録に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 本登録に成功
|
|
|
|
return ['status_code' => 200, 'success_messages' => ['本登録に成功しました。'], 'params' => ['tel' => $r->tel, 'password' => $password]];
|
|
|
|
}
|
2021-10-29 10:36:05 +09:00
|
|
|
|
|
|
|
public function requestPassword (Request $r) {
|
2021-11-10 11:42:07 +09:00
|
|
|
// 電話番号の文字数。
|
|
|
|
Validator::extend('tel_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->telsize($value);
|
2021-11-10 11:42:07 +09:00
|
|
|
});
|
|
|
|
|
2021-10-29 10:36:05 +09:00
|
|
|
$validate = Validator::make($r->all(), [
|
2021-11-10 11:42:07 +09:00
|
|
|
'tel' => 'required|numeric|starts_with:0|tel_size'
|
2021-10-29 10:36:05 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validate->fails()) {
|
|
|
|
// バリデーションエラー
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
2021-10-29 17:32:00 +09:00
|
|
|
if (null === ($result = Child::select('id')->where('tel', $r->tel)->first())) {
|
2021-10-29 10:36:05 +09:00
|
|
|
// メールアドレス照合に失敗
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['電話番号が未登録です。入力した情報を確認してください。']];
|
|
|
|
}
|
|
|
|
|
2021-11-22 21:48:48 +09:00
|
|
|
$token = bin2hex(random_bytes(24));
|
2021-11-28 16:27:04 +09:00
|
|
|
|
2021-10-29 10:36:05 +09:00
|
|
|
$create = [
|
|
|
|
'type' => 1,
|
|
|
|
'child_id' => $result->id,
|
|
|
|
'tel' => $r->tel,
|
|
|
|
'token' => $token,
|
2021-11-28 16:27:04 +09:00
|
|
|
'ttl' => date('Y-m-d H:i:s', strtotime("8 hour")),
|
2021-10-29 10:36:05 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
try {
|
2021-11-10 15:45:09 +09:00
|
|
|
// DBに入る又は変えります。
|
|
|
|
TelActivation::where('child_id', $result->id)->delete();
|
2021-10-29 10:36:05 +09:00
|
|
|
TelActivation::create($create);
|
|
|
|
|
|
|
|
// SMSを送ります。
|
2021-11-23 15:12:22 +09:00
|
|
|
$message = view('sms.children.password', ['token' => $token]);
|
2021-11-05 18:20:36 +09:00
|
|
|
\Notification::route('nexmo', '81'.substr($r->tel, 1))->notify(new SmsNotification($message));
|
2021-10-29 10:36:05 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
return ['status_code' => 400, 'error_messages' => '電話番号が未登録です。入力した情報を確認してください。'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
'id' => $result->id,
|
|
|
|
'tel' => $r->tel,
|
|
|
|
];
|
|
|
|
|
|
|
|
// メールアドレス照合に成功
|
|
|
|
return ['status_code' => 200, 'params' => $params, 'success_messages' => ['再発行用パスワードの送信に成功しました。']];
|
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
public function search (Request $r) {
|
|
|
|
if (!isset($r->keyword)) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['画像の更新に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null === ($result = Child::where('first_name', 'LIKE', '%'.$r->keyword.'%')->orWhere('last_name', 'LIKE', '%'.$r->keyword.'%')->orderBy('created_at', 'desc')->get())) {
|
|
|
|
// 親一覧の取得に失敗
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 親一覧の取得に成功
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
public function list () {
|
2021-11-17 16:58:01 +09:00
|
|
|
$child_select = ['id', 'first_name', 'last_name', 'tel', 'image'];
|
2021-11-16 18:57:48 +09:00
|
|
|
|
|
|
|
if (null === ($result = Child::select($child_select)->orderBy('created_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
// 親一覧の取得に失敗
|
|
|
|
return ['status_code' => 400];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
// 親一覧の取得に成功
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
2021-11-10 21:51:31 +09:00
|
|
|
public function listOfFather (Request $r) {
|
|
|
|
if (!isset($r->father_id)) {
|
2021-10-30 19:02:09 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-10-06 14:50:13 +09:00
|
|
|
$result = [];
|
2021-12-15 16:22:19 +09:00
|
|
|
$child_select = ['id', 'image', 'first_name', 'last_name', 'company', 'tel', 'email'];
|
2021-10-06 14:50:13 +09:00
|
|
|
|
2021-11-10 21:51:31 +09:00
|
|
|
if (null === ($list = FatherRelation::select('child_id')->where('father_id', (int)$r->father_id)->orderBy('created_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-30 19:02:09 +09:00
|
|
|
foreach ($list as $i => $l) {
|
|
|
|
if (null === ($result[] = Child::select($child_select)->where('id', $l->child_id)->first())) {
|
|
|
|
$result[$i] = [];
|
2021-10-07 13:51:53 +09:00
|
|
|
}
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
public function listOfMeeting (Request $r) {
|
|
|
|
$result = [];
|
|
|
|
$child_select = ['id', 'image', 'last_name', 'first_name'];
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-25 20:16:43 +09:00
|
|
|
if (null === ($list = MeetingApprovals::select('child_id')->where('meeting_id', (int)$r->meeting_id)->orderBy('created_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $l) {
|
|
|
|
if (null === ($result[] = Child::select($child_select)->find($l->child_id))) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
public function listOfMeetingNotifyUnapprovel (Request $r) {
|
|
|
|
if (!isset($r->meeting_id)) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['画像の更新に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = [];
|
|
|
|
$child_select = ['id', 'image', 'last_name', 'first_name', 'tel'];
|
|
|
|
$meeting_approvals_select = ['approval_at'];
|
|
|
|
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$r->meeting_id)->whereNull('approval_at')->orderBy('created_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-10-06 14:50:13 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
|
|
|
if (null === ($result[] = Child::select($child_select)->where('id', $l->child_id)->get())) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
$result[$i]['meeting_approval'] = $l->approval_at;
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
public function listOfMeetingNotifyApprovel (Request $r) {
|
|
|
|
if (!isset($r->meeting_id)) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['画像の更新に失敗しました。']];
|
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
$result = [];
|
|
|
|
$child_select = ['id', 'image', 'last_name', 'first_name', 'tel'];
|
|
|
|
$meeting_approvals_select = ['approval_at'];
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($list = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', $r->meeting_id)->whereNotNull('approval_at')->orderBy('created_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $i => $l) {
|
|
|
|
if (null === ($result[] = Child::select($child_select)->where('id', $l->child_id)->get())) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
$result[$i]['meeting_approval'] = $l->approval_at;
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
public function detail (Request $r, $child_id) {
|
2021-11-03 20:46:48 +09:00
|
|
|
if (!isset($child_id)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
2021-10-29 17:58:06 +09:00
|
|
|
$child_select = ['email', 'tel', 'last_name', 'first_name', 'identity', 'image', 'company'];
|
2021-11-17 01:20:01 +09:00
|
|
|
$father_relations_select = ['hire_at'];
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// 親詳細の取得に成功
|
2021-10-28 17:12:12 +09:00
|
|
|
if (null === ($params = Child::select($child_select)->where('id', (int)$child_id)->first())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-11-29 16:10:40 +09:00
|
|
|
// 親画面から他の親としてアクセスすれば、404となります。
|
|
|
|
$err = 'アクセスできません。';
|
|
|
|
if (request()->route()->action['as'] == 'cdp') {
|
|
|
|
abort_if(null === session()->get('fathers') || null === ($rel = FatherRelation::where('child_id', (int)$child_id)->where('father_id', (int)session()->get('fathers')['id'])->first()), 404, $err);
|
2021-12-23 14:00:44 +09:00
|
|
|
unset($params->email);
|
|
|
|
unset($params->tel);
|
2021-11-29 16:10:40 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// 同じく子画面から他の親の詳細ページをアクセスすれば、404となります。
|
|
|
|
if (request()->route()->action['as'] == 'cdc') {
|
|
|
|
abort_if(null === session()->get('children') || (int)session()->get('children')['id'] != (int)$child_id, 404, $err);
|
|
|
|
}
|
|
|
|
|
2021-11-22 19:08:15 +09:00
|
|
|
if (request()->route()->action['as'] == 'cdp') {
|
2021-11-17 21:54:35 +09:00
|
|
|
if (null === ($params->father_relations = FatherRelation::select($father_relations_select)->where('child_id', (int)$child_id)->where('father_id', (int)$r->father_id)->first())) {
|
2021-11-17 22:18:02 +09:00
|
|
|
$params->father_relations = new \stdClass();
|
2021-11-17 16:33:53 +09:00
|
|
|
}
|
2021-11-17 01:20:01 +09:00
|
|
|
}
|
|
|
|
|
2021-10-28 17:12:12 +09:00
|
|
|
return ['status_code' => 200, 'params' => $params];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:30:16 +09:00
|
|
|
public function updateImage (Request $r, $child_id=null) {
|
|
|
|
if (isset($r->child_id)) {
|
|
|
|
$child_id = $r->child_id;
|
|
|
|
}
|
|
|
|
|
2021-10-28 17:12:12 +09:00
|
|
|
if (!isset($r->image) || !isset($child_id)) {
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['画像の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
2021-11-28 17:10:40 +09:00
|
|
|
if (count(Storage::disk('private')->files('/')) >= 9999) {
|
|
|
|
Log::critical('ストレージの限界を超えています。9999個ファイルまで保存可能ですので、不要なファイルを削除して下さい。');
|
2021-11-26 16:15:22 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
2021-11-30 12:45:32 +09:00
|
|
|
// ファイルサイズは5MiB以内
|
2021-10-28 17:12:12 +09:00
|
|
|
Validator::extend('image_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagesize($value);
|
2021-10-28 17:12:12 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// ミームタイプ
|
|
|
|
Validator::extend('image_meme', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagememe($value);
|
2021-10-28 17:12:12 +09:00
|
|
|
});
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// バリデーションエラー
|
2021-10-28 17:12:12 +09:00
|
|
|
$validate = Validator::make($r->all(), ['image' => 'image_size|image_meme']);
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-11-30 13:34:14 +09:00
|
|
|
$filename = $this->uuidv4().'.jpg';
|
2021-11-26 15:19:42 +09:00
|
|
|
$oldimg = null;
|
2021-11-23 11:36:07 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
try {
|
2021-11-26 15:19:42 +09:00
|
|
|
DB::beginTransaction();
|
|
|
|
|
2021-10-28 17:12:12 +09:00
|
|
|
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->put($filename, $image);
|
2021-12-01 13:40:37 +09:00
|
|
|
$this->fiximg($filename);
|
2021-11-29 14:43:35 +09:00
|
|
|
|
2021-11-26 15:19:42 +09:00
|
|
|
$child = Child::find((int)$child_id);
|
|
|
|
if (!is_null($child->image) && $child->image != '/assets/default/avatar.jpg') {
|
|
|
|
$oldimg = str_replace('/files/', '', $child->image);
|
|
|
|
if (!Storage::disk('private')->exists($oldimg)) {
|
|
|
|
Log::warning($oldimg.'というパスは不正です。');
|
|
|
|
$oldimg = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$child->image = '/files/'.$filename;
|
|
|
|
$child->save();
|
2021-11-12 17:47:44 +09:00
|
|
|
|
2021-12-22 00:03:39 +09:00
|
|
|
if (request()->route()->action['as'] == 'cic') {
|
|
|
|
$login_user_datum = $child->toArray();
|
|
|
|
unset($login_user_datum['password']);
|
|
|
|
|
|
|
|
// セッションに保存する
|
|
|
|
session()->put('children', $login_user_datum);
|
|
|
|
}
|
2021-11-30 13:47:26 +09:00
|
|
|
|
|
|
|
DB::commit();
|
2021-10-06 14:50:13 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->delete($filename);
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['画像の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-11-26 15:19:42 +09:00
|
|
|
if (!is_null($oldimg)) {
|
|
|
|
Storage::disk('private')->delete($oldimg);
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// 成功
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 200, 'success_messages' => ['画像の更新に成功しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:30:16 +09:00
|
|
|
public function updateProfile (Request $r, $child_id=null) {
|
|
|
|
if (isset($r->child_id)) {
|
|
|
|
$child_id = $r->child_id;
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
if (!isset($child_id)) {
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['子の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-11-10 11:42:07 +09:00
|
|
|
// 電話番号の文字数。
|
|
|
|
Validator::extend('tel_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->telsize($value);
|
2021-11-10 11:42:07 +09:00
|
|
|
});
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// バリデーションエラー
|
|
|
|
$validate = Validator::make($r->all(), [
|
2021-10-25 20:16:43 +09:00
|
|
|
'email' => 'required|max:255|email',
|
2021-11-10 11:42:07 +09:00
|
|
|
'tel' => 'required|numeric|starts_with:0|tel_size',
|
2021-10-06 14:50:13 +09:00
|
|
|
'last_name' => 'required|max:100',
|
|
|
|
'first_name' => 'required|max:100',
|
2021-10-29 17:58:06 +09:00
|
|
|
'identity' => 'required|max:20|alpha_num',
|
2021-10-06 14:50:13 +09:00
|
|
|
'company' => 'max:100',
|
|
|
|
]);
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-10-25 20:16:43 +09:00
|
|
|
$update = [
|
|
|
|
'email' => $r->email,
|
|
|
|
'tel' => $r->tel,
|
|
|
|
'last_name' => $r->last_name,
|
|
|
|
'first_name' => $r->first_name,
|
2021-10-29 17:58:06 +09:00
|
|
|
'identity' => $r->identity,
|
2021-10-25 20:16:43 +09:00
|
|
|
'company' => $r->company,
|
|
|
|
];
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
try {
|
2021-10-25 20:16:43 +09:00
|
|
|
Child::where('id', (int)$child_id)->update($update);
|
2021-10-06 14:50:13 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['子の更新に失敗しました。']];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// 成功
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 200, 'success_messages' => ['子の更新に成功しました。']];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-11-10 13:53:01 +09:00
|
|
|
public function updatePassword (Request $r, $child_id=null) {
|
2021-11-10 14:59:40 +09:00
|
|
|
if (isset($r->child_id)) {
|
|
|
|
$child_id = $r->child_id;
|
|
|
|
}
|
|
|
|
|
2021-11-10 13:53:01 +09:00
|
|
|
if (is_null($child_id) && !isset($r->token)) {
|
2021-11-10 14:59:40 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['パスワードの更新に失敗しました。']];
|
2021-11-10 10:30:16 +09:00
|
|
|
}
|
|
|
|
|
2021-11-10 15:45:09 +09:00
|
|
|
if (isset($r->token)) {
|
2021-11-10 16:41:29 +09:00
|
|
|
if (null === ($ta = TelActivation::select('child_id')->where('token', $r->token)->first())) {
|
2021-11-10 15:45:09 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['パスワードの更新に失敗しました。']];
|
|
|
|
}
|
2021-11-10 16:41:29 +09:00
|
|
|
|
|
|
|
$child_id = $ta->child_id;
|
2021-11-10 15:45:09 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// バリデーションエラー
|
|
|
|
$validate = Validator::make($r->all(), [
|
2021-12-19 11:32:45 +09:00
|
|
|
'password' => ['required', 'min:8', 'max:72', 'confirmed', new \App\Rules\Hankaku],
|
2021-10-06 14:50:13 +09:00
|
|
|
]);
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-25 20:16:43 +09:00
|
|
|
$update = [
|
|
|
|
'password' => Hash::make($r->password),
|
|
|
|
];
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
try {
|
2021-10-25 20:16:43 +09:00
|
|
|
Child::where('id', (int)$child_id)->update($update);
|
2021-10-06 14:50:13 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['パスワードの更新に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 成功
|
|
|
|
return ['status_code' => 200, 'success_messages' => ['パスワードの更新に成功しました。']];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
|
2021-11-08 22:10:31 +09:00
|
|
|
public function withdrawal (Request $r) {
|
2021-10-06 14:50:13 +09:00
|
|
|
// 削除成功
|
2021-10-07 13:51:53 +09:00
|
|
|
try {
|
2021-11-30 17:05:54 +09:00
|
|
|
// DBに入ります。
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
$child = Child::find((int)$r->child_id);
|
|
|
|
$img = $child->image;
|
|
|
|
$child->delete();
|
|
|
|
|
2021-12-15 09:45:21 +09:00
|
|
|
if (!is_null($img) && $img != '/assets/default/avatar.jpg') {
|
2021-11-30 17:05:54 +09:00
|
|
|
$img = str_replace('/files/', '', $child->image);
|
|
|
|
if (!Storage::disk('private')->exists($img)) {
|
|
|
|
Log::warning($img.'というパスは不正です。');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Storage::disk('private')->delete($img);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-08 22:10:31 +09:00
|
|
|
Session::forget($this->getGuard());
|
2021-11-30 17:05:54 +09:00
|
|
|
DB::commit();
|
2021-10-07 13:51:53 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-30 17:05:54 +09:00
|
|
|
DB::rollback();
|
2021-10-07 13:51:53 +09:00
|
|
|
return ['status_code' => 400];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:27:25 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// 削除失敗
|
2021-10-05 00:35:47 +09:00
|
|
|
return ['status_code' => 200];
|
2021-09-30 13:27:25 +09:00
|
|
|
}
|
|
|
|
}
|