diff --git a/app/controller/api/dataview/User.php b/app/controller/api/dataview/User.php index 145697d3..aef30ed0 100644 --- a/app/controller/api/dataview/User.php +++ b/app/controller/api/dataview/User.php @@ -67,21 +67,26 @@ class User extends BaseController $endCurrDay1 = $startCurrDay1+ 86399; $userCountlist[] = $this->getTimeRangeUserCount([$startCurrDay1, $endCurrDay1]); - // 地方店铺数量统计 - // 该地区下所有乡镇 - $geoStreetList = Db::name('geo_street')->where('area_code',$this->areaCode)->select()->toArray(); - // 遍历统计每个乡镇的店铺数 $merchantTotalCount = 0; - foreach ($geoStreetList as $street) { - $temp['street_name'] = $street['street_name']; - $temp['merchant_count'] = Db::name('merchant')->where('street_id', $street['street_code'])->count(); - $merchantTotalCount += $temp['merchant_count']; - $merchatCountList[] = $temp; - unset($temp); + + // 查镇的用户统计不需要查店铺数 + if ($this->streetCode != '') { + + // 该地区下所有乡镇 + $geoStreetList = Db::name('geo_street')->where('area_code',$this->areaCode)->select()->toArray(); + + foreach ($geoStreetList as $street) { + $temp['street_name'] = $street['street_name']; + $temp['merchant_count'] = Db::name('merchant')->where('street_id', $street['street_code'])->count(); + $merchantTotalCount += $temp['merchant_count']; + $merchatCountList[] = $temp; + unset($temp); + } } + return app('json')->success(compact('merchantTotalCount' ,'userCountlist', 'merchatCountList')); } public function getTimeRangeUserCount($timeRange=[]) @@ -96,7 +101,7 @@ class User extends BaseController $query->where('ua.district', $this->areaCode); } }) - ->whereTime('u.create_time', 'between', $timeRange)->fetchSql() + ->whereTime('u.create_time', 'between', $timeRange) ->count(); // 访问 @@ -109,7 +114,7 @@ class User extends BaseController $query->where('ua.district', $this->areaCode); } }) - ->whereTime('u.last_time', 'between', $timeRange)->fetchSql() + ->whereTime('u.last_time', 'between', $timeRange) ->count(); // 累计 @@ -122,7 +127,7 @@ class User extends BaseController $query->where('ua.district', $this->areaCode); } }) - ->whereTime('u.create_time', '<', $timeRange[1])->fetchSql() + ->whereTime('u.create_time', '<', $timeRange[1]) ->count(); return compact('newUserCount', 'viewUserCount', 'totalUserCount');