Explorar el Código

微信月 季度 年 统计接口

ylchen %!s(int64=4) %!d(string=hace) años
padre
commit
842be95665

+ 54 - 0
dtkf_new/app/Http/Controllers/Dtkf/WechatExternalInterface.php

@@ -138,4 +138,58 @@ class WechatExternalInterface extends Controller {
138 138
 
139 139
 		return $res;
140 140
 	}
141
+    /**
142
+     * 微信当月每天数量统计
143
+     */
144
+    public function countCurrentmonth() {
145
+        $begin = date('Y-m-01');
146
+        $res = KfCustomerMsg::select(DB::raw('count(*) as num,FROM_UNIXTIME(created_at, \'%e\') as day'))
147
+            ->where('app', 0)
148
+            ->where('source',0)
149
+            ->where('created_at', '>=', strtotime($begin))
150
+            ->groupBy('day')
151
+            ->pluck('num', 'day');
152
+
153
+        $d = (int) date('t');
154
+        $data = [];
155
+        for ($i = 1; $i <= $d; $i++) {
156
+            $data[$i] = $res[$i] ?? 0;
157
+        }
158
+
159
+        return $data;
160
+    }
161
+
162
+    /**
163
+     * 微信季度数量统计
164
+     */
165
+    public function countQuarter() {
166
+        $begin = date('Y-01-01');
167
+        $res = KfCustomerMsg::select(DB::raw('count(*) as num,QUARTER(FROM_UNIXTIME(created_at)) as quarter'))
168
+            ->where('app', 0)
169
+            ->where('source',0)
170
+            ->where('created_at', '>=', strtotime($begin))
171
+            ->groupBy('quarter')
172
+            ->pluck('num', 'quarter');
173
+
174
+        $q = 4;
175
+        $data = [];
176
+        for ($i = 1; $i <= $q; $i++) {
177
+            $data[$i] = $res[$i] ?? 0;
178
+        }
179
+
180
+        return $data;
181
+    }
182
+
183
+    /**
184
+     * 微信年度数量统计
185
+     */
186
+    public function countYear() {
187
+        $res = KfCustomerMsg::select(DB::raw('count(*) as num,year(FROM_UNIXTIME(created_at)) as year'))
188
+            ->where('app', 0)
189
+            ->where('source',0)
190
+            ->groupBy('year')
191
+            ->pluck('num', 'year');
192
+
193
+        return $res;
194
+    }
141 195
 }

+ 3 - 0
dtkf_new/routes/api.php

@@ -22,6 +22,9 @@ Route::prefix('external')->middleware('cross')->group(function () {
22 22
 	Route::get('wxreply', 'Dtkf\WechatExternalInterface@countReply'); //统计回复数
23 23
 	Route::get('wxmonth', 'Dtkf\WechatExternalInterface@countMonth'); //微信月统计
24 24
 	Route::get('wxautoreply', 'Dtkf\WechatExternalInterface@countAutoReply'); //自动回复数
25
+    Route::get('wxcurrentmonth', 'Dtkf\WechatExternalInterface@countCurrentmonth'); //微信当月每天数量统计
26
+    Route::get('wxquarter', 'Dtkf\WechatExternalInterface@countQuarter'); //微信当年季度数量统计
27
+    Route::get('wxyear', 'Dtkf\WechatExternalInterface@countYear'); //微信年度数量统计
25 28
 
26 29
 	Route::get('wbmsg', 'Dtkf\WeiboExternalInterface@msg'); //获取消息
27 30
 	Route::get('wbcount', 'Dtkf\WeiboExternalInterface@countMsg'); //统计消息数