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
153
154
155
156
|
<?php
namespace addons\antis\model;
use think\Exception;
use think\Model;
use traits\model\SoftDelete;
/**
*费用表
*/
class Consume Extends Model {
use SoftDelete;
// 表名,不含前缀
protected $name = 'qingdong_consume';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'file_text',
];
// 图片
public function getFileTextAttr($value, $data)
{
if(!isset($data['file_ids'])){
return '';
}
if(is_array($value)){
return $value;
}
$value = $value ? $value : $data['file_ids'];
$files = explode(',',$value);
$files_v = [];
foreach ($files as $fid) {
if($fid){
$files_v[] = cdnurl(File::getUrl($fid), true);
}
}
return $files_v;
}
//添加费用
public static function createConsume($params) {
$staff = Staff::info();
$staff_id = $staff->id;
if($params['customer_id']){
$staff_id = Customer::where(['id'=>$params['customer_id']])->value('owner_staff_id');
}
$params['staff_id'] = $staff_id;
$params['check_status'] = 1;
$flow = Flow::getsteplist(Flow::CONSUME_STATUS);
$params['flow_id'] = $flow['flow_id'];
$params['order_id'] = $flow['order_id'];
if ($flow['status'] == 0) {//发起人自选
if (empty($params['flow_staff_ids'])) {
throw new Exception('审批人必须选择');
}
$params['flow_staff_ids'] = trim($params['flow_staff_ids']);
} else {
$params['flow_staff_ids'] = trim($flow['flow_staff_ids']);
}
$Model = new self;
$result = $Model->allowField(true)->save($params);
if (false === $result) {
// 验证失败 输出错误信息
throw new Exception($Model->getError());
}
$lastId= $Model->getLastInsID();
if ($params['file_ids'] && $params['customer_id']) {
CustomerFile::addFiles($params['file_ids'], $params['customer_id']);
}
$staff_id = explode(',', $params['flow_staff_ids'])[0];
ExamineRecord::addExaminse(ExamineRecord::CONSUME_TYPE,$lastId, $staff_id);
return true;
}
//编辑费用
public static function updateConsume($params) {
$params['check_status'] = 1;
$flow = Flow::getsteplist(Flow::CONSUME_STATUS);
$params['flow_id'] = $flow['flow_id'];
$params['order_id'] = $flow['order_id'];
if ($flow['status'] == 0) {//发起人自选
if (empty($params['flow_staff_ids'])) {
throw new Exception('审批人必须选择');
}
$params['flow_staff_ids'] = trim($params['flow_staff_ids']);
} else {
$params['flow_staff_ids'] = trim($flow['flow_staff_ids']);
}
$Model = new self;
// 调用当前模型对应的User验证器类进行数据验证
$result = $Model->save($params,['id'=>$params['id']]);
if (false === $result) {
// 验证失败 输出错误信息
throw new Exception($Model->getError());
}
if ($flow['status'] == 1) {//固定审批
//发送审批通知
Flow::sendStepRecord($flow,Flow::CONSUME_STATUS, $params['id']);
} else {//发起人自选 依次审批
$staff_id = explode(',', $params['flow_staff_ids'])[0];
if ($staff_id) {
ExamineRecord::addExaminse(ExamineRecord::CONSUME_TYPE, $params['id'], $staff_id);
}
}
return true;
}
public function getCreatetimeAttr($value){
if(empty($value)){
return $value;
}
return date('Y-m-d H:i:s',$value);
}
public function getUpdatetimeAttr($value){
if(empty($value)){
return $value;
}
return date('Y-m-d H:i:s',$value);
}
//销售
public function staff() {
return $this->hasOne(Staff::class, 'id', 'staff_id')->field('id,img,name');
}
//审核人
public function followStaff() {
return $this->hasOne(Staff::class, 'id', 'flow_staff_ids')->field('id,img,name');
}
//客户
public function customer() {
return $this->hasOne(Customer::class, 'id', 'customer_id')->field('id,name');
}
}
|