MemberBenefit.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\model;
  3. use DateTimeInterface;
  4. use support\Model;
  5. class MemberBenefit extends Model
  6. {
  7. protected $table = 'member_benefit';
  8. protected $primaryKey = 'member_benefit_id';
  9. public $keyType = 'string';
  10. protected $dateFormat = 'U';
  11. const CREATED_AT = 'member_benefit_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 member()
  18. {
  19. return $this->hasOne(Member::class, 'member_id', 'join_benefit_member_id')
  20. ->select('member_id', 'member_mobile');
  21. }
  22. public function cert()
  23. {
  24. return $this->hasOne(MemberCert::class, 'join_cert_member_id', 'member');
  25. }
  26. public function goods()
  27. {
  28. return $this->hasOne(Goods::class, 'goods_id', 'join_benefit_goods_id')
  29. ->select('goods_id', 'goods_cover', 'goods_name');
  30. }
  31. public function package()
  32. {
  33. return $this->hasOne(Goods::class, 'goods_id', 'join_benefit_package_id')
  34. ->select('goods_id', 'goods_cover', 'goods_name');
  35. }
  36. public function order()
  37. {
  38. return $this->hasOne(Order::class, 'order_id', 'join_benefit_order_id')
  39. ->select('order_id', 'order_name');
  40. }
  41. }