123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Models;
- class Vaccine extends BaseModel
- {
- const FREETYPE = 1, NOFREETYPE =2;
- protected $appends = ['use_count','appoint_count'];
- protected static $_type = [
- self::FREETYPE => 'Ⅰ类',
- self::NOFREETYPE => 'Ⅱ类',
- ];
- public static function getType(){
- return self::$_type;
- }
- //导入格式
- protected $fillable = ['type','price',"name","remark","supplier",'stock','states'];
- public function organization()
- {
- return $this->belongsToMany(Organization::class,'org_id');
- }
- protected function getUseCountAttribute()
- {
- $id = $this->attributes['id'];
- if(empty($id)) return 0;
- return OrderVaccine::where(['vaccine_id'=>$id])->whereHas('orders',function($query){
- $query->where('order_status',4);
- })->count();
- }
- protected function getAppointCountAttribute()
- {
- $id = $this->attributes['id'];
- if(empty($id)) return 0;
- return OrderVaccine::where(['vaccine_id'=>$id])->whereHas('orders',function($query){
- $query->whereIn('order_status',[3,7]);
- })->count();
- }
- public function organizationvaccines(){
- return $this->hasMany(OrganizationVaccines::class,'vaccine_id');
- }
- public function vaccineAppoint()
- {
- return $this->hasMany(VaccineAppoint::class);
- }
- }
|