123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace app\common\model;
- use think\Model;
- /**
- * 邮箱验证码
- */
- class Goods Extends Model
- {
- protected $type=[
- 'logo'=>'json',
- ];
- public static $read=[
- 'num_sell'
- ];
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- public function sku(){
- return $this->hasMany(GoodsSku::class)->where('is_del',0);
- }
- public function detail(){
- return $this->hasMany(GoodsDetail::class);
- }
- public function service(){
- return $this->hasMany(GoodsService::class);
- }
- public function binds(){
- return $this->hasMany(GoodsBind::class);
- }
- public function category(){
- return $this->belongsTo(Category::class);
- }
- public static $status=[
- 1=>'正常',
- 2=>'下架',
- ];
- /**
- * @return string[]
- */
- public static function getStatus(): array
- {
- return self::$status;
- }
- public static function show(){
- return self::where('status',1);
- }
- protected static function init()
- {
- self::beforeWrite(function (self $goods){
- if(!empty($goods['is_hot']) && $goods['is_hot']==1){
- $goods['hot_at']=time();
- }
- if(!empty($goods['is_kill']) && $goods['is_kill']==1){
- $goods['kill_at']=time();
- }
- });
- self::afterDelete(function (self $goods){
- $goods->detail()->delete();
- $goods->service()->delete();
- $goods->sku()->delete();
- $goods->binds()->delete();
- GoodsBind::where('bind_goods_id',$goods['id'])->delete();
- });
- }
- }
|