GoodsSku.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\common\model;
  3. use app\common\validate\KillService;
  4. use think\db\Query;
  5. use think\Model;
  6. /**
  7. * 邮箱验证码
  8. */
  9. class GoodsSku Extends Model
  10. {
  11. public function scopeShow(Query $query){
  12. $query->where('is_del',0);
  13. }
  14. public function bindGoods(){
  15. return $this->belongsToMany(Goods::class,GoodsBind::class,'bind_goods_id','goods_sku_id');
  16. }
  17. public function bindSku(){
  18. return $this->belongsToMany(GoodsSku::class,GoodsBind::class,'bind_goods_sku_id','goods_sku_id');
  19. }
  20. public function binds(){
  21. return $this->hasMany(GoodsBind::class);
  22. }
  23. public static function show(){
  24. return self::where('is_del',0);
  25. }
  26. public function goods(){
  27. return $this->belongsTo(Goods::class);
  28. }
  29. public function getRealAmount(){
  30. $open=KillService::open();
  31. if($open){
  32. return $this['amount_kill'];
  33. }
  34. return $this['amount'];
  35. }
  36. protected static function init()
  37. {
  38. self::afterDelete(function (self $sku){
  39. GoodsCart::where('goods_sku_id',$sku['id'])->delete();
  40. GoodsBind::where('goods_sku_id',$sku['id'])->delete();
  41. GoodsBind::where('bind_goods_sku_id',$sku['id'])->delete();
  42. GoodsInstallLink::where('goods_sku_id',$sku['id'])->delete();
  43. Favourite::where('goods_sku_id',$sku['id'])->delete();
  44. });
  45. }
  46. }