diff --git a/app/Console/Commands/Distribution/PreIncomeSettleCommand.php b/app/Console/Commands/Distribution/PreIncomeSettleCommand.php index 3b623057..22d32728 100644 --- a/app/Console/Commands/Distribution/PreIncomeSettleCommand.php +++ b/app/Console/Commands/Distribution/PreIncomeSettleCommand.php @@ -48,6 +48,18 @@ class PreIncomeSettleCommand extends Command $preIncome ); + // 计算配额 + $quota = round(bcmul($preIncome->total_revenue, app_settings('distribution.quota_v2_rate', 0), 4), 3); + $preIncome->user->userInfo()->update([ + 'quota_v2' => DB::raw("quota_v2+{$quota}"), + ]); + $preIncome->user->quotaLogs()->create([ + 'loggable_id' => $preIncome->id, + 'loggable_type' => $preIncome->getMorphClass(), + 'change_quota' => $quota, + ]); + + // 将预收益标记为已结算 $preIncome->update([ 'completed_at' => now(), 'status' => DistributionPreIncome::STATUS_PROCESSED, diff --git a/app/Models/QuotaLog.php b/app/Models/QuotaLog.php new file mode 100644 index 00000000..af5f7043 --- /dev/null +++ b/app/Models/QuotaLog.php @@ -0,0 +1,18 @@ +hasMany(DistributionPreIncome::class, 'user_id'); } + /** + * 用户的配额日志 + */ + public function quotaLogs() + { + return $this->hasMany(QuotaLog::class); + } + /** * 用户的粉丝 * diff --git a/database/migrations/2021_12_29_201548_create_quota_logs_table.php b/database/migrations/2021_12_29_201548_create_quota_logs_table.php new file mode 100644 index 00000000..d283678d --- /dev/null +++ b/database/migrations/2021_12_29_201548_create_quota_logs_table.php @@ -0,0 +1,36 @@ +id(); + $table->unsignedBigInteger('user_id')->comment('用户ID'); + $table->nullableMorphs('loggable'); + $table->decimal('change_quota', 18, 3)->default(0)->comment('变更的配额'); + $table->timestamps(); + + $table->index('user_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('quota_logs'); + } +} diff --git a/database/seeders/AppSettingSeeder.php b/database/seeders/AppSettingSeeder.php index 4ead3795..3149d38e 100644 --- a/database/seeders/AppSettingSeeder.php +++ b/database/seeders/AppSettingSeeder.php @@ -100,6 +100,8 @@ class AppSettingSeeder extends Seeder 'value' => [ // 分销结算时间 'settle_days' => '7', + // 新配额比例 + 'quota_v2_rate' => '0.01', // 会员差价手续费 'price_diff_fee_rate' => '0.23', // 平级奖励手续费