新增用户查询AI商机列表接口

This commit is contained in:
yaooo 2023-10-16 11:30:57 +08:00
parent 1ef7446e43
commit b69fc141d1
2 changed files with 35 additions and 0 deletions

View File

@ -128,4 +128,26 @@ class InformationController extends BaseApiController
}
return $this->success('成功');
}
public function business_opportunity()
{
$param = Request()->param();
[$page, $limit] = $this->getPage();
if (isset($param['user_id']) && $param['user_id'] > 0) {
$data[] = ['create_user_id', '=', $param['user_id']];
} else {
$data[] = ['company_id', '=', $this->userInfo['company_id']];
}
$res = UserInformationg::list($data, $page, $limit);
if ($res != true) {
return $this->fail(BaseLogic::getError());
}
$informationg_array = ($res->toArray()) ?? [];
$informationg_id_array = ($res->column('id')) ?? [];
$opportunity = UserInformationg::business_opportunity($informationg_id_array);
foreach($informationg_array as $k=>$v) {
$informationg_array[$k]['opportunity'] = $opportunity[$v['id']] ?? [];
}
return $this->success('ok', $informationg_array);
}
}

View File

@ -152,6 +152,19 @@ class UserInformationg extends BaseModel
return $item;
}
public static function business_opportunity($informationg_id_array)
{
$demand_id_array = UserInformationgDemand::whereIn('information_id', $informationg_id_array)->where('status', 1)->field(['max(id) as demand_id'])->group('information_id')->select()->column('demand_id');
$data = UserInformationgDemand::whereIn('id', $demand_id_array)->column('*', 'information_id');
foreach($data as &$item) {
$item['data'] = json_decode($item['data'], true);
$item['data_field'] = json_decode($item['data_field'], true);
$item['relation_goods'] = [];
}
unset($item);
return $data;
}
public function company()
{
return $this->hasOne(Company::class, 'id', 'company_id')->field(['id', 'company_name', 'admin_id']);