MeetingModel.php 3.7 KB

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