'在售', (string)self::STATUS_OFF => '已下架', ]; } public static function allowScoreTextList(): array { return [ (string)self::ALLOW_ONLY_BUY => '购买', (string)self::ALLOW_BUY_AND_SCORE => '购买或积分兑换', (string)self::ALLOW_ONLY_SCORE => '积分兑换', ]; } public static function onAfterInsert(Model $item) { $item->sort = $item->id; $item->save(); } /** * 模型关联:商品分类 * * @return HasOne */ public function category(): HasOne { return $this->hasOne(SkuCategory::class, 'id', 'category_id'); } /** * 生成 SKU coding * 年份 + 2位随机码 + 时间戳(秒[10位] + 微妙[4位]) * @length 18 */ public static function generateCoding(): string { $randStr = str_pad(mt_rand(1,99), 2, '0', STR_PAD_LEFT); $prefix = date('y').$randStr; $mt = microtime(true); list($time, $micro) = explode('.', $mt); $micro = str_pad($micro, 4, '0', STR_PAD_RIGHT); $micro = substr($micro, 0, 4); return $prefix.$time.$micro; } /** * @return HasOne */ public function spu(): HasOne { return $this->hasOne(Spu::class, 'id', 'spu_id'); } /** * 关联活动商品 * * @return HasOne */ public function activity(): HasOne { return $this->hasOne(SpuActivity::class, 'id', 'spu_activity_id'); } }