<?php
namespace app\index\controller;

use think\Db;
use tools\Qxsms;

class Timer
{

    public function apply(){ // 流程超时提醒

        $apps = Db::name('approval')->where('max_day','>',0)->field('id,max_day')->select();
        $curDate = date('Y-m-d');
        $cts = strtotime($curDate.' 00:00:00');
        $cte = strtotime($curDate.' 00:00:00')+24*60*60;
        if($apps){
            $allphones = [];
            foreach ($apps as $v){
                $st = date('Y-m-d H:i:s',$cts - $v['max_day']*24*60*60);
                $et = date('Y-m-d H:i:s',$cte - $v['max_day']*24*60*60);
                $phones = Db::name('apply_record')
                    ->alias('ar')
                    ->join('apply a','a.id = ar.apply_id')
                    ->join('user u','ar.user_id = u.id')
                    ->where('ar.status',0)
                    ->where('ar.del',0)
                    ->where('ar.type','in','2,8')
                    ->where('a.status',1)
                    ->where('a.approval_id',$v['id'])
                    ->where('a.create_time','>=',$st)
                    ->where('a.create_time','<',$et)
                    ->column('u.phone');
                if($phones){
                    $allphones = array_merge($allphones,$phones);
                }
            }
            if($allphones){
                $allphones = array_unique($allphones);
                $phonestr = implode(',',$allphones);
                $smsconfig = config('app.sms_config');
                $qxsms = new Qxsms($smsconfig);
                $content = "【基建物业管理中心】您有审批单未处理,请及时处理。";
                $ret = $qxsms->send($phonestr,$content);
                trace($phonestr);
            }
        }


    }

    public function tt(){
        halt(request()->domain(true));
    }
}