CouponPacket.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\model;
  3. use DateTimeInterface;
  4. use support\Model;
  5. class CouponPacket extends Model
  6. {
  7. protected $table = 'coupon_packet';
  8. protected $primaryKey = 'coupon_packet_id';
  9. protected $keyType = 'string';
  10. protected $dateFormat = 'U';
  11. const CREATED_AT = 'coupon_packet_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 dept()
  22. {
  23. return $this->hasOne(SysDept::class,'dept_id','join_coupon_packet_dept_id')->select('dept_id','dept_name');
  24. }
  25. public function category(){
  26. return $this->hasOne(SysCategory::class,'category_id','join_coupon_packet_category_id')->select('category_id','category_name');
  27. }
  28. public function user(){
  29. return $this->hasOne(SysUser::class,'user_id','join_coupon_packet_user_id')->select('user_id','user_name');
  30. }
  31. }