love_php/app/Console/Commands/ActivitySms.php
2026-04-02 09:20:51 +08:00

79 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\User;
use App\Models\Wechat;
use App\Models\Message;
use App\Utils\Messenger;
use App\Jobs\SendSmsBatch;
class ActivitySms extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'send:sms';
/**
* 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()
{
$user_open_ids = User::where('created_at','>','2021-05-20 00:00:00')->whereNotNull('from_openid')->pluck('from_openid')->toArray();
$counts = array_count_values($user_open_ids);
$final_openids = [];//收短信人from_openid
foreach ($counts as $key => $count) {
if ($count >= 10) {
$final_openids[] = $key;
}
}
$user_ids = Wechat::whereIn('openid',$final_openids)->pluck('user_id')->toArray();
$mobiles = User::whereIn('id',$user_ids)->pluck('mobile')->toArray();
$phone = Message::where('message','like','%可得电影首映礼观影票一张,点击领取%')->pluck('phone')->toArray();
$mobiles = array_diff($mobiles,$phone);//发短信号码集合
foreach ($mobiles as $mobile) {
$m = Message::create([
'phone' => $mobile,
'message' => '',
'confirmed' => 1,
'code' => '活动',
'ip' => request() ? request()->ip() : '127.0.0.1',
]);
$url = \CommonUtilsService::shortUrl('https://love.ufutx.com/api/admin/get/phone?&uri=http://love.ufutx.com/h5/#/holidayActivity&message_id='.$m->id);
$url = $url ['url'];
$message = "恭喜您已推荐10位小伙伴成功注册福恋可得电影首映礼观影票一张点击领取";
$m->message = $message;
Messenger::sendSMS($mobile, $message);
}
}
}