86 lines
2.1 KiB
PHP
86 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Modules\SystemUser\Models\SysUserModel;
|
|
|
|
/**
|
|
* 门店账单模型(采购单完成后按门店生成;商品金额由订单汇总快照,生成后不可修改)
|
|
*/
|
|
class BillModel extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'bill';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $fillable = [
|
|
'bill_no',
|
|
'purchase_id',
|
|
'store_id',
|
|
'bill_date',
|
|
'product_amount',
|
|
'delivery_fee',
|
|
'box_num',
|
|
'tray_num',
|
|
'box_price',
|
|
'tray_price',
|
|
'added_amount',
|
|
'total_amount',
|
|
'operator_id',
|
|
'remark',
|
|
];
|
|
|
|
protected $casts = [
|
|
'purchase_id' => 'integer',
|
|
'store_id' => 'integer',
|
|
'bill_date' => 'date:Y-m-d',
|
|
'product_amount' => 'decimal:2',
|
|
'delivery_fee' => 'decimal:2',
|
|
'box_num' => 'integer',
|
|
'tray_num' => 'integer',
|
|
'box_price' => 'decimal:2',
|
|
'tray_price' => 'decimal:2',
|
|
'added_amount' => 'decimal:2',
|
|
'total_amount' => 'decimal:2',
|
|
'operator_id' => 'integer',
|
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
|
];
|
|
|
|
/**
|
|
* 所属门店(含软删除门店,保证历史账单可见)
|
|
*/
|
|
public function store(): BelongsTo
|
|
{
|
|
return $this->belongsTo(StoreModel::class, 'store_id', 'id')->withTrashed();
|
|
}
|
|
|
|
/**
|
|
* 关联采购单
|
|
*/
|
|
public function purchase(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PurchaseOrderModel::class, 'purchase_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 生成人(后台系统用户)
|
|
*/
|
|
public function operator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SysUserModel::class, 'operator_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 本账单关联的门店订单
|
|
*/
|
|
public function orders(): HasMany
|
|
{
|
|
return $this->hasMany(StoreOrderModel::class, 'bill_id', 'id');
|
|
}
|
|
}
|