first commit
This commit is contained in:
22
app/common/model/CompanyOperators.php
Normal file
22
app/common/model/CompanyOperators.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
class CompanyOperators extends Model
|
||||
{
|
||||
protected $table = 'company_operators';
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(Companys::class, 'company_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function getCompanyNameAttr($value, $data)
|
||||
{
|
||||
return $this->company->company_name ?? null;
|
||||
}
|
||||
}
|
||||
12
app/common/model/Companys.php
Normal file
12
app/common/model/Companys.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
class Companys extends Model
|
||||
{
|
||||
protected $table = 'companys';
|
||||
|
||||
}
|
||||
32
app/common/model/Customers(待删除).php
Normal file
32
app/common/model/Customers(待删除).php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use app\common\model\CustomerEmployees;
|
||||
|
||||
class Customers extends Model
|
||||
{
|
||||
protected $table = 'customers';
|
||||
|
||||
public function employees()
|
||||
{
|
||||
return $this->hasMany(CustomerEmployees::class, 'customer_id', 'id');
|
||||
}
|
||||
|
||||
/* 模型事件:在删除客户记录之后执行 */
|
||||
public static function onAfterDelete($customer)
|
||||
{
|
||||
// 删除与该客户相关的员工记录
|
||||
$customer->employees()->delete();
|
||||
}
|
||||
|
||||
|
||||
public function getCompanyOfAccount(){
|
||||
return $this->hasMany(User::class,'company_id','id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
94
app/common/model/Tickets.php
Normal file
94
app/common/model/Tickets.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
class Tickets extends Model
|
||||
{
|
||||
protected $table = 'tickets';
|
||||
|
||||
# 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
# 定义时间戳字段名
|
||||
protected $createTime = 'create_time';
|
||||
protected $updateTime = 'update_time';
|
||||
|
||||
|
||||
# 定义字段类型
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'company_id' => 'integer',
|
||||
'operator_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'website' => 'string',
|
||||
'datanum' => 'string',
|
||||
'progress' => 'integer',
|
||||
'status' => 'integer',
|
||||
'remark' => 'string',
|
||||
'lock_time' => 'integer',
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
];
|
||||
|
||||
|
||||
/*
|
||||
时间戳获取器
|
||||
*/
|
||||
public function getCreateTimeAttr($value)
|
||||
{
|
||||
return date('Y-m-d H:i', $value);
|
||||
}
|
||||
|
||||
public function getUpdateTimeAttr($value)
|
||||
{
|
||||
return date('Y-m-d H:i', $value);
|
||||
}
|
||||
|
||||
public function getLockTimeAttr($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
return date('Y-m-d H:i', $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联:工单关联负责人
|
||||
*/
|
||||
public function ticketStaff()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function ticketCompany()
|
||||
{
|
||||
return $this->belongsTo(Companys::class, 'company_id', 'id');
|
||||
}
|
||||
|
||||
public function ticketOperator()
|
||||
{
|
||||
return $this->belongsTo(CompanyOperators::class, 'operator_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
// --- 定义虚拟属性 (获取关联表的值) ---
|
||||
|
||||
public function getUsernameAttr($value, $data)
|
||||
{
|
||||
return $this->ticketStaff->username ?? '';
|
||||
}
|
||||
|
||||
public function getCompanyNameAttr($value, $data)
|
||||
{
|
||||
return $this->ticketCompany->company_name ?? '';
|
||||
}
|
||||
|
||||
public function getOperatorNameAttr($value, $data)
|
||||
{
|
||||
return $this->ticketOperator->operator_name ?? '';
|
||||
}
|
||||
}
|
||||
16
app/common/model/User.php
Normal file
16
app/common/model/User.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
protected $table = 'users';
|
||||
|
||||
public function company(){
|
||||
return $this->belongsTo(Companys::class,'company_id','id');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user