MeetingModel.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 会议-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class MeetingModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'meetings';
  22. protected $appends = ['areas','start_time','meeting_time','time_text','time_text1'];
  23. public function getThumbAttribute($value)
  24. {
  25. return $value? get_image_url($value) : '';
  26. }
  27. // 时间
  28. public function getTimeTextAttribute()
  29. {
  30. $startTime = $this->start_at? strtotime($this->start_at) : 0;
  31. $endTime = $this->end_at? strtotime($this->end_at) : time();
  32. $startAt = $this->start_at? datetime($this->start_at,'m月d日 H:i') : '';
  33. $formatType = 'm月d日 H:i';
  34. if($endTime && $endTime <= $startTime+86400){
  35. $formatType = 'H:i';
  36. }
  37. $endAt = date($formatType,$endTime);
  38. return $startAt.' - '.$endAt;
  39. }
  40. // 倒计时开始
  41. public function getStartTimeAttribute()
  42. {
  43. $dateTime = time();
  44. $time = $this->start_at? strtotime($this->start_at) : 0;
  45. return $time>$dateTime?intval($dateTime-$time) : 0;
  46. }
  47. // 会议时长
  48. public function getMeetingTimeAttribute()
  49. {
  50. $startTime = $this->start_at? strtotime($this->start_at) : 0;
  51. $endTime = $this->end_at? strtotime($this->end_at) : time();
  52. return $endTime>$startTime?intval($endTime-$startTime) : 0;
  53. }
  54. // 时间
  55. public function getTimeText1Attribute()
  56. {
  57. $weeks = ['周日','周一','周二','周三','周四','周五','周六'];
  58. $startTime = $this->start_at? strtotime($this->start_at) : 0;
  59. $endTime = $this->end_at? strtotime($this->end_at) : time();
  60. $w = date('w',$startTime);
  61. $week = isset($weeks[$w])?' '.$weeks[$w].' ': '';
  62. $startAt = $this->start_at? datetime($this->start_at,"Y年m月d日").$week.datetime($this->start_at,"H:i") : '';
  63. $formatType = 'm月d日 H:i';
  64. if($endTime && $endTime <= $startTime+86400){
  65. $formatType = 'H:i';
  66. }
  67. $endAt = date($formatType,$endTime);
  68. return $startAt.' - '.$endAt;
  69. }
  70. /**
  71. * @return array
  72. */
  73. public function getAreasAttribute()
  74. {
  75. return [$this->province_id.'',$this->city_id.'',$this->district_id.''];
  76. }
  77. /**
  78. * @return array
  79. */
  80. public function getStoreIdsAttribute($value)
  81. {
  82. return $value? array_filter(explode(',', $value)):[];
  83. }
  84. /**
  85. * @return array
  86. */
  87. public function getSupervisorIdsAttribute($value)
  88. {
  89. return $value? array_filter(explode(',', $value)):[];
  90. }
  91. /**
  92. * 推荐组织人
  93. */
  94. public function member()
  95. {
  96. return $this->hasOne(MemberModel::class, 'id','user_id')
  97. ->where(['mark'=>1])
  98. ->select(['id', 'nickname','avatar', 'realname','position','company','department','is_auth', 'mobile', 'status']);
  99. }
  100. /**
  101. * 省份
  102. */
  103. public function province()
  104. {
  105. return $this->hasOne(CityModel::class, 'citycode','province_id')
  106. ->where(['mark'=>1]);
  107. }
  108. /**
  109. * 城市
  110. */
  111. public function city()
  112. {
  113. return $this->hasOne(CityModel::class, 'citycode','city_id')
  114. ->where(['mark'=>1]);
  115. }
  116. /**
  117. * 区县
  118. */
  119. public function district()
  120. {
  121. return $this->hasOne(CityModel::class, 'citycode','district_id')
  122. ->where(['mark'=>1]);
  123. }
  124. /**
  125. * 签到记录
  126. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  127. */
  128. public function records()
  129. {
  130. return $this->hasMany(MeetingRecordsModel::class, 'meeting_id','id')
  131. ->where(['mark'=>1]);
  132. }
  133. }