areaCode = $this->request->param('areaCode', ''); $this->streetCode = $this->request->param('streetCode', ''); if ($this->areaCode == '') { throw new ValidateException('未获取到位置信息'); } } public function deviceAlarmCount() { $list = MonitorAlarm::alias('ma')->field('ma.*,d.code AS device_code,d.name AS device_name') ->join('device d', 'ma.device_id=d.id') ->join('product_device pd', 'd.id=pd.device_id') ->join('land_product lp', 'pd.product_id=lp.product_id') ->join('land l', 'l.id=lp.land_id') ->where(function ($query) { if ($this->streetCode != '') { $query->where('l.street_code', $this->streetCode); } else { $query->where('l.area_code', $this->areaCode); } }) ->whereWeek('ma.create_time') ->limit(30) ->select(); return $this->success('成功', compact('list')); } }