ProjectOut.php 2.35 KB
<?php


namespace App\Console\Commands;


use App\Http\Service\ImSign;
use App\Http\Service\ImSendService;
use App\Models\Pivots\ProjectMemberPivot;
use App\Models\Pivots\UserProjectPivot;
use App\Models\Project;
use App\Models\SystemConfig;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Auth;

class ProjectOut extends Command
{
    protected $signature = 'project:out';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '自动退出厂牌';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(): int
    {
        $members = ProjectMemberPivot::query()->where('status', 3)->where('updated_at', '<=', now()->subDays($this->getLimitDay()))->get();
        foreach ($members as $member){
            $MsgBody =  [
                [
                    "MsgType" => "TIMCustomElem",
                    "MsgContent" => [
                        "Data" =>  "{\"businessID\": \"system_notice\",\"text\": \"厂牌成员提醒\",\"title\": \"厂牌成员提醒\",\"content\": \"到期自动退出厂牌\",\"version\": 4}",
                        "Desc" => "notification",
                        "Ext" => "url",
                        "Sound" => "dingdong.aiff"
                    ]
                ]
            ];

            $OfflinePushInfo =  [
                "PushFlag" => 0,
                "Title" =>'厂牌提醒',
                "Desc" => "到期自动退出厂牌",
                "Ext" => "到期自动退出厂牌",
                "AndroidInfo" => [
                    "Sound" => "android.mp3"
                ],
                "ApnsInfo" => [
                    "Sound" => "apns.mp3",
                    "BadgeMode" => 1,
                    "Image" => "www.image.com"
                ]
            ];
            $sendData = ['MsgBody'=>$MsgBody,'OfflinePushInfo'=>$OfflinePushInfo];
            $getSign = new ImSign();
            $sendService = new ImSendService();
            $sign = $getSign->genUserSig('administrator');
            $sendService->batchSend($sign,[$member->user_id],"system",$sendData,2);
            $member->delete();
        }
        return self::SUCCESS;
    }


    public function getLimitDay()
    {
        return SystemConfig::query()->where('identifier', 'i9V0wD_FitcGXR3HxUK5C')->value('content') ?? 7;
    }

}