MeetingModel.php 5.0 KB

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