6
0
Fork 0

计算配额

release
李静 2021-12-29 20:59:36 +08:00
parent 22c59d1e4e
commit 2655a2eec0
5 changed files with 76 additions and 0 deletions

View File

@ -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,

View File

@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class QuotaLog extends Model
{
/**
* @var array
*/
protected $fillable = [
'user_id',
'loggable_id',
'loggable_type',
'change_quota',
];
}

View File

@ -228,6 +228,14 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
return $this->hasMany(DistributionPreIncome::class, 'user_id');
}
/**
* 用户的配额日志
*/
public function quotaLogs()
{
return $this->hasMany(QuotaLog::class);
}
/**
* 用户的粉丝
*

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateQuotaLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('quota_logs', function (Blueprint $table) {
$table->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');
}
}

View File

@ -100,6 +100,8 @@ class AppSettingSeeder extends Seeder
'value' => [
// 分销结算时间
'settle_days' => '7',
// 新配额比例
'quota_v2_rate' => '0.01',
// 会员差价手续费
'price_diff_fee_rate' => '0.23',
// 平级奖励手续费