123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- <?php
- namespace App\Console\Commands\Notices;
- use App\Services\NoticeService\Channels\WeChatTemplateChannel;
- use Illuminate\Console\Command;
- class SyjCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'notice:syj {notice}';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '时遇记营销通知';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- public const PUBLIC_ID = 'gh_c94c95866ca5';
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- //
- $notice = $this->argument('notice');
- \DB::connection()->enableQueryLog(); // 开启查询日志
- switch ($notice) {
- case 'a':
- dump($this->pair1());
- break;
- case 'b':
- dump($this->pair2());
- break;
- case 'c':
- dump($this->card1());
- break;
- case 'd':
- dump($this->card2());
- break;
- case 'e':
- dump($this->card3());
- break;
- }
- $queries = \DB::getQueryLog(); // 获取查询日志
- dump($queries);
- }
- // 关注公众号、有手机号,未参与过活动的
- public function pair1()
- {
- $title = '老用户召回syj-活动召回';
- if (
- \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->where('date', date("Y-m-d"))
- ->count() >= 3000
- ) {
- return false;
- }
- // 过滤发送过的人
- $filter_users = \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->distinct()
- ->pluck('openid');
- $users = \DB::table('kddx_user_openid as o')
- ->select('o.openid', 'o.sex')
- ->join('kdgx_partner_charge_user as u', 'u.uid', '=', 'o.uid')
- ->where('o.public_id', self::PUBLIC_ID)
- ->where('o.subscribe', 1)
- ->whereNotNull('u.phone')
- ->whereRaw(" u.`uid` NOT IN( SELECT DISTINCT(`uid`) FROM `kdgx_partner_charge_pair`) ")
- ->whereNotIn('o.openid', $filter_users)
- ->orderBy('o.id', 'asc')
- ->limit(rand(1, 5))
- ->get();
- foreach ($users as $user) {
- $ta = ($user->sex == 2) ? '小哥哥' : '小姐姐';
- $templates = [
- [
- 'template_id' => 'y-SOmy9b5AaN_h652VXw0zWr6E9vKiAojWN0JhJq7-E',
- 'data' => [
- 'first' => [
- 'value' => "你收到一条约会邀请,有{$ta}邀请你谈一场72小时的恋爱!",
- ],
- 'keyword1' => [
- 'value' => '72小时恋爱体验',
- ],
- 'keyword2' => [
- 'value' => '约会邀请',
- ],
- 'keyword4' => [
- 'value' => date('Y-m-d')
- ],
- 'remark' => [
- 'value' => "点此进入了解详情,{$ta}在等你哦~",
- ]
- ]
- ],
- [
- 'template_id' => 'buiSCGP-jKweNEVi7V8ZK-8Lspem1FopbD5Kvupg1Ig',
- 'data' => [
- 'first' => [
- 'value' => "你收到一条约会邀请,有{$ta}邀请你谈一场72小时的恋爱!",
- ],
- 'keyword1' => [
- 'value' => '72小时恋爱体验',
- ],
- 'keyword2' => [
- 'value' => '约会待开启',
- ],
- 'remark' => [
- 'value' => "点此进入了解详情,{$ta}在等你哦~",
- ]
- ]
- ],
- [
- 'template_id' => '22_U9jXaYpyk65P9-bPPe_INmrlY2TYooH3pe0kDkxA',
- 'data' => [
- 'first' => [
- 'value' => "你收到一条约会邀请,有{$ta}邀请你谈一场72小时的恋爱!",
- ],
- 'keyword1' => [
- 'value' => '72小时恋爱体验',
- ],
- 'keyword3' => [
- 'value' => date("Y-m-d"),
- ],
- 'keyword4' => [
- 'value' => '当前时间',
- ],
- 'keyword5' => [
- 'value' => '约会邀请',
- ],
- 'remark' => [
- 'value' => "点此进入了解详情,{$ta}在等你哦~",
- ]
- ]
- ]
- ];
- $rand = rand(0, count($templates) - 1);
- $templateId = $templates[$rand]['template_id'];
- $parameters = $templates[$rand]['data'];
- $page = "pages/pu-article/pu-article?from=template";
- $weChatTemplate = new WeChatTemplateChannel();
- $weChatTemplate->setAppId(self::PUBLIC_ID)
- ->setTitle($title)
- ->toUser($user->openid)
- ->setPage($page)
- ->setTemplateId($templateId)
- ->setParameters($parameters)
- ->send();
- }
- return ($users);
- }
- /*
- * 关注公众号、有手机号,仅参与过一次活动,最后登录时间为一个月前的用户
- */
- public function pair2()
- {
- $title = '老用户召回syj-活动召回2';
- if (
- \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->where('date', date("Y-m-d"))
- ->count() >= 3000
- ) {
- return false;
- }
- // 过滤发送过的人
- $filter_users = \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->distinct()
- ->pluck('openid');
- // 关注公众号、有手机号、登陆时间为一个月之前的人
- // 仅参加一次活动
- $users = \DB::table('kddx_user_openid as o')
- ->select('o.openid', 'o.sex')
- ->join('kdgx_partner_charge_user as u', 'u.uid', '=', 'o.uid')
- ->whereNotNull('u.phone')
- ->where('u.login_at', '<', strtotime("-1 month"))
- ->where('o.public_id', self::PUBLIC_ID)
- ->where('o.subscribe', 1)
- ->whereRaw(" u.`uid` IN( SELECT `uid` FROM `kdgx_partner_charge_pair` GROUP BY `uid` HAVING COUNT(*)= 1 )")
- ->whereNotIn('o.openid', $filter_users)
- ->orderBy('o.id', 'asc')
- ->limit(rand(1, 5))
- ->get();
- foreach ($users as $user) {
- $ta = ($user->sex == 2) ? '小哥哥' : '小姐姐';
- $templates = [
- [
- 'template_id' => 'y-SOmy9b5AaN_h652VXw0zWr6E9vKiAojWN0JhJq7-E',
- 'data' => [
- 'first' => [
- 'value' => "你收到一条约会邀请,有{$ta}邀请你谈一场72小时的恋爱!",
- ],
- 'keyword1' => [
- 'value' => '72小时恋爱体验',
- ],
- 'keyword2' => [
- 'value' => '约会邀请',
- ],
- 'keyword4' => [
- 'value' => date('Y-m-d')
- ],
- 'remark' => [
- 'value' => "点此进入了解详情,{$ta}在等你哦~",
- ]
- ]
- ],
- [
- 'template_id' => 'buiSCGP-jKweNEVi7V8ZK-8Lspem1FopbD5Kvupg1Ig',
- 'data' => [
- 'first' => [
- 'value' => "你收到一条约会邀请,有{$ta}邀请你谈一场72小时的恋爱!",
- ],
- 'keyword1' => [
- 'value' => '72小时恋爱体验',
- ],
- 'keyword2' => [
- 'value' => '约会待开启',
- ],
- 'remark' => [
- 'value' => "点此进入了解详情,{$ta}在等你哦~",
- ]
- ]
- ],
- [
- 'template_id' => '22_U9jXaYpyk65P9-bPPe_INmrlY2TYooH3pe0kDkxA',
- 'data' => [
- 'first' => [
- 'value' => "你收到一条约会邀请,有{$ta}邀请你谈一场72小时的恋爱!",
- ],
- 'keyword1' => [
- 'value' => '72小时恋爱体验',
- ],
- 'keyword3' => [
- 'value' => date("Y-m-d"),
- ],
- 'keyword4' => [
- 'value' => '当前时间',
- ],
- 'keyword5' => [
- 'value' => '约会邀请',
- ],
- 'remark' => [
- 'value' => "点此进入了解详情,{$ta}在等你哦~",
- ]
- ]
- ]
- ];
- $rand = rand(0, count($templates) - 1);
- $templateId = $templates[$rand]['template_id'];
- $parameters = $templates[$rand]['data'];
- $page = "pages/pu-article/pu-article?from=template";
- $weChatTemplate = new WeChatTemplateChannel();
- $weChatTemplate->setAppId(self::PUBLIC_ID)
- ->setTitle($title)
- ->toUser($user->openid)
- ->setPage($page)
- ->setTemplateId($templateId)
- ->setParameters($parameters)
- ->send();
- }
- return ($users);
- }
- /*
- * 关注公众号、无卡片ID/有卡片ID(无照片&无语音&无联系方式)
- */
- public function card1()
- {
- $title = "老用户召回syj-卡片1";
- if (
- \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->where('date', date("Y-m-d"))
- ->count() >= 3000
- ) {
- return false;
- }
- // 过滤发送过的人
- $filter_users = \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->distinct()
- ->pluck('openid');
- $users = \DB::table('kddx_user_openid as o')
- ->select('o.openid', 'o.sex')
- ->leftjoin("kdgx_partner_charge_partner as p", function ($join) {
- $join->on('o.uid', '=', 'p.uid')
- ->whereRaw(" (p.`photo_src`!= ''
- or p.`photo_1`!= ''
- or p.`photo_2`!= ''
- or p.`photo_3`!= ''
- or p.`photo_4`!= ''
- or p.`voice`!= ''
- or p.`weixin` is NOT null
- or p.`qq` IS NOT NULL)");
- })
- ->whereNull('p.id')
- ->where('o.public_id', self::PUBLIC_ID)
- ->where('o.subscribe', 1)
- ->whereNotIn('o.openid', $filter_users)
- ->orderBy('o.id', 'asc')
- ->limit(rand(1, 5))
- ->get();
- foreach ($users as $user) {
- switch ($user->sex) {
- case '1':
- $ta = '小姐姐';
- break;
- case '2':
- $ta = '小哥哥';
- break;
- default:
- $ta = '新朋友';
- break;
- }
- $templates = [
- [
- 'template_id' => '94ootk_SJuBQE9Y9d--Ag5lwcEs61NRV4AsimsV3F6Q',
- 'data' => [
- 'first' => [
- 'value' => "小遇今日为你精选了56个兴趣相投又好看的{$ta}。说不定其中就有你心动的人哦!",
- ],
- 'keyword1' => [
- 'value' => '匹配通知',
- ],
- 'keyword2' => [
- 'value' => date('Y-m-d')
- ],
- 'remark' => [
- 'value' => "他们之中离你最近的只有0.5km哦~",
- ]
- ]
- ],
- [
- 'template_id' => 'buiSCGP-jKweNEVi7V8ZK-8Lspem1FopbD5Kvupg1Ig',
- 'data' => [
- 'first' => [
- 'value' => "小遇今日为你精选了56个兴趣相投又好看的{$ta}。说不定其中就有你心动的人哦!",
- ],
- 'keyword1' => [
- 'value' => '推荐提醒',
- ],
- 'keyword2' => [
- 'value' => date("Y-m-d"),
- ],
- 'remark' => [
- 'value' => "他们之中离你最近的只有0.5km哦~",
- ]
- ]
- ],
- [
- 'template_id' => 'dD4V6t1sbBDGit_eVq0gZ6bX3RmLPeZU0sdK-bBJRds',
- 'data' => [
- 'first' => [
- 'value' => "小遇今日为你精选了56个兴趣相投又好看的{$ta}。说不定其中就有你心动的人哦!",
- ],
- 'keyword1' => [
- 'value' => '小遇',
- ],
- 'keyword2' => [
- 'value' => '推荐提醒',
- ],
- 'remark' => [
- 'value' => "他们之中离你最近的只有0.5km哦~",
- ]
- ]
- ]
- ];
- $rand = rand(0, count($templates) - 1);
- $templateId = $templates[$rand]['template_id'];
- $parameters = $templates[$rand]['data'];
- $page = "pages/index/index";
- $weChatTemplate = new WeChatTemplateChannel();
- $weChatTemplate->setAppId(self::PUBLIC_ID)
- ->setTitle($title)
- ->toUser($user->openid)
- ->setPage($page)
- ->setTemplateId($templateId)
- ->setParameters($parameters)
- ->send();
- }
- return ($users);
- }
- /**
- * 关注服务号,有卡片信息(照片or语音),未上架的用户
- * @return bool
- */
- public function card2()
- {
- $title = "老用户召回syj-卡片2";
- if (
- \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->where('date', date("Y-m-d"))
- ->count() >= 3000
- ) {
- return false;
- }
- // 过滤发送过的人
- $filter_users = \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->distinct()
- ->pluck('openid');
- $users = \DB::table('kddx_user_openid as o')
- ->select('o.openid', 'o.nickname')
- ->join("kdgx_partner_charge_partner as p", function ($join) {
- $join->on('o.uid', '=', 'p.uid');
- })
- ->where('o.public_id', self::PUBLIC_ID)
- ->where('o.subscribe', 1)
- ->whereRaw(" (p.`photo_src`!= ''
- or p.`photo_1`!= ''
- or p.`photo_2`!= ''
- or p.`photo_3`!= ''
- or p.`photo_4`!= ''
- or p.`voice`!= ''
- )")
- ->where('p.is_sell', '<>', 1)
- ->whereNotIn('o.openid', $filter_users)
- ->orderBy('o.id', 'asc')
- ->limit(rand(1, 5))
- ->get();
- foreach ($users as $user) {
- $x = rand(100, 1000);
- $templates = [
- [
- 'template_id' => 'RJNTbLGdlK7tLRgt5uoKIEWxlB7-bwCdwgE5yR11aHk',
- 'data' => [
- 'first' => [
- 'value' => "你的交友卡片尚未修改或完善,已错过{$x}次推荐曝光机会",
- ],
- 'keyword1' => [
- 'value' => $user->nickname,
- ],
- 'keyword2' => [
- 'value' => "交友卡片待完善",
- ],
- 'keyword3' => [
- 'value' => date('Y-m-d')
- ],
- 'remark' => [
- 'value' => "点此继续完善卡片重新提交审核,通过后将优先把你推荐给附近的人",
- ]
- ]
- ],
- [
- 'template_id' => 'T5AvN3tkUKywz1-hVeW2RFLNYV1Ex_EfXI0OE_JQBxM',
- 'data' => [
- 'first' => [
- 'value' => "你的交友卡片尚未修改或完善,已错过{$x}次推荐曝光机会",
- ],
- 'keyword1' => [
- 'value' => date("Y-m-d"),
- ],
- 'keyword2' => [
- 'value' => '交友卡片待完善',
- ],
- 'remark' => [
- 'value' => "点此继续完善卡片重新提交审核,通过后将优先把你推荐给附近的人",
- ]
- ]
- ],
- [
- 'template_id' => 'nMFoJQdUqb4IB5S-rs1PruWjC1H9HvvGfLCrPkl9iMs',
- 'data' => [
- 'first' => [
- 'value' => "你的交友卡片尚未修改或完善,已错过{$x}次推荐曝光机会",
- ],
- 'keyword1' => [
- 'value' => '交友卡片',
- ],
- 'keyword2' => [
- 'value' => '交友卡片待完善',
- ],
- 'keyword3' => [
- 'value' => '交友卡片',
- ],
- 'keyword4' => [
- 'value' => date('Y-m-d'),
- ],
- 'remark' => [
- 'value' => "点此继续完善卡片重新提交审核,通过后将优先把你推荐给附近的人",
- ]
- ]
- ]
- ];
- $rand = rand(0, count($templates) - 1);
- $templateId = $templates[$rand]['template_id'];
- $parameters = $templates[$rand]['data'];
- $page = "pages/my-friend-card-editor/my-friend-card-editor";
- $weChatTemplate = new WeChatTemplateChannel();
- $weChatTemplate->setAppId(self::PUBLIC_ID)
- ->setTitle($title)
- ->toUser($user->openid)
- ->setPage($page)
- ->setTemplateId($templateId)
- ->setParameters($parameters)
- ->send();
- }
- return $users;
- }
- /**
- * 关注服务号,有交友卡片,超1月未登录
- * @return bool
- */
- public function card3()
- {
- $title = "老用户召回syj-卡片3";
- if (
- \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->where('date', date("Y-m-d"))
- ->count() >= 3000
- ) {
- return false;
- }
- // 过滤发送过的人
- $filter_users = \DB::connection('mysql_datalog')
- ->table("notice_logs")
- ->where('title', $title)
- ->distinct()
- ->pluck('openid');
- $users = \DB::table('kddx_user_openid as o')
- ->select('o.openid', 'o.nickname', 'o.sex')
- ->join('kdgx_partner_charge_user as u', 'o.uid', '=', 'u.uid')
- ->where('u.login_at', '<', strtotime("-1 month"))
- ->where('o.public_id', self::PUBLIC_ID)
- ->where('o.subscribe', 1)
- ->whereNotIn('o.openid', $filter_users)
- ->orderBy('o.id', 'asc')
- ->limit(rand(1, 5))
- ->get();
- foreach ($users as $user) {
- $x = rand(100, 1000);
- switch ($user->sex) {
- case '1':
- $ta = '小姐姐';
- break;
- case '2':
- $ta = '小哥哥';
- break;
- default:
- $ta = '小姐姐';
- break;
- }
- $templates = [
- [
- 'template_id' => 'buiSCGP-jKweNEVi7V8ZK-8Lspem1FopbD5Kvupg1Ig',
- 'data' => [
- 'first' => [
- 'value' => "你不在的这段时间里,已经有{$x}个{$ta}看过你的交友卡片了!快来看看都有哪些人吧~",
- ],
- 'keyword1' => [
- 'value' => "访客通知",
- ],
- 'keyword2' => [
- 'value' => date('Y-m-d')
- ],
- 'remark' => [
- 'value' => "他们之中离你最近的只有0.5km哦,来看看你附近的{$ta}吧~",
- ]
- ]
- ],
- [
- 'template_id' => 'HgmFhBPrOry3i647Zu9AF4Vcfs0MaIj8bE83-G5Kg6Q',
- 'data' => [
- 'first' => [
- 'value' => "你不在的这段时间里,已经有{$x}个{$ta}看过你的交友卡片了!快来看看都有哪些人吧~",
- ],
- 'keyword1' => [
- 'value' => '访客通知',
- ],
- 'keyword2' => [
- 'value' => '分配对象个人中心',
- ],
- 'keyword3' => [
- 'value' => '访客通知',
- ],
- 'keyword4' => [
- 'value' => date("Y-m-d"),
- ],
- 'remark' => [
- 'value' => "他们之中离你最近的只有0.5km哦,来看看你附近的{$ta}吧~",
- ]
- ]
- ],
- [
- 'template_id' => 'dD4V6t1sbBDGit_eVq0gZ6bX3RmLPeZU0sdK-bBJRds',
- 'data' => [
- 'first' => [
- 'value' => "你不在的这段时间里,已经有{$x}个{$ta}看过你的交友卡片了!快来看看都有哪些人吧~",
- ],
- 'keyword1' => [
- 'value' => '小遇',
- ],
- 'keyword2' => [
- 'value' => '访客提醒',
- ],
- 'remark' => [
- 'value' => "他们之中离你最近的只有0.5km哦,来看看你附近的{$ta}吧~",
- ]
- ]
- ]
- ];
- $rand = rand(0, count($templates) - 1);
- $templateId = $templates[$rand]['template_id'];
- $parameters = $templates[$rand]['data'];
- $page = "pages/index/index";
- $weChatTemplate = new WeChatTemplateChannel();
- $weChatTemplate->setAppId(self::PUBLIC_ID)
- ->setTitle($title)
- ->toUser($user->openid)
- ->setPage($page)
- ->setTemplateId($templateId)
- ->setParameters($parameters)
- ->send();
- }
- return $users;
- }
- }
|