12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\common\model;
- use think\db\Query;
- use think\Model;
- /**
- * 邮箱验证码
- */
- class GoodsSku Extends Model
- {
- public function scopeShow(Query $query){
- $query->where('is_del',0);
- }
- public function bindGoods(){
- return $this->belongsToMany(Goods::class,GoodsBind::class,'bind_goods_id','goods_sku_id');
- }
- public function bindSku(){
- return $this->belongsToMany(GoodsSku::class,GoodsBind::class,'bind_goods_sku_id','goods_sku_id');
- }
- public function binds(){
- return $this->hasMany(GoodsBind::class);
- }
- public static function show(){
- return self::where('is_del',0);
- }
- public function goods(){
- return $this->belongsTo(Goods::class);
- }
- protected static function init()
- {
- self::afterDelete(function (self $sku){
- GoodsCart::where('goods_sku_id',$sku['id'])->delete();
- GoodsBind::where('goods_sku_id',$sku['id'])->delete();
- GoodsBind::where('bind_goods_sku_id',$sku['id'])->delete();
- GoodsInstallLink::where('goods_sku_id',$sku['id'])->delete();
- Favourite::where('goods_sku_id',$sku['id'])->delete();
- });
- }
- }
|