job.table.php
2.13 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* [WeEngine System] Copyright (c) 2014 WE7.CC
* WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
*/
defined('IN_IA') or exit('Access Denied');
class JobTable extends We7Table {
protected $tableName = 'core_job';
protected $field = array('type', 'payload', 'status', 'handled', 'uniacid', 'title', 'total', 'createtime', 'endtime', 'updatetime', 'isdeleted', 'uid');
protected $default = array('status'=>0, 'handled'=>0, 'total'=>0, 'createtime'=>'custom', 'updatetime'=>'custom', 'isdeleted'=>0, 'uid'=>0);
const DELETE_ACCOUNT = 10;
const SYNC_FANS = 20;
protected function defaultCreatetime() {
return TIMESTAMP;
}
protected function defaultUpdatetime() {
return TIMESTAMP;
}
public function jobs() {
return $this->where('status', 0)->getall();
}
public function alljobs() {
return $this->getall();
}
public function exitsJob($uniacid, $type)
{
$result = table('job')->where('uniacid', $uniacid)->where('type', $type)->get();
return !empty($result);
}
public function createDeleteAccountJob($uniacid, $accountName, $total, $uid)
{
if ($this->exitsJob($uniacid, self::DELETE_ACCOUNT)) {
return error(1, '任务已存在');
}
$data = array(
'type' => self::DELETE_ACCOUNT,
'title'=> "删除{$accountName}的素材数据",
'uniacid'=>$uniacid,
'total'=> $total,
'uid'=>$uid
);
return $this->createJob($data);
}
public function createSyncFans($uniacid, $accountName, $total ) {
if ($this->exitsJob($uniacid, self::SYNC_FANS)) {
return error(1, '同步任务已存在');
}
$data = array(
'type' => self::SYNC_FANS,
'title'=> "同步 $accountName ($uniacid) 的公众号粉丝数据",
'uniacid'=>$uniacid,
);
return $this->createJob($data);
}
private function createJob($data)
{
$this->fill($data);
$result = $this->save();
if ($result) {
return pdo_insertid();
}
return $result;
}
public function clear($uid, $isfounder) {
$table = table('job')
->where('status', 1)
->fill('isdeleted', 1);
if (!$isfounder) {
$table->where('uid', $uid);
}
return $table->save();
}
}