Pārlūkot izejas kodu

ゆうちょ振込の顧客割り当て自動対応

master
sosuke.iwabuchi pirms 1 gada
vecāks
revīzija
d49b230562
5 mainītis faili ar 173 papildinājumiem un 1 dzēšanām
  1. +128
    -0
      app/Console/Commands/PoolTransfer/YuchoResolveCustomer.php
  2. +3
    -1
      app/Console/Schedules/PoolTransfer.php
  3. +34
    -0
      app/Kintone/Models/YuchoPaymentRelationSetting.php
  4. +7
    -0
      app/Kintone/Models/YuchoPaymentResult.php
  5. +1
    -0
      config/kintone.php

+ 128
- 0
app/Console/Commands/PoolTransfer/YuchoResolveCustomer.php Parādīt failu

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

namespace App\Console\Commands\PoolTransfer;

use App\Console\Commands\BaseCommand;
use App\Exceptions\SkipException;
use App\Kintone\KintoneRecordQueryOperator;
use App\Kintone\Models\YuchoPaymentRelationSetting;
use App\Kintone\Models\YuchoPaymentResult;
use App\Util\DateUtil;
use Illuminate\Support\Collection;

class YuchoResolveCustomer extends BaseCommand
{

const COMMAND = "pool-transfer:yucho-resolve-customer";


/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = self::COMMAND;

/**
* The console command description.
*
* @var string
*/
protected $description = 'ゆうちょ振込情報の顧客コードを解決する';

static public function getCommand()
{
return self::COMMAND;
}

/** @var Collection<int, YuchoPaymentRelationSetting> */
private Collection $settings;

/**
* 振込者名がキー
* @var Collection<string, YuchoPaymentRelationSetting>
**/
private Collection $settingMap;


/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function service(): int
{

$this->getSettings();

$targets = $this->getTargets();

$this->outputInfo(sprintf("総件数:%d件", $targets->count()));

foreach ($targets as $target) {

try {
$this->handleData($target);
} catch (SkipException $e) {
$this->outputWarn($e->getMessage());
}
}
return self::RESULTCODE_SUCCESS;
}

public function handleData(YuchoPaymentResult $payment)
{
$this->resolve($payment);
}

private function getSettings()
{

// 設定をキャッシュする
$this->settings = YuchoPaymentRelationSetting::getAccess()->all();
$ret = collect();
foreach ($this->settings as $setting) {
$name = $setting->paymentName;
$ret->put($name, $setting);
}
$this->settingMap = $ret;
}

private function findSetting(string $paymentName)
{
return $this->settingMap->get($paymentName);
}

private function resolve(YuchoPaymentResult $payment)
{
$setting = $this->findSetting($payment->paymentName);
if ($setting) {
$payment->customerCode = $setting->customerCode;
$this->outputInfo(sprintf("割り当て from <%s> to <%s>(%d)", $payment->paymentName, $setting->customerName, $setting->customerCode));
$payment->save();
}
}

public function getTargets()
{

$limitDate = DateUtil::now()->addDays(-7);
// 未充当の入金一覧を取得する
// 直近7日分を対象とする
$targets = YuchoPaymentResult::getAccess()->all(YuchoPaymentResult::getQuery()
->whereNull(YuchoPaymentResult::FIELD_CUSTOMER_CODE)
->whereDate(YuchoPaymentResult::FIELD_PAYMENT_DATE, $limitDate, KintoneRecordQueryOperator::GE));

return $targets;
}
}

+ 3
- 1
app/Console/Schedules/PoolTransfer.php Parādīt failu

@@ -4,6 +4,7 @@ namespace App\Console\Schedules;

use App\Console\Commands\PoolTransfer\MoveToPool;
use App\Console\Commands\PoolTransfer\AttachToPaymentPlan;
use App\Console\Commands\PoolTransfer\YuchoResolveCustomer;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Facades\Artisan;

@@ -12,10 +13,11 @@ class PoolTransfer extends BaseSchedule

static public function register(Schedule $schedule)
{
$schedule->command(MoveToPool::class)
$schedule->command(YuchoResolveCustomer::class)
->twiceDaily(10, 16)
->description("プール金異動")
->onSuccess(function () {
Artisan::call(MoveToPool::class);
Artisan::call(AttachToPaymentPlan::class);
});
}


+ 34
- 0
app/Kintone/Models/YuchoPaymentRelationSetting.php Parādīt failu

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

namespace App\Kintone\Models;

use Illuminate\Support\Carbon;

/**
* アプリ名 ゆうちょ振込割り当て設定
*
* @property int paymentName
* @property int customerCode
* @property string customerName
*/
class YuchoPaymentRelationSetting extends KintoneModel
{
const CONFIG_KEY = "KINTONE_APP_YUCHO_PAYMENT_RELATION_SETTING";

const FIELD_PAYMENT_NAME = "振込者名義";
const FIELD_CUSTOMER_CODE = "顧客コード";
const FIELD_CUSTOMER_NAME = "顧客名";

protected const FIELDS = [
...parent::FIELDS,
self::FIELD_PAYMENT_NAME => FieldType::SINGLE_LINE_TEXT,
self::FIELD_CUSTOMER_CODE => FieldType::NUMBER,
self::FIELD_CUSTOMER_NAME => FieldType::SINGLE_LINE_TEXT,
];

protected const FIELD_NAMES = [
...parent::FIELD_NAMES,
];

protected const RELATIONS = [];
}

+ 7
- 0
app/Kintone/Models/YuchoPaymentResult.php Parādīt failu

@@ -11,6 +11,7 @@ use Illuminate\Support\Carbon;
* @property string customerName
* @property Carbon paymentDate
* @property int paymentAmount
* @property string paymentName
* @property string[] poolDone
*/
class YuchoPaymentResult extends KintoneModel
@@ -21,6 +22,7 @@ class YuchoPaymentResult extends KintoneModel
const FIELD_CUSTOMER_NAME = "顧客名";
const FIELD_PAYMENT_DATE = "取引日";
const FIELD_PAYMENT_AMOUNT = "受入金額";
const FIELD_PAYMENT_NAME = "詳細2";
const FIELD_POOL_DONE = "プール済み";

protected const FIELDS = [
@@ -29,10 +31,15 @@ class YuchoPaymentResult extends KintoneModel
self::FIELD_CUSTOMER_NAME => FieldType::SINGLE_LINE_TEXT,
self::FIELD_PAYMENT_DATE => FieldType::DATE,
self::FIELD_PAYMENT_AMOUNT => FieldType::NUMBER,
self::FIELD_PAYMENT_NAME => FieldType::SINGLE_LINE_TEXT,
self::FIELD_POOL_DONE => FieldType::CHECK_BOX,
];

protected const FIELD_NAMES = [
...parent::FIELD_NAMES,
];

protected const RELATIONS = [
Customer::class,
];
}

+ 1
- 0
config/kintone.php Parādīt failu

@@ -52,6 +52,7 @@ return [
...App\Kintone\Models\SmbcPayment::setConfig(),
...App\Kintone\Models\SmbcAccountTransferResult::setConfig(),
...App\Kintone\Models\YuchoPaymentResult::setConfig(),
...App\Kintone\Models\YuchoPaymentRelationSetting::setConfig(),
...App\Kintone\Models\Pool::setConfig(),
...App\Kintone\Models\PoolTransferHistory::setConfig(),
...App\Kintone\Models\BankCheckResult::setConfig(),


Notiek ielāde…
Atcelt
Saglabāt