Crontab.php 851 字节
<?php

namespace app\api\controller;

use app\api\model\Study;
use app\common\controller\Api;
use app\common\controller\Resource;

class Crontab extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle (定时任务)
     */
    public function index()
    {
        //查询未生成的条形码
        $id = db('study')->where('barcode', '')->limit(10)->column('id');
        foreach ($id as $k => $v){
            $res = str_pad($v, 8, "0", STR_PAD_LEFT);
            $barpath = Resource::StudyBar($res);
            db('study')
                ->where('id',$v)
                ->update([
                    'barcode' => $barpath,
                    'unique' => $res
                ]);
        }
    }
}