Browse Source

增加修复pv脚本

hefei 1 year ago
parent
commit
db462bf8c9
2 changed files with 61 additions and 1 deletions
  1. 59 0
      app/command/repairPvLog.php
  2. 2 1
      config/console.php

+ 59 - 0
app/command/repairPvLog.php

@@ -0,0 +1,59 @@
1
+<?php
2
+declare (strict_types=1);
3
+
4
+namespace app\command;
5
+
6
+use think\console\Command;
7
+use think\console\Input;
8
+use think\console\Output;
9
+use think\facade\Db;
10
+
11
+class repairPvLog extends Command
12
+{
13
+    protected function configure()
14
+    {
15
+        // 指令配置
16
+        $this->setName('repair_pv_log')
17
+            ->setDescription('修复老数据pv记录');
18
+    }
19
+
20
+    /**
21
+     * @param Input $input
22
+     * @param Output $output
23
+     * @return void
24
+     */
25
+    protected function execute(Input $input, Output $output)
26
+    {
27
+        $user_id_list = Db::name('user')->where([['pv','=',0],['contribute','>',0]])->column('uid');
28
+        if($user_id_list){
29
+            foreach ($user_id_list as $user_id) {
30
+                $order_list = Db::name('store_order')->where(['uid' => $user_id,'paid' => 1,'gzc' => 1])->select();
31
+                if($order_list) {
32
+                    $pv = 0;
33
+                    foreach ($order_list as $order) {
34
+                        if($order['mer_id'] == 496){
35
+                            $pv_tmp = ($order['total_price']/1180) * 700;
36
+                            $pv_log_data = [
37
+                                'uid' => $user_id,
38
+                                'pv' => $pv_tmp,
39
+                                'status' => 1,
40
+                                'mark' => '会员专区消费获得PV(老数据)',
41
+                                'order_id' => $order['order_sn'],
42
+                                'settlement_time' => '2025-03-01 00:00:00',
43
+                                'addtime' => 1740758400
44
+                            ];
45
+                            Db::name('user_pv_log')->insert($pv_log_data);
46
+                            $pv += $pv_tmp;
47
+                        }
48
+                    }
49
+                    if($pv){
50
+                        Db::name('user')->where(['uid' => $user_id])->update(['pv' => $pv]);
51
+                        $output->writeln('user_id = ' . $user_id . '添加成功 pv = ' . $pv);
52
+                    }
53
+                }
54
+            }
55
+        }
56
+        $output->writeln('执行结束');
57
+    }
58
+
59
+}

+ 2 - 1
config/console.php

@@ -26,6 +26,7 @@ return [
26 26
         'movie_city_area' => 'app\command\MovieCityAreaCommand',
27 27
         'movie_cinema' => 'app\command\MovieCinemaCommand',
28 28
         'movie_film' => 'app\command\MovieFilmCommand',
29
-        'cinema_film_sched' => 'app\command\CinemaSchedCommand'
29
+        'cinema_film_sched' => 'app\command\CinemaSchedCommand',
30
+        'repair_pv_log' => 'app\command\repairPvLog',
30 31
     ],
31 32
 ];