<?php
namespace app\rongyu\model;
use app\common\model\Base;
class JsRongyu extends Base
{
public function search($search)
{
$fzschool = $search['fzschool'];
$category = $search['category'];
$order_field = $search['order_field'];
$order = $search['order'];
$category = $search['category'];
$search = $search['search'];
$data = $this->order([$order_field =>$order])
->when(strlen($fzschool)>0,function($query) use($fzschool){
$query->where('fzschool','in',$fzschool);
})
->when(strlen($category)>0,function($query) use($category){
$query->where('category','in',$category);
})
->when(strlen($search)>0,function($query) use($search){
$query->where('title','like',$search);
})
->with(
[
'fzSchool'=>function($query){
$query->field('id,jiancheng');
},
'lxCategory'=>function($query){
$query->field('id,title');
},
]
)
->append(['cnt'])
->select();
return $data;
}
public function fzSchool()
{
return $this->belongsTo('\app\system\model\School','fzschool','id');
}
public function lxCategory()
{
return $this->belongsTo('\app\system\model\Category','category','id');
}
public function ryInfo()
{
return $this->hasMany('JsRongyuInfo','rongyuce','id');
}
public function getCntAttr()
{
return $this->ryInfo->count();
}
public function setFzshijianAttr($value)
{
return strtotime($value);
}
public function getFzshijianAttr($value)
{
if ($value>0)
{
$value = date('Y-m-d',$value);
}else{
$value = "";
}
return $value;
}
}