|
@@ -5,6 +5,7 @@ namespace App\Console\Commands;
|
|
|
use App\Modules\Book\Services\BookSubscribleChapterService;
|
|
|
use App\Modules\Subscribe\Services\ChapterOrderService;
|
|
|
use App\Modules\YunQi\Models\BookUser;
|
|
|
+use App\Modules\YunQi\Models\YqUserBidRelation;
|
|
|
use GuzzleHttp\Client;
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
@@ -319,98 +320,83 @@ class BookTest extends Command
|
|
|
private function you2(){
|
|
|
$sql1 = 'TRUNCATE yq_stats';
|
|
|
DB::update($sql1);
|
|
|
- $result = [];
|
|
|
+
|
|
|
$info = BookUser::where('type','ENABLE')->select('bid','uid','type','updated_at')
|
|
|
- ->orderBy('updated_at')->limit(1000)->get();
|
|
|
+ ->orderBy('updated_at')->limit(1500)->get();
|
|
|
$info2 = BookUser::where('type','GROUP_1')
|
|
|
- ->select('bid','uid','type','updated_at')->orderBy('updated_at')->limit(1000)->get();
|
|
|
+ ->select('bid','uid','type','updated_at')->orderBy('updated_at')->limit(1500)->get();
|
|
|
+ $this->you2Type($info,'GROUP_2');
|
|
|
+ $this->you2Type($info2,'GROUP_1');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function you2Type($info,$type){
|
|
|
+ $result = [];
|
|
|
+ $chapter_model = new ChapterOrder();
|
|
|
foreach ($info as $item){
|
|
|
- $bid_price = Order::where('uid',$item->uid)
|
|
|
- ->where('status','PAID')
|
|
|
- ->where('created_at','>=',$item->updated_at)
|
|
|
- ->where('created_at','<=',date('Y-m-d H:i:s',strtotime($item->updated_at)+86400))
|
|
|
- ->where('from_bid',$item->bid)
|
|
|
- ->sum('price');
|
|
|
- $all_price = Order::where('uid',$item->uid)
|
|
|
- ->where('status','PAID')
|
|
|
- ->where('created_at','>=',$item->updated_at)
|
|
|
- ->where('created_at','<=',date('Y-m-d H:i:s',strtotime($item->updated_at)+86400))
|
|
|
- ->sum('price');
|
|
|
- $chapter_model = new ChapterOrder();
|
|
|
+ $to_bids = YqUserBidRelation::where('uid',$item->uid)->select('to_bid','created_at')->get()->pluck('created_at','to_bid')->all();
|
|
|
+ $from_bid = YqUserBidRelation::where('uid',$item->uid)->select('from_bid','created_at')->get()->pluck('created_at','from_bid')->all();
|
|
|
$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');
|
|
|
- $books = DB::table('book_configs')->where('bid',$item->bid)->select('book_name')->first();
|
|
|
- if($books){
|
|
|
- $book_name = $books->book_name;
|
|
|
- }else{
|
|
|
- $book_name = 'un';
|
|
|
+ if($to_bids){
|
|
|
+ foreach ($to_bids as $to_bid=>$time){
|
|
|
+ if(!$to_bid) continue;
|
|
|
+ $fee = $chapter_model->where('uid',$item->uid)
|
|
|
+ ->where('bid',$to_bid)
|
|
|
+ ->where('created_at','>=',$time)
|
|
|
+ ->sum('fee');
|
|
|
+ $amount = Order::where('uid',$item->uid)
|
|
|
+ ->where('from_bid',$to_bid)
|
|
|
+ ->where('created_at','>=',$time)
|
|
|
+ ->where('status','PAID')
|
|
|
+ ->sum('price');
|
|
|
+ $result[] = [
|
|
|
+ 'bid'=>$to_bid,
|
|
|
+ 'uid'=>$item->uid,
|
|
|
+ 'fee'=>$fee,
|
|
|
+ 'amount'=>$amount,
|
|
|
+ 'start_time'=>$time,
|
|
|
+ 'type'=>'to',
|
|
|
+ 'group'=>$type,
|
|
|
+ 'created_at'=>date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at'=>date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if($result){
|
|
|
+ DB::table('yq_stats2')->insert($result);
|
|
|
+ $result = [];
|
|
|
+ }
|
|
|
}
|
|
|
- $result[] = [
|
|
|
- 'uid'=>$item->uid,
|
|
|
- 'type'=>$item->type,
|
|
|
- 'amount'=>$bid_price?$bid_price:0,
|
|
|
- 'fee'=>$chapter_fee?$chapter_fee:0,
|
|
|
- 'bid'=>$item->bid,
|
|
|
- 'total_amount'=>$all_price?$all_price:0,
|
|
|
- 'total_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)
|
|
|
- ->where('status','PAID')
|
|
|
- ->where('created_at','>=',$item->updated_at)
|
|
|
- ->where('created_at','<=',date('Y-m-d H:i:s',strtotime($item->updated_at)+86400))
|
|
|
- ->sum('price');
|
|
|
- $chapter_model = new ChapterOrder();
|
|
|
- $chapter_model->setCurrentTable($item->uid);
|
|
|
- $all = $chapter_model->where('uid', $item->uid)
|
|
|
- ->where('created_at','>=',$item->updated_at)
|
|
|
- ->where('created_at','<=',date('Y-m-d H:i:s',strtotime($item->updated_at)+86400))
|
|
|
- ->groupBy('bid')
|
|
|
- ->select(DB::raw('sum(fee) as fee'),'bid','book_name')
|
|
|
- ->orderBy('fee','desc')
|
|
|
- ->first();
|
|
|
- $all_fee = 0;
|
|
|
- $bid = 0;
|
|
|
- $book_name = '';
|
|
|
- if($all){
|
|
|
- $all_fee = $all->fee;
|
|
|
- $bid = $all->bid;
|
|
|
- $book_name = $all->book_name;
|
|
|
+
|
|
|
+ if($from_bid){
|
|
|
+ foreach ($from_bid as $to_bid=>$time){
|
|
|
+ if(!$to_bid) continue;
|
|
|
+ $fee = $chapter_model->where('uid',$item->uid)
|
|
|
+ ->where('bid',$to_bid)
|
|
|
+ ->where('created_at','>=',$time)
|
|
|
+ ->sum('fee');
|
|
|
+ $amount = Order::where('uid',$item->uid)
|
|
|
+ ->where('from_bid',$to_bid)
|
|
|
+ ->where('created_at','>=',$time)
|
|
|
+ ->where('status','PAID')
|
|
|
+ ->sum('price');
|
|
|
+ $result[] = [
|
|
|
+ 'bid'=>$to_bid,
|
|
|
+ 'uid'=>$item->uid,
|
|
|
+ 'fee'=>$fee,
|
|
|
+ 'amount'=>$amount,
|
|
|
+ 'start_time'=>$time,
|
|
|
+ 'type'=>'from',
|
|
|
+ 'group'=>$type,
|
|
|
+ 'created_at'=>date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at'=>date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if($result){
|
|
|
+ DB::table('yq_stats2')->insert($result);
|
|
|
+ $result = [];
|
|
|
+ }
|
|
|
}
|
|
|
- $bid_price = Order::where('uid',$item->uid)
|
|
|
- ->where('status','PAID')
|
|
|
- ->where('created_at','>=',$item->updated_at)
|
|
|
- ->where('created_at','<=',date('Y-m-d H:i:s',strtotime($item->updated_at)+86400))
|
|
|
- ->where('from_bid',$bid)
|
|
|
- ->sum('price');
|
|
|
- $chapter_fee = $chapter_model->where('uid', $item->uid)
|
|
|
- ->where('bid', $bid)
|
|
|
- ->where('created_at','>=',$item->updated_at)
|
|
|
- ->where('created_at','<=',date('Y-m-d H:i:s',strtotime($item->updated_at)+86400))
|
|
|
- ->sum('fee');
|
|
|
- $result[] = [
|
|
|
- 'uid'=>$item->uid,
|
|
|
- 'type'=>$item->type,
|
|
|
- 'amount'=>$bid_price?$bid_price:0,
|
|
|
- 'fee'=>$chapter_fee,
|
|
|
- 'bid'=>$bid,
|
|
|
- 'total_amount'=>$all_price?$all_price:0,
|
|
|
- 'total_fee'=>$all_fee?$all_fee:0,
|
|
|
- 'book_name'=>$book_name
|
|
|
- ];
|
|
|
}
|
|
|
- DB::table('yq_stats')->insert($result);
|
|
|
}
|
|
|
|
|
|
}
|