模型层:
public function product(){
return $this->hasOne("product","nid","product_id");
}
public function storage(){
return $this->hasOne("storage","nid","storage_id");
}
控制器层:
$product_name=input('product_name');
$StockModel=new StockModel();
$StockModel->hasWhere('product',function($query) use($product_name) {
$query->where('product_name','like','%'.$product_name.'%');
})->with(['product'=>function($query) use($product_name) {
$query->field('product_name,nid');
},'storage'=>function($query){
$query->field('storage_name,nid');
}])->where('stock_code','xxxxx')->select();