新增根据地区查询商品总数

This commit is contained in:
yaooo 2023-08-23 14:47:33 +08:00
parent 6b58878cbf
commit 65294eb944

View File

@ -1013,4 +1013,39 @@ class Auth extends BaseController
return app('json')->success($data);
}
//根据地址信息查询商品数
public function goodsStatistics()
{
$districtCode = $this->request->param('district_code', '');
$streetCode = $this->request->param('street_code', '');
$villageCode = $this->request->param('village_code', '');
$startDate = $this->request->param('start_date', '');
$endDate = $this->request->param('end_date', '');
$villageId = Db::name('GeoVillage')->where('village_code', $villageCode)->fetchSql(false)->value('village_id', 0);
$queryBuilder = Db::name('Merchant')->where('status', 1);
if ($districtCode) {
$queryBuilder = $queryBuilder->where('area_id', $districtCode);
}
if ($streetCode) {
$queryBuilder = $queryBuilder->where('street_id', $streetCode);
}
if ($villageId) {
$queryBuilder = $queryBuilder->where('village_id', $villageId);
}
$merIdArray = $queryBuilder->fetchSql(false)->column('mer_id');
$prodQueryBuilder = Db::name('StoreProduct')->where('is_show', 1)->where('status', 1)->whereIn('mer_id', $merIdArray);
if ($startDate) {
$prodQueryBuilder = $prodQueryBuilder->whereTime('create_time', '>=', trim($startDate));
}
if ($endDate) {
$prodQueryBuilder = $prodQueryBuilder->whereTime('create_time', '<=', trim($endDate) . ' 23:59:59');
}
$prodNum = $prodQueryBuilder->fetchSql(false)->count();
$data = [
'where' => $this->request->param(),
'goods_num' => $prodNum
];
return app('json')->success($data);
}
}