Gorden преди 8 месеца
родител
ревизия
71d913cdbf
променени са 2 файла, в които са добавени 37 реда и са изтрити 3 реда
  1. 26 3
      app/admin/service/statistics/MemberService.php
  2. 11 0
      app/functions.php

+ 26 - 3
app/admin/service/statistics/MemberService.php

@@ -25,10 +25,33 @@ class MemberService
         $data['monthCount'] = Member::where('member_addtimes', '>', $monthTime)->where('member_is_owner', 'N')->count();
 
         // 折线图-会员
-        $newAddition = Db::select("SELECT DATE_FORMAT(FROM_UNIXTIME(member_addtimes), '%Y/%m') AS `month`,count(*) as `num` FROM app_member where member_is_owner='N' group by month order by month asc ");
+        $newAddition = Db::select("
+            SELECT
+                DATE_FORMAT(FROM_UNIXTIME(member_addtimes), '%Y/%m') AS `month`,
+                count(*) as `num` 
+            FROM app_member 
+            where member_is_owner='N' and member_addtimes >= UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 12 MONTH)) and member_addtimes <= UNIX_TIMESTAMP()
+            group by month 
+            order by month asc ");
+        $newAddition12Month = [];
+        $months = month_12();
+        foreach ($months as $key => $month){
+            foreach ($newAddition as $item){
+                if ($month == $item->month){
+                    $newAddition12Month[$key] = $item;
+                }
+            }
+            if (!isset($newAddition12Month[$key])){
+                $std = new \stdClass();
+                $std->month = $month;
+                $std->num = 0;
+
+                $newAddition12Month[$key] = $std;
+            }
+        }
 
         $category = [];
-        foreach ($newAddition as $item) {
+        foreach ($newAddition12Month as $item) {
             $category[] = $item->month;
 //            $newAdditionData['member']['category'][] = $item->month;
 //            $newAdditionData['member']['data'][] = $item->num;
@@ -47,7 +70,7 @@ class MemberService
         foreach ($category as $item) {
             $isHaveMember = false;
             $isHaveOwner = false;
-            foreach ($newAddition as $item2) {
+            foreach ($newAddition12Month as $item2) {
                 if ($item == $item2->month) {
                     $isHaveMember = true;
                     $newAdditionData['member']['category'][] = $item;

+ 11 - 0
app/functions.php

@@ -22,4 +22,15 @@ if (!function_exists('http_post')) {
         curl_close($ch);
         return $output;
     }
+}
+
+if (!function_exists('month_12')){
+    function month_12(){
+        $months = [];
+        for ($i=0;$i<12;$i++){
+            $months[$i] = date('Y/m',strtotime("-".$i."month"));
+        }
+
+        return $months;
+    }
 }