ServicePack.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-10-4
  6. * Time: 下午7:11
  7. */
  8. namespace App\Models;
  9. class ServicePack extends BaseModel
  10. {
  11. protected $appends = ['label_texts', 'service_pack_protocol', 'service_agreement_protocol'];
  12. protected $table = 'service_packs';
  13. protected $casts = [
  14. 'label' => 'json',
  15. 'team_id' => 'json'
  16. ];
  17. public function getLabelTextsAttribute()
  18. {
  19. $data = [];
  20. if (!empty($this->label)) {
  21. $map = config('config.pack_label_map');
  22. foreach ($this->label as $k => $v) {
  23. $data[$k]['name'] = $map[$v]??'';
  24. }
  25. }
  26. return $data;
  27. }
  28. public function systemconfig(){
  29. return $this->hasOne(SystemConfig::class,'id','agreement_id');
  30. }
  31. public function getServicePackProtocolAttribute()
  32. {
  33. $data = '';
  34. if (!empty($this->agreement_id)) {
  35. $data = InsuranceAgreement::where('id', $this->agreement_id)->value('content');
  36. }
  37. return $data;
  38. }
  39. public function getServiceAgreementProtocolAttribute()
  40. {
  41. $data = '';
  42. if (!empty($this->service_agreement_id)) {
  43. $data = ServiceAgreement::where('id', $this->service_agreement_id)->value('content');
  44. }
  45. return $data;
  46. }
  47. public function insuranceagreement()
  48. {
  49. return $this->hasOne(InsuranceAgreement::class,'id','agreement_id');
  50. }
  51. public function serviceagreement()
  52. {
  53. return $this->hasOne(ServiceAgreement::class,'id','service_agreement_id');
  54. }
  55. }