From d49b23056255b2d701d56ca39f3f37e6e77ac838 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Fri, 7 Jun 2024 10:08:02 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=86=E3=81=86=E3=81=A1=E3=82=87=E6=8C=AF?= =?UTF-8?q?=E8=BE=BC=E3=81=AE=E9=A1=A7=E5=AE=A2=E5=89=B2=E3=82=8A=E5=BD=93?= =?UTF-8?q?=E3=81=A6=E8=87=AA=E5=8B=95=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PoolTransfer/YuchoResolveCustomer.php | 128 ++++++++++++++++++ app/Console/Schedules/PoolTransfer.php | 4 +- .../Models/YuchoPaymentRelationSetting.php | 34 +++++ app/Kintone/Models/YuchoPaymentResult.php | 7 + config/kintone.php | 1 + 5 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/PoolTransfer/YuchoResolveCustomer.php create mode 100644 app/Kintone/Models/YuchoPaymentRelationSetting.php diff --git a/app/Console/Commands/PoolTransfer/YuchoResolveCustomer.php b/app/Console/Commands/PoolTransfer/YuchoResolveCustomer.php new file mode 100644 index 0000000..347ae0b --- /dev/null +++ b/app/Console/Commands/PoolTransfer/YuchoResolveCustomer.php @@ -0,0 +1,128 @@ + */ + private Collection $settings; + + /** + * 振込者名がキー + * @var Collection + **/ + 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; + } +} diff --git a/app/Console/Schedules/PoolTransfer.php b/app/Console/Schedules/PoolTransfer.php index 1a5db0f..98804ac 100644 --- a/app/Console/Schedules/PoolTransfer.php +++ b/app/Console/Schedules/PoolTransfer.php @@ -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); }); } diff --git a/app/Kintone/Models/YuchoPaymentRelationSetting.php b/app/Kintone/Models/YuchoPaymentRelationSetting.php new file mode 100644 index 0000000..0d4bfb9 --- /dev/null +++ b/app/Kintone/Models/YuchoPaymentRelationSetting.php @@ -0,0 +1,34 @@ + 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 = []; +} diff --git a/app/Kintone/Models/YuchoPaymentResult.php b/app/Kintone/Models/YuchoPaymentResult.php index 6341f68..89eefe9 100644 --- a/app/Kintone/Models/YuchoPaymentResult.php +++ b/app/Kintone/Models/YuchoPaymentResult.php @@ -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, + ]; } diff --git a/config/kintone.php b/config/kintone.php index 2fbf5e7..315848e 100644 --- a/config/kintone.php +++ b/config/kintone.php @@ -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(),