Organization.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-9-29
  6. * Time: 下午2:35
  7. */
  8. namespace App\Models;
  9. class Organization extends BaseModel
  10. {
  11. CONST HOSPITOAL = 1, ORGANIZATION = 2, CLINC = 3;
  12. protected $appends = ['can_vaccine_days', 'can_nurse_days'];
  13. protected static $_getType = [
  14. self::HOSPITOAL => '医院',
  15. self::ORGANIZATION => '机构',
  16. self::CLINC => '医院',
  17. ];
  18. public static function getType()
  19. {
  20. return self::$_getType;
  21. }
  22. public function docter()
  23. {
  24. $ret = $this->belongsToMany(Docter::class)->where('status', 1);
  25. $req = request()->post();
  26. if (!empty($req['schedule_type'])) {
  27. $ret->where('type', $req['schedule_type']);
  28. }
  29. return $ret;
  30. }
  31. public function vaccines()
  32. {
  33. return $this->belongsToMany(Vaccines::class,'vaccines_id');
  34. }
  35. public function user()
  36. {
  37. return $this->hasOne(CdmsUsers::class,'org_id','id');
  38. }
  39. public function communityNotice()
  40. {
  41. return $this->hasOne(CommunityNotice::class, 'organization_id', 'id');
  42. }
  43. public function offices(){
  44. return $this->hasMany(Office::class,'org_id','id');
  45. }
  46. public function docterOrganization()
  47. {
  48. return $this->hasMany(DocterOrganization::class)->where('state', 1)->where('authentication_end_time', '>', time());
  49. }
  50. public function getCanVaccineDaysAttribute()
  51. {
  52. $show_days = DocterSetting::where('org_id', $this->id)->where('type', 2)->value('show_days');
  53. return !empty($show_days) ? $show_days : 0;
  54. }
  55. public function getCanNurseDaysAttribute()
  56. {
  57. $show_days = DocterSetting::where('org_id', $this->id)->where('type', 3)->value('show_days');
  58. return !empty($show_days) ? $show_days : 0;
  59. }
  60. }