Vaccine.php 877 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Models;
  3. class Vaccine extends BaseModel
  4. {
  5. const FREETYPE = 1, NOFREETYPE =2;
  6. protected $appends = ['use_count'];
  7. protected static $_type = [
  8. self::FREETYPE => 'Ⅰ类',
  9. self::NOFREETYPE => 'Ⅱ类',
  10. ];
  11. public static function getType(){
  12. return self::$_type;
  13. }
  14. //导入格式
  15. protected $fillable = ['type','price',"name","remark","supplier",'stock','states'];
  16. public function organization()
  17. {
  18. return $this->belongsToMany(Organization::class,'org_id');
  19. }
  20. protected function getUseCountAttribute()
  21. {
  22. $id = $this->attributes['id'];
  23. if(empty($id)) return 0;
  24. return OrderVaccine::where(['vaccine_id'=>$id])->count();
  25. }
  26. public function organizationvaccines(){
  27. return $this->hasMany(OrganizationVaccines::class,'vaccine_id');
  28. }
  29. }