1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Repositories\Models\Dwbs;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Model;
- use BaconQrCode\Common\Mode;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- class Good extends Model
- {
- /**
- * @var string
- */
- protected $table = 'dwbs_goods';
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- protected $casts = [];
- public function getCoverAttribute($val)
- {
- if (empty($val)) {
- return config('app.url') . '/default/headimg.png';
- }
- return path_to_url($val);
- }
- public function setCoverAttribute($val)
- {
- $this->attributes['cover'] = url_to_path($val);
- }
- public static function byId($id)
- {
- // return Cache::remember("model:good:byId:{$id}", Carbon::now()->addHours(1), function () use ($id) {
- return self::query()->where('id', $id)->where('status', ModelStatusEnum::OK)->first();
- // });
- }
- public static function getNames()
- {
- return Cache::remember("model:good:getNames", Carbon::now()->addHours(1), function () {
- return self::query()->where('status', ModelStatusEnum::OK)->select(['id', 'name'])->get();
- });
- }
- }
|