生成按照天數初始化的隨機九位唯一自增字串

qiaoshuai_job發表於2019-08-28
//獲取本月起始時間戳和結束時間戳
public static function month_start_end(){
    $beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
    $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
    $date_data['start'] = $beginThismonth;
    $date_data['end'] = $endThismonth;
    return $date_data;
}

//生成隨機字串,位數九位
public function CkServiceId($lastnum){
    $date_data = ArrayHelper::month_start_end();
    $time = time();
    if ($time <= $date_data['end'] && $time >= $date_data['start']){
        $ckserviceid = date('ymd') . sprintf('%03d',$lastnum+1);
    }else{
        $ckserviceid = date('ymd') . sprintf('%03d',1);
    }
    return $ckserviceid;
}

qiaoshuai_job

相關文章