Coupon.php 882 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\model;
  3. use DateTimeInterface;
  4. use support\Model;
  5. class Coupon extends Model
  6. {
  7. protected $table = 'coupon';
  8. protected $primaryKey = 'coupon_id';
  9. protected $keyType = 'string';
  10. protected $dateFormat = 'U';
  11. const CREATED_AT = 'coupon_addtimes';
  12. const UPDATED_AT = null;
  13. public function serializeDate(DateTimeInterface $date)
  14. {
  15. return $date->format('Y-m-d H:i:s');
  16. }
  17. public function detail()
  18. {
  19. return $this->hasMany(CouponDetail::class,'join_detail_coupon_id','coupon_id');
  20. }
  21. public function category(){
  22. return $this->hasOne(SysCategory::class,'category_id','join_coupon_category_id')->select('category_id','category_name');
  23. }
  24. public function user(){
  25. return $this->hasOne(SysUser::class,'user_id','coupon_creator_user_id')->select('user_id','user_name');
  26. }
  27. }