You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4 KiB

5 years ago
<?php
namespace App\Models;
use App\Customer;
use App\Manager;
class Recharge extends SoftDeletesModel
{
protected $table = "recharge";
5 years ago
protected $appends = ["payment_name"];
5 years ago
public $payment_methods = [
"cash" => "现金",
"weixin" => "微信",
"alipay" => "支付宝",
"pos" => "POS机"
];
5 years ago
5 years ago
public function getPaymentNameAttribute()
5 years ago
{
5 years ago
$payment_name = $this->payment;
5 years ago
if (isset($this->payment_methods[$payment_name])) {
$payment_name = $this->payment_methods[$payment_name];
5 years ago
}
5 years ago
return $payment_name;
5 years ago
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function manager()
{
return $this->belongsTo(Manager::class);
}
public function order()
{
return $this->belongsTo(Orders::class);
}
5 years ago
public function patient()
{
return $this->hasOneThrough(Patient::class, Orders::class, "id", "id", "order_id", "patient_id");
5 years ago
}
5 years ago
public function refunds()
{
return $this->hasMany(Refund::class, "recharge_id");
5 years ago
}
public function getSerial()
{
if ($this->serial) {
return $this;
}
$serial = date("YmdHis", strtotime($this->created_at)) . sprintf("%06d", $this->id);
$this->update(["serial" => $serial]);
return $this;
}
}