浏览代码

Merge branch 'auth'

zz 6 年之前
父节点
当前提交
8e302516b5
共有 2 个文件被更改,包括 154 次插入2 次删除
  1. 152 1
      app/Console/Commands/BookTest.php
  2. 2 1
      app/Libs/Helpers.php

+ 152 - 1
app/Console/Commands/BookTest.php

@@ -4,6 +4,7 @@ namespace App\Console\Commands;
 
 use App\Modules\Book\Services\BookSubscribleChapterService;
 use App\Modules\Subscribe\Services\ChapterOrderService;
+use App\Modules\User\Services\ReadRecordService;
 use App\Modules\YunQi\Models\BookUser;
 use App\Modules\YunQi\Models\YqUserBidRelation;
 use App\Modules\YunQi\Models\YqZsyTest;
@@ -66,7 +67,8 @@ class BookTest extends Command
         //$this->activity();
         //$this->testBookSmartPushStats();
         //$this->sendOrderStats105();
-        $this->you2();
+        //$this->you2();
+        $this->transfromUserOrder();
     }
 
 
@@ -343,14 +345,17 @@ class BookTest extends Command
                 foreach ($to_bids as $v){
                     $to_bid = $v->to_bid;
                     $time = $v->created_at->format('Y-m-d H:i:s');
+                    $end_time = date('Y-m-d H:i:s',strtotime($time)+2*86400);
                     if(!$to_bid) continue;
                     $fee = $chapter_model->where('uid',$item->uid)
                         ->where('bid',$to_bid)
                         ->where('created_at','>=',$time)
+                        ->where('created_at','<=',$end_time)
                         ->sum('fee');
                     $amount = Order::where('uid',$item->uid)
                         ->where('from_bid',$to_bid)
                         ->where('created_at','>=',$time)
+                        ->where('created_at','<=',$end_time)
                         ->where('status','PAID')
                         ->sum('price');
                     $result[] = [
@@ -377,13 +382,16 @@ class BookTest extends Command
                     $test = YqZsyTestService::getByBid($bid);
                     if($test) continue;
                     $time = $from_bid->created_at->format('Y-m-d H:i:s');
+                    $end_time = date('Y-m-d H:i:s',strtotime($time)+2*86400);
                     $fee = $chapter_model->where('uid',$item->uid)
                         ->where('bid',$bid)
                         ->where('created_at','>=',$time)
+                        ->where('created_at','<=',$end_time)
                         ->sum('fee');
                     $amount = Order::where('uid',$item->uid)
                         ->where('from_bid',$bid)
                         ->where('created_at','>=',$time)
+                        ->where('created_at','<=',$end_time)
                         ->where('status','PAID')
                         ->sum('price');
                     $result[] = [
@@ -406,4 +414,147 @@ class BookTest extends Command
         }
     }
 
+    private function transfromUserOrder(){
+        $user = DB::table('users')
+            ->where('distribution_channel_id',4815)
+            ->where('created_at','>=','2019-01-31 15:00:00')
+            ->select('openid','id')
+            ->get();
+        $chapter_model = new ChapterOrder();
+        foreach ($user as $v){
+            Log::info('now user is :');
+            Log::info('openid is: '.$v->openid.',old uid is :'.$v->id);
+            $froce_user = DB::table('force_subscribe_users')
+                ->where('openid',$v->openid)
+                ->where('distribution_channel_id',384)
+                ->select('uid')
+                ->first();
+            if(!$froce_user){
+                continue;
+            }
+            Log::info('$froce_user user is :');
+            Log::info('$froce_user is: '.$froce_user->uid);
+
+            if($froce_user && $froce_user->uid != $v->id){
+                $chapter_model->setCurrentTable($froce_user->uid);
+                $data = [];
+                //章节订购
+                $chapter_order_info = $chapter_model->where('uid',$froce_user->uid)->get();
+                Log::info('$chapter_order_info user is :');
+                Log::info($chapter_order_info);
+                if($chapter_order_info){
+                    foreach ($chapter_order_info as $chapter_order_item){
+                        $data = [
+                            'distribution_channel_id'=>4815,
+                            'bid'=>$chapter_order_item->bid,
+                            'cid'=>$chapter_order_item->cid,
+                            'chapter_name'=>$chapter_order_item->chapter_name,
+                            'book_name'=>$chapter_order_item->book_name,
+                            'uid'=>$v->id,
+                            'send_order_id'=>0,
+                            'fee'=>0,
+                            'created_at'=>$chapter_order_item->created_at,
+                            'updated_at'=>date('Y-m-d H:i:s'),
+                            'charge_balance'=>0,
+                            'reward_balance'=>0
+                        ];
+                        $chapter_model->setCurrentTable($v->id);
+                        $old = $chapter_model->where('uid',$v->id)
+                            ->where('bid',$chapter_order_item->bid)
+                            ->where('cid',$chapter_order_item->cid)
+                            ->select('id')->first();
+                        if(!$old){
+                            $chapter_model->insert($data);
+                        }
+
+                    }
+                }
+                /*if($data){
+                    Log::info('$chapter_order_info user $data is :');
+                    Log::info($data);
+                    $chapter_model->setCurrentTable($v->id);
+                    $chapter_model->insert($data);
+                }*/
+
+                //单本订购
+                if($froce_user && $froce_user->uid != $v->id){
+                    $book_order_data = [];
+                    $book_orders = DB::table('book_orders')->where('uid',$froce_user->uid)->get();
+                    Log::info('$book_orders user  is :');
+                    if($book_orders){
+                        foreach ($book_orders as $book_order_item){
+                            $book_order_data[] = [
+                                'uid'=>$v->id,
+                                'distribution_channel_id'=>4815,
+                                'bid'=>$book_order_item->bid,
+                                'book_name'=>$book_order_item->book_name,
+                                'u'=>$book_order_item->u,
+                                'send_order_id'=>0,
+                                'charge_balance'=>0,
+                                'reward_balance'=>0,
+                                'fee'=>0,
+                                'created_at'=>$book_order_item->created_at,
+                                'updated_at'=>date('Y-m-d H:i:s'),
+                            ];
+                        }
+                    }
+                    if($book_order_data){
+                        Log::info('$book_order_data user  is :');
+                        Log::info($book_order_data);
+                        foreach ($book_order_data as $book_o ){
+                            $old = DB::table('book_orders')
+                                ->where('uid',$book_o['uid'])
+                                ->where('bid',$book_o['bid'])
+                                ->select('id')->first();
+                            if(!$old){
+                                DB::table('book_orders')->insert($book_order_data);
+                            }
+                        }
+                    }
+                }
+
+
+                //阅读记录
+                $read_bids = Redis::hgetall('book_read:' . $froce_user->uid);
+
+                Log::info('$read_bids   is :');
+                Log::info($read_bids);
+
+                if ($read_bids){
+                    foreach ($read_bids as  $key=>$field){
+                        Redis::hset('book_read:' . $v->id,$key,$field);
+                    }
+                }
+
+                //用户信息
+                $old_user = DB::table('users')->where('id', $froce_user->uid)->first();
+                if($old_user){
+                    DB::table('users')->where('id',$v->id)->update([
+                        'balance'=>$old_user->balance,
+                        'charge_balance'=>$old_user->charge_balance,
+                        'reward_balance'=>$old_user->reward_balance,
+                    ]);
+                }
+
+                //年费
+                $year = DB::table('year_orders')->where('uid',$froce_user->uid)->orderBy('id','desc')->first();
+                if($year){
+                    $old_year = DB::table('year_orders')->where('uid',$v->id)->orderBy('id','desc')->first();
+                    if(!$old_year){
+                        DB::table('year_orders')->insert([[
+                            'uid'=>$v->id,
+                            'begin_time'=>$year->begin_time,
+                            'end_time'=>$year->end_time,
+                            'distribution_channel_id'=>4815,
+                            'created_at'=>$year->created_at,
+                            'updated_at'=>date('Y-m-d H:i:s'),
+                            'fee'=>0,
+                        ]]);
+                    }
+                }
+            }
+
+        }
+    }
+
 }

+ 2 - 1
app/Libs/Helpers.php

@@ -480,6 +480,7 @@ function specialChannelAuthInfoV2(){
         '4433'=>'wx449a65a9bbc7d50a',
         '4434'=>'wx7ea67b55ac102fd3',
         '4440'=>'wxddd622a5c195a3a9',
-        '4438'=>'wx007ef65244b47f7c'
+        '4438'=>'wx007ef65244b47f7c',
+        '4815'=>'wx33f6cc190b194b3e'
     ];
 }