瀏覽代碼

生产信息统计表显示优化

unknown 5 天之前
父節點
當前提交
c3996f56f2
共有 1 個文件被更改,包括 20 次插入0 次删除
  1. 20 0
      application/api/controller/ProductionInformationStatistics.php

+ 20 - 0
application/api/controller/ProductionInformationStatistics.php

@@ -145,11 +145,31 @@ class ProductionInformationStatistics extends Api
         }
 
         $query = $this->parseQueryTime($time);
+        if (!$this->hasStatsInPeriod($query)) {
+            if ($query['type'] === 'day') {
+                $this->error(date('Y-m-d', strtotime($query['start'])) . '没有数据,请添加后查询');
+            }
+            $this->error($query['month'] . '没有数据,请添加后查询');
+        }
+
         $list = $this->buildDisplayList($query);
 
         $this->success('成功', $list);
     }
 
+    /**
+     * 判断指定时间段内是否存在统计数据
+     */
+    protected function hasStatsInPeriod(array $query)
+    {
+        $count = Db::name($this->tableName)
+            ->where('sczl_rq', '>=', $query['start'])
+            ->where('sczl_rq', '<=', $query['end'])
+            ->count();
+
+        return $count > 0;
+    }
+
     /**
      * 解析查询时间:Y-m-d 为日,Y-m 为月
      */