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
namespace App\Model\v3;
use App\Constants\v3\Goods as GoodsConstants;use App\Constants\v3\SsdbKeys;use App\Model\Model;use Hyperf\Database\Model\Builder;use Hyperf\Utils\ApplicationContext;
class GoodsActivity extends Model{ protected $table = 'lanzu_goods_activity';
protected $casts = [ 'details_imgs' => 'array', 'spec' => 'array', 'tags' => 'array', ];
protected $appends = [ 'month_sales', 'cart_num', ];
protected function boot(): void { parent::boot(); self::addGlobalScope('normal', function (Builder $builder) { $builder->where(['on_sale' => GoodsConstants::ON_SALE_YES]); }); }
public function getMonthSalesAttribute() { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); return (integer)$ssdb->exec('get', SsdbKeys::GOODS_MONTH_SALES.date('YM').'_'.$this->id); }
public function getCartNumAttribute() { return (integer)$this->shopCartService->check($this->id); }
public function store() { return $this->belongsTo(Store::class, 'store_id', 'goods_id'); }}
|