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.
|
|
<?php
declare (strict_types=1);namespace App\Model\v3;
use App\Model\Model;use Hyperf\Database\Model\Builder;use Hyperf\Database\Model\SoftDeletes;
/** */class Store extends Model{ use SoftDeletes;
const IS_OPEN_YES = 1; const IS_OPEN_NO = 2; const STATUS_EXAMINING = 1; const STATUS_PASS = 2; const STATUS_REFUSE = 3; const STATUS_EXPIRED = 4;
/** * The table associated with the model. * * @var string */ protected $table = 'lanzu_store'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = []; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [];
protected $appends = [ 'month_sales' ];
protected function boot(): void { parent::boot(); self::addGlobalScope('normal', function (Builder $builder) { $builder->where(['is_open' => self::IS_OPEN_YES, 'status' => self::STATUS_PASS]); }); }
public function scopeOrderByDefault($query, $sort) { return $query->orderBy('sort', $sort)->orderBy('id', $sort); }
public function scopeOrderBySales($query, $sort) { return $query->orderBy('sales', $sort); }
public function getMonthSalesAttribute() { return mt_rand(0,100); }
public function goods() { return $this->hasMany(Goods::class, 'store_id', 'id'); }}
|