MeetingModel.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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($time-$dateTime) : 0;
  46. }
  47. // 会议时长
  48. public function getMeetingTimeAttribute()
  49. {
  50. $dateTime = time();
  51. $startTime = $this->start_at? strtotime($this->start_at) : 0;
  52. $endTime = $this->end_at? strtotime($this->end_at) : time();
  53. $startTime = $dateTime>$startTime?$dateTime:$startTime;
  54. return $endTime>$startTime?intval($endTime-$startTime) : 0;
  55. }
  56. // 时间
  57. public function getTimeText1Attribute()
  58. {
  59. $weeks = ['周日','周一','周二','周三','周四','周五','周六'];
  60. $startTime = $this->start_at? strtotime($this->start_at) : 0;
  61. $endTime = $this->end_at? strtotime($this->end_at) : time();
  62. $w = date('w',$startTime);
  63. $week = isset($weeks[$w])?' '.$weeks[$w].' ': '';
  64. $startAt = $this->start_at? datetime($this->start_at,"Y年m月d日").$week.datetime($this->start_at,"H:i") : '';
  65. $formatType = 'm月d日 H:i';
  66. if($endTime && $endTime <= $startTime+86400){
  67. $formatType = 'H:i';
  68. }
  69. $endAt = date($formatType,$endTime);
  70. return $startAt.' - '.$endAt;
  71. }
  72. /**
  73. * @return array
  74. */
  75. public function getAreasAttribute()
  76. {
  77. return [$this->province_id.'',$this->city_id.'',$this->district_id.''];
  78. }
  79. /**
  80. * @return array
  81. */
  82. public function getStoreIdsAttribute($value)
  83. {
  84. return $value? array_filter(explode(',', $value)):[];
  85. }
  86. /**
  87. * @return array
  88. */
  89. public function getSupervisorIdsAttribute($value)
  90. {
  91. return $value? array_filter(explode(',', $value)):[];
  92. }
  93. /**
  94. * 主办单位
  95. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  96. */
  97. public function company()
  98. {
  99. return $this->hasOne(StoreModel::class, 'id', 'company_id')
  100. ->select(['id','user_id', 'realname','avatar', 'nickname', 'mobile', 'status']);
  101. }
  102. /**
  103. * 推荐组织人
  104. */
  105. public function member()
  106. {
  107. return $this->hasOne(MemberModel::class, 'id','user_id')
  108. ->where(['mark'=>1])
  109. ->select(['id', 'nickname','avatar', 'realname','position','company','department','is_auth', 'mobile', 'status']);
  110. }
  111. /**
  112. * 省份
  113. */
  114. public function province()
  115. {
  116. return $this->hasOne(CityModel::class, 'citycode','province_id')
  117. ->where(['mark'=>1]);
  118. }
  119. /**
  120. * 城市
  121. */
  122. public function city()
  123. {
  124. return $this->hasOne(CityModel::class, 'citycode','city_id')
  125. ->where(['mark'=>1]);
  126. }
  127. /**
  128. * 区县
  129. */
  130. public function district()
  131. {
  132. return $this->hasOne(CityModel::class, 'citycode','district_id')
  133. ->where(['mark'=>1]);
  134. }
  135. /**
  136. * 签到记录
  137. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  138. */
  139. public function records()
  140. {
  141. return $this->hasMany(MeetingRecordsModel::class, 'meeting_id','id')
  142. ->where(['mark'=>1]);
  143. }
  144. }