81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?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;
|
|
use App\Services\CommonUtilsService;
|
|
use App\Services\UserService;
|
|
|
|
class BirthdayRemind extends Command
|
|
{
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'send:birthday';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '每天10.00 发送生日提醒给当天生日的用户';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
$todayBirthdayUserList = UserService::getTodayBirthdayUserList();
|
|
foreach ($todayBirthdayUserList as $user_item) {
|
|
$this->sendBirthdayBlessing($user_item->mobile,$user_item->nickname);
|
|
}
|
|
}
|
|
|
|
|
|
//发送生日短信
|
|
function sendBirthdayBlessing($mobile,$nickname){
|
|
$code = '生日提醒短信';
|
|
//如果今年已经发送过一次短信则不在发送
|
|
$this_year_initial_date = date('Y-01-01');
|
|
if (empty($mobile)) return false;
|
|
// $result = Message::where('phone', $mobile)
|
|
// ->where('created_at','>=', $this_year_initial_date)
|
|
// ->where('code', $code)
|
|
// ->count();
|
|
// if($result){
|
|
// return false;
|
|
// }
|
|
$m = Message::create([
|
|
'phone' => $mobile,
|
|
'message' => '',
|
|
'confirmed' => 1,
|
|
'code' => $code,
|
|
'ip' => request() ? request()->ip() : '127.0.0.1',
|
|
]);
|
|
$url = '';
|
|
$wecharLink = \CommonUtilsService::getWecharLink('/pages/home/birthdayPresent');
|
|
$url = \CommonUtilsService::createShortUrl(env('APP_URL').'/h5/#/jump_url?url='.$wecharLink,$m->id);
|
|
$message = "亲爱的 $nickname 生日快乐! 福恋悄悄给你送了一个神秘的专属礼物哦,点击链接 $url 拆开你的礼物吧!";
|
|
$m->message = $message;
|
|
$m->save();
|
|
Messenger::sendSMS($mobile, $message);
|
|
return $url;
|
|
}
|
|
|
|
}
|