Docter.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 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. }