Patient.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. class Patient extends BaseModel
  10. {
  11. protected $appends = ['age'];
  12. public function getAgeAttribute()
  13. {
  14. return birthday_to_age($this->birthday);
  15. }
  16. public function getOrderNumAttribute()
  17. {
  18. return Order::where('patient_id', $this->id)->where('payment_status', 2)->where('product_type', '<', 6)->count();
  19. }
  20. public function getPackDocterNumAttribute()
  21. {
  22. $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();
  23. return TeamDocter::whereIn('team_id', $team_ids)->count();
  24. }
  25. public function getPerfectdDegreeAttribute()
  26. {
  27. $field = ['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'card_number'];
  28. $total = count($field);
  29. $fill = 0;
  30. foreach ($field as $k => $v) {
  31. if (!empty($this->$v)) {
  32. $fill++;
  33. }
  34. }
  35. $text = round($fill/$total*100) . '%';
  36. return $text;
  37. }
  38. }