6
0
Fork 0

经销商余额

release
李静 2022-01-25 13:47:10 +08:00
parent 68a5e419f3
commit 4140f5aeac
6 changed files with 169 additions and 1 deletions

View File

@ -0,0 +1,6 @@
<?php
namespace App\Enums;
enum DealerWalletAction: int {
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DealerWallet extends Model
{
/**
* @var array
*/
protected $attributes = [
'balance' => 0,
'total_revenue' => 0,
'total_expenses' => 0,
'withdrawable' => false,
];
/**
* @var array
*/
protected $casts = [
'withdrawable' => 'bool',
];
/**
* @var array
*/
protected $fillable = [
'user_id',
'balance',
'total_expenses',
'total_revenue',
'withdrawable',
];
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Models;
use App\Enums\DealerWalletAction;
use Illuminate\Database\Eloquent\Model;
class DealerWalletLog extends Model
{
/**
* @var array
*/
protected $casts = [
'action' => DealerWalletAction::class,
];
/**
* @var array
*/
protected $fillable = [
'user_id',
'loggable_id',
'loggable_type',
'action',
'before_balance',
'change_balance',
'remarks',
];
/**
* 此余额日志关联的用户
*/
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@ -143,7 +143,7 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
}
/**
* 属于用户得经销商身份
* 属于用户得经销商身份
*
* @return void
*/
@ -152,6 +152,22 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
return $this->hasOne(Dealer::class, 'user_id');
}
/**
* 属于此用户得经销商余额
*/
public function dealerWallet()
{
return $this->hasOne(DealerWallet::class, 'user_id');
}
/**
* 属于此用户得经销商余额日志
*/
public function dealerWalletLogs()
{
return $this->hasMany(DealerWalletLog::class, 'user_id');
}
/**
* 经销商订购订单
*

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateDealerWalletsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('dealer_wallets', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id')->unique()->comment('用户ID');
$table->unsignedDecimal('balance', 12, 2)->default(0)->comment('余额');
$table->unsignedDecimal('total_expenses', 12, 2)->default(0)->comment('总支出');
$table->unsignedDecimal('total_revenue', 12, 2)->default(0)->comment('总收入');
$table->boolean('withdrawable')->default(true)->comment('是否可提现');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('dealer_wallets');
}
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateDealerWalletLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('dealer_wallet_logs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id')->comment('用户ID');
$table->nullableMorphs('loggable');
$table->tinyInteger('action')->comment('操作类型');
$table->decimal('before_balance', 12, 2)->default(0)->comment('变更前的余额');
$table->decimal('change_balance', 12, 2)->default(0)->comment('变动余额');
$table->string('remarks')->nullable()->comment('备注');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('dealer_wallet_logs');
}
}