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