更新
This commit is contained in:
50
modules/Account/app/Models/Bill.php
Normal file
50
modules/Account/app/Models/Bill.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Account\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class Bill extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'account_bills';
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'family_id',
|
||||
'type',
|
||||
'amount',
|
||||
'category',
|
||||
'remark',
|
||||
'bill_date'
|
||||
];
|
||||
protected $dateFormat = 'Y-m-d H:i:s';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'bill_date' => 'date',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'deleted_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 账单所属用户
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\Modules\Member\Models\Member::class, 'user_id', 'uid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 账单所属家庭
|
||||
*/
|
||||
public function family()
|
||||
{
|
||||
return $this->belongsTo(Family::class);
|
||||
}
|
||||
}
|
||||
65
modules/Account/app/Models/Family.php
Normal file
65
modules/Account/app/Models/Family.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Account\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Family extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'account_families';
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'owner_id',
|
||||
'invite_code'
|
||||
];
|
||||
protected $dateFormat = 'Y-m-d H:i:s';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'deleted_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 家主
|
||||
*/
|
||||
public function owner()
|
||||
{
|
||||
return $this->belongsTo(\Modules\Member\Models\Member::class, 'owner_id', 'uid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 家庭成员
|
||||
*/
|
||||
public function members()
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
\Modules\Member\Models\Member::class,
|
||||
'account_family_members',
|
||||
'family_id',
|
||||
'user_id'
|
||||
)->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* 家庭成员关系
|
||||
*/
|
||||
public function familyMembers()
|
||||
{
|
||||
return $this->hasMany(FamilyMember::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 账单
|
||||
*/
|
||||
public function bills()
|
||||
{
|
||||
return $this->hasMany(Bill::class);
|
||||
}
|
||||
}
|
||||
39
modules/Account/app/Models/FamilyMember.php
Normal file
39
modules/Account/app/Models/FamilyMember.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Account\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FamilyMember extends Model
|
||||
{
|
||||
protected $table = 'account_family_members';
|
||||
protected $fillable = [
|
||||
'family_id',
|
||||
'user_id'
|
||||
];
|
||||
protected $dateFormat = 'Y-m-d H:i:s';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 所属家庭
|
||||
*/
|
||||
public function family()
|
||||
{
|
||||
return $this->belongsTo(Family::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 成员用户
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\Modules\Member\Models\Member::class, 'user_id', 'uid');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user