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.
69 lines
1.5 KiB
69 lines
1.5 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Customer;
|
|
use App\Manager;
|
|
|
|
class Recharge extends SoftDeletesModel
|
|
{
|
|
protected $table = "recharge";
|
|
protected $appends = ["payment_name"];
|
|
|
|
public function getPaymentNameAttribute()
|
|
{
|
|
$payment_name = $this->payment;
|
|
switch ($this->payment) {
|
|
case "weixin":
|
|
$payment_name = "微信";
|
|
break;
|
|
case "alipay":
|
|
$payment_name = "支付宝";
|
|
break;
|
|
case "cash":
|
|
$payment_name = "现金";
|
|
break;
|
|
case "pos":
|
|
$payment_name = "POS机";
|
|
break;
|
|
}
|
|
return $payment_name;
|
|
}
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
public function manager()
|
|
{
|
|
return $this->belongsTo(Manager::class);
|
|
}
|
|
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Orders::class);
|
|
}
|
|
|
|
public function patient()
|
|
{
|
|
return $this->hasOneThrough(Patient::class, Orders::class, "id", "id", "order_id", "patient_id");
|
|
}
|
|
|
|
public function refunds()
|
|
{
|
|
return $this->hasMany(Refund::class, "recharge_id");
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|