Patient.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-10-1
  6. * Time: 上午12:10
  7. */
  8. namespace App\Models;
  9. use App\Models\User;
  10. class Patient extends BaseModel
  11. {
  12. protected $appends = ['age'];
  13. public function getAgeAttribute()
  14. {
  15. return birthday_to_age($this->birthday);
  16. }
  17. public function getOrderNumAttribute()
  18. {
  19. return Order::where('patient_id', $this->id)->where('payment_status', 2)->where('product_type', '<', 6)->count();
  20. }
  21. public function getPackDocterNumAttribute()
  22. {
  23. $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();
  24. return TeamDocter::whereIn('team_id', $team_ids)->count();
  25. }
  26. public function getPerfectdDegreeAttribute()
  27. {
  28. $field = ['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'card_number', 'email', 'phone', 'social_card_number', 'born_hospital', 'guardian_name', 'address'];
  29. $total = count($field);
  30. $fill = 0;
  31. foreach ($field as $k => $v) {
  32. if (!empty($this->$v)) {
  33. $fill++;
  34. }
  35. }
  36. $text = round($fill/$total*100) . '%';
  37. return $text;
  38. }
  39. public function users(){
  40. return $this->belongsTo(User::class,'id','user_id');
  41. }
  42. public function order(){
  43. return $this->hasMany(Order::class);
  44. }
  45. }