Browse Source

book yunqi

zz 6 years ago
parent
commit
3a31b49dfe
1 changed files with 34 additions and 3 deletions
  1. 34 3
      app/Console/Commands/BookTest.php

+ 34 - 3
app/Console/Commands/BookTest.php

@@ -319,28 +319,59 @@ class BookTest extends Command
     private function you2(){
         $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();
         foreach ($info as $item){
             $bid_price = Order::where('uid',$item->uid)
                 ->where('status','PAID')
                 ->where('created_at','>=',$item->updated_at)
                 ->where('from_bid',$item->bid)
                 ->sum('price');
+            $all_price = Order::where('uid',$item->uid)
+                ->where('status','PAID')
+                ->where('created_at','>=',$item->updated_at)
+                ->sum('price');
             $chapter_model = new ChapterOrder();
             $chapter_model->setCurrentTable($item->uid);
             $chapter_fee = $chapter_model->where('uid', $item->uid)
                 ->where('bid', $item->bid)
                 ->where('created_at','>=',$item->updated_at)
                 ->sum('fee');
+            $all_fee = $chapter_model->where('uid', $item->uid)
+                ->where('created_at','>=',$item->updated_at)
+                ->sum('fee');
             $result[] = [
                 'uid'=>$item->uid,
                 'type'=>$item->type,
                 'amount'=>$bid_price?$bid_price:0,
                 'fee'=>$chapter_fee?$chapter_fee:0,
-                'bid'=>$item->bid
+                'bid'=>$item->bid,
+                'all_price'=>$all_price?$all_price:0,
+                'all_fee'=>$all_fee?$all_fee:0
+            ];
+        }
+        $item = null;
+        foreach ($info2 as $item){
+            $all_price = Order::where('uid',$item->uid)
+                ->where('status','PAID')
+                ->where('created_at','>=',$item->updated_at)
+                ->sum('price');
+            $chapter_model = new ChapterOrder();
+            $chapter_model->setCurrentTable($item->uid);
+            $all_fee = $chapter_model->where('uid', $item->uid)
+                ->where('created_at','>=',$item->updated_at)
+                ->sum('fee');
+            $result[] = [
+                'uid'=>$item->uid,
+                'type'=>$item->type,
+                'amount'=>0,
+                'fee'=>0,
+                'bid'=>$item->bid,
+                'all_price'=>$all_price?$all_price:0,
+                'all_fee'=>$all_fee?$all_fee:0
             ];
         }
 
-        $str = "图书id,书名,用户类型,用户id,订阅书币,充值\r\n";
+        $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);
@@ -357,7 +388,7 @@ class BookTest extends Command
             }else{
                 $type = 'GROUP_2';
             }
-            $t = "{$val['bid']},{$book_name},{$type},{$val['uid']},{$val['fee']},{$val['amount']}\r\n";
+            $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);