6
0
Fork 0
release
李静 2022-01-18 13:25:39 +08:00
parent a09af07021
commit 2987b097d8
9 changed files with 191 additions and 82 deletions

View File

@ -165,7 +165,7 @@ class Dealer extends Model
$before = $this->lvl;
if ($lvl->value < DealerLvl::Contracted) {
if ($lvl->value < DealerLvl::Contracted->value) {
$this->contracted_lvl_at = null;
} elseif ($lvl->value >= DealerLvl::Contracted->value && $this->contracted_lvl_at === null) {
$this->contracted_lvl_at = now();

View File

@ -0,0 +1,28 @@
<?php
namespace App\Models;
use App\Enums\DealerLvl;
use Illuminate\Database\Eloquent\Model;
class DealerChannelSubsidyLog extends Model
{
protected $casts = [
'lvl' => DealerLvl::class,
'order_completed_at' => 'datetime',
];
protected $fillable = [
'user_id',
'order_id',
'lvl',
'total_amount',
'order_completed_at',
'remark',
];
public function earning()
{
return $this->morphOne(DealerEarning::class, 'earningable');
}
}

View File

@ -3,56 +3,36 @@
namespace App\Models;
use App\Enums\DealerEarningStatus;
use App\Enums\DealerEarningType;
use App\Enums\DealerLvl;
use Illuminate\Database\Eloquent\Model;
class DealerEarning extends Model
{
protected $attributes = [
'status' => DealerEarningStatus::Pending,
];
protected $casts = [
'start_at' => 'datetime',
'end_at' => 'datetime',
'type' => DealerEarningType::class,
'status' => DealerEarningStatus::class,
'lvl' => DealerLvl::class,
'is_manager' => 'bool',
'completed_at' => 'datetime',
'is_manager'=> 'bool',
'status' => DealerEarningStatus::class,
];
protected $fillable = [
'user_id',
'total_amount',
'fee',
'fee_rate',
'type',
'start_at',
'end_at',
'earningable_type',
'earningable_id',
'lvl',
'is_manager',
'total_amount',
'total_earnings',
'fee',
'fee_rate',
'payer_id',
'pay_info',
'pay_at',
'settle_at',
'status',
'description',
'completed_at',
'remark',
];
/**
* 仅查询管理补贴
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeManageSubsidy($query)
{
return $query->where('type', DealerEarningType::ManageSubsidy);
}
/**
* 仅查询管理者补贴
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeManagerSubsidy($query)
{
return $query->where('type', DealerEarningType::ManagerSubsidy);
}
}

View File

@ -111,6 +111,14 @@ class DealerOrder extends Model
return $this->belongsTo(UserInfo::class, 'user_id', 'user_id');
}
/**
* 此订单所属的经销商
*/
public function dealer()
{
return $this->belongsTo(Dealer::class, 'user_id', 'user_id');
}
/**
* 属于此订单的商品
*/

View File

@ -47,6 +47,7 @@ class AppServiceProvider extends ServiceProvider
'quota_v1_send_logs' => \App\Models\QuotaV1SendLog::class,
'dealer_manager_subsidy' => \App\Models\DealerManagerSubsidy::class,
'dealer_manage_subsidy' => \App\Models\DealerManageSubsidy::class,
'dealer_channel_subsidy_log' => \App\Models\DealerChannelSubsidyLog::class,
]);
JsonResource::withoutWrapping();

View File

@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateDealerEarningsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('dealer_earnings', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id')->comment('用户ID');
$table->string('earningable_type')->nullable();
$table->unsignedBigInteger('earningable_id')->nullable();
$table->tinyInteger('lvl')->comment('经销商等级');
$table->boolean('is_manager')->default(false)->comment('是否是管理者');
$table->unsignedDecimal('total_amount', 10, 2)->default(0)->comment('总金额');
$table->unsignedDecimal('total_earnings', 10, 2)->default(0)->comment('总收入=总金额-手续费');
$table->unsignedDecimal('fee', 10, 2)->default(0)->comment('手续费');
$table->unsignedDecimal('fee_rate', 4, 2)->default(0)->comment('手续费率');
$table->unsignedBigInteger('payer_id')->nullable()->comment('付款人的用户ID');
$table->text('pay_info')->nullable()->comment('收款信息');
$table->timestamp('pay_at')->nullable()->comment('付款时间');
$table->timestamp('settle_at')->nullable()->comment('结算时间');
$table->tinyInteger('status')->default(0)->comment('状态');
$table->text('remark')->nullable()->comment('备注');
$table->timestamps();
$table->unique(['user_id', 'earningable_type', 'earningable_id']);
$table->index(['earningable_type', 'earningable_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('dealer_earnings');
}
}

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateDealerChannelSubsidyLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('dealer_channel_subsidy_logs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id')->comment('经销商的用户ID');
$table->tinyInteger('lvl')->comment('经销商等级');
$table->unsignedBigInteger('order_id')->comment('订单ID');
$table->unsignedDecimal('total_amount', 10, 2)->default(0)->comment('补贴总额');
$table->timestamp('order_completed_at')->nullable()->comment('订单完成时间');
$table->string('remark')->nullable()->comment('备注');
$table->timestamps();
$table->unique(['user_id', 'order_id']);
$table->index('order_id');
$table->index('order_completed_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('dealer_channel_subsidy_logs');
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateDealerUpgradeLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('dealer_upgrade_logs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->tinyInteger('before_lvl');
$table->tinyInteger('change_lvl');
$table->string('remark');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('dealer_upgrade_logs');
}
}

View File

@ -189,66 +189,33 @@ class AppSettingSeeder extends Seeder
'channel_rules' => [
// 签约 -> 签约 ->签约
DealerLvl::Contracted->value.'_'.DealerLvl::Contracted->value => [
DealerLvl::Contracted->value.'_0' => [
'name' => '签约1',
'value' => '3960',
],
DealerLvl::Contracted->value.'_1' => [
'name' => '签约2',
'value' => '790',
],
DealerLvl::Contracted->value.'_0' => '3960',
DealerLvl::Contracted->value.'_1' => '790',
],
// 签约 -> 特邀 -> 签约 -> 签约
DealerLvl::Contracted->value.'_'.DealerLvl::Special->value => [
DealerLvl::Special->value.'_0' => [
'name' => '特邀',
'value' => '2640',
],
DealerLvl::Contracted->value.'_1' => [
'name' => '签约1',
'value' => '1320',
],
DealerLvl::Contracted->value.'_2' => [
'name' => '签约2',
'value' => '790',
],
DealerLvl::Special->value.'_0' => '2640',
DealerLvl::Contracted->value.'_1' => '1320',
DealerLvl::Contracted->value.'_2' => '790',
],
// 特邀 -> 特邀 ->特邀
DealerLvl::Special->value.'_'.DealerLvl::Special->value => [
DealerLvl::Special->value.'_0' => [
'name' => '特邀1',
'value' => '800',
],
DealerLvl::Special->value.'_1' => [
'name' => '特邀2',
'value' => '200',
],
DealerLvl::Special->value.'_0' => '800',
DealerLvl::Special->value.'_1' => '200',
],
// 特邀 -> 金牌 -> 特邀 -> 特邀
DealerLvl::Special->value.'_'.DealerLvl::Gold->value => [
DealerLvl::Gold->value.'_0' => [
'name' => '金牌',
'value' => '500',
],
DealerLvl::Special->value.'_1' => [
'name' => '特邀1',
'value' => '300',
],
DealerLvl::Special->value.'_2' => [
'name' => '特邀2',
'value' => '200',
],
DealerLvl::Gold->value.'_0' => '500',
DealerLvl::Special->value.'_1' => '300',
DealerLvl::Special->value.'_2' => '200',
],
// 金牌 -> 金牌
DealerLvl::Gold->value.'_'.DealerLvl::Gold->value => [
DealerLvl::Gold->value.'_0' => [
'name' => '金牌',
'value' => '300',
],
DealerLvl::Gold->value.'_0' => '300',
],
],