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
|
<?php
namespace addons\antis\model;
use think\Exception;
use think\Model;
use think\Session;
use traits\model\SoftDelete;
/**
*操作记录
*/
class OperationLog Extends Model {
use SoftDelete;
// 表名,不含前缀
protected $name = 'qingdong_operation_log';
const CUSTOMER_TYPE = 1;//客户
const CONTACTS_TYPE = 2;//联系人
const CONTRACT_TYPE = 3;//合同
const LEADS_TYPE = 4;//线索
const RECEIVABLES_TYPE = 5;//回款记录
const WORKORDER_TYPE = 6;//工单
const APPROVAL_TYPE = 7;//const
const BUSINESS_TYPE = 8;//项目
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
public function getCreatetimeAttr($value){
return date('Y-m-d H:i',$value);
}
//获取跟进记录列表
public static function getList($relation_type, $relation_id) {
return self::where(['relation_type' => $relation_type, 'relation_id' => $relation_id])->with(['staff','admin'])->field('content,operation_id,createtime,operation_type')->order('id desc')->select();
}
//员工
public function staff() {
return $this->hasOne(Staff::class, 'id', 'operation_id')->removeOption('soft_delete')->field('id,name,img');
}
//员工
public function admin() {
return $this->hasOne(\app\admin\model\Admin::class, 'id', 'operation_id')->field('id,nickname');
}
//创建日志
public static function createLog($relation_type, $relation_id, $content) {
$staff = Staff::info();
if(empty($staff)){
$admin = Session::get('admin');
$data = [
'content' => $content,
'operation_type' => 2,
'operation_id' => $admin['id']??0,
'relation_type' => $relation_type,
'relation_id' => $relation_id,
];
}else{
$data = [
'content' => $content,
'operation_type' => 1,
'operation_id' => $staff->id,
'relation_type' => $relation_type,
'relation_id' => $relation_id,
];
}
$Enent = new self;
$result = $Enent->save($data);
if (false === $result) {
// 验证失败 输出错误信息
throw new Exception($Enent->getError());
}
return true;
}
}
|