Discount.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/2/28
  6. * Time: 下午7:16
  7. */
  8. namespace app\common\models\goods;
  9. use app\common\models\BaseModel;
  10. use app\backend\modules\goods\observers\DiscountObserver;
  11. class Discount extends BaseModel
  12. {
  13. public $table = 'yz_goods_discount';
  14. protected $guarded = ['created_at', 'updated_at'];
  15. public static function getGoodsDiscountList($goodsId)
  16. {
  17. $goodsDiscountInfo = self::where('goods_id', $goodsId)
  18. ->get();
  19. return $goodsDiscountInfo;
  20. }
  21. /**
  22. * 自定义字段名
  23. * 可使用
  24. * @return array
  25. */
  26. public function atributeNames()
  27. {
  28. return [
  29. // 'level_discount_type' => '等级方式',
  30. // 'discount_method' => '折扣方式',
  31. // 'level_id' => '会员等级id',
  32. // 'discount_value' => '折扣或金额数值'
  33. ];
  34. }
  35. public function rules()
  36. {
  37. return [
  38. // 'level_discount_type' => 'numeric',
  39. // 'discount_method' => 'numeric',
  40. // 'level_id' => 'integer',
  41. // 'discount_value' => 'numeric'
  42. ];
  43. }
  44. public static function boot()
  45. {
  46. parent::boot();
  47. //注册观察者
  48. static::observe(new DiscountObserver);
  49. }
  50. }