<?php
namespace app\cron;

use app\common\util\AppMsg;
use think\Db;
use yunwuxin\cron\Task;

// 会议室预定提醒
class Meeting extends Task
{
    public function configure()
    {
        $this->everyMinute(); //每分钟执行一次
    }

    /**
     * 执行任务
     * @return mixed
     */
    protected function execute()
    {
        try {
            $this->remind();
        } catch (\Exception $e) {
            trace($e->getMessage());
        }
    }


    public function remind(){
        $curTime = time() - 30*60;
        $lists = Db::name('meeting_apply')
            ->where('status',1)
            ->where('del',0)
            ->where('start_time',date('Y-m-d H:i:00',$curTime))
            ->field('id,org_id,user_ids')
            ->select();
        foreach ($lists as $k=>$v){
            $uids = $v['user_ids']?explode(',',$v['user_ids']):[];

            if($uids){
                send_jpush($uids,AppMsg::PUSH_CUSTOM,'您有会议将要开始,请做好准备!');
//                $uinfo = Db::name('user')->where('del',0)->whereIn('id',$uids)->field('mobile,real_name')->select();
//                if($uinfo){
//                    // 添加短信队列
//                    $content = AppMsg::getSmsMsg(AppMsg::SMS_MEETING,[
//                        'name' => $v['real_name'],
//                    ]);
//                    send_sms([$v['mobile']],$content,$v['org_id'],$v['id']);
//                }
            }
        }

    }



}