123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-9-29
- * Time: 上午11:12
- */
- namespace App\Models;
- class Docter extends BaseModel
- {
- protected $casts = [
- 'label' => 'json',
- ];
- protected $appends = ['is_collect', 'label_texts', 'is_can_phone', 'is_can_chat'];
- public function office()
- {
- return $this->belongsTo(Office::class)->select(['id', 'name']);
- }
- public function qualification()
- {
- return $this->belongsTo(Qualification::class)->select(['id', 'name']);
- }
- public function DocterOrganization()
- {
- return $this->belongsTo(DocterOrganization::class,'docter_id','id');
- }
- public function evaluate()
- {
- return $this->hasMany(Evaluate::class)->where('status', 2);
- }
- public function teamdocter()
- {
- return $this->hasOne(TeamDocter::class);
- }
- public function order()
- {
- return $this->hasMany(Order::class,'docter_id','id');
- }
- public function DocterTimes(){
- return $this->belongsTo(DocterTimes::class);
- }
- public function getIsCollectAttribute()
- {
- if (!empty(request()->header('token'))) {
- $user = User::getUserByToken();
- if (Collection::where('user_id', $user['id'])->where('docter_id', $this->id)->exists()) {
- return 1;
- }
- }
- return 0;
- }
- public function serviceapplys()
- {
- return $this->hasOne(Serviceapplys::class);
- }
- public function serviceapply()
- {
- return $this->hasMany(Serviceapplys::class);
- }
- public function getLabelTextsAttribute()
- {
- $data = [];
- if (!empty($this->label) && is_array($this->label)) {
- $data = DocterLabel::select(['label_name'])->whereIn('id', $this->label)->where('status', 1)->get()->toArray();
- }
- return $data;
- }
- public function organization()
- {
- return $this->belongsToMany(Organization::class);
- }
- public function getChatPriceAttribute()
- {
- $base_price = DocterTimes::where('docter_id', $this->id)->where('type', 2)->value('base_price');
- return $base_price*100;
- }
- public function getPhonePriceAttribute()
- {
- $base_price = DocterTimes::where('docter_id', $this->id)->where('type', 1)->value('base_price');
- return $base_price*100;
- }
- public function getAppointPriceAttribute()
- {
- $appoint_price = DocterSetting::where('docter_id', $this->id)->where('type', 1)->where('status', 2)->orderBy('id', 'asc')->value('appoint_price');
- return $appoint_price*100;
- }
- public function getIsCanPhoneAttribute()
- {
- if ($this->is_phone == 1) {
- $now_line = (int)date('Hi');
- if (DocterServiceTime::where('docter_id', $this->id)->where('type', 1)->where('start_time_line', '<=', $now_line)->where('end_time_line', '>', $now_line)->exists()) {
- return 1;
- }
- }
- return 0;
- }
- public function getIsCanChatAttribute()
- {
- if ($this->is_chat == 1) {
- $now_line = (int)date('Hi');
- if (DocterServiceTime::where('docter_id', $this->id)->where('type', 2)->where('start_time_line', '<=', $now_line)->where('end_time_line', '>', $now_line)->exists()) {
- return 1;
- }
- }
- return 0;
- }
- public function getPhoneMinutesAttribute()
- {
- if (!empty($this->phone_minutes)) {
- return SystemConfig::where('group', 'docter_config')->where('key', 'phone_base_time')->value('value');
- }
- return $this->phone_minutes;
- }
- }
|