51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class OfflineOrderItem extends Model
|
|
{
|
|
use HasFactory, HasDateTimeFormatter;
|
|
|
|
protected $attributes = [
|
|
'discount_reduction_amount' => 0,
|
|
'points_deduction_amount' => 0,
|
|
];
|
|
|
|
protected $fillable = [
|
|
'order_id',
|
|
'product_category_id',
|
|
'products_total_amount',
|
|
'discount_reduction_amount',
|
|
'points_deduction_amount',
|
|
'payment_amount',
|
|
];
|
|
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(OfflineOrder::class, 'order_id');
|
|
}
|
|
|
|
public function productCategory()
|
|
{
|
|
return $this->belongsTo(OfflineProductCategory::class, 'product_category_id');
|
|
}
|
|
|
|
public function getDiscount()
|
|
{
|
|
$discount = '';
|
|
|
|
if ($this->discount_reduction_amount > 0 && $this->products_total_amount > 0) {
|
|
// 应付金额
|
|
$total = $this->products_total_amount - $this->discount_reduction_amount;
|
|
|
|
$discount = round(bcdiv($total * 10, $this->products_total_amount, 3), 2);
|
|
}
|
|
|
|
return $discount;
|
|
}
|
|
}
|