From e35656f87df46739694993dd0a72ee881716b5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 30 Dec 2021 14:38:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E9=A2=9D=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Distribution/PreIncomeSettleCommand.php | 10 ++++-- .../Merchant/QuotaLogController.php | 29 +++++++++++++++++ .../Api/Http/Resources/QuotaLogResource.php | 23 +++++++++++++ app/Endpoint/Api/routes.php | 6 ++-- app/Models/DistributionPreIncome.php | 12 ++++++- app/Models/QuotaLog.php | 1 + ...142454_add_remarks_to_quota_logs_table.php | 32 +++++++++++++++++++ 7 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 app/Endpoint/Api/Http/Controllers/Merchant/QuotaLogController.php create mode 100644 app/Endpoint/Api/Http/Resources/QuotaLogResource.php create mode 100644 database/migrations/2021_12_30_142454_add_remarks_to_quota_logs_table.php diff --git a/app/Console/Commands/Distribution/PreIncomeSettleCommand.php b/app/Console/Commands/Distribution/PreIncomeSettleCommand.php index 22d32728..cdb46e85 100644 --- a/app/Console/Commands/Distribution/PreIncomeSettleCommand.php +++ b/app/Console/Commands/Distribution/PreIncomeSettleCommand.php @@ -49,14 +49,18 @@ class PreIncomeSettleCommand extends Command ); // 计算配额 - $quota = round(bcmul($preIncome->total_revenue, app_settings('distribution.quota_v2_rate', 0), 4), 3); + $changeQuota = bcmul($preIncome->total_revenue, app_settings('distribution.quota_v2_rate', 0), 4); + $changeQuota = round($changeQuota, 3); + $preIncome->user->userInfo()->update([ - 'quota_v2' => DB::raw("quota_v2+{$quota}"), + 'quota_v2' => DB::raw("quota_v2+{$changeQuota}"), ]); + $preIncome->user->quotaLogs()->create([ 'loggable_id' => $preIncome->id, 'loggable_type' => $preIncome->getMorphClass(), - 'change_quota' => $quota, + 'change_quota' => $changeQuota, + 'remarks' => $preIncome->type_text.'得配额', ]); // 将预收益标记为已结算 diff --git a/app/Endpoint/Api/Http/Controllers/Merchant/QuotaLogController.php b/app/Endpoint/Api/Http/Controllers/Merchant/QuotaLogController.php new file mode 100644 index 00000000..936c967a --- /dev/null +++ b/app/Endpoint/Api/Http/Controllers/Merchant/QuotaLogController.php @@ -0,0 +1,29 @@ +user() + ->quotaLogs() + ->latest('id') + ->simplePaginate($perPage); + + return QuotaLogResource::collection($quotaLogs); + } +} diff --git a/app/Endpoint/Api/Http/Resources/QuotaLogResource.php b/app/Endpoint/Api/Http/Resources/QuotaLogResource.php new file mode 100644 index 00000000..b4008933 --- /dev/null +++ b/app/Endpoint/Api/Http/Resources/QuotaLogResource.php @@ -0,0 +1,23 @@ + $this->change_quota, + 'remarks' => (string) $this->remarks, + 'created_at' => $this->created_at->toDateTimeString(), + ]; + } +} diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index ef18a3bf..864de908 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -182,9 +182,11 @@ Route::group([ ], ], function () { Route::get('account', [Merchant\UserController::class, 'account']); - // 个人销售值 + // 配额日志 + Route::get('quota-logs', [Merchant\QuotaLogController::class, 'index']); + // 个人销售值日志 Route::get('sales-value-logs', [Merchant\SalesValueLogController::class, 'index']); - // 团队销售值 + // 团队销售值日志 Route::get('team-sales-value-logs', [Merchant\TeamSalesValueLogController::class, 'index']); }); }); diff --git a/app/Models/DistributionPreIncome.php b/app/Models/DistributionPreIncome.php index b9dfe095..102eaaf1 100644 --- a/app/Models/DistributionPreIncome.php +++ b/app/Models/DistributionPreIncome.php @@ -53,7 +53,7 @@ class DistributionPreIncome extends Model public static $typeTexts = [ self::TYPE_PRICE_DIFF => '推粉丝赚差价', self::TYPE_LEVEL_SAME => '平级奖励', - self::TYPE_LEVEL_DIFF => '级差奖金', + self::TYPE_LEVEL_DIFF => '级差奖励', ]; /** @@ -117,4 +117,14 @@ class DistributionPreIncome extends Model { return UserInfo::$agentLevelTexts[$this->agent_level] ?? '未知'; } + + /** + * 获取类型文本 + * + * @return string + */ + public function getTypeTextAttribute(): string + { + return static::$typeTexts[$this->type] ?? '其它'; + } } diff --git a/app/Models/QuotaLog.php b/app/Models/QuotaLog.php index af5f7043..830c4b1d 100644 --- a/app/Models/QuotaLog.php +++ b/app/Models/QuotaLog.php @@ -14,5 +14,6 @@ class QuotaLog extends Model 'loggable_id', 'loggable_type', 'change_quota', + 'remarks', ]; } diff --git a/database/migrations/2021_12_30_142454_add_remarks_to_quota_logs_table.php b/database/migrations/2021_12_30_142454_add_remarks_to_quota_logs_table.php new file mode 100644 index 00000000..5b8c9a9c --- /dev/null +++ b/database/migrations/2021_12_30_142454_add_remarks_to_quota_logs_table.php @@ -0,0 +1,32 @@ +string('remarks')->nullable()->comment('备注'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('quota_logs', function (Blueprint $table) { + $table->dropColumn(['remarks']); + }); + } +}