Browse Source

整備

develop
sosuke.iwabuchi 2 years ago
parent
commit
8ba83f4d6f
34 changed files with 727 additions and 53 deletions
  1. +3
    -1
      .env.example
  2. +9
    -0
      app/Codes/Custom.php
  3. +15
    -0
      app/Codes/ReceiptIssuingOrderType.php
  4. +12
    -19
      app/Http/Controllers/Web/Auth/LoginController.php
  5. +1
    -1
      app/Http/Controllers/Web/Auth/LoginParam.php
  6. +32
    -0
      app/Http/Controllers/Web/Auth/LogoutController.php
  7. +13
    -0
      app/Http/Controllers/Web/Auth/LogoutParam.php
  8. +24
    -0
      app/Http/Controllers/Web/Auth/Me.php
  9. +50
    -0
      app/Http/Controllers/Web/Auth/MeController.php
  10. +13
    -0
      app/Http/Controllers/Web/Auth/MeParam.php
  11. +73
    -0
      app/Http/Controllers/Web/Custom/HelloTechno/CreateReceiptIssuingOrderController.php
  12. +38
    -0
      app/Http/Controllers/Web/Custom/HelloTechno/CreateReceiptIssuingOrderParam.php
  13. +46
    -0
      app/Http/Controllers/Web/Custom/HelloTechno/CustomersController.php
  14. +19
    -0
      app/Http/Controllers/Web/Custom/HelloTechno/CustomersParam.php
  15. +49
    -0
      app/Http/Controllers/Web/Custom/HelloTechno/ParkingsController.php
  16. +20
    -0
      app/Http/Controllers/Web/Custom/HelloTechno/ParkingsParam.php
  17. +32
    -2
      app/Http/Controllers/Web/WebController.php
  18. +5
    -0
      app/Logic/ReceiptIssuingOrder/CreateManager.php
  19. +50
    -0
      app/Logic/ReceiptIssuingOrder/Custom/HelloTechno/CreateManager.php
  20. +2
    -2
      app/Logic/SMS/FourSMessageManager.php
  21. +2
    -2
      app/Logic/SMS/LogManager.php
  22. +24
    -0
      app/Models/BaseModel.php
  23. +15
    -1
      app/Models/Contract.php
  24. +4
    -0
      app/Models/ReceiptIssuingHTParkingCustomOrder.php
  25. +3
    -2
      app/Models/ReceiptIssuingOrder.php
  26. +2
    -15
      app/Models/User.php
  27. +86
    -0
      app/Util/Custom/HelloTechno/API.php
  28. +8
    -1
      config/logic.php
  29. +3
    -2
      database/migrations/2023_04_15_152400_create_receipt_issuing_orders_table.php
  30. +3
    -3
      database/migrations/2023_04_18_131700_create_sms_send_orders_table.php
  31. +54
    -0
      database/seeders/TestUserSeeder.php
  32. +3
    -0
      docker/8.2/php.ini
  33. +12
    -0
      routes/api.php
  34. +2
    -2
      tests/Feature/SMSTest.php

+ 3
- 1
.env.example View File

@@ -61,4 +61,6 @@ SAIL_XDEBUG_MODE=debug,develop

SMS_PROVIDER=log
SMS_FOURS_MESSAGE_USER=null
SMS_FOURS_MESSAGE_PASSWORD=null
SMS_FOURS_MESSAGE_PASSWORD=null

CUSTOM_HELLOTECHNO_API_HOST="http://localhost"

+ 9
- 0
app/Codes/Custom.php View File

@@ -0,0 +1,9 @@
<?php

namespace App\Codes;

enum Custom: string
{
case NONE = "NONE";
case HELLO_TECHNO = "HELLO_TECHNO";
}

+ 15
- 0
app/Codes/ReceiptIssuingOrderType.php View File

@@ -0,0 +1,15 @@
<?php

namespace App\Codes;

/**
* 領収証発行依頼ステータス
*/
enum ReceiptIssuingOrderType: string
{
case NONE = "";

case NORMAL = "NORMAL";

case HT_CUSTOM_PARKING_RECEIPT = "HT_CUSTOM_PARKING_RECEIPT";
}

+ 12
- 19
app/Http/Controllers/Web/Auth/LoginController.php View File

@@ -1,18 +1,17 @@
<?php

namespace App\Http\Controllers\Web\Login;
namespace App\Http\Controllers\Web\Auth;

use App\Codes\UserRole;
use App\Http\Controllers\Web\WebController;
use App\Models\User;
use App\Repositories\MeRepository;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends WebController
{
use Me;

public function name(): string
{
return "ログイン";
@@ -23,23 +22,15 @@ class LoginController extends WebController
return "ログインを行う";
}

use AuthenticatesUsers;

public function __construct(LoginParam $param)
{
$this->param = $param;
}

public function param(): LoginParam
public function __construct(protected LoginParam $param)
{
return $this->param;
}

protected function run(Request $request): JsonResponse
{
// 取得したユーザ情報を登録しログインを行う
$param = $this->param();

$param = $this->param;

$user = User::whereEmail($param->email)->first();
if ($user === null) {
@@ -47,15 +38,17 @@ class LoginController extends WebController
}

if (Auth::attempt([
$this->username() => $param->email,
'email' => $param->email,
'password' => $param->password,
])) {

$user = Auth::user();
$me = $this->me();

return $this->successResponse();
} else {
return $this->failedResponse([], '認証失敗');
if ($me !== null) {
return $this->successResponse($me);
}
}

return $this->failedResponse([], '認証失敗');
}
}

+ 1
- 1
app/Http/Controllers/Web/Auth/LoginParam.php View File

@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers\Web\Login;
namespace App\Http\Controllers\Web\Auth;

use App\Http\Controllers\Web\BaseParam;



+ 32
- 0
app/Http/Controllers/Web/Auth/LogoutController.php View File

@@ -0,0 +1,32 @@
<?php

namespace App\Http\Controllers\Web\Auth;

use App\Http\Controllers\Web\Auth\LogoutParam;
use App\Http\Controllers\Web\WebController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LogoutController extends WebController
{
public function name(): string
{
return "ログアウト";
}

public function description(): string
{
return "ログアウトを行う";
}

public function __construct(protected LogoutParam $param)
{
}

protected function run(Request $request): JsonResponse
{
Auth::logout();
return $this->successResponse();
}
}

+ 13
- 0
app/Http/Controllers/Web/Auth/LogoutParam.php View File

@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers\Web\Auth;

use App\Http\Controllers\Web\BaseParam;

class LogoutParam extends BaseParam
{
public function rules(): array
{
return [];
}
}

+ 24
- 0
app/Http/Controllers/Web/Auth/Me.php View File

@@ -0,0 +1,24 @@
<?php

namespace App\Http\Controllers\Web\Auth;

use App\Models\User;
use App\Codes\UserRole;
use Illuminate\Support\Facades\Auth;

trait Me
{
protected function me()
{
if (Auth::check()) {
$user = Auth::user()->toArray();

return array_intersect_key($user, array_flip([
User::COL_NAME_ID,
User::COL_NAME_CONTRACT_ID,
User::COL_NAME_ROLE,
]));
}
return null;
}
}

+ 50
- 0
app/Http/Controllers/Web/Auth/MeController.php View File

@@ -0,0 +1,50 @@
<?php

namespace App\Http\Controllers\Web\Auth;

use App\Http\Controllers\Web\IParam;
use App\Http\Controllers\Web\WebController;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class MeController extends WebController
{

use Me;

public function name(): string
{
return "自身参照";
}

public function description(): string
{
return "自身情報を参照する";
}

public function __construct(protected MeParam $param)
{
}


protected function run(Request $request): JsonResponse
{

$me = $this->me();
if ($me !== null) {
return $this->successResponse($me);
}
return $this->failedResponse();
// if (Auth::check()) {
// $user = Auth::user();
// $ret = $user->get([
// User::COL_NAME_CONTRACT_ID,
// User::COL_NAME_ROLE,
// ]);

// } else {
// }
}
}

+ 13
- 0
app/Http/Controllers/Web/Auth/MeParam.php View File

@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers\Web\Auth;

use App\Http\Controllers\Web\BaseParam;

class MeParam extends BaseParam
{
public function rules(): array
{
return [];
}
}

+ 73
- 0
app/Http/Controllers/Web/Custom/HelloTechno/CreateReceiptIssuingOrderController.php View File

@@ -0,0 +1,73 @@
<?php

namespace App\Http\Controllers\Web\Custom\HelloTechno;

use App\Codes\UserRole;
use App\Http\Controllers\Web\IParam;
use App\Http\Controllers\Web\WebController;
use App\Logic\ReceiptIssuingOrder\Custom\HelloTechno\CreateManager;
use App\Models\ReceiptIssuingOrder as Order;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CreateReceiptIssuingOrderController extends WebController
{
public function name(): string
{
return "[HelloTechno専用]領収証発行依頼作成";
}

public function description(): string
{
return "[HelloTechno専用]領収証発行依頼を作成する";
}

public function __construct(
protected CreateReceiptIssuingOrderParam $param,
private CreateManager $manager
) {
$this->middleware('auth:sanctum');
$this->roleAllow(UserRole::NORMAL_ADMIN);
}

protected function getParam(): IParam
{
return $this->param;
}

protected function run(Request $request): JsonResponse
{
$param = $this->param;

// TODO 顧客情報取得
// TODO 駐車場情報取得

$orderData = [
...$param->toArray(),
Order::COL_NAME_HANDLER_ID => Auth::id(),
Order::COL_NAME_SUMMARY_KEY1 => $param->customerCode,
Order::COL_NAME_SUMMARY_KEY2 => $param->parkingManagementCode,
Order::COL_NAME_RECEIPT_PURPOSE => "駐車領収証",
Order::COL_NAME_RECEIPT_INVOICE_NO => "##TODO インボイス登録番号##",
Order::COL_NAME_RECEIPT_PURPOSE => "駐車料金",
Order::COL_NAME_RECEIPT_ISSUER => "##TODO 発行者名##",
Order::COL_NAME_RECEIPT_SHOP_NAME => "##TODO 駐車場名##",
Order::COL_NAME_RECEIPT_PURPOSE => "駐車料金",
Order::COL_NAME_MEMO => "駐車料金",
];

logger($orderData);

$messages = $this->manager->init()
->fill($orderData)
->create();

if (count($messages) !== 0) {
return $this->failedResponse([], $messages);
}


return $this->successResponse();
}
}

+ 38
- 0
app/Http/Controllers/Web/Custom/HelloTechno/CreateReceiptIssuingOrderParam.php View File

@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers\Web\Custom\HelloTechno;

use App\Http\Controllers\Web\BaseParam;
use App\Models\ReceiptIssuingOrder;
use App\Models\ReceiptIssuingHTParkingCustomOrder as HT;
use App\Rules\PhoneNumber;
use Carbon\Carbon;

/**
* @property string $customerCode
* @property string $parkingManagementCode
* @property int $adjustSeqNo
* @property string $receiptName
* @property Carbon $receiptUseDatetime
* @property int $receiptAmount
* @property ?string $memo
* @property string $smsPhoneNumber
*/

class CreateReceiptIssuingOrderParam extends BaseParam
{
public function rules(): array
{
return [
HT::COL_NAME_CUSTOMER_CODE => $this->str(),
HT::COL_NAME_PARKING_MANAGEMENT_CODE => $this->str(),
HT::COL_NAME_ADJUST_SEQ_NO => $this->numeric(true),
ReceiptIssuingOrder::COL_NAME_RECEIPT_USE_DATETIME => $this->date(),
ReceiptIssuingOrder::COL_NAME_RECEIPT_NAME => $this->str(),
ReceiptIssuingOrder::COL_NAME_RECEIPT_AMOUNT => $this->numeric(['min:0', 'max:999999']),
ReceiptIssuingOrder::COL_NAME_MEMO => $this->text(true),
ReceiptIssuingOrder::COL_NAME_SMS_PHONE_NUMBER => $this->str([new PhoneNumber()]),

];
}
}

+ 46
- 0
app/Http/Controllers/Web/Custom/HelloTechno/CustomersController.php View File

@@ -0,0 +1,46 @@
<?php

namespace App\Http\Controllers\Web\Custom\HelloTechno;

use App\Codes\Custom;
use App\Codes\UserRole;
use App\Http\Controllers\Web\IParam;
use App\Http\Controllers\Web\WebController;
use App\Util\Custom\HelloTechno\API;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CustomersController extends WebController
{
public function name(): string
{
return "[HelloTechno専用]顧客情報取得";
}

public function description(): string
{
return "[HelloTechno専用]顧客情報を取得する";
}

public function __construct(
protected CustomersParam $param,
) {
$this->middleware('auth:sanctum');
$this->roleAllow(UserRole::NORMAL_ADMIN);
$this->customAllow = [Custom::HELLO_TECHNO];
}

protected function getParam(): IParam
{
return $this->param;
}

protected function run(Request $request): JsonResponse
{
$param = $this->param;

$list = API::getCustomers($param->customerCode);

return $this->successResponse(['records' => $list]);
}
}

+ 19
- 0
app/Http/Controllers/Web/Custom/HelloTechno/CustomersParam.php View File

@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers\Web\Custom\HelloTechno;

use App\Http\Controllers\Web\BaseParam;

/**
* @property ?string $customerCode
*/

class CustomersParam extends BaseParam
{
public function rules(): array
{
return [
'customer_code' => $this->str(true),
];
}
}

+ 49
- 0
app/Http/Controllers/Web/Custom/HelloTechno/ParkingsController.php View File

@@ -0,0 +1,49 @@
<?php

namespace App\Http\Controllers\Web\Custom\HelloTechno;

use App\Codes\Custom;
use App\Codes\UserRole;
use App\Http\Controllers\Web\IParam;
use App\Http\Controllers\Web\WebController;
use App\Logic\ReceiptIssuingOrder\CreateManager;
use App\Util\Custom\HelloTechno\API;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class ParkingsController extends WebController
{
public function name(): string
{
return "[HelloTechno専用]駐車場情報取得";
}

public function description(): string
{
return "[HelloTechno専用]駐車場情報を取得する";
}

public function __construct(
protected ParkingsParam $param,
) {
$this->middleware('auth:sanctum');
$this->roleAllow(UserRole::NORMAL_ADMIN);
$this->customAllow = [Custom::HELLO_TECHNO];
}

protected function getParam(): IParam
{
return $this->param;
}

protected function run(Request $request): JsonResponse
{
$param = $this->param;

$list = API::getParkings($param->customerCode, $param->parkingManagementCode);

return $this->successResponse(['records' => $list]);
}
}

+ 20
- 0
app/Http/Controllers/Web/Custom/HelloTechno/ParkingsParam.php View File

@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers\Web\Custom\HelloTechno;

use App\Http\Controllers\Web\BaseParam;

/**
* @property string $customerCode
* @property ?string $parkingManagementCode
*/
class ParkingsParam extends BaseParam
{
public function rules(): array
{
return [
'customer_code' => $this->str(),
'parking_management_code' => $this->str(true)
];
}
}

+ 32
- 2
app/Http/Controllers/Web/WebController.php View File

@@ -84,7 +84,10 @@ abstract class WebController extends BaseController
/**
* パラメータオブジェクト
*/
abstract protected function getParam(): IParam;
protected function getParam(): IParam
{
return $this->param;
}


/**
@@ -281,6 +284,7 @@ abstract class WebController extends BaseController
// 以下 認可関係
protected array|null $roleAllow = null;
protected array|null $roleDisallow = null;
protected array|null $customAllow = null;

protected function roleAllow(UserRole $role)
{
@@ -314,7 +318,33 @@ abstract class WebController extends BaseController
if (is_array($this->roleDisallow) && in_array($role, $this->roleDisallow)) {
return false;
}
return true;

return $this->canCustomAccess();
}

public function canCustomAccess(): bool
{

if (Auth::user()->role === UserRole::SUPER_ADMIN) {
return true;
}

if ($this->customAllow === null) {
return true;
}

$myCustoms = Auth::user()->contract->custom();




foreach ($this->customAllow as $targetCustom) {
logger(['myCustoms' => $myCustoms, 'target' => $targetCustom]);
if (in_array($targetCustom, $myCustoms, true)) {
return true;
}
}
return false;
}

// 返却用データの登録


+ 5
- 0
app/Logic/ReceiptIssuingOrder/CreateManager.php View File

@@ -27,6 +27,11 @@ class CreateManager extends ReceiptIssuingOrderManager
return $this;
}

public function id(): string
{
return $this->order->id ?? "";
}

public function fill(array $attr)
{
$this->order->fill($attr);


+ 50
- 0
app/Logic/ReceiptIssuingOrder/Custom/HelloTechno/CreateManager.php View File

@@ -0,0 +1,50 @@
<?php

namespace App\Logic\ReceiptIssuingOrder\Custom\HelloTechno;

use App\Codes\ReceiptIssuingOrderStatus;
use App\Codes\SMSSendPurpose;
use App\Logic\ReceiptIssuingOrder\CreateManager as BaseManager;
use App\Logic\SMS\SMSManager;
use App\Models\ReceiptIssuingHTParkingCustomOrder;
use App\Models\ReceiptIssuingOrder;
use Illuminate\Support\Facades\View;
use LogicException;

class CreateManager
{

public function __construct(
protected BaseManager $manager,
private ReceiptIssuingHTParkingCustomOrder $customOrder,
) {
}

public function init(): static
{
$this->manager->init();
return $this;
}

public function fill(array $attr): static
{
$this->manager->fill($attr);
$this->customOrder->fill($attr);

return $this;
}

public function create(): array
{
$messages = $this->manager->create();

if (count($messages) !== 0) {
return $messages;
}

$this->customOrder->setReceiptIssuingOrder($this->manager->id());
$this->customOrder->save();

return [];
}
}

+ 2
- 2
app/Logic/SMS/FourSMessageManager.php View File

@@ -48,8 +48,8 @@ class FourSMessageManager implements SMSManager
$order->receipt_issuing_order_id = $receiptIssuingOrder->id;
$order->contract_id = $receiptIssuingOrder->contract_id;
$order->phone_number = $receiptIssuingOrder->sms_phone_number;
$order->sumamry_key1 = $receiptIssuingOrder->sumamry_key1;
$order->sumamry_key2 = $receiptIssuingOrder->sumamry_key2;
$order->summary_key1 = $receiptIssuingOrder->summary_key1;
$order->summary_key2 = $receiptIssuingOrder->summary_key2;

$order->purpose = $purpose;
$order->content = $contents;


+ 2
- 2
app/Logic/SMS/LogManager.php View File

@@ -21,8 +21,8 @@ class LogManager implements SMSManager
$order->receipt_issuing_order_id = $receiptIssuingOrder->id;
$order->contract_id = $receiptIssuingOrder->contract_id;
$order->phone_number = $receiptIssuingOrder->sms_phone_number;
$order->sumamry_key1 = $receiptIssuingOrder->sumamry_key1;
$order->sumamry_key2 = $receiptIssuingOrder->sumamry_key2;
$order->summary_key1 = $receiptIssuingOrder->summary_key1;
$order->summary_key2 = $receiptIssuingOrder->summary_key2;

$order->purpose = $purpose;
$order->content = $contents;


+ 24
- 0
app/Models/BaseModel.php View File

@@ -9,7 +9,9 @@ use App\Models\Feature\IModelFeature;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

abstract class BaseModel extends Model implements IModelFeature
{
@@ -41,6 +43,17 @@ abstract class BaseModel extends Model implements IModelFeature
return (new static)->getTable();
}

public static function hasColumn(string $columnName): bool
{
$target = sprintf("%s::COL_NAME_%s", static::class, Str::upper($columnName));
$ret = defined($target);
if (!$ret) {
logger(sprintf("does not have column [%s] on [%s] [%s]", Str::upper($columnName), static::getTableName(), $target));
}
return $ret;
}


public function copy(IModelFeature $from): static
{
$data = $from->getAttributeKeys();
@@ -66,4 +79,15 @@ abstract class BaseModel extends Model implements IModelFeature
'updating' => UpdatingEvent::class,
'deleted' => DeletedEvent::class,
];


// カラムが存在する項目のみfillするようオーバーライド
public function fill(array $atr)
{
$filterd = array_filter($atr, function ($value, $key) {
return static::hasColumn($key);
}, ARRAY_FILTER_USE_BOTH);

return parent::fill($filterd);
}
}

+ 15
- 1
app/Models/Contract.php View File

@@ -3,6 +3,7 @@
namespace App\Models;

use Illuminate\Support\Str;
use App\Codes\Custom;

class Contract extends AppModel
{
@@ -20,11 +21,24 @@ class Contract extends AppModel
return in_array($target, $this->custom(), true);
}

/**
* @return Custom[]
*/
public function custom(): array
{
$custom = data_get($this, self::COL_NAME_CUSTOM);
if ($custom) {
return explode(',', $custom);


$strList = explode(',', $custom);
$ret = [];
foreach ($strList as $str) {
$c = Custom::tryFrom($str);
if ($c !== null) {
$ret[] = $c;
}
}
return $ret;
} else {
return [];
}


+ 4
- 0
app/Models/ReceiptIssuingHTParkingCustomOrder.php View File

@@ -8,6 +8,10 @@ class ReceiptIssuingHTParkingCustomOrder extends AppModel
{
use ReceiptIssuingOrderFeature;

const COL_NAME_CUSTOMER_CODE = "customer_code";
const COL_NAME_PARKING_MANAGEMENT_CODE = "parking_management_code";
const COL_NAME_ADJUST_SEQ_NO = "adjust_seq_no";

public function getModelName(): string
{
return "領収証発行依頼(HT駐車場カスタム)";


+ 3
- 2
app/Models/ReceiptIssuingOrder.php View File

@@ -12,8 +12,8 @@ class ReceiptIssuingOrder extends AppModel
const COL_NAME_HANDLER_ID = "handler_id";
const COL_NAME_ORDER_DATETIME = "order_datetime";
const COL_NAME_STATUS = "status";
const COL_NAME_SUMMARY_KEY1 = "sumamry_key1";
const COL_NAME_SUMMARY_KEY2 = "sumamry_key2";
const COL_NAME_SUMMARY_KEY1 = "summary_key1";
const COL_NAME_SUMMARY_KEY2 = "summary_key2";
const COL_NAME_ACCESS_TOKEN = "access_token";
const COL_NAME_ACCESS_TOKEN_EXPIRES_AT = "access_token_expires_at";
const COL_NAME_SMS_PHONE_NUMBER = "sms_phone_number";
@@ -22,6 +22,7 @@ class ReceiptIssuingOrder extends AppModel
const COL_NAME_RECEIPT_USE_DATETIME = "receipt_use_datetime";
const COL_NAME_RECEIPT_SHOP_NAME = "receipt_shop_name";
const COL_NAME_RECEIPT_ISSUER = "receipt_issuer";
const COL_NAME_RECEIPT_NAME = "receipt_name";
const COL_NAME_RECEIPT_PURPOSE = "receipt_purpose";
const COL_NAME_RECEIPT_INVOICE_NO = "receipt_invoice_no";
const COL_NAME_RECEIPT_AMOUNT = "receipt_amount";


+ 2
- 15
app/Models/User.php View File

@@ -19,22 +19,9 @@ class User extends Authenticatable implements IModelFeature
{
use HasApiTokens, HasFactory, Notifiable, HasUuids, ContractFeature;

const COL_NAME_ID = 'id';
const COL_NAME_ROLE = 'role';

// public function __construct(...$params)
// {
// $this->dispatchesEvents = [
// 'created' => CreatedListener::class,
// 'updating' => UpdatingListener::class,
// 'deleting' => DeletingListener::class,
// ];
// protected $dispatchesEvents = [
// 'created' => CreatedEvent::class,
// 'updating' => UpdatingEvent::class,
// 'deleted' => DeletedEvent::class,
// ];
// parent::__construct(...$params);
// }
const COL_NAME_EMAIL = 'email';

/**
* The attributes that should be hidden for serialization.


+ 86
- 0
app/Util/Custom/HelloTechno/API.php View File

@@ -0,0 +1,86 @@
<?php

namespace App\Util\Custom\HelloTechno;

use App\Exceptions\AppCommonException;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class API
{

private const RESULT_CODE = 'result_code';
private const RESULT_CODE_SUCCESS = 'SUCCESS';
private const FIELD_DATA = 'data';


private const URL_CUSTOMERS = 'customers';
private const URL_PARKINGS = 'parkings';
private const URL_ADJUST_DATA = 'adjust-data';

private const CONFIG_KEY_API_HOST = "logic.custom.hellotechno.host";

public static function getCustomers(?string $customerCde = null)
{
$res = Http::get(static::getCustomersUrl($customerCde));
return static::handleResponse($res);
}

public static function getParkings(string $customerCode, ?string $parkingManagementCode = null)
{
$res = Http::get(static::getParkingsUrl($customerCode, $parkingManagementCode));
return static::handleResponse($res);
}

public static function getAdjustData(string $customerCode, string $parkingManagementCode, int $adjustSeqNo)
{
$res = Http::get(static::getAdjustDataUrl($customerCode, $parkingManagementCode, $adjustSeqNo));
return static::handleResponse($res);
}

private static function getHost(): string
{
return config(static::CONFIG_KEY_API_HOST, "http://localhost");
}

private static function getCustomersUrl(?string $customerCode)
{
$condition = [static::getHost(), static::URL_CUSTOMERS];
if ($customerCode) {
$condition[] = $customerCode;
}
return implode('/', $condition);
}

private static function getParkingsUrl(string $customerCode, ?string $parkingManagementCode)
{
$condition = [static::getHost(), static::URL_PARKINGS, $customerCode];
if ($parkingManagementCode) {
$condition[] = $parkingManagementCode;
}
return implode('/', $condition);
}

private static function getAdjustDataUrl(string $customerCode, string $parkingManagementCode, int $adjustSeqNo)
{
$condition = [static::getHost(), static::URL_ADJUST_DATA, $customerCode, $parkingManagementCode, $adjustSeqNo];
return implode('/', $condition);
}

private static function handleResponse(Response $res): array
{
if ($res->failed()) {
throw $res->throw();
}
$data = $res->json();

if (data_get($data, static::RESULT_CODE) !== static::RESULT_CODE_SUCCESS) {
Log::error("HT RESPONSE ERROR");
Log::error($data);
throw new AppCommonException('HT API 失敗');
}

return data_get($data, static::FIELD_DATA, []);
}
}

+ 8
- 1
config/logic.php View File

@@ -18,5 +18,12 @@ return [
'userId' => env("SMS_FOURS_MESSAGE_USER"),
'password' => env("SMS_FOURS_MESSAGE_PASSWORD"),
]
]
],


'custom' => [
'hellotechno' => [
'host' => env('CUSTOM_HELLOTECHNO_API_HOST', 'http://localhost')
],
],
];

+ 3
- 2
database/migrations/2023_04_15_152400_create_receipt_issuing_orders_table.php View File

@@ -37,8 +37,8 @@ return new class extends Migration
$table->string("handler_id")->comment("担当者ID")->nullable();
$table->datetime("order_datetime")->comment("依頼日時")->nullable();
$table->string("status")->comment("ステータス")->nullable();
$table->string("sumamry_key1")->comment("集計キー1")->nullable();
$table->string("sumamry_key2")->comment("集計キー2")->nullable();
$table->string("summary_key1")->comment("集計キー1")->nullable();
$table->string("summary_key2")->comment("集計キー2")->nullable();
$table->string("access_token")->comment("アクセストークン")->nullable();
$table->datetime("access_token_expires_at")->comment("アクセストークン有効期限日時")->nullable();

@@ -53,6 +53,7 @@ return new class extends Migration
$table->string("receipt_shop_name")->comment("領収証_発行店名")->nullable();
$table->string("receipt_issuer")->comment("領収証_発行者名")->nullable();
$table->string("receipt_purpose")->comment("領収証_但書き")->nullable();
$table->string("receipt_name")->comment("領収証_宛名")->nullable();
$table->string("receipt_invoice_no")->comment("領収証_インボイス登録番号")->nullable();
$table->string("receipt_amount")->comment("領収証_金額")->nullable();
$table->string("receipt_how_to_receive")->comment("領収証_取得希望方法")->nullable();


+ 3
- 3
database/migrations/2023_04_18_131700_create_sms_send_orders_table.php View File

@@ -47,13 +47,13 @@ return new class extends Migration
$table->text('content')->comment("本文")->nullable();
$table->text('phone_number')->comment("送信先電話番号")->nullable();

$table->string("sumamry_key1")->comment("集計キー1")->nullable();
$table->string("sumamry_key2")->comment("集計キー2")->nullable();
$table->string("summary_key1")->comment("集計キー1")->nullable();
$table->string("summary_key2")->comment("集計キー2")->nullable();


$helper->index(1, [ColumnName::CONTRACT_ID, 'send_datetime']);
$helper->index(2, [ColumnName::CONTRACT_ID, 'done']);
$helper->index(3, [ColumnName::CONTRACT_ID, 'sumamry_key1', 'sumamry_key2']);
$helper->index(3, [ColumnName::CONTRACT_ID, 'summary_key1', 'summary_key2']);

$helper->index(4, [ColumnName::CONTRACT_ID, 'done']);
};


+ 54
- 0
database/seeders/TestUserSeeder.php View File

@@ -0,0 +1,54 @@
<?php

namespace Database\Seeders;

use App\Codes\Custom;
use App\Codes\SMSProviderName;
use App\Codes\UserRole;
use App\Models\Contract;
use App\Models\SMSProvider;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class TestUserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{

$contract = Contract::factory()->create([
Contract::COL_NAME_NAME => 'テスト用契約'
]);

$emails = [
['normal@aa.com', UserRole::NORMAL_ADMIN],
['contract@aa.com', UserRole::CONTRACT_ADMIN],
['admin@aa.com', UserRole::SUPER_ADMIN],
];

foreach ($emails as [$email, $role]) {
if (!User::whereEmail($email)->exists()) {
User::factory()->for($contract)->create([
User::COL_NAME_EMAIL => $email,
User::COL_NAME_ROLE => $role,
]);
}
}

$contract = Contract::factory()->create([
Contract::COL_NAME_NAME => 'テスト用契約 HT',
Contract::COL_NAME_CUSTOM => Custom::HELLO_TECHNO,
]);

$email = 'hello@aa.com';
if (!User::whereEmail($email)->exists()) {
User::factory()->for($contract)->create([
User::COL_NAME_EMAIL => $email,
User::COL_NAME_ROLE => UserRole::NORMAL_ADMIN,
]);
}
}
}

+ 3
- 0
docker/8.2/php.ini View File

@@ -5,3 +5,6 @@ variables_order = EGPCS

[opcache]
opcache.enable_cli=1

[xdebug]
xdebug.start_with_request=yes

+ 12
- 0
routes/api.php View File

@@ -10,3 +10,15 @@
| be assigned to the "api" middleware group. Make something great!
|
*/

use App\Util\RouteHelper;

RouteHelper::get('/me', App\Http\Controllers\Web\Auth\MeController::class);
RouteHelper::post('/login', App\Http\Controllers\Web\Auth\LoginController::class);
RouteHelper::get('/logout', App\Http\Controllers\Web\Auth\LogoutController::class);

// Custom for HelloTechno
RouteHelper::get('/custom/hello-techno/customers', App\Http\Controllers\Web\Custom\HelloTechno\CustomersController::class);
RouteHelper::get('/custom/hello-techno/parkings', App\Http\Controllers\Web\Custom\HelloTechno\ParkingsController::class);
// RouteHelper::get('/custom/hello-techno/adjust-data', App\Http\Controllers\Web\Custom\HelloTechno\CustomersController::class);
RouteHelper::post('/custom/hello-techno/receipt-issuing-order/create', App\Http\Controllers\Web\Custom\HelloTechno\CreateReceiptIssuingOrderController::class);

+ 2
- 2
tests/Feature/SMSTest.php View File

@@ -33,8 +33,8 @@ class SMSTest extends TestCase
$receiptIssuingOurder->contract_id = $contract->id;
$receiptIssuingOurder->status = "NEW";

$receiptIssuingOurder->sumamry_key1 = "京都";
$receiptIssuingOurder->sumamry_key2 = "駅前駐車場";
$receiptIssuingOurder->summary_key1 = "京都";
$receiptIssuingOurder->summary_key2 = "駅前駐車場";
$receiptIssuingOurder->sms_phone_number = "09093604589";
$receiptIssuingOurder->save();



Loading…
Cancel
Save