Orders.php
2.6 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
<?php
namespace addons\workorder\model;
use think\Model;
use traits\model\SoftDelete;
/**
* 工程师模型
*/
class Orders extends Model
{
use SoftDelete;
// 表名
protected $name = 'workorder_orders';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
protected $append = [
'createtime_text'
];
protected static function init()
{
}
public function getCreatetimeTextAttr($value, $data)
{
return human_date($data['createtime']);
}
public static function getFields($values = null, $position = -1)
{
$where['status'] = 1;
if ($position != -1) {
$where['position'] = $position;
}
$fields = \app\admin\model\workorder\Fields::where($where)->order('weigh desc,id desc')->select();
foreach ($fields as $k => $v) {
$v->value = isset($values[$v['name']]) ? $values[$v['name']] : '';
if (!$v->value) {
$v->value = $v->default;
}
$v->rule = str_replace(',', '; ', $v->rule);
if (in_array($v->type_list, ['checkbox', 'lists', 'images'])) {
$checked = '';
if ($v['minimum'] && $v['maximum']) {
$checked = "{$v['minimum']}~{$v['maximum']}";
} elseif ($v['minimum']) {
$checked = "{$v['minimum']}~";
} elseif ($v['maximum']) {
$checked = "~{$v['maximum']}";
}
if ($checked) {
$v->rule .= (';checked(' . $checked . ')');
}
}
if (in_array($v->type_list, ['checkbox', 'radio']) && stripos($v->rule, 'required') !== false) {
$v->rule = str_replace('required', 'checked', $v->rule);
}
if (in_array($v->type_list, ['selects'])) {
$v->extend .= (' ' . 'data-max-options="' . $v['maximum'] . '"');
}
}
return $fields;
}
public function user()
{
return $this->hasOne('app\admin\model\User', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
}
public function category()
{
return $this->hasOne('app\admin\model\workorder\Category', 'id', 'category_id', [], 'LEFT')->setEagerlyType(0);
}
public function urgentrank()
{
return $this->hasOne('app\admin\model\workorder\Urgentrank', 'id', 'urgency', [], 'LEFT')->setEagerlyType(0);
}
}