|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Customer;
|
|
|
|
|
use App\Manager;
|
|
|
|
|
|
|
|
|
|
class Recharge extends SoftDeletesModel
|
|
|
|
|
{
|
|
|
|
|
protected $table = "recharge";
|
|
|
|
|
protected $appends = ["payment_name"];
|
|
|
|
|
public $payment_methods = [
|
|
|
|
|
"cash" => "现金",
|
|
|
|
|
"weixin" => "微信",
|
|
|
|
|
"alipay" => "支付宝",
|
|
|
|
|
"pos" => "POS机",
|
|
|
|
|
"offline_pos" => "线下POS",
|
|
|
|
|
"offline_cash" => "线下现金",
|
|
|
|
|
"offline_qrcode" => "线下二维码",
|
|
|
|
|
"transfer" => "转账"
|
|
|
|
|
];
|
|
|
|
|
public $payment_online_methods = [
|
|
|
|
|
"weixin" => "微信",
|
|
|
|
|
"alipay" => "支付宝"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function getPaymentNameAttribute()
|
|
|
|
|
{
|
|
|
|
|
$payment_name = $this->payment;
|
|
|
|
|
if (isset($this->payment_methods[$payment_name])) {
|
|
|
|
|
$payment_name = $this->payment_methods[$payment_name];
|
|
|
|
|
}
|
|
|
|
|
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 project()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOneThrough(Project::class, Orders::class, "id", "id", "order_id", "project_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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|