Docter.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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'];
  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 getLabelTextsAttribute()
  57. {
  58. $data = [];
  59. if (!empty($this->label)) {
  60. $data = DocterLabel::select(['label_name'])->whereIn('id', $this->label)->where('status', 1)->get()->toArray();
  61. }
  62. return $data;
  63. }
  64. public function organization()
  65. {
  66. return $this->belongsToMany(Organization::class);
  67. }
  68. }