123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-10-1
- * Time: 上午12:10
- */
- namespace App\Models;
- class Patient extends BaseModel
- {
- protected $appends = ['age'];
- protected $table = "patients";
- public function getAgeAttribute()
- {
- return birthday_to_age($this->birthday);
- }
- public function getOrderNumAttribute()
- {
- return Order::where('patient_id', $this->id)->where('payment_status', 2)->where('product_type', '<', 6)->count();
- }
- public function getPackDocterNumAttribute()
- {
- $team_ids = OrderPack::join('orders', 'orders.id', '=', 'order_packs.order_id')->where('orders.patient_id', $this->id)->where('orders.payment_status', 2)->where('orders.product_type', 7)->pluck('order_packs.team_id')->toArray();
- return TeamDocter::whereIn('team_id', $team_ids)->count();
- }
- public function getPerfectdDegreeAttribute()
- {
- $field = ['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'card_number', 'email', 'phone', 'social_card_number', 'born_hospital', 'guardian_name', 'address'];
- $total = count($field);
- $fill = 0;
- foreach ($field as $k => $v) {
- if (!empty($this->$v)) {
- $fill++;
- }
- }
- $text = round($fill/$total*100) . '%';
- return $text;
- }
- public function users()
- {
- return $this->belongsTo(User::class,'user_id','id');
- }
- public function userspatient()
- {
- return $this->belongsTo(User::class,'user_id','id');
- }
- public function order()
- {
- return $this->hasMany(Order::class);
- }
- public function user()
- {
- return $this->belongsTo(User::class);
- }
- public function orderPatient()
- {
- return $this->hasOne(OrderPatient::class,'patient_id','id');
- }
- public function getRelationshipTypeTextAttribute()
- {
- return config('config.relationship_type_map')[$this->relationship_type] ?? '';
- }
- }
|