123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace App\Http\Models;
- use Auth;
- use Eloquent;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Carbon;
- class Payment extends Model
- {
- protected $table = 'payment';
- protected $primaryKey = 'id';
- protected $appends = ['status_label'];
- function scopeUid($query)
- {
- return $query->whereUserId(Auth::user()->id);
- }
- function user()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
- function order()
- {
- return $this->belongsTo(Order::class, 'oid', 'oid');
- }
- function getAmountAttribute($value)
- {
- return $value/100;
- }
- function setAmountAttribute($value)
- {
- return $this->attributes['amount'] = $value*100;
- }
-
- function getStatusLabelAttribute()
- {
- switch($this->attributes['status']){
- case -1:
- $status_label = '支付失败';
- break;
- case 1:
- $status_label = '支付成功';
- break;
- case 0:
- default:
- $status_label = '等待支付';
- }
- return $status_label;
- }
- }
|