xialei 1 год назад
Родитель
Сommit
cd99c35a46

+ 376 - 60
app/common/repositories/finance/FinanceRepository.php

@@ -28,98 +28,415 @@ class FinanceRepository extends BaseRepository
28 28
      */
29 29
     public function order_overview($mer_id = 0)
30 30
     {
31
-        if ($mer_id) {
32
-            $where = "mer_id = " . $mer_id . " and paid = 1";
33
-        } else {
31
+        // if ($mer_id) {
32
+        //     $where = "mer_id = " . $mer_id . " and paid = 1";
33
+        // } else {
34 34
             $where = " paid = 1";
35
+        // }
36
+
37
+        $type = input('type', 1);
38
+        $day = input('day', '');
39
+        //天
40
+        if ($type == 1 and $day != '') {
41
+            $where .= " and DATE(create_time) = '" . $day . "'";
42
+        }
43
+        //月
44
+        if ($type == 2 and $day != '') {
45
+            $date = new \DateTime($day);
46
+            $year = $date->format('Y');
47
+            $month = $date->format('m');
48
+            $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
35 49
         }
36 50
 
51
+        $weekWhere = " paid = 1";
52
+        $dayWhere = " paid = 1";
53
+        // 获取今天的日期和时间
54
+        $today = new \DateTime();
55
+        // 计算一周前的日期
56
+        $oneWeekAgo = clone $today; // 克隆一个对象,避免修改原始对象
57
+        $oneWeekAgo->sub(new \DateInterval('P1W')); // 减去一周
58
+        
59
+        // 格式化日期
60
+        $todayFormatted = $today->format('Y-m-d');
61
+        $oneWeekAgoFormatted = $oneWeekAgo->format('Y-m-d');
62
+
63
+        //周时间条件
64
+        $weekWhere .= " and DATE(create_time) >= '" . $oneWeekAgoFormatted . "' and DATE(create_time) <= '" . $todayFormatted . "'";
65
+        //今日时间条件
66
+        $dayWhere .= " and DATE(create_time) = '" . $todayFormatted . "'";
67
+
68
+
69
+        // 会员专区订单总数
70
+        //总数
71
+        $chengjiaomoney = Db::name('store_order')->where($where)->where('mer_id', 496)->count();
72
+        $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 496)->count();
73
+        $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 496)->count();
74
+        $list1[] = ['count' => $weekCount, 'name' => '周订单总数'];
75
+        $list1[] = ['count' => $todayCount, 'name' => '日订单总数'];
76
+
77
+        //精彩生活区订单总数
78
+        //总数
79
+        $chengjiaocount = Db::name('store_order')->where($where)->where('mer_id', 439)->count();
80
+        $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 439)->count();
81
+        $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 439)->count();
82
+        $list2[] = ['count' => $weekCount, 'name' => '周订单总数'];
83
+        $list2[] = ['count' => $todayCount, 'name' => '日订单总数'];
84
+
85
+        //商贸区订单总数
86
+        //总数
87
+        $chengjiaoren = Db::name('store_order')->where($where)->whereNotIn('mer_id', [496, 439, 491])->count();
88
+        $weekCount = Db::name('store_order')->where($weekWhere)->whereNotIn('mer_id', [496, 439, 491])->count();
89
+        $todayCount = Db::name('store_order')->where($dayWhere)->whereNotIn('mer_id', [496, 439, 491])->count();
90
+        $list3[] = ['count' => $weekCount, 'name' => '周订单总数'];
91
+        $list3[] = ['count' => $todayCount, 'name' => '日订单总数'];
92
+
93
+        //复购区订单总数
94
+        //总数
95
+        $tuikuanmoney = Db::name('store_order')->where($where)->where('mer_id', 491)->count();
96
+        $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 491)->count();
97
+        $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 491)->count();
98
+        $list4[] = ['count' => $weekCount, 'name' => '周订单总数'];
99
+        $list4[] = ['count' => $todayCount, 'name' => '日订单总数'];
100
+
101
+        //三方平台订单总数
102
+        //总数
103
+
104
+        //话费
105
+        $whereNew = str_replace("paid", "status", $where);
106
+        $weekWhereNew = str_replace("paid", "status", $weekWhere);
107
+        $dayWhereNew = str_replace("paid", "status", $dayWhere);
108
+        $huafei = Db::name('order_huafei_hf')->where($whereNew)->count();
109
+        $huafei_week = Db::name('order_huafei_hf')->where($weekWhereNew)->count();
110
+        $huafei_today = Db::name('order_huafei_hf')->where($dayWhereNew)->count();
111
+
112
+
113
+        //京东
114
+        $whereNew = str_replace(" paid = 1", " status IN (16, 17)", $where);
115
+        $weekWhereNew = str_replace(" paid = 1", " status IN (16, 17)", $weekWhere);
116
+        $dayWhereNew = str_replace(" paid = 1", " status IN (16, 17)", $dayWhere);
117
+        $jd = Db::name('order_jd')->where($whereNew)->count();
118
+        $jd_week = Db::name('order_jd')->where($weekWhereNew)->count();
119
+        $jd_today = Db::name('order_jd')->where($dayWhereNew)->count();
120
+
121
+        //拼多多
122
+        $whereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $where);
123
+        $weekWhereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $weekWhere);
124
+        $dayWhereNew = str_replace(" paid = 1", " pin_order_status IN (0, 2, 3)", $dayWhere);
125
+        $pdd = Db::name('order_pdd')->where($whereNew)->count();
126
+        $pdd_week = Db::name('order_pdd')->where($weekWhereNew)->count();
127
+        $pdd_today = Db::name('order_pdd')->where($dayWhereNew)->count();
128
+
129
+        //淘宝
130
+        $whereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $where);
131
+        $weekWhereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $weekWhere);
132
+        $dayWhereNew = str_replace(" paid = 1", " tk_status IN (12, 3)", $dayWhere);
133
+        $tb = Db::name('order_tb')->where($whereNew)->count();
134
+        $tb_week = Db::name('order_tb')->where($weekWhereNew)->count();
135
+        $tb_today = Db::name('order_tb')->where($dayWhereNew)->count();
136
+
137
+        //电影票
138
+        $whereNew = str_replace(" paid = 1", " status IN (1, 4)", $where);
139
+        $weekWhereNew = str_replace(" paid = 1", " status IN (1, 4)", $weekWhere);
140
+        $dayWhereNew = str_replace(" paid = 1", " status IN (1, 4)", $dayWhere);
141
+        $movie = Db::name('order_movie')->where($whereNew)->count();
142
+        $movie_week = Db::name('order_movie')->where($weekWhereNew)->count();
143
+        $movie_today = Db::name('order_movie')->where($dayWhereNew)->count();
144
+
145
+        $tuikuancount = $huafei+$jd+$pdd+$tb+$movie;
146
+        $weekCount = $huafei_week+$jd_week+$pdd_week+$tb_week+$movie_week;
147
+        $todayCount = $huafei_today+$jd_today+$pdd_today+$tb_today+$movie_today;
148
+        $list5[] = ['count' => $weekCount, 'name' => '周订单总数'];
149
+        $list5[] = ['count' => $todayCount, 'name' => '日订单总数'];
150
+
151
+        //线下订单总数
152
+        //总数
153
+        $tuikuanren = Db::name('order_merchant')->where($where)->count();
154
+        $weekCount = Db::name('order_merchant')->where($weekWhere)->count();
155
+        $todayCount = Db::name('order_merchant')->where($dayWhere)->count();
156
+        $list6[] = ['count' => $weekCount, 'name' => '周订单总数'];
157
+        $list6[] = ['count' => $todayCount, 'name' => '日订单总数'];
158
+
159
+
160
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaomoney), 'name' => '会员专区订单总数', 'list' => $list1];
161
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaocount), 'name' => '精彩生活区订单总数', 'list' => $list2];
162
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaoren), 'name' => '商贸区订单总数', 'list' => $list3];
163
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanmoney), 'name' => '复购区订单总数', 'list' => $list4];
164
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuancount), 'name' => '三方平台订单总数', 'list' => $list5];
165
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanren), 'name' => '线下订单总数', 'list' => $list6];
166
+        return $data;
167
+    }
168
+
169
+    /**
170
+     * 用户概况
171
+     * @param int $mer_id
172
+     * @return array
173
+     * @throws \Exception
174
+     */
175
+    public function user_overview($mer_id = 0)
176
+    {
177
+        $where = "1=1 ";
178
+        if ($mer_id) {
179
+            $mer_uid = Db::name('merchant')->where('mer_id', $mer_id)->value('uid');
180
+            $userRepository = app()->make(UserRepository::class);
181
+            $chilid_userids = $userRepository->getSpreadUidBreak($mer_uid);
182
+            $chilid_userids_string = "1";
183
+            if (!empty($chilid_userids)) {
184
+                $chilid_userids_string = implode(',',$chilid_userids);
185
+            }
186
+            $where .= "and uid in ({$chilid_userids_string})";
187
+        }
37 188
         $type = input('type', 1);
38 189
         $day = input('day', '');
39 190
 
40 191
         if ($type == 1 and $day != '') {
41
-            $where .= " and DATE(pay_time) = '" . $day . "'";
192
+            $where .= " and DATE(create_time) = '" . $day . "'";
42 193
         }
43 194
         if ($type == 2 and $day != '') {
44 195
             $date = new \DateTime($day);
45 196
             $year = $date->format('Y');
46 197
             $month = $date->format('m');
198
+            $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
199
+        }
200
+        $dataQuery = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where {$where} group by user_group");
201
+        $dataQuery = array_column($dataQuery, 'count', 'user_group');
47 202
 
48
-            $where .= " and YEAR(pay_time) = " . $year . " AND MONTH(pay_time) = " . $month;
203
+        $maker = Db::query("SELECT CONCAT(`user_group`, '-',`is_show`) as k, count(uid) count FROM `rrx_user` where {$where} group by user_group,is_show");
204
+        $maker = array_column($maker, 'count', 'k');
205
+
206
+
207
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[1] ?? 0), 'name' => '消费者'];
208
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[2] ?? 0), 'name' => '业务员'];
209
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[3] ?? 0), 'name' => '业务经理'];
210
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[5] ?? 0), 'name' => '初级合伙人'];
211
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[6] ?? 0), 'name' => '中级合伙人'];
212
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[7] ?? 0), 'name' => '高级合伙人'];
213
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[8] ?? 0), 'name' => '董事'];
214
+
215
+        $maker = Db::query("SELECT count(uid) as count FROM `rrx_user` where {$where} and originator_id_old > 0");
216
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '联创'];
217
+
218
+        $maker = Db::query("SELECT count(user_id) as count FROM `rrx_old_user_stock` where {$where}");
219
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '股权'];
220
+
221
+        $maker = Db::query("SELECT count(uid) as count FROM `rrx_merchant` where {$where}");
222
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '商户'];
223
+
224
+        $res['left'][] = $data;
225
+        // $maker = Db::query("SELECT count(uid) as count FROM `rrx_merchant` where {$where}");
226
+        // $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '创客'];
227
+
228
+        return $res;
229
+    }
230
+
231
+
232
+
233
+    /**
234
+     * 会员概况
235
+     * @param int $mer_id
236
+     * @return array
237
+     * @throws \Exception
238
+     */
239
+    public function member_overview($mer_id = 0)
240
+    {
241
+        $where = "1=1 ";
242
+        if ($mer_id) {
243
+            $mer_uid = Db::name('merchant')->where('mer_id', $mer_id)->value('uid');
244
+            $userRepository = app()->make(UserRepository::class);
245
+            $chilid_userids = $userRepository->getSpreadUidBreak($mer_uid);
246
+            $chilid_userids_string = "1";
247
+            if (!empty($chilid_userids)) {
248
+                $chilid_userids_string = implode(',',$chilid_userids);
249
+            }
250
+            $where .= "and uid in ({$chilid_userids_string})";
251
+        }
252
+        $type = input('type', 1);
253
+        $day = input('day', '');
254
+
255
+        if ($type == 1 and $day != '') {
256
+            $where .= " and DATE(create_time) = '" . $day . "'";
49 257
         }
50
-        $xianshangzhifu = Db::name('store_order')->where($where)->whereIn('pay_type', [0, 1])->sum('pay_price');
51
-        $xianshangzhifu_xuni = Db::name('store_order')->where($where)->where('pay_type', 0)->sum('pay_price');
52
-        $hongjifenxiaofei = Db::name('store_order')->where($where)->where("pay_type", 5)->sum('pay_price');
53
-//        echo Db::name('store_order')->getLastSql();
54
-
55
-        $chengjiaomoney = decimal2($xianshangzhifu + $hongjifenxiaofei);
56
-        $list1[] = ['count' => set_price_rtrim($xianshangzhifu), 'name' => '线上支付金额'];
57
-        if (!$mer_id) {
58
-            $list1[] = ['count' => set_price_rtrim($xianshangzhifu_xuni), 'name' => '虚拟支付金额'];
258
+        if ($type == 2 and $day != '') {
259
+            $date = new \DateTime($day);
260
+            $year = $date->format('Y');
261
+            $month = $date->format('m');
262
+            $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
59 263
         }
60
-        $list1[] = ['count' => 0, 'name' => '代付金额'];
61
-        $xianshangzhifunum = Db::name('store_order')->where($where)->whereIn('pay_type', [0, 1])->count();
62
-        $xianshangzhifunum_xuni = Db::name('store_order')->where($where)->where('pay_type', 0)->count();
63
-        $hongjifenxiaofeinum = Db::name('store_order')->where($where)->where("pay_type", 5)->count();
264
+        $dataQuery = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where {$where} group by user_group");
265
+        $dataQuery = array_column($dataQuery, 'count', 'user_group');
266
+        $shopPartnerCount = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where mer_id={$mer_id} and is_shop_partner=1 group by user_group");
267
+
268
+        $maker = Db::query("SELECT CONCAT(`user_group`, '-',`is_show`) as k, count(uid) count FROM `rrx_user` where {$where} group by user_group,is_show");
269
+        $maker = array_column($maker, 'count', 'k');
64 270
 
65
-        $chengjiaocount = $xianshangzhifunum + $hongjifenxiaofeinum;
271
+        $userByCodeCount = Db::query("SELECT 'temp' as `temp1`, count(*) count FROM `rrx_user` where {$where} and user_group =4 and is_show = 3");
272
+        $userByCodeCount = array_column($userByCodeCount, 'count', 'temp1');
66 273
 
67
-        $list2[] = ['count' => $xianshangzhifunum, 'name' => '线上支付订单量'];
68
-        if (!$mer_id) {
69
-            $list2[] = ['count' => $xianshangzhifunum_xuni, 'name' => '虚拟支付订单量'];
274
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[1] ?? 0), 'name' => '消费者'];
275
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[2] ?? 0), 'name' => '业务员'];
276
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[3] ?? 0), 'name' => '业务经理'];
277
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[5] ?? 0), 'name' => '初级合伙人'];
278
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[6] ?? 0), 'name' => '中级合伙人'];
279
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[7] ?? 0), 'name' => '高级合伙人'];
280
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[8] ?? 0), 'name' => '董事'];
281
+        $list1 = array(
282
+            array('className' => 'el-icon-s-goods', 'count' => intval($maker['4-2'] ?? 0), 'name' => '集团会员'),//is_show=2
283
+            array('className' => 'el-icon-s-goods', 'count' => intval($maker['4-1'] ?? 0), 'name' => '电商创客'),
284
+            array('className' => 'el-icon-s-goods', 'count' => intval($userByCodeCount['temp'] ?? 0), 'name' => '激活创客'),
285
+        );
286
+
287
+        if ($mer_id) {
288
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[4] ?? 0), 'name' => '创客'];
70 289
         }
71
-        $list2[] = ['count' => 0, 'name' => '代付订单量'];
72
-        $xianshangzhifuren = Db::name('store_order')->where($where)->whereIn('pay_type', [0, 1])->group('uid')->count();
73
-        $xianshangzhifuren_xuni = Db::name('store_order')->where($where)->where('pay_type', 0)->group('uid')->count();
74
-        $hongjifenxiaofeiren = Db::name('store_order')->where($where)->where("pay_type", 5)->group('uid')->count();
75
-
76
-        $chengjiaoren = Db::name('store_order')->where($where)->whereIn('pay_type', [0, 1, 5])->group('uid')->count();
77
-        $list3[] = ['count' => set_price_rtrim($xianshangzhifuren), 'name' => '线上支付人数'];
78
-        if (!$mer_id) {
79
-            $list3[] = ['count' => set_price_rtrim($xianshangzhifuren_xuni), 'name' => '虚拟支付人数'];
290
+        $res['left'][] = $data;
291
+        $maker = Db::query("SELECT count(uid) as count FROM `rrx_merchant` where {$where}");
292
+        $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '创客'];
293
+
294
+        return $res;
295
+    }
296
+
297
+
298
+
299
+
300
+    /**
301
+     * pv概况
302
+     * @param int $mer_id
303
+     * @return array
304
+     * @throws \Exception
305
+     */
306
+    public function pv_overview($mer_id = 0)
307
+    {
308
+        $where = "1=1 ";
309
+        if ($mer_id) {
310
+            $mer_uid = Db::name('merchant')->where('mer_id', $mer_id)->value('uid');
311
+            $userRepository = app()->make(UserRepository::class);
312
+            $chilid_userids = $userRepository->getSpreadUidBreak($mer_uid);
313
+            $chilid_userids_string = "1";
314
+            if (!empty($chilid_userids)) {
315
+                $chilid_userids_string = implode(',',$chilid_userids);
316
+            }
317
+            $where .= "and uid in ({$chilid_userids_string})";
80 318
         }
81
-        $list3[] = ['count' => 0, 'name' => '代付人数'];
319
+        $type = input('type', 1);
320
+        $day = input('day', '');
82 321
 
322
+        if ($type == 1 and $day != '') {
323
+            $where .= " and DATE(create_time) = '" . $day . "'";
324
+        }
325
+        if ($type == 2 and $day != '') {
326
+            $date = new \DateTime($day);
327
+            $year = $date->format('Y');
328
+            $month = $date->format('m');
329
+            $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
330
+        }
331
+        $dataQuery = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where {$where} group by user_group");
332
+        $dataQuery = array_column($dataQuery, 'count', 'user_group');
333
+        $shopPartnerCount = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where mer_id={$mer_id} and is_shop_partner=1 group by user_group");
83 334
 
84
-        $xianshangtuikuan = Db::name('store_order')->where($where)->where('status', -1)->sum('pay_price');
335
+        $maker = Db::query("SELECT CONCAT(`user_group`, '-',`is_show`) as k, count(uid) count FROM `rrx_user` where {$where} group by user_group,is_show");
336
+        $maker = array_column($maker, 'count', 'k');
85 337
 
86
-        $tuikuanmoney = $xianshangtuikuan;
87
-        $list4 = array(
88
-            array('count' => $xianshangtuikuan, 'name' => '线上支付退单'),
89
-            array('count' => 0, 'name' => '代付退单'),
90
-        );
91
-        $xianshangzhifutuinum = Db::name('store_order')->where($where)->where('status', -1)->count();
338
+        $userByCodeCount = Db::query("SELECT 'temp' as `temp1`, count(*) count FROM `rrx_user` where {$where} and user_group =4 and is_show = 3");
339
+        $userByCodeCount = array_column($userByCodeCount, 'count', 'temp1');
92 340
 
93
-        $tuikuancount = $xianshangzhifutuinum;
94
-        $list5 = array(
95
-            array('count' => set_price_rtrim($xianshangzhifutuinum), 'name' => '线上支付退单量'),
96
-            array('count' => 0, 'name' => '代付退单量'),
341
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[1] ?? 0), 'name' => '消费者'];
342
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[2] ?? 0), 'name' => '业务员'];
343
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[3] ?? 0), 'name' => '业务经理'];
344
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[5] ?? 0), 'name' => '初级合伙人'];
345
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[6] ?? 0), 'name' => '中级合伙人'];
346
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[7] ?? 0), 'name' => '高级合伙人'];
347
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[8] ?? 0), 'name' => '董事'];
348
+        $list1 = array(
349
+            array('className' => 'el-icon-s-goods', 'count' => intval($maker['4-2'] ?? 0), 'name' => '集团会员'),//is_show=2
350
+            array('className' => 'el-icon-s-goods', 'count' => intval($maker['4-1'] ?? 0), 'name' => '电商创客'),
351
+            array('className' => 'el-icon-s-goods', 'count' => intval($userByCodeCount['temp'] ?? 0), 'name' => '激活创客'),
97 352
         );
98
-        $xianshangzhifutuiremn = Db::name('store_order')->where($where)->where('status', -1)->group('uid')->count();
99 353
 
100
-        $tuikuanren = $xianshangzhifutuiremn;
101
-        $list6 = array(
102
-            array('count' => set_price_rtrim($xianshangzhifutuiremn), 'name' => '线上支付退单人数'),
103
-            array('count' => 0, 'name' => '代付退单数'),
354
+        if ($mer_id) {
355
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[4] ?? 0), 'name' => '创客'];
356
+        }
357
+        $res['left'][] = $data;
358
+        $maker = Db::query("SELECT count(uid) as count FROM `rrx_merchant` where {$where}");
359
+        $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '创客'];
360
+
361
+        return $res;
362
+    }
363
+
364
+
365
+
366
+
367
+    /**
368
+     * vr概况
369
+     * @param int $mer_id
370
+     * @return array
371
+     * @throws \Exception
372
+     */
373
+    public function vr_overview($mer_id = 0)
374
+    {
375
+        $where = "1=1 ";
376
+        if ($mer_id) {
377
+            $mer_uid = Db::name('merchant')->where('mer_id', $mer_id)->value('uid');
378
+            $userRepository = app()->make(UserRepository::class);
379
+            $chilid_userids = $userRepository->getSpreadUidBreak($mer_uid);
380
+            $chilid_userids_string = "1";
381
+            if (!empty($chilid_userids)) {
382
+                $chilid_userids_string = implode(',',$chilid_userids);
383
+            }
384
+            $where .= "and uid in ({$chilid_userids_string})";
385
+        }
386
+        $type = input('type', 1);
387
+        $day = input('day', '');
388
+
389
+        if ($type == 1 and $day != '') {
390
+            $where .= " and DATE(create_time) = '" . $day . "'";
391
+        }
392
+        if ($type == 2 and $day != '') {
393
+            $date = new \DateTime($day);
394
+            $year = $date->format('Y');
395
+            $month = $date->format('m');
396
+            $where .= " and YEAR(create_time) = " . $year . " AND MONTH(create_time) = " . $month;
397
+        }
398
+        $dataQuery = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where {$where} group by user_group");
399
+        $dataQuery = array_column($dataQuery, 'count', 'user_group');
400
+        $shopPartnerCount = Db::query("SELECT user_group,count(uid) count FROM `rrx_user` where mer_id={$mer_id} and is_shop_partner=1 group by user_group");
401
+
402
+        $maker = Db::query("SELECT CONCAT(`user_group`, '-',`is_show`) as k, count(uid) count FROM `rrx_user` where {$where} group by user_group,is_show");
403
+        $maker = array_column($maker, 'count', 'k');
404
+
405
+        $userByCodeCount = Db::query("SELECT 'temp' as `temp1`, count(*) count FROM `rrx_user` where {$where} and user_group =4 and is_show = 3");
406
+        $userByCodeCount = array_column($userByCodeCount, 'count', 'temp1');
407
+
408
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[1] ?? 0), 'name' => '消费者'];
409
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[2] ?? 0), 'name' => '业务员'];
410
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[3] ?? 0), 'name' => '业务经理'];
411
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[5] ?? 0), 'name' => '初级合伙人'];
412
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[6] ?? 0), 'name' => '中级合伙人'];
413
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[7] ?? 0), 'name' => '高级合伙人'];
414
+        $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[8] ?? 0), 'name' => '董事'];
415
+        $list1 = array(
416
+            array('className' => 'el-icon-s-goods', 'count' => intval($maker['4-2'] ?? 0), 'name' => '集团会员'),//is_show=2
417
+            array('className' => 'el-icon-s-goods', 'count' => intval($maker['4-1'] ?? 0), 'name' => '电商创客'),
418
+            array('className' => 'el-icon-s-goods', 'count' => intval($userByCodeCount['temp'] ?? 0), 'name' => '激活创客'),
104 419
         );
105 420
 
421
+        if ($mer_id) {
422
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[4] ?? 0), 'name' => '创客'];
423
+        }
424
+        $res['left'][] = $data;
425
+        $maker = Db::query("SELECT count(uid) as count FROM `rrx_merchant` where {$where}");
426
+        $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '创客'];
106 427
 
107
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaomoney), 'name' => '成交金额', 'list' => $list1];
108
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaocount), 'name' => '成交订单量', 'list' => $list2];
109
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaoren), 'name' => '支付人数', 'list' => $list3];
110
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanmoney), 'name' => '退款金额', 'list' => $list4];
111
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuancount), 'name' => '退款订单量', 'list' => $list5];
112
-        $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanren), 'name' => '退款人数', 'list' => $list6];
113
-        return $data;
428
+        return $res;
114 429
     }
115 430
 
431
+
432
+
116 433
     /**
117
-     * 用户概况
434
+     * 积分概况
118 435
      * @param int $mer_id
119 436
      * @return array
120 437
      * @throws \Exception
121 438
      */
122
-    public function user_overview($mer_id = 0)
439
+    public function jifen_overview($mer_id = 0)
123 440
     {
124 441
         $where = "1=1 ";
125 442
         if ($mer_id) {
@@ -168,18 +485,17 @@ class FinanceRepository extends BaseRepository
168 485
         );
169 486
 
170 487
         if ($mer_id) {
171
-//            $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($shopPartnerCount), 'name' => '创客合伙人'];
172 488
             $data[] = ['className' => 'el-icon-s-goods', 'count' => (int)($dataQuery[4] ?? 0), 'name' => '创客'];
173 489
         }
174 490
         $res['left'][] = $data;
175
-        // $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim(intval($maker['4-2'] ?? 0) + intval($maker['4-1'] ?? 0) + intval($userByCodeCount['temp'] ?? 0)), 'name' => '创客'];
176
-
177 491
         $maker = Db::query("SELECT count(uid) as count FROM `rrx_merchant` where {$where}");
178 492
         $res['right'][] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($maker[0]['count'] ?? 0), 'name' => '创客'];
179 493
 
180 494
         return $res;
181 495
     }
182 496
 
497
+
498
+
183 499
     public function jieyu($type, $day, $mer_id = 0)
184 500
     {
185 501
 

+ 88 - 36
app/controller/admin/finance/Finance.php

@@ -20,8 +20,9 @@ class Finance extends BaseController
20 20
         $data = $financeRepository->order_overview();
21 21
         return app('json')->success('ok', $data);
22 22
     }
23
+    
23 24
     /**
24
-     * 订单概况
25
+     * 用户概况
25 26
      * @return mixed
26 27
      */
27 28
     public function user_overview()
@@ -31,6 +32,92 @@ class Finance extends BaseController
31 32
         return app('json')->success('ok', $data);
32 33
     }
33 34
 
35
+
36
+    /**
37
+     * 会员概况
38
+     * @return mixed
39
+     */
40
+    public function member_overview()
41
+    {
42
+        $financeRepository = app()->make(FinanceRepository::class);
43
+        $data = $financeRepository->member_overview();
44
+        return app('json')->success('ok', $data);
45
+    }
46
+
47
+
48
+
49
+    /**
50
+     * pv概况
51
+     * @return mixed
52
+     */
53
+    public function pv_overview()
54
+    {
55
+        $financeRepository = app()->make(FinanceRepository::class);
56
+        $data = $financeRepository->pv_overview();
57
+        return app('json')->success('ok', $data);
58
+    }
59
+
60
+
61
+    /**
62
+     * vr概况
63
+     * @return mixed
64
+     */
65
+    public function vr_overview()
66
+    {
67
+        $financeRepository = app()->make(FinanceRepository::class);
68
+        $data = $financeRepository->vr_overview();
69
+        return app('json')->success('ok', $data);
70
+    }
71
+
72
+
73
+    /**
74
+     * 积分概况
75
+     * @return mixed
76
+     */
77
+    public function jifen_overview()
78
+    {
79
+        $financeRepository = app()->make(FinanceRepository::class);
80
+        $data = $financeRepository->jifen_overview();
81
+        return app('json')->success('ok', $data);
82
+    }
83
+
84
+
85
+    /**
86
+     * 交易概况
87
+     * @return mixed
88
+     */
89
+    public function transaction_overview()
90
+    {
91
+
92
+        try {
93
+            $type = input('type', 1);
94
+            $day = input('day', '');
95
+            $mer_id = $this->request->merId();
96
+    
97
+            $financeRepository = app()->make(FinanceRepository::class);
98
+            $arr = $financeRepository->jieyu($type,$day,$mer_id);
99
+    
100
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yingyemoney']), 'name' => '营业总额'];
101
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['ruzhang']), 'name' => '入账总额'];
102
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['shouyi']), 'name' => '佣金奖励总额'];
103
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jieyu']), 'name' => '结余总额'];
104
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hf_fee_amt']), 'name' => '汇付通道服务费金额'];
105
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['integral']), 'name' => '积分总数'];
106
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['tixinan']), 'name' => '提现支出总额'];
107
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yanglao']), 'name' => '养老金总额'];
108
+    
109
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['gongxian']), 'name' => '贡献值总额'];
110
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jingdou']), 'name' => '京豆总额'];
111
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hongbao']), 'name' => '红包总额'];
112
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['fugou']), 'name' => '复购金总额'];
113
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['vr']), 'name' => 'VR总额'];
114
+            return app('json')->success('ok', $data);
115
+        } catch (\Exception $e) {
116
+            Db::name('log')->insert(['data' => '交易详情统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
117
+            return app('json')->fail('统计失败'. $e->getMessage());
118
+        }
119
+    }
120
+
34 121
     /**
35 122
      * 积分统计
36 123
      * @return mixed
@@ -188,41 +275,6 @@ class Finance extends BaseController
188 275
         }
189 276
     }
190 277
 
191
-    /**
192
-     * 交易详情
193
-     * @return mixed
194
-     */
195
-    public function transaction_overview()
196
-    {
197
-
198
-        try {
199
-            $type = input('type', 1);
200
-            $day = input('day', '');
201
-            $mer_id = $this->request->merId();
202
-    
203
-            $financeRepository = app()->make(FinanceRepository::class);
204
-            $arr = $financeRepository->jieyu($type,$day,$mer_id);
205
-    
206
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yingyemoney']), 'name' => '营业总额'];
207
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['ruzhang']), 'name' => '入账总额'];
208
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['shouyi']), 'name' => '佣金奖励总额'];
209
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jieyu']), 'name' => '结余总额'];
210
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hf_fee_amt']), 'name' => '汇付通道服务费金额'];
211
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['integral']), 'name' => '积分总数'];
212
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['tixinan']), 'name' => '提现支出总额'];
213
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['yanglao']), 'name' => '养老金总额'];
214
-    
215
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['gongxian']), 'name' => '贡献值总额'];
216
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['jingdou']), 'name' => '京豆总额'];
217
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['hongbao']), 'name' => '红包总额'];
218
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['fugou']), 'name' => '复购金总额'];
219
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($arr['vr']), 'name' => 'VR总额'];
220
-            return app('json')->success('ok', $data);
221
-        } catch (\Exception $e) {
222
-            Db::name('log')->insert(['data' => '交易详情统计错误:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】']);
223
-            return app('json')->fail('统计失败'. $e->getMessage());
224
-        }
225
-    }
226 278
 
227 279
     public function day_bill_list()
228 280
     {

+ 4 - 0
route/admin.php

@@ -857,6 +857,10 @@ Route::group(config('admin.api_admin_prefix') . '/', function () {
857 857
         Route::group('finance', function () {
858 858
             Route::get('order_overview', '/order_overview');
859 859
             Route::get('user_overview', '/user_overview');
860
+            Route::get('member_overview', '/member_overview');
861
+            Route::get('pv_overview', '/pv_overview');
862
+            Route::get('vr_overview', '/vr_overview');
863
+            Route::get('jifen_overview', '/jifen_overview');
860 864
             Route::get('transaction_overview', '/transaction_overview');
861 865
             Route::get('user_bill', '/user_bill');
862 866
             Route::get('integral_list', '/integral_list');