2db47680
hexiaodong
chore: 初始提交 php 遗...
|
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
<?php
namespace addons\antis\model;
use think\Exception;
use think\Model;
use traits\model\SoftDelete;
/**
*审批记录
*/
class ExamineRecord Extends Model {
use SoftDelete;
// 表名,不含前缀
protected $name = 'qingdong_examine_record';
const CONSUME_TYPE = 'consume';//费用
const CONTRACT_TYPE = 'contract';//合同
const RECEIVABLES_TYPE = 'receivables';//回款
const ACHIEVEMENT_TYPE = 'achievement';//业绩目标
const APPROVAL_TYPE = 'approval';//审批
const CARD_TYPE = 'card';//补卡
const LEAVE_TYPE = 'leave';//请假
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
public function checkStaff() {
return $this->hasOne(Staff::class, 'id', 'check_staff_id')->field('id,name,img');
}
//获取审批记录
public static function getList($relation_type, $relation_id) {
return self::where([
'relation_type' => $relation_type,
'relation_id' => $relation_id
])->with(['checkStaff'])->field('content,check_staff_id,check_time,status,createtime')->order('id asc')->select();
}
public function getCheckTimeAttr($value) {
if ($value) {
return date('Y-m-d H:i', $value);
}
return $value;
}
public function getCreatetimeAttr($value) {
if ($value) {
return date('Y-m-d H:i', $value);
}
return $value;
}
/**
* 添加审批
* @param $relation_type string 关联类型
* @param $relation_id int 关联id
* @param $staff_id int 审批人ID
*/
public static function addExaminse($relation_type, $relation_id, $staff_id) {
$staff = Staff::info();
$data = [
'relation_type' => $relation_type,
'relation_id' => $relation_id,
'check_staff_id' => $staff_id,
'status' => 0
];
if (self::where($data)->find()) {//已发送过审批通知
return true;
}
$Model = new self;
$result = $Model->save($data);
if (false === $result) {
// 验证失败 输出错误信息
throw new Exception($Model->getError());
}
//发送通知
Message::addMessage(Message::EXAMINE_TYPE, $Model->getLastInsID(), $staff_id, $staff->id);
return true;
}
/**
*是否审批
*/
public static function isExaminse($relation_type, $relation_id) {
$staff = Staff::info();
if (self::where([
'relation_type' => $relation_type,
'relation_id' => $relation_id,
'status' => 0,
'check_staff_id' => $staff->id
])->find()) {
return 1;
}
return 0;
}
//合同
public function contract() {
return $this->hasOne(Contract::class, 'id', 'relation_id')
->field('id,name,owner_staff_id');
}
//费用
public function consume() {
return $this->hasOne(Consume::class, 'id', 'relation_id')->field('id,consume_time,consume_type,money,staff_id');
}
//回款
public function receivables() {
return $this->hasOne(Receivables::class, 'id', 'relation_id')->field('id,return_time,return_type,number,create_staff_id,money');
}
//业绩目标
public function achievement() {
return $this->hasOne(AchievementRecords::class, 'id', 'relation_id');
}
//办公审批
public function approval() {
return $this->hasOne(Approval::class, 'id', 'relation_id')->field('id,formapproval_id,create_staff_id');
}
public static function cancelExaminse($relation_type, $relation_id)
{
$record = ExamineRecord::where([
'relation_type' => $relation_type,
'relation_id' => $relation_id,
'status' => 0
])->find();
if(empty($record)){
return true;
}
if ($message = Message::where([
'relation_type' => 'examine',
'relation_id' => $record['id'],
])->find()) {
Message::where(['id' => $message['id']])->update(['status' => 1, 'read_time' => time()]);
}
ExamineRecord::where([
'relation_type' => $relation_type,
'relation_id' => $relation_id,
'status' => 0
])->update(['status' => 3]);
return true;
}
}
|