Patient.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. protected $table="patients";
  14. public function getAgeAttribute()
  15. {
  16. return birthday_to_age($this->birthday);
  17. }
  18. public function getOrderNumAttribute()
  19. {
  20. return Order::where('patient_id', $this->id)->where('payment_status', 2)->where('product_type', '<', 6)->count();
  21. }
  22. public function getPackDocterNumAttribute()
  23. {
  24. $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();
  25. return TeamDocter::whereIn('team_id', $team_ids)->count();
  26. }
  27. public function getPerfectdDegreeAttribute()
  28. {
  29. $field = ['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'card_number', 'email', 'phone', 'social_card_number', 'born_hospital', 'guardian_name', 'address'];
  30. $total = count($field);
  31. $fill = 0;
  32. foreach ($field as $k => $v) {
  33. if (!empty($this->$v)) {
  34. $fill++;
  35. }
  36. }
  37. $text = round($fill/$total*100) . '%';
  38. return $text;
  39. }
  40. public function users(){
  41. return $this->belongsTo(User::class,'id','user_id');
  42. }
  43. public function order(){
  44. return $this->hasMany(Order::class);
  45. }
  46. }