Quellcode durchsuchen

用户分群详情

liuzejian vor 1 Jahr
Ursprung
Commit
4bd36bfea9

+ 65 - 1
modules/Audience/Http/Controllers/UserGroupController.php

@@ -61,13 +61,77 @@ class UserGroupController extends CatchController
             $uids = UserGroupService::getSQL($tags)->distinct()->select('a.uid')->get()->pluck('uid')->toArray();
             $uids = UserGroupService::dealHistoryReadBooks(UserGroupService::dealPayVideo($uids, $tags), $tags);
             $obj->user_num = count($uids);
-            $obj->tags_arr = $tags;
+
+            $tags = \json_decode($obj->tags, true);
+            $tag_arr = $this->strTagArr($tags);
+            $obj->tags_arr = $tag_arr;
             $obj->gzh_names = $gzhInfo->pluck('nick_name')->toArray();
         }
 
         return $obj;
     }
 
+    private function strTagArr($tags) {
+        $tagFields = [
+            't1' => [
+                'attention_hour' => '关注时间(小时)',
+                'in_48_hour' => '仅48小时内和公众号有互动的粉丝才能收到',
+                'interact_hour' => '上次互动时间(小时)',
+                'last_watch_day' => '最近观看时间(天)',
+                'register_day' => '用户注册日期(天)',
+                'total_watch_day' => '累计观看天数',
+                'video_watch' => '历史观看短剧',
+                'video_charge' => '充值过短剧',
+            ],
+            't2' => [
+                'charge_type' => '付费类型',
+                'total_charge_money' => '累计充值金额',
+                'avg_charge_money' => '平均充值金额',
+                'charge_num' => '充值次数',
+                'remain_coin' => '看币余额',
+                'last_charge_day' => '上次充值日期',
+            ]
+        ];
+        $t1 = [];
+        $t2 = [];
+        foreach ($tags as $key => $val) {
+            if($val) {
+                $valStr = $this->strVal($key, $val);
+                if(in_array($key, array_keys($tagFields['t1']))) {
+                    $t1[] = $tagFields['t1'][$key] . ':'. $valStr;
+                } else {
+                    $t2[] = $tagFields['t2'][$key]. ':'. $valStr;
+                }
+            }
+        }
+
+        return [
+            'active' => $t1, 'pay' => $t2
+        ];
+    }
+
+    private function strVal($key, $val) {
+        if('charge_type' == $key) {
+            return ['1' => '未付费', '2' => '待支付', '3' => '已付费', '4' => 'VIP用户'][$val] ?? '';
+        }
+        if(in_array($key, ['video_watch', 'video_charge'])) {
+            return DB::table('videos')
+                ->whereIn('id', $val)
+                ->select('name')->get()->pluck('name')->join(', ');
+        }
+        if('in_48_hour' == $key) {
+            return ['1' => '是', '2' => '否'][$val] ?? '';
+        }
+        $arr = explode('-', $val);
+        if($arr[0] == $arr[1]) {
+            return $arr[0];
+        }
+        if($arr[1] == 0) {
+            return $arr[0] . '-不限';
+        }
+        return $val;
+    }
+
     /**
      * 添加用户分群
      * @param Request $request

+ 1 - 1
tests/Audience/Http/Controllers/UserGroupControllerTest.php

@@ -30,7 +30,7 @@ class UserGroupControllerTest extends UsedTestCase
         $res = $this->withHeaders([
             'Authorization' => 'Bearer '. $this->token,
         ])->json('get','http://localhost/api/audienceManage/userGroup/detail', [
-            'id' => 1
+            'id' => 4
         ]);
         $this->dumpJson($res);
     }