Crontab.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace app\api\controller;
use app\api\model\Study;
use app\common\controller\Api;
use app\common\controller\Resource;
/**
* 定时任务
* @ApiWeigh (93)
*/
class Crontab extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['*'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* @ApiTitle (定时任务)
*/
public function index()
{
//查询未生成的条形码
$id = db('study')->where('generate', 0)->limit(10)->column('id');
if (empty($id)) {
$this->error('不执行', ['status' => 0]);
}
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,
'generate' => 1
]);
}
$this->success('执行成功', ['status' => 1]);
}
}