InvitationGift.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\common\model\plus\invitationgift;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 邀请有礼模型
  6. */
  7. class InvitationGift extends BaseModel
  8. {
  9. protected $name = 'invitation_gift';
  10. protected $pk = 'invitation_gift_id';
  11. /**
  12. * 礼包详情
  13. */
  14. public static function detail($invitation_gift_id)
  15. {
  16. return (new static())->with(['image'])->find($invitation_gift_id);
  17. }
  18. /**
  19. * 关联奖励
  20. */
  21. public function reward()
  22. {
  23. return $this->hasMany('app\\common\\model\\plus\\invitationgift\\InvitationReward', 'invitation_gift_id', 'invitation_gift_id')->order(['invitation_num' => 'asc']);
  24. }
  25. /**
  26. * 开始时间
  27. */
  28. public function getStartTimeAttr($value)
  29. {
  30. return ['text' => date('Y-m-d H:i:s', $value), 'value' => $value];
  31. }
  32. /**
  33. * 有效期-结束时间
  34. */
  35. public function getEndTimeAttr($value)
  36. {
  37. return ['text' => date('Y-m-d H:i:s', $value), 'value' => $value];
  38. }
  39. /**
  40. * 状态
  41. */
  42. public function getStatusAttr($value, $data)
  43. {
  44. $text = '';
  45. if($value == 1){
  46. $text = '未生效';
  47. }else{
  48. if ($data['start_time'] > time()) {
  49. $text = '未开始';
  50. }
  51. if ($data['end_time'] < time()) {
  52. $text = '已结束';
  53. }
  54. if ($data['start_time'] < time() && $data['end_time'] > time()) {
  55. $text = '进行中';
  56. }
  57. }
  58. return ['text' => $text, 'value' => $value];
  59. }
  60. /**
  61. * 关联文件库
  62. */
  63. public function image()
  64. {
  65. return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id')
  66. ->bind(['file_path']);
  67. }
  68. /**
  69. * 关联文件库
  70. */
  71. public function share()
  72. {
  73. return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'share_image_id', 'file_id');
  74. }
  75. }