浏览代码

activity and you2

zz 6 年之前
父节点
当前提交
1f0d5f5cac
共有 1 个文件被更改,包括 28 次插入27 次删除
  1. 28 27
      app/Console/Commands/BookTest.php

+ 28 - 27
app/Console/Commands/BookTest.php

@@ -317,9 +317,13 @@ class BookTest extends Command
     }
 
     private function you2(){
+        $sql1 = 'TRUNCATE yq_stats';
+        DB::update($sql1);
         $result = [];
-        $info = BookUser::where('bid','>',0)->select('bid','uid','type','updated_at')->get();
-        $info2 = BookUser::where('type','GROUP_1')->select('bid','uid','type','updated_at')->get();
+        $info = BookUser::where('type','ENABLE')->select('bid','uid','type','updated_at')
+            ->orderBy('updated_at')->limit(1000)->get();
+        $info2 = BookUser::where('type','GROUP_1')
+            ->select('bid','uid','type','updated_at')->orderBy('updated_at')->limit(1000)->get();
         foreach ($info as $item){
             $bid_price = Order::where('uid',$item->uid)
                 ->where('status','PAID')
@@ -339,6 +343,12 @@ class BookTest extends Command
             $all_fee = $chapter_model->where('uid', $item->uid)
                 ->where('created_at','>=',$item->updated_at)
                 ->sum('fee');
+            $books = DB::table('book_configs')->where('bid',$val['bid'])->select('book_name')->first();
+            if($books){
+                $book_name = $books->book_name;
+            }else{
+                $book_name = 'un';
+            }
             $result[] = [
                 'uid'=>$item->uid,
                 'type'=>$item->type,
@@ -346,9 +356,12 @@ class BookTest extends Command
                 'fee'=>$chapter_fee?$chapter_fee:0,
                 'bid'=>$item->bid,
                 'all_price'=>$all_price?$all_price:0,
-                'all_fee'=>$all_fee?$all_fee:0
+                'all_fee'=>$all_fee?$all_fee:0,
+                'book_name'=>$book_name
             ];
         }
+        DB::table('yq_stats')->insert($result);
+        $result = [];
         $item = null;
         foreach ($info2 as $item){
             $all_price = Order::where('uid',$item->uid)
@@ -371,39 +384,27 @@ class BookTest extends Command
                 $bid = $all->bid;
                 $book_name = $all->book_name;
             }
+            $bid_price = Order::where('uid',$item->uid)
+                ->where('status','PAID')
+                ->where('created_at','>=',$item->updated_at)
+                ->where('from_bid',$bid)
+                ->sum('price');
+            $chapter_fee = $chapter_model->where('uid', $item->uid)
+                ->where('bid', $bid)
+                ->where('created_at','>=',$item->updated_at)
+                ->sum('fee');
             $result[] = [
                 'uid'=>$item->uid,
                 'type'=>$item->type,
-                'amount'=>0,
-                'fee'=>0,
+                'amount'=>$bid_price?$bid_price:0,
+                'fee'=>$chapter_fee,
                 'bid'=>$bid,
                 'all_price'=>$all_price?$all_price:0,
                 'all_fee'=>$all_fee?$all_fee:0,
                 'book_name'=>$book_name
             ];
         }
-
-        $str = "图书id,书名,用户类型,用户id,本书订阅书币,本书充值,总充值,总订阅\r\n";
-        $str = mb_convert_encoding($str, 'gbk');
-        $file_name = date('Y-m-d') . '-you2.csv';
-        file_put_contents($file_name, $str);
-        $temp = '';
-        foreach ($result as $val) {
-            $books = DB::table('book_configs')->where('bid',$val['bid'])->select('book_name')->first();
-            if($books){
-                $book_name = $books->book_name;
-            }else{
-                $book_name = 'un';
-            }
-            if($val['type'] == 'GROUP_1'){
-                $type = 'GROUP_1';
-            }else{
-                $type = 'GROUP_2';
-            }
-            $t = "{$val['bid']},{$book_name},{$type},{$val['uid']},{$val['fee']},{$val['amount']},{$val['all_price']},{$val['all_fee']}\r\n";
-            $temp .=  mb_convert_encoding($t, 'gbk');
-        }
-        file_put_contents($file_name, $temp, FILE_APPEND);
+        DB::table('yq_stats')->insert($result);
     }
 
 }