Jelajahi Sumber

Merge branch 'master' of qk:wangdu/wangdu_wechat

zhoulj 4 tahun lalu
induk
melakukan
bf6ed07ec4

+ 0 - 229
app/Console/Commands/SmartPush/KeepContinueRead.php

@@ -1,229 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: z-yang
- * Date: 2019/8/20
- * Time: 14:00
- */
-
-namespace App\Console\Commands\SmartPush;
-
-use Illuminate\Console\Command;
-use DB;
-use Redis;
-use App\Modules\Book\Services\BookConfigService;
-use GuzzleHttp\Client;
-use App\Http\Controllers\WechatController;
-use GuzzleHttp\Psr7\Request as GuzzleRequest;
-use Hashids;
-use GuzzleHttp\Pool;
-
-class KeepContinueRead extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'SmartPush:KeepContinueRead';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = '持续阅读推送';
-
-    /**
-     * Create a new command instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        $this->send();
-    }
-
-    private  function generateRequest()
-    {
-        $switch_array = [];
-        $now_hour = date('G');
-        $temp = 0;
-        $continueReadUrlFormat = 'https://site%s.%s.com%s';
-        while (true){
-            $user =  DB::connection('api_mysql')->table('temp_force_subscribe_users')
-                ->select('id','uid','distribution_channel_id','openid','appid')
-                ->where('id','>',$temp)
-                ->orderBy('id')
-                ->limit(1000)
-                ->get();
-            if(!$user) break;
-
-            foreach ($user as $item){
-                /*if(!in_array($item->distribution_channel_id,[5,8,123,146,155,160,211,255,256,691,695,722,4025,4053,4174,4236,4237,4241,4326,4334,4364,4426,4427,4487,4488,4556,4593,4742,4889,4891,5204,5611,6122,6123,6124,6460,6907,6929,6987])){
-                    continue;
-                }*/
-               
-		\Log::info( '---------------------------start--start-------------------------------------------' );
-		//\Log::info('$item->distribution_channel_id is :'.$item->distribution_channel_id  );
-		\Log::info( '$item->id is :'.$item->id );
-                if(!isset($switch_array[$item->distribution_channel_id])){
-                    $switch = DB::connection('api_mysql')->table('custom_msg_switchs_msgs')
-                        ->where('distribution_channel_id',$item->distribution_channel_id)
-                        ->where('custom_category','continue_read')
-                        ->select('status')
-                        ->first();
-                    if($switch){
-                        $switch_array[$item->distribution_channel_id] = $switch->status;
-                    }else{
-                        $switch_array[$item->distribution_channel_id] = 1;
-                    }
-                }
-
-                $switch_status = $switch_array[$item->distribution_channel_id];
-                if($switch_status == 2) continue;
-		//\Log::info( '$item->distribution_channel_id in is :'.$item->distribution_channel_id );
-
-                $read_info = $this->getFirstReadRecord($item->uid);
-		//\Log::info( $read_info );
-		\Log::info( 'uid is :'.$item->uid  );
-                if(!$read_info) continue;
-
-                //获取本次发送的时间间隔
-                $this_push_hour = Redis::hget('book_read:'.$item->uid,'next_push_hour');
-                //上次发送时间
-                $prev_send_info = DB::connection('api_mysql')->table('custom_push_keep_continue')->where('uid',$item->uid)->select('send_time')->orderBy('id','desc')->first();
-
-                $diff = $this_push_hour?$this_push_hour:8;
-                if($diff == 8){
-                    if((time()-$read_info['time']) > 3600*8){
-                        $send_hour = $now_hour;
-                    }else{
-                        $send_hour = -1;
-                    }
-                }else{
-                    if($prev_send_info){
-                        //$send_hour = date('G',strtotime($prev_send_info->send_time)+$diff*3600);
-                        if((time()-strtotime($prev_send_info->send_time)) >$diff*3600){
-                            $send_hour = $now_hour;
-                        }else{
-                            $send_hour = -1;
-                        }
-                    }else{
-                        $send_hour = $now_hour;
-                    }
-                }
-
-                if($send_hour != $now_hour ) continue;
-                $openid = $item->openid;
-                $appid = $item->appid;
-                $content_format = "您看的小说有更新\r\n\r\n<a href='%s'>《%s》剧情已更新,点击继续阅读</a> \r\n\r\n记得点击菜单栏签到领书币哦";
-                $content = sprintf($content_format,
-                    sprintf($continueReadUrlFormat,
-                        encodeDistributionChannelId($item->distribution_channel_id),
-                        env('CUSTOM_HOST'),
-                        $read_info['url']
-                    ),
-                    $read_info['book_name']
-                );
-                $accecc_token = $this->getAccessToken($appid);
-                if(!$accecc_token)continue;
-
-                $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$accecc_token;
-                $request = new GuzzleRequest('post',$url,[],\GuzzleHttp\json_encode([
-                    'touser'=>$openid,
-                    'msgtype'=>'text',
-                    'text'=>['content'=>$content]
-                ],JSON_UNESCAPED_UNICODE));
-
-                DB::connection('api_mysql')->table('custom_push_keep_continue')->insert([
-                    'uid'=>$item->uid,
-                    'time_diff'=>$diff,
-                    'send_time'=>date('Y-m-d H:i:s'),
-                    'day'=>date('Y-m-d'),
-                    'created_at'=>date('Y-m-d H:i:s'),
-                    'updated_at'=>date('Y-m-d H:i:s')
-                ]);
-                if($diff == 8){
-                    $next = 5;
-                }else{
-                    $next = 12;
-                }
-                Redis::hset('book_read:'.$item->uid,'next_push_hour',$next);
-		\Log::info( '----------------------------end-end-end-------------------------------------------' );
-                yield $request;
-            }
-            $temp = $item->id;
-        }
-    }
-
-
-    private  function getFirstReadRecord($uid){
-        //Redis::hget('book_base:' . $uid, 'last_read', "{$bid}_{$cid}_{$book_name}_{$chapter_name}_" . time());
-        $record = Redis::hget('book_read:' . $uid, 'last_read');
-        if($record){
-            $record_arr = explode('_',$record);
-            $bid = $record_arr[0];
-            $book_name = $this->bid2BookName($bid);
-            $bid = Hashids::encode($bid);
-            $cid = $record_arr[1];
-            $time = $record_arr[2];
-            $res = [
-                'url' => '/reader?bid='.$bid.'&cid='.$cid.'&fromtype=continue_read',
-                'book_name'=>$book_name,
-                'bid'=>$bid,
-                'time'=>$time
-            ];
-            return $res;
-        }
-        return [];
-    }
-
-    private  function bid2BookName($bid){
-        $book_name = null;
-        if(is_null($book_name)){
-            $book_key = 'wap:string:book:'.$bid;
-            $book_name = Redis::get($book_key);
-            Redis::EXPIRE($book_key,3600);
-            if(!$book_name){
-                $book_name = '';
-                $book_info = BookConfigService::getBookById($bid);
-                if($book_info && isset($book_info->book_name)){
-                    $book_name = $book_info->book_name;
-                }
-            }
-        }
-        return $book_name;
-    }
-
-    private function getAccessToken($appid){
-        $WechatController = new WechatController($appid);
-        $accessToken = $WechatController->app->access_token; // EasyWeChat\Core\AccessToken 实例
-        $token = $accessToken->getToken(); // token 字符串
-        return $token;
-    }
-
-    private function send(){
-        $client = new Client();
-        $requests = $this->generateRequest();
-        $pool = new Pool($client, $requests, [
-            'concurrency' => 25,
-            'fulfilled' => function ($response, $index) {
-            },
-            'rejected' => function ($reason, $index) {
-            },
-        ]);
-        $promise = $pool->promise();
-        $promise->wait();
-    }
-}

+ 0 - 312
app/Console/Commands/SmartPush/KeepContinueReadV3.php

@@ -1,312 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: z-yang
- * Date: 2020/6/8
- * Time: 17:41
- */
-
-namespace App\Console\Commands\SmartPush;
-
-use Illuminate\Console\Command;
-use DB;
-use Redis;
-use GuzzleHttp\Client;
-use App\Http\Controllers\WechatController;
-use GuzzleHttp\Psr7\Request as GuzzleRequest;
-use GuzzleHttp\Pool;
-use Hashids;
-use Log;
-
-/*
-继续阅读智能推送时间逻辑:
-
-遍历阅读后离开阅读器的用户,若3小时后未再次访问阅读器,需推送一条继续阅读智能推送消息
-
-若再过5小时后扔未访问,需推送第二条继续阅读智能推送消息
-
-若再过5小时后扔未访问,需推送第三条继续阅读智能推送消息
-
-若再过12小时后扔未访问,需推送第四条继续阅读智能推送消息
-
-若再过12小时后扔未访问,需推送第五条继续阅读智能推送消息
-
-期间任何一个时间节点遍历时若被打断,则重新开始计算
-*/
-class KeepContinueReadV3 extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'SmartPush:KeepContinueReadV3';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = '持续阅读推送';
-
-    private static $role = [0,3,5,5,12,12];
-
-    /**
-     * Create a new command instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        $str = str_random(32);
-        Log::info('KeepContinueReadV3 start at :'.date('Y-m-d H:i:s').',flag is :'.$str);
-        $this->send();
-        Log::info('KeepContinueReadV3 end at :'.date('Y-m-d H:i:s').',flag is :'.$str);
-    }
-
-    private function send(){
-        $client = new Client();
-        $channel_id = $this->getAllSite();
-        if(!$channel_id)  return ;
-        $requests = $this->start($channel_id);
-        $pool = new Pool($client, $requests, [
-            'concurrency' => 5,
-            'fulfilled' => function ($response, $index) {
-            },
-            'rejected' => function ($reason, $index) {
-
-            },
-        ]);
-        $promise = $pool->promise();
-        $promise->wait();
-    }
-
-    private function getAllSite(){
-        $info = DB::connection('api_mysql')->table('custom_msg_switchs')->where('custom_category','continue_read')->first();
-        if(!$info) return [];
-        $default_status = $info->default_switch_status;
-        $site_list = explode(',',redisEnv('INNER_SITE'));
-        $on_distribution_channel_id = [];
-        foreach ($site_list as $distribution_channel_id){
-            $switch_info = DB::connection('api_mysql')->table('custom_msg_switchs_msgs')
-                ->where('distribution_channel_id',$distribution_channel_id)
-                ->where('custom_category','continue_read')
-                ->select('status')
-                ->first();
-            if($switch_info){
-                $switch = $switch_info->status;
-            }else{
-                $switch = $default_status;
-            }
-            if($switch != 1) continue;
-            $on_distribution_channel_id[] = $distribution_channel_id;
-        }
-        return $on_distribution_channel_id;
-    }
-
-    private function start($distribution_channel_ids){
-        $temp = 0;
-        //$sites = $this->channelIds();
-        while (true){
-            $user =  DB::connection('api_mysql')->table('temp_force_subscribe_users')
-                ->select('id','uid','distribution_channel_id','openid','appid','last_interactive_time')
-                ->where('id','>',$temp)
-                ->whereIn('distribution_channel_id',$distribution_channel_ids)
-                ->orderBy('id')
-                ->limit(1000)
-                ->get();
-            if(!$user) break;
-            foreach ($user as $item){
-                $temp = $item->id;
-                if( (time() - strtotime($item->last_interactive_time)) > 2*86400 ) continue;
-                //if(!in_array($item->distribution_channel_id,$sites)) continue;
-                $read_info = $this->getReadRecord($item->uid);
-                if(empty($read_info['first']) || !isset($read_info['time']) || empty($read_info['time'])){
-                    continue;
-                }
-                $is_access = $this->isAccess($item->uid,$read_info['time'],$now_role,$is_first);
-                if(!$is_access) continue;
-                $access_token = $this->getAccessToken($item->appid);
-                if(!$access_token)continue;
-                $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_token;
-                $content = $this->content($item->uid,$item->distribution_channel_id,$read_info);
-                $request = new GuzzleRequest('post',$url,[],\GuzzleHttp\json_encode([
-                    'touser'=>$item->openid,
-                    'msgtype'=>'text',
-                    'text'=>['content'=>$content]
-                ],JSON_UNESCAPED_UNICODE));
-                if($is_first){
-                    DB::connection('api_mysql')->table('custom_push_keep_continue_v2')->where('uid',$item->uid)->update([
-                        'times'=>$now_role,
-                        'updated_at'=>date('Y-m-d H:i:s')
-                    ]);
-                }else{
-                    DB::connection('api_mysql')->table('custom_push_keep_continue_v2')->insert([
-                        'uid'=>$item->uid,
-                        'times'=>$now_role,
-                        'created_at'=>date('Y-m-d H:i:s'),
-                        'updated_at'=>date('Y-m-d H:i:s')
-                    ]);
-                }
-                yield $request;
-            }
-        }
-    }
-
-    private function isAccess($uid,$last_read_time,&$now_role,&$is_first){
-        //获取用户上次发送的规则
-        $prev_send_info = DB::connection('api_mysql')->table('custom_push_keep_continue_v2')->where('uid',$uid)->select('updated_at','times')->orderBy('id','desc')->first();
-        //上次发送规则
-        $last_role = 0;
-        $is_first = false;
-        $last_send_time = 0;
-        if($prev_send_info){
-            $is_first = true;
-            $last_role = $prev_send_info->times;
-            $last_send_time = strtotime($prev_send_info->updated_at);
-        }
-        $now_role = $last_role+1;
-        if($now_role == 6) $now_role = 1;
-        //上次更新时间,也就是上次发送时间
-
-        //第一次发送是根据用户离开阅读器的时间,即当前时间和用户上次阅读的时间比较是否查过规定的时间
-        if($now_role == 1){
-            if((time() - $last_read_time) < self::$role[$now_role] * 3600){
-                //小于发送时间
-                return false;
-            }
-            return true;
-        }
-        //是否到达检测时间,即上次发送时间加上当前规则所规定的时间,差距在半个小时以内就算到达
-        if(abs( time()-($last_send_time+self::$role[$now_role] * 3600)) > 1800){
-            //没有到达时间
-            return false;
-        }
-        //用户阅读时间是否符合条件
-        $time_diff = 0;
-        foreach (self::$role as $k=>$t){
-            if($k <= $now_role){
-                $time_diff += $t;
-            }
-        }
-        if( (time() - $last_read_time) >= $time_diff*3600){
-            //到了时间还是没阅读,就发送
-            return true;
-        }else{
-            //时间节点遍历时若被打断,则重新开始计算
-            DB::connection('api_mysql')->table('custom_push_keep_continue_v2')->where('uid',$uid)->update([
-                'times'=>0,
-                'updated_at'=>date('Y-m-d H:i:s')
-            ]);
-            return false;
-        }
-    }
-
-    private function content($uid,$distribution_channel_id,$read_info){
-        $domain = sprintf('https://site%s.%s.com',encodeDistributionChannelId($distribution_channel_id),
-            env('CUSTOM_HOST'));
-        $user_info = DB::connection('api_mysql')->table('users')->where('id',$uid)->select('nickname')->first();
-        $nickname = '读者';
-        if($user_info && $user_info->nickname)$nickname = $user_info->nickname;
-        $content_format = "@%s 为您推荐上次未看完的小说\r\n\r\n点击<a href='%s'>继续阅读</a>❤\r\n\r\n";
-        $content = sprintf($content_format,$nickname,$domain.$read_info['first']['url']);
-        if(!empty($read_info['seconds'])){
-            $content .=  "历史阅读记录:\r\n\r\n";
-            foreach ($read_info['seconds'] as $record_item){
-                $content .= sprintf(" 🌳 <a href='%s'>%s</a>\r\n",$domain.$record_item['url'],$record_item['book_name']);
-            }
-        }
-        $content .= "\r\n为了方便下次阅读,请<a href='http://cdn-pro.18yuedu.com/h5/top.html'>置顶公众号</a>";
-        return $content;
-    }
-
-    private function getAccessToken($appid){
-        try{
-            $WechatController = new WechatController($appid);
-            $accessToken = $WechatController->app->access_token; // EasyWeChat\Core\AccessToken 实例
-            $token = $accessToken->getToken(); // token 字符串
-            return $token;
-        }catch(\Exception $e){
-            \Log::error($e->getMessage());
-        }
-        return '';
-    }
-
-    private function getReadRecord($uid){
-        $records = Redis::hgetall('book_read:' . $uid);
-        $data = ['first'=>[],'seconds'=>[],'time'=>''];
-        foreach ($records as $k=>$item){
-            if($k == 'last_read'){
-                $record_arr = explode('_',$item);
-                $bid = $record_arr[0];
-                //$book_name = $this->bid2BookName($bid);
-                $bid = Hashids::encode($bid);
-                $cid = $record_arr[1];
-                $time = $record_arr[2];
-                $data['first'] = [
-                    'url' => '/reader?bid='.$bid.'&cid='.$cid.'&fromtype=continue_read_v2',
-                    'book_name'=>'',
-                ];
-                $data['time'] = $time;
-                continue;
-            }
-            if(!is_numeric($k)) continue;
-            $record = explode('_', $item);
-            $latest_read_cid = $record[0];
-            $book_name = self::bid2BookName($k);
-            $latest_read_time = $record[count($record) - 1];
-            $data['seconds'][] =[
-                'url' => '/reader?bid='.Hashids::encode($k).'&cid='.$latest_read_cid.'&fromtype=continue_read_v2',
-                'book_name'=>$book_name,
-                'time'=>$latest_read_time
-            ];
-        }
-        $temp = $data['seconds'];
-        if($temp){
-            usort($temp, function ($a, $b) {
-                if ($a['time'] >= $b['time']) return -1;
-                return 1;
-            });
-        }
-        $temp_res = [];
-        foreach ($temp as $k=>$it){
-            $temp_res[] = $it;
-            if($k>=2) break;
-        }
-        $data['seconds'] = $temp_res;
-        return $data;
-    }
-    private  function bid2BookName($bid){
-        $book_name = null;
-        if(is_null($book_name)){
-            $book_key = 'wap:string:book:'.$bid;
-            $book_name = Redis::get($book_key);
-            Redis::EXPIRE($book_key,3600);
-            if(!$book_name){
-                $book_name = '';
-                $book_info = DB::connection('api_mysql')->table('book_configs')->where('bid',$bid)->select('book_name')->first();
-                //$book_info = BookConfigService::getBookById($bid);
-                if($book_info && isset($book_info->book_name)){
-                    $book_name = $book_info->book_name;
-                    Redis::setex($book_key,3600,$book_name);
-                }
-            }
-        }
-        return $book_name;
-    }
-
-    private function channelIds(){
-        $str = '5,123,14,13,8';
-        return explode(',',$str);
-    }
-}

+ 0 - 327
app/Console/Commands/SmartPush/RfmPush.php

@@ -1,327 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: z-yang
- * Date: 2020/8/13
- * Time: 11:44
- */
-
-namespace App\Console\Commands\SmartPush;
-
-use App\Modules\Order\Models\Order;
-use App\Modules\OfficialAccount\Models\ForceSubscribeUsers;
-use App\Modules\User\Services\UserService;
-use Illuminate\Console\Command;
-use DB;
-use Redis;
-use GuzzleHttp\Client;
-use App\Http\Controllers\WechatController;
-use GuzzleHttp\Psr7\Request as GuzzleRequest;
-use GuzzleHttp\Pool;
-
-class RfmPush extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'SmartPush:RfmPush {--type=} {--time=}';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = '签到提醒';
-
-    /**
-     * Create a new command instance.
-     *
-     * @return void
-     */
-
-    private $user;
-
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    private $Level = [
-        'new_user_activity_sm'=>['222','212','122','112'],
-        'new_user_activity_bm'=>['212','122','112'],
-        'new_user_activity_for_free'=>['000']
-    ];
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        $type = $this->option('type');
-        $time = $this->option('time');
-        if(!$type || !$time) return ;
-        $client = new Client();
-        $this->getUser($time);
-        if(!$this->user) return ;
-        if($type == 'sm' || $type == 'bm'){
-            $requests = $this->newUserSmAndBm();
-            if($requests){
-                $pool = new Pool($client, $requests, ['concurrency' => 5,
-                    'fulfilled' => function ($response, $index) {},
-                    'rejected' => function ($reason, $index) {},
-                ]);
-                $promise = $pool->promise();
-                $promise->wait();
-            }
-        }
-
-        if($type == 'all'){
-            $requests =$this->newUserAll();
-            if($requests){
-                $pool = new Pool($client, $requests, ['concurrency' => 5,
-                    'fulfilled' => function ($response, $index) {},
-                    'rejected' => function ($reason, $index) {},
-                ]);
-                $promise = $pool->promise();
-                $promise->wait();
-            }
-        }
-        if($type == 'free-24'){
-            $requests =$this->newUserFree();
-            if($requests){
-                $pool = new Pool($client, $requests, ['concurrency' => 5,
-                    'fulfilled' => function ($response, $index) {},
-                    'rejected' => function ($reason, $index) {},
-                ]);
-                $promise = $pool->promise();
-                $promise->wait();
-            }
-        }
-        if($type == 'free-36'){
-            $requests =$this->newUserFreeSmall();
-            if($requests){
-                $pool = new Pool($client, $requests, ['concurrency' => 5,
-                    'fulfilled' => function ($response, $index) {},
-                    'rejected' => function ($reason, $index) {},
-                ]);
-                $promise = $pool->promise();
-                $promise->wait();
-            }
-        }
-    }
-
-
-    private function newUserFree(){
-        $user = $this->user;
-        foreach ($user as $item){
-            $charge = Order::where('uid',$item->uid)->where('status','PAID')->count();
-            if($charge) continue;
-            $force_subscribe_info = DB::connection('api_mysql')->table('temp_force_subscribe_users')
-                ->where('uid',$item->uid)->where('is_subscribed',1)->select('appid','openid','distribution_channel_id')->first();
-            if(!$force_subscribe_info) continue;
-            $accecc_token = $this->getAccessToken($force_subscribe_info->appid);
-            if(!$accecc_token)continue;
-            $status = $this->isAccess($item->uid,'new_user_activity_for_free',$distribution_channel_id);
-            if($status){
-                $content = $this->newUserActivityBmContent($force_subscribe_info->distribution_channel_id);
-                $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$accecc_token;
-                $request = new GuzzleRequest('post',$url,[],\GuzzleHttp\json_encode([
-                    'touser'=>$force_subscribe_info->openid,
-                    'msgtype'=>'text',
-                    'text'=>['content'=>$content]
-                ],JSON_UNESCAPED_UNICODE));
-                yield $request;
-            }
-        }
-    }
-
-    private function newUserFreeSmall(){
-        $user = $this->user;
-        foreach ($user as $item){
-            $charge = Order::where('uid',$item->uid)->where('status','PAID')->count();
-            if($charge) continue;
-            $force_subscribe_info = DB::connection('api_mysql')->table('temp_force_subscribe_users')
-                ->where('uid',$item->uid)->where('is_subscribed',1)->select('appid','openid','distribution_channel_id')->first();
-            if(!$force_subscribe_info) continue;
-            $accecc_token = $this->getAccessToken($force_subscribe_info->appid);
-            if(!$accecc_token)continue;
-            $status = $this->isAccess($item->uid,'new_user_activity_for_free',$distribution_channel_id);
-            if($status){
-                $content = $this->newUserAllContent($force_subscribe_info->distribution_channel_id);
-                $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$accecc_token;
-                $request = new GuzzleRequest('post',$url,[],\GuzzleHttp\json_encode([
-                    'touser'=>$force_subscribe_info->openid,
-                    'msgtype'=>'text',
-                    'text'=>['content'=>$content]
-                ],JSON_UNESCAPED_UNICODE));
-                yield $request;
-            }
-        }
-    }
-
-    //新用户大礼包-全量用户
-    private function newUserAll(){
-        $user = $this->user;
-        foreach ($user as $item){
-            $charge = Order::where('uid',$item->uid)->where('status','PAID')->count();
-            if($charge) continue;
-            $force_subscribe_info = DB::connection('api_mysql')->table('temp_force_subscribe_users')
-                ->where('uid',$item->uid)->where('is_subscribed',1)->select('appid','openid','distribution_channel_id')->first();
-            if(!$force_subscribe_info) continue;
-            $accecc_token = $this->getAccessToken($force_subscribe_info->appid);
-            if(!$accecc_token)continue;
-            $content = $this->newUserAllContent($force_subscribe_info->distribution_channel_id);
-            $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$accecc_token;
-            $request = new GuzzleRequest('post',$url,[],\GuzzleHttp\json_encode([
-                'touser'=>$force_subscribe_info->openid,
-                'msgtype'=>'text',
-                'text'=>['content'=>$content]
-            ],JSON_UNESCAPED_UNICODE));
-            yield $request;
-        }
-    }
-
-    private function getUser($time){
-        $s_time = $time+0.5;
-        $b_time = $time-0.5;
-        $user = DB::connection('api_mysql')->table('rfm_ab_test_user')
-            ->where('created_at','>=',date('Y-m-d H:i:s',time()-$s_time*3600))
-            ->where('created_at','<=',date('Y-m-d H:i:s',time()-$b_time*3600))
-            ->where('type','B')
-            ->select('uid','created_at')
-            ->get();
-        if(!$user){
-            $this->user = null;
-            return ;
-        }
-        $this->user = $user;
-    }
-
-    //新用户大礼包-小M值用户   新用户大礼包-大M值用户
-    private function newUserSmAndBm(){
-        $user = $this->user;
-        foreach ($user as $item){
-            $charge = Order::where('uid',$item->uid)->where('status','PAID')->count();
-            if($charge) continue;
-            $force_subscribe_info = DB::connection('api_mysql')->table('temp_force_subscribe_users')
-                ->where('uid',$item->uid)->where('is_subscribed',1)->select('appid','openid','distribution_channel_id')->first();
-            if(!$force_subscribe_info) continue;
-            $status = $this->isAccessSmAndBm($item->uid,$distribution_channel_id);
-            $accecc_token = $this->getAccessToken($force_subscribe_info->appid);
-            if(!$accecc_token)continue;
-            if($status['new_user_activity_sm']){
-                $content = $this->newUserActivitySmContent($force_subscribe_info->distribution_channel_id);
-                $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$accecc_token;
-                $request = new GuzzleRequest('post',$url,[],\GuzzleHttp\json_encode([
-                    'touser'=>$force_subscribe_info->openid,
-                    'msgtype'=>'text',
-                    'text'=>['content'=>$content]
-                ],JSON_UNESCAPED_UNICODE));
-                yield $request;
-            }
-            if($status['new_user_activity_bm']){
-                $content = $this->newUserActivityBmContent($force_subscribe_info->distribution_channel_id);
-                $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$accecc_token;
-                $request = new GuzzleRequest('post',$url,[],\GuzzleHttp\json_encode([
-                    'touser'=>$force_subscribe_info->openid,
-                    'msgtype'=>'text',
-                    'text'=>['content'=>$content]
-                ],JSON_UNESCAPED_UNICODE));
-                yield $request;
-            }
-        }
-    }
-
-
-    private function isAccessSmAndBm($uid,&$distribution_channel_id){
-        $sql = 'select id,created_at,distribution_channel_id from users WHERE  openid = (SELECT  openid FROM  users WHERE  id = '.$uid.')';
-        $result = DB::connection('api_mysql')->select($sql);
-        $return_status = [
-            'new_user_activity_sm'=>false,
-            'new_user_activity_bm'=>false
-        ];
-        foreach ($result as $item){
-            if($item->id == $uid) {
-                $distribution_channel_id = $item->distribution_channel_id;
-                continue;
-            }
-            if($return_status['new_user_activity_sm'] && $return_status['new_user_activity_bm']){
-                return $return_status;
-            }
-            $this_user_level = UserService::rfmLevel($item->id,strtotime($item->created_at));
-            if($this_user_level){
-                $this_user_level_text = implode('',$this_user_level);
-                if(in_array($this_user_level_text,$this->Level['new_user_activity_sm'])){
-                    $return_status['new_user_activity_sm'] = true;
-                }
-                if(in_array($this_user_level_text,$this->Level['new_user_activity_bm'])){
-                    $return_status['new_user_activity_bm'] = true;
-                }
-            }
-        }
-        return $return_status;
-    }
-
-    private function isAccess($uid,$k,&$distribution_channel_id){
-        $sql = 'select id,created_at,distribution_channel_id from users WHERE  openid = (SELECT  openid FROM  users WHERE  id = '.$uid.')';
-        $result = DB::connection('api_mysql')->select($sql);
-        foreach ($result as $item){
-            if($item->id == $uid) {
-                $distribution_channel_id = $item->distribution_channel_id;
-                continue;
-            }
-            $this_user_level = UserService::rfmLevel($item->id,strtotime($item->created_at));
-            if($this_user_level){
-                $this_user_level_text = implode('',$this_user_level);
-                if(in_array($this_user_level_text,$this->Level[$k])){
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-
-    private function newUserActivitySmContent($distribution_channel_id){
-        $text = "您的新用户专享礼包已送达\r\n\r\n充19.9得4000书币,充38得8800书币,只有一次机会哦!\r\n\r\n过期失效,不要错过!\r\n\r\n<a href='%s'>点击立即领取>></a>\r\n\r\n为方便下次阅读,请<a href='%s'>置顶公众号</a>";
-        $link_format = 'https://site%s.%s.com/activity/rfmNUSm?send_time='.time();
-        $link = sprintf($link_format,encodeDistributionChannelId($distribution_channel_id),env('CUSTOM_HOST'));
-        $top = 'https://help.zhuishuyun.com/top.html';
-        return sprintf($text,$link,$top);
-    }
-
-    private function newUserActivityBmContent($distribution_channel_id){
-        $text = "您的新用户专享礼包已送达\r\n\r\n <a href='%s'>优惠充值特惠</a> \r\n\r\n过期失效,不要错过!\r\n\r\n<a href='%s'>点击立即领取>></a>\r\n\r\n为方便下次阅读,请<a href='%s'>置顶公众号</a>";
-        $link_format = 'https://site%s.%s.com/sale/newUserSale?send_time='.time();
-        $link = sprintf($link_format,encodeDistributionChannelId($distribution_channel_id),env('CUSTOM_HOST'));
-        $top = 'https://help.zhuishuyun.com/top.html';
-        return sprintf($text,$link,$link,$top);
-    }
-
-    private function newUserAllContent($distribution_channel_id){
-        $text = "您的新用户专享礼包已送达\r\n\r\n充9.9得2000书币,只有一次机会哦!\r\n\r\n过期失效,不要错过!\r\n\r\n<a href='%s'>点击立即领取>></a>\r\n\r\n为方便下次阅读,请<a href='%s'>置顶公众号</a>";
-        $link_format = 'https://site%s.%s.com/sale/newUserActivity?send_time='.time();
-        $link = sprintf($link_format,encodeDistributionChannelId($distribution_channel_id),env('CUSTOM_HOST'));
-        $top = 'https://help.zhuishuyun.com/top.html';
-        return sprintf($text,$link,$top);
-    }
-
-    private function getAccessToken($appid){
-        try{
-            $WechatController = new WechatController($appid);
-            $accessToken = $WechatController->app->access_token; // EasyWeChat\Core\AccessToken 实例
-            $token = $accessToken->getToken(); // token 字符串
-            return $token;
-        }catch(\Exception $e){
-            \Log::error($e->getMessage());
-        }
-        return '';
-    }
-
-
-
-}

+ 35 - 0
app/Console/Commands/Test.php

@@ -0,0 +1,35 @@
+<?php
+
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class Test extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'test';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+
+    /**
+     * @return bool
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function handle()
+    {
+       
+
+    }
+
+}

+ 0 - 115
app/Console/Commands/Test3.php

@@ -1,115 +0,0 @@
-<?php
-
-
-namespace App\Console\Commands;
-
-
-use App\Modules\OfficialAccount\Services\CustomMsgService;
-use App\Modules\WechatMaterial\Models\BatchWechatMaterial;
-use App\Modules\WechatMaterial\Models\WechatMaterial;
-use App\Modules\WechatMaterial\Models\WechatMaterialSendMsg;
-use Illuminate\Console\Command;
-
-class Test3 extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'test:3 {appId} {channelId} {batchId}';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'Command description';
-
-    private $_task = 'ActionTrigger:sync_zs_wechat_material ';
-
-    /**
-     * @return bool
-     * @throws \GuzzleHttp\Exception\GuzzleException
-     */
-    public function handle()
-    {
-        [$appId, $batchId, $channelId] = [$this->argument('appId'), $this->argument('batchId'), $this->argument('channelId')];
-
-        // 获取参数
-        if (!$appId || !$batchId || !$channelId) {
-            return false;
-        }
-
-        // 获取msg信息,未查询到数据或者media_id已存在则不再继续往下执行
-        $msgInfo = WechatMaterialSendMsg::getMsgByAppBatchChannelId($appId, $batchId, $channelId);
-        \Log::info($this->_task . 'msgInfo');
-        \Log::info($msgInfo);
-        if (!$msgInfo) {
-            return false;
-        }
-
-        // 获取素材数据
-        $materials = WechatMaterial::getWeChatMaterials($batchId);
-        $materials = $materials ? $materials->toArray() : [];
-        \Log::info($this->_task . 'materials_ids');
-        \Log::info(array_column($materials, 'id'));
-        if (!$materials) {
-            return false;
-        }
-
-        // 筛选出内容中的所有图片
-        $contents = implode(',', array_column($materials, 'content'));
-        $images   = CustomMsgService::extract_content_images($contents);
-        \Log::info($this->_task . 'extract_content_image_urls');
-        \Log::info($images);
-
-        // 上传内容中的图片,替换内容中图片链接
-        $upImagesRes = CustomMsgService::multi_upload_material_imgs($appId, $images);
-        [$oldUrls, $newUrls] = [array_column($upImagesRes['urls'], 'old_url'), array_column($upImagesRes['urls'], 'new_url')];
-        $materials = CustomMsgService::replace_content_images($materials, $oldUrls, $newUrls);
-
-        dd($images, $upImagesRes, $oldUrls, $newUrls, $materials);
-
-        // 批量上传缩略图
-        $thumbImages = array_column($materials, 'cover_url');
-        $upThumbsRes = CustomMsgService::multi_upload_material_imgs($appId, $thumbImages, 'thumb');
-
-        // 上传article
-        $upArticleRes = CustomMsgService::upload_articles($channelId, $msgInfo, $materials, $upThumbsRes['urls']);
-        $wxMediaId    = getProp($upArticleRes['data'], 'media_id');
-        if ($wxMediaId) {
-            // 更新media_id
-            WechatMaterialSendMsg::where('id', getProp($msgInfo, 'id'))->update([
-                'wechat_media_id' => $wxMediaId,
-                'upload_result'   => json_encode([
-                    'up_images'   => $upImagesRes['urls'],
-                    'up_thumbs'   => $upThumbsRes['urls'],
-                    'up_articles' => $upArticleRes
-                ]),
-                'status'          => 'push_wechat_material',
-                'updated_at'      => date('Y-m-d H:i:s')
-            ]);
-
-            // 更新batch同步状态
-            BatchWechatMaterial::where('id', $batchId)->update([
-                'status'     => 'push_wechat_material',
-                'updated_at' => date('Y-m-d H:i:s')
-            ]);
-        } else {
-            $msg = 'upload fail';
-            if ($upArticleRes && !$upArticleRes['code']) $msg = $upArticleRes['msg'];
-            if (getProp($upThumbsRes['error'], 'thumb')) $msg = getProp($upThumbsRes['error'], 'thumb');
-            if (getProp($upImagesRes['error'], 'common')) $msg = getProp($upImagesRes['error'], 'common');
-
-            // 更新上传结果
-            WechatMaterialSendMsg::where('id', getProp($msgInfo, 'id'))->update([
-                'upload_result' => $msg,
-                'status'        => 'fail_push_wechat_material',
-                'updated_at'    => date('Y-m-d H:i:s')
-            ]);
-        }
-
-    }
-
-}

+ 0 - 166
app/Console/Commands/test2.php

@@ -1,166 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use GuzzleHttp\Client;
-use Illuminate\Console\Command;
-use Redis;
-use WechatOP;
-use DB;
-
-class test2 extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'test:test3';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'Command description';
-
-    /**
-     * Create a new command instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        parent::__construct();
-        $this->appId='wx1037462ad78bf1f2';
-        $this->appSecret='d6bda51bfdb4cf6eb504c622fd72c210';
-    }
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        $this->fix();
-    }
-
-    private function  https_request($url, $data = null, $timeout = 5000)
-    {
-        $curl = curl_init();
-        curl_setopt($curl, CURLOPT_URL, $url);
-        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
-        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
-        if (! empty($data)) {
-            curl_setopt($curl, CURLOPT_POST, 1);
-            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
-        }
-        if ($timeout) {
-            curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
-        }
-
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
-        $output = curl_exec($curl);
-        if ($output === false) {
-            \Log::error('Curl error: ' . curl_error($curl).". url:".$url);
-        }
-
-        curl_close($curl);
-        return $output;
-    }
-
-    public function getToken($is_force = true )
-    {
-
-        $appId = $this->appId;
-        $appSecret = $this->appSecret;
-        $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appId . '&secret=' . $appSecret;
-        $rs1 = $this->https_request($url);
-        \Log::info(($this->appId).'get_token-'.$rs1);
-        if ($rs1)
-        {
-            $rs = json_decode($rs1, true);
-            if (is_array($rs) && $rs['access_token'])
-            {
-                $access_token = $rs['access_token'];
-                $expires_in = intval($rs['expires_in'], 10);
-                if ($expires_in <= 0)
-                {
-                    $expires_in = 5;
-                } else if ($expires_in >= 7200)
-                {
-                    $expires_in = 7000;
-                }
-
-                $data = array();
-                $data['expire_time'] = time() + $expires_in;
-                $data['access_token'] = $access_token;
-
-                Redis::setex(($this->appId).'access_token', $expires_in, serialize($data));
-                return $access_token;
-            } else
-            {
-                $content = "get access token error:" . $rs1;
-                \Log::info(($this->appId).$content);
-            }
-        } else
-        {
-            $content = "get access token error:" . $rs1;
-            \Log::info(($this->appId).$content);
-        }
-
-        return false;
-    }
-
-    //修复crm用户昵称问题
-    public function fix()
-    {
-        
-        $uids = collect(DB::select("select distinct uid from yueduyun.user_bind_hk_welfare
- where not exists(select 1 from zsy_crm.crm_users where uid = yueduyun.user_bind_hk_welfare.uid)"))->pluck('uid');//->map(function ($user){ return $user->id;});
-        $sub_users = DB::table('yueduyun.force_subscribe_users')->whereIn('uid',$uids)->where('is_subscribed',1)->get();
-        $time = date("Y-m-d H:i:s");
-        foreach($sub_users as $sub_user)
-        {
-            $appid = $sub_user->appid;
-            $openid = $sub_user->openid;
-            $redis_key = '[wechat_op.common.component_refresh_token.'.$appid.']';
-            $component_refresh_token = Redis::Get($redis_key);
-
-            $options = [
-                'app_id'    => $appid,
-                'secret'    => env('WECHAT_OP_SECRET'),   // 仅适用于 单独配置公众号
-                'token'     => env('WECHAT_OP_TOKEN'),   // 仅适用于 单独配置公众号
-                'aes_key'   => env('WECHAT_OP_AES_KEY'),   // 仅适用于 单独配置公众号
-                'auth_type' => 'COMPONENT', // COMPONENT 开放平台授权公众号,MANUAL 单独配置公众号
-                'component_refresh_token' => $component_refresh_token,   // 授权回调时获取的 authorizer_refresh_token,仅适用于 开放品台授权公众号
-                'oauth'     => [
-                    'scopes' => ['snsapi_base'], // 公众号授权用户方式 snsapi_base, snsapi_userinfo
-                    'callback' => '/oauth_callback',
-                ],
-                'cache'   => [
-                    'driver' => 'redis',   // redis, filesystem, laravel
-                    'dir' => storage_path('tmp') // 只有为filesystem时候这个目录才有效
-                ],
-            ];
-            try{
-                $app = WechatOP::app($options);
-
-                $user_data = $app->user->get($openid);
-                if(isset($user_data))
-                {
-                    //DB::table('yueduyun.users')->where('id',$sub_user->uid)->update(['nickname'=>$user_data->nickname]);
-                    DB::connection('command_mysql')->table('zsy_crm.crm_users')->insert(['uid'=>$sub_user->uid,'nickname'=>$user_data->nickname,'created_at'=>$time,'updated_at'=>$time]);
-                }
-
-                dump($user_data);
-            }catch (\Exception $e){
-                dump($e->getMessage());
-            };
-
-
-        }
-    }
-}
-

+ 0 - 92
app/Console/Commands/test_queue.php

@@ -1,92 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use Illuminate\Console\Command;
-use PhpAmqpLib\Connection\AMQPStreamConnection;
-use PhpAmqpLib\Message\AMQPMessage;
-define('HOST', '120.55.25.252');
-define('PORT', 5672);
-define('USER', 'test');
-define('PASS', '6acbQWE13');
-define('VHOST', '/');
-//If this is enabled you can see AMQP output on the CLI
-define('AMQP_DEBUG', true);
-
-class test_queue extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'command:tqueue';
-
-    /**
-     * The console command description.
-     *
-     * @var string
-     */
-    protected $description = 'tqueue';
-
-    /**
-     * Create a new command instance.
-     *
-     * @return void
-     */
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    /**
-     * Execute the console command.
-     *
-     * @return mixed
-     */
-    public function handle()
-    {
-        echo 'publish';
-    	$this->exchange = 'router';
-    	$this->queue = 'msg';
-    	$connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);
-    	$channel = $connection->channel();
-    	echo $channel;
-    	/*
-    	 The following code is the same both in the consumer and the producer.
-    	In this way we are sure we always have a queue to consume from and an
-    	exchange where to publish messages.
-    	*/
-    	/*
-    	 name: $queue
-    	passive: false
-    	durable: true // the queue will survive server restarts
-    	exclusive: false // the queue can be accessed in other channels
-    	auto_delete: false //the queue won't be deleted once the channel is closed.
-    	*/
-    	$channel->queue_declare($this->queue, false, true, false, false);
-    	/*
-    	 name: $exchange
-    	type: direct
-    	passive: false
-    	durable: true // the exchange will survive server restarts
-    	auto_delete: false //the exchange won't be deleted once the channel is closed.
-    	*/
-    	$channel->exchange_declare($exchange, 'direct', false, true, false);
-    	$channel->queue_bind($queue, $exchange);
-    	
-    	// $messageBody = implode(' ', array_slice($argv, 1));
-    	$messageBody = 'msg1';
-    	$options = getopt("f:hp:");
-    	var_dump('$options');
-    	var_dump($options);
-    	
-    	$message = new AMQPMessage($messageBody, array('content_type' => 'text/plain', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT));
-    	
-    	$channel->basic_publish($message, $exchange);
-    	$channel->close();
-    	$connection->close();
-        
-    }
-
-}

+ 3 - 36
app/Console/Kernel.php

@@ -14,11 +14,8 @@ class Kernel extends ConsoleKernel
      */
     protected $commands = [
         Commands\Inspire::class,
-        Commands\test2::class,
-        Commands\Test3::class,
-        Commands\SmartPush\KeepContinueRead::class,
+        Commands\Test::class,
         Commands\SmartPush\KeepContinueReadV2::class,
-        Commands\SmartPush\KeepContinueReadV3::class,
         Commands\GZH\FansStat::class,
         Commands\GZH\ForceUserProperty::class,
         Commands\Wechat\AdReport::class,
@@ -30,7 +27,6 @@ class Kernel extends ConsoleKernel
         Commands\SmartPush\ForceSubscribeDelayMsg::class,
         Commands\SmartPush\CouponExpirePush::class,
         Commands\BatchWechatMaterial\SyncWechatMaterialStatistics::class,
-        Commands\SmartPush\RfmPush::class,
         //更新推送
         Commands\SmartPush\BookUpdatePush::class,
 
@@ -59,8 +55,6 @@ class Kernel extends ConsoleKernel
     protected function schedule(Schedule $schedule)
     {
 
-        $schedule->command('SmartPush:KeepContinueReadV3')->cron('02 7-23 * * *');
-
         $schedule->command('SmartPush:KeepContinueReadV2')->cron('06 7-23 * * *');
 
         //拉取公众号后台粉丝数据
@@ -78,21 +72,7 @@ class Kernel extends ConsoleKernel
         //$schedule->command('Wechat:ReportRetry')->hourly();
 
         //未签到提醒
-        $schedule->command('SmartPush:remindSign --start=0 --end=70000000')->dailyAt('08:01');
-        $schedule->command('SmartPush:remindSign --start=70000000 --end=100000000')->dailyAt('08:03');
-        $schedule->command('SmartPush:remindSign --start=100000000 --end=118000000')->dailyAt('08:05');
-        $schedule->command('SmartPush:remindSign --start=118000000 --end=126000000')->dailyAt('08:07');
-        $schedule->command('SmartPush:remindSign --start=126000000 --end=132000000')->dailyAt('08:09');
-        $schedule->command('SmartPush:remindSign --start=132000000 --end=136000000')->dailyAt('08:11');
-        $schedule->command('SmartPush:remindSign --start=136000000 --end=139000000')->dailyAt('08:13');
-        $schedule->command('SmartPush:remindSign --start=139000000 --end=140700000')->dailyAt('08:14');
-        $schedule->command('SmartPush:remindSign --start=140700000 --end=141150000')->dailyAt('08:14');
-        $schedule->command('SmartPush:remindSign --start=141150000 --end=141270000')->dailyAt('08:15');
-        $schedule->command('SmartPush:remindSign --start=141270000 --end=141400000')->dailyAt('08:16');
-        $schedule->command('SmartPush:remindSign --start=141400000 --end=141550000')->dailyAt('08:17');
-        $schedule->command('SmartPush:remindSign --start=141550000 --end=141750000')->dailyAt('08:18');
-        $schedule->command('SmartPush:remindSign --start=141550000 --end=141680000')->dailyAt('08:19');
-        $schedule->command('SmartPush:remindSign --start=141680000 --end=-1')->dailyAt('08:21');
+        $schedule->command('SmartPush:remindSign --start=0 --end=7000000')->dailyAt('08:01');
 
 
         $schedule->command('UpdateHighQualityBooks')->hourly();
@@ -102,23 +82,10 @@ class Kernel extends ConsoleKernel
         //$schedule->command('SmartPush:ForceSubscribeDelayMsg')->everyFiveMinutes();
         $schedule->command('SmartPush:ForceSubscribeDelayMsg')->cron('*/2 * * * *');
 
-
         //微信批量素材
         $schedule->command('BatchWechatMaterial:SendCustomWechatMaterial')->everyFiveMinutes();
 
-        //rfm 推送*******************************
-        //新用户大礼包-小M值用户
-        $schedule->command('SmartPush:RfmPush --type=sm  --time=4')->cron('*/59 * * * *');
-        //新用户大礼包-大M值用户
-        $schedule->command('SmartPush:RfmPush --type=bm  --time=23')->cron('*/58 * * * *');
-        //新用户大礼包-全量用户
-        $schedule->command('SmartPush:RfmPush --type=all  --time=23')->cron('*/57 * * * *');
-        //新用户大礼包-免费用户
-        $schedule->command('SmartPush:RfmPush --type=free-24  --time=24')->cron('*/56 * * * *');
-        //新用户大礼包-免费用户
-        $schedule->command('SmartPush:RfmPush --type=free-24  --time=36')->cron('*/55 * * * *');
-
         //更新推送
-        $schedule->command('SmartPush:BookUpdatePush')->cron('*/6 * * * *');
+        //$schedule->command('SmartPush:BookUpdatePush')->cron('*/6 * * * *');
     }
 }

+ 2 - 1
app/Http/Controllers/Wechat/OfficialAccount/OfficialInteractiveEventController.php

@@ -217,7 +217,8 @@ class OfficialInteractiveEventController extends Controller
                 $booksInfo = BookConfig::getBooksByKey($content, 1);
                 try {
                     if (count($booksInfo) == 0) {
-                        $role_book = BookConfig::getFromRole($content);
+                        //$role_book = BookConfig::getFromRole($content);
+                        $role_book = BookConfigService::getBookByRole($content);
                         if ($role_book) {
                             $booksInfo[] = [
                                 'book_name' => $role_book->book_name,

+ 7 - 0
app/Modules/Book/Models/BookConfig.php

@@ -1244,4 +1244,11 @@ class BookConfig extends Model
         \Log::info('last_bids:' . json_encode($last_bids));
         return [$last_bids, $test_bid];
     }
+
+    //获取图书
+    public static function getSimpleBooksByIds($bids)
+    {
+        $fields = ['book_name','bid','cover'];
+        return self::select($fields)->whereIn('bid',$bids)->where('is_on_shelf',2)->order('id','desc')->get();
+    }
 }

+ 18 - 0
app/Modules/Book/Models/BookRole.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Modules\Book\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+class BookRole extends Model
+{
+    protected $connection = 'api_mysql';
+
+    protected $table = 'book_roles';
+
+    public static function getBidByRole($role)
+    {
+        return self::where('role',$role)->get()->plcuk('bid');
+    }
+}

+ 19 - 0
app/Modules/Book/Services/BookConfigService.php

@@ -10,6 +10,7 @@ namespace App\Modules\Book\Services;
 
 
 use App\Modules\Book\Models\BookConfig;
+use App\Modules\Book\Models\BookRole;
 use App\Modules\Product\Services\ProductService;
 use App\Modules\Book\Models\Book;
 use Redis;
@@ -31,6 +32,24 @@ class BookConfigService
     }
 
     /**
+     * 获取角色图书
+     */
+    public static function getBookByRole($role)
+    {
+        $book = [];
+        if($role)
+        {
+            $bids = BookRole::getBidByRole($role);
+            if($bids)
+            {
+                $books = BookConfig::getSimpleBooksByIds($bids);
+                $books && $book = array_shift($books);
+            }
+        }
+        return $book;
+    }
+
+    /**
      * 根据bid数组获取多本图书
      * @param $where
      * @param null $order

+ 0 - 1
public/1492985165.txt

@@ -1 +0,0 @@
-7bb0d655c5be9b491a86548a3ee55c0c

+ 0 - 1
public/5756267817.txt

@@ -1 +0,0 @@
-63d6a3d0654aa0e21e279cd4fb422398

+ 0 - 1
public/MP_verify_llzpVQoJadKcUCRR.txt

@@ -1 +0,0 @@
-llzpVQoJadKcUCRR

TEMPAT SAMPAH
public/favicon.ico


+ 1 - 26
readme.md

@@ -1,27 +1,2 @@
-## Laravel PHP Framework
+# wangdu_modify_wechat
 
-[![Build Status](https://travis-ci.org/laravel/framework.svg)](https://travis-ci.org/laravel/framework)
-[![Total Downloads](https://poser.pugx.org/laravel/framework/d/total.svg)](https://packagist.org/packages/laravel/framework)
-[![Latest Stable Version](https://poser.pugx.org/laravel/framework/v/stable.svg)](https://packagist.org/packages/laravel/framework)
-[![Latest Unstable Version](https://poser.pugx.org/laravel/framework/v/unstable.svg)](https://packagist.org/packages/laravel/framework)
-[![License](https://poser.pugx.org/laravel/framework/license.svg)](https://packagist.org/packages/laravel/framework)
-
-Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, queueing, and caching.
-
-Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.
-
-## Official Documentation
-
-Documentation for the framework can be found on the [Laravel website](http://laravel.com/docs).
-
-## Contributing
-
-Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions).
-
-## Security Vulnerabilities
-
-If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.
-
-### License
-
-The Laravel framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)