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\Constants\v3\SsdbKeys;use App\Model\Model;use App\TaskWorker\SSDBTask;use Hyperf\Database\Model\Builder;use Hyperf\Database\Model\SoftDeletes;use Hyperf\Utils\ApplicationContext;use App\Constants\v3\Store as StoreConstants;
/** */class Store extends Model{ use SoftDeletes;
/** * 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' => StoreConstants::IS_OPEN_YES, 'status' => StoreConstants::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() { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); return (integer)$ssdb->exec('get', SsdbKeys::STORE_MONTH_SALES.date('YM').'_'.$this->id); }
public function goods() { return $this->hasMany(Goods::class, 'store_id', 'id'); }
public function shoppingCart() { return $this->hasMany(ShoppingCart::class, 'store_id', 'id'); }
public function market() { return $this->belongsTo(Market::class, 'market_id', 'id'); }}
|