Docter.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-9-29
  6. * Time: 上午11:12
  7. */
  8. namespace App\Models;
  9. class Docter extends BaseModel
  10. {
  11. protected $casts = [
  12. 'label' => 'json',
  13. ];
  14. protected $appends = ['is_collect', 'label_texts', 'is_can_phone', 'is_can_chat', 'can_appoint_days'];
  15. public function office()
  16. {
  17. return $this->belongsTo(Office::class)->select(['id', 'name']);
  18. }
  19. public function qualification()
  20. {
  21. return $this->belongsTo(Qualification::class)->select(['id', 'name']);
  22. }
  23. public function DocterOrganization()
  24. {
  25. return $this->belongsTo(DocterOrganization::class,'docter_id','id');
  26. }
  27. public function evaluate()
  28. {
  29. return $this->hasMany(Evaluate::class)->where('status', 2);
  30. }
  31. public function teamdocter()
  32. {
  33. return $this->hasOne(TeamDocter::class);
  34. }
  35. public function order()
  36. {
  37. return $this->hasMany(Order::class,'docter_id','id');
  38. }
  39. public function DocterTimes(){
  40. return $this->belongsTo(DocterTimes::class);
  41. }
  42. public function getIsCollectAttribute()
  43. {
  44. if (!empty(request()->header('token'))) {
  45. $user = User::getUserByToken();
  46. if (Collection::where('user_id', $user['id'])->where('docter_id', $this->id)->exists()) {
  47. return 1;
  48. }
  49. }
  50. return 0;
  51. }
  52. public function serviceapplys()
  53. {
  54. return $this->hasOne(Serviceapplys::class);
  55. }
  56. public function serviceapply()
  57. {
  58. return $this->hasMany(Serviceapplys::class);
  59. }
  60. public function getLabelTextsAttribute()
  61. {
  62. $data = [];
  63. if (!empty($this->label) && is_array($this->label)) {
  64. $data = DocterLabel::select(['label_name'])->whereIn('id', $this->label)->where('status', 1)->get()->toArray();
  65. }
  66. return $data;
  67. }
  68. public function organization()
  69. {
  70. return $this->belongsToMany(Organization::class);
  71. }
  72. public function getChatPriceAttribute()
  73. {
  74. $base_price = DocterTimes::where('docter_id', $this->id)->where('type', 2)->value('base_price');
  75. return $base_price*100;
  76. }
  77. public function getPhonePriceAttribute()
  78. {
  79. $base_price = DocterTimes::where('docter_id', $this->id)->where('type', 1)->value('base_price');
  80. return $base_price*100;
  81. }
  82. public function getAppointPriceAttribute()
  83. {
  84. $appoint_price = DocterSetting::where('docter_id', $this->id)->where('type', 1)->where('status', 2)->orderBy('id', 'asc')->value('appoint_price');
  85. return $appoint_price*100;
  86. }
  87. public function getIsCanPhoneAttribute()
  88. {
  89. if ($this->is_phone == 1) {
  90. $now_line = (int)date('Hi');
  91. if (DocterServiceTime::where('docter_id', $this->id)->where('type', 1)->where('start_time_line', '<=', $now_line)->where('end_time_line', '>', $now_line)->exists()) {
  92. return 1;
  93. }
  94. }
  95. return 0;
  96. }
  97. public function getIsCanChatAttribute()
  98. {
  99. if ($this->is_chat == 1) {
  100. $now_line = (int)date('Hi');
  101. if (DocterServiceTime::where('docter_id', $this->id)->where('type', 2)->where('start_time_line', '<=', $now_line)->where('end_time_line', '>', $now_line)->exists()) {
  102. return 1;
  103. }
  104. }
  105. return 0;
  106. }
  107. public function getPhoneMinutesAttribute()
  108. {
  109. if (!isset($this->phone_minutes) || empty($this->phone_minutes)) {
  110. return SystemConfig::where('group', 'docter_config')->where('key', 'phone_base_time')->value('value');
  111. }
  112. return $this->phone_minutes;
  113. }
  114. public function getCanAppointDaysAttribute()
  115. {
  116. $show_days = DocterSetting::where('docter_id', $this->id)->where('type', 1)->value('show_days');
  117. return !empty($show_days) ? $show_days : 0;
  118. }
  119. }