123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Trace extends Model
- {
- public $fillable = ['key', 'gid'];
- public $appends = ['slug_value'];
- public function good()
- {
- return $this->belongsTo(Good::class, 'gid');
- }
- public function getKeyAttribute()
- {
- if ($this->attributes['id'] <= 50000) {
- return number_format(10000000 + $this->attributes['id'], 0, '', '');
- } else {
- return bcadd('1000000000000000', "{$this->attributes['id']}");
- }
- }
- public static function get_key($id)
- {
- if ($id <= 10050000) {
- $id = bcsub("{$id}", '10000000');
- } else {
- $id = bcsub("{$id}", '1000000000000000');
- }
- return $id;
- }
- public function dealer()
- {
- return $this->belongsTo(Dealer::class);
- }
- public function getSlugAttribute($value)
- {
- return config('app.url') . '/key/' . $value;
- }
- public function getSlugValueAttribute()
- {
- return $this->attributes['slug'];
- }
- public function setSlugValueAttribute($val)
- {
- $this->attributes['slug'] = $val;
- }
- }
|