feat: 需求列表完善

master
yin5th 2023-08-15 14:36:06 +08:00
parent b292dc74f1
commit 4bafdb2687
2 changed files with 6 additions and 3 deletions

View File

@ -32,7 +32,7 @@ class Demand extends Api
$count = thisModel::where($where)->count();
$list = thisModel::field(['id', 'name', 'create_time'])
$list = thisModel::withCount(['reports'])->field(['id', 'name', 'create_time'])
->where($where)
->order($order)
->page($page,$limit)
@ -54,7 +54,7 @@ class Demand extends Api
public function detail()
{
$id = input('id/d', 0);
if (!$item = thisModel::where('id', $id)->find()) {
if (!$item = thisModel::withCount(['reports'])->where('id', $id)->find()) {
return JsonServer::error('记录不存在');
}
return JsonServer::success('获取成功', $item->toArray());

View File

@ -5,5 +5,8 @@ use app\common\basics\Models;
class Demand extends Models
{
public function reports()
{
return $this->hasMany(DemandReport::class, 'demand_id', 'id');
}
}