فهرست منبع

you2 data and year activty init

zz 6 سال پیش
والد
کامیت
37a07ad59c
2فایلهای تغییر یافته به همراه116 افزوده شده و 85 حذف شده
  1. 71 85
      app/Console/Commands/BookTest.php
  2. 45 0
      app/Http/Controllers/Wap/Web/WelcomeController.php

+ 71 - 85
app/Console/Commands/BookTest.php

@@ -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);
     }
 
 }

+ 45 - 0
app/Http/Controllers/Wap/Web/WelcomeController.php

@@ -1628,4 +1628,49 @@ class WelcomeController extends BaseController
 
         return view('pay.order.greatColdActivity', ['url' => $url, 'code' => 0, 'type' => $type,'img'=>$img]);
     }
+
+    public function channelYearActivity(Request $request){
+        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
+        $token = $request->input('token');
+        $activity_info = ActivityService::getByToken($token);
+        if ($activity_info && $activity_info->product_id) {
+            $from = $request->input('fromtype', 'main');
+            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
+            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
+            $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
+            $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
+            Redis::sadd($uv_key, $this->uid);
+            Redis::hincrby($pv_key, date('Y-m-d'), 1);
+            //渠道不符合
+            if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
+                return view('pay.order.longactivitynine', ['url' => '###', 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
+            }
+
+            //活动未开始
+            if (time() < strtotime($activity_info->start_time)) {
+                return view('pay.order.longactivitynine', ['url' => '###', 'code' => -3, 'start_time' => '', 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
+            }
+
+            //活动结束
+            if (time() > strtotime($activity_info->end_time)) {
+                return view('pay.order.longactivitynine', ['url' => '###', 'code' => -1, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
+            }
+
+
+            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time) && empty($order)) {
+                $param = [
+                    'uid' => $this->uid,
+                    'distribution_channel_id' => $this->distribution_channel_id,
+                    'product_id' => $activity_info->product_id,
+                    'activity_id' => $activity_info->id,
+                    'fromtype' => $from,
+                    'limit' => 1,
+                    'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
+                ];
+                $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
+                return view('pay.order.longactivitynine', ['url' => $url, 'code' => 0, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
+            }
+        }
+        return view('pay.order.longactivitynine', ['url' => '###', 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
+    }
 }