125 lines
3.8 KiB
PHP
125 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\UserInfo;
|
|
use Illuminate\Console\Command;
|
|
use App\Jobs\SendIMPushMsg;
|
|
use App\Models\PayLog;
|
|
use App\Models\SignLog;
|
|
use App\Services\IMService;
|
|
use App\Models\User;
|
|
|
|
class signNotice extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'signNotice';
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
//获取设置签到提醒的用户
|
|
$ids = UserInfo::where('sign_notice',1)->pluck('user_id')->toarray();
|
|
//查询今日是否已经签到
|
|
$start = Date('Y-m-d 00:00:00',time());
|
|
$sign_ids = SignLog::wherein('user_id',$ids)->wherebetween('sign_date',[$start,now()])->pluck('user_id')->toarray();
|
|
// 取差集
|
|
$sign_ids = array_diff($ids,$sign_ids);
|
|
|
|
foreach ($sign_ids as $key => $value) {
|
|
$user = User::select('id','app_avatar','photo','circle_avatar','nickname')->where('id',$value)->first();
|
|
if($user){
|
|
$content = '亲爱的'. $user->nickname.',您今日还未签到,赶快签到领取更多的奖励把~';
|
|
$pay = new PayLog();
|
|
$pay->type = 'signNotice';
|
|
$pay->user_id = $user->id;
|
|
$pay->remark = $content;
|
|
$pay->save();
|
|
$this->sendAttachMsg($user->id, 'sign_notice', $content, 0,$user->id,$user->avatar);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 发送推送消息
|
|
* @param [type] $type_id 类型id
|
|
* @param [type] $type 类型
|
|
* @param [type] $content 推送文字
|
|
* @param [type] $from 来自用户
|
|
* @param [type] $to 接收用户
|
|
* @param [type] $image 来自用户头像
|
|
* @return [type] 是否成功
|
|
*/
|
|
public function sendAttachMsg($type_id, $type, $content, $from, $to, $image)
|
|
{
|
|
$body = "点击查看>>";
|
|
//发送评论自定义系统消息
|
|
$im_service = new IMService();
|
|
$attach = ["myattach"=>$content, $type.'_id'=>$type_id];
|
|
$payload = [
|
|
"apsField"=>[
|
|
"alert"=>[
|
|
"title"=>'每日签到提醒通知',
|
|
"body"=> $body,
|
|
],
|
|
"mutable-content"=>1
|
|
],
|
|
"hwField"=>[
|
|
"click_action"=>[
|
|
"type"=>1,
|
|
"intent"=>"intent://com.huawei.codelabpush/deeplink?id=".$type_id."&customType=".$type."#Intent;scheme=pushscheme;launchFlags=0x4000000;end",
|
|
],
|
|
"title"=>'每日签到提醒通知',
|
|
"body"=>$body,
|
|
],
|
|
"oppoField"=>[
|
|
"click_action_type"=>1,
|
|
"click_action_activity"=>"com.oppo.codelabpush.intent.action.test",
|
|
"action_parameters"=>[
|
|
"id"=>$type_id,
|
|
"customType"=>"moment",
|
|
],
|
|
],
|
|
"apnsText"=>$body,
|
|
"pushTitle"=>'每日签到提醒通知',
|
|
"customType"=>$type,
|
|
"content"=>$body,
|
|
"media_image"=>$image,
|
|
"media_type"=>'image',
|
|
"id"=>$type_id,
|
|
"type"=>$type,
|
|
'passThrough'=>1,
|
|
];
|
|
$result = $im_service->sendAttachMsg($from,0,$to,json_encode($attach),$content,$payload);
|
|
return true;
|
|
}
|
|
}
|