企业微信外部联系人同步

This commit is contained in:
Guoxianpeng
2026-04-22 12:19:24 +08:00
parent 906684c1ed
commit 6e37c6ec05
25 changed files with 3362 additions and 325 deletions
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace app\common\model;
use think\Model;
/**
* 客户添加日志模型
*/
class QywxCustomerAddLog extends Model
{
protected $table = 'zyt_qywx_customer_add_log';
protected $autoWriteTimestamp = true;
// 字段类型
protected $type = [
'staff_id' => 'integer',
'add_time' => 'datetime',
'created_at' => 'datetime',
];
// 隐藏字段
protected $hidden = [];
// 验证规则
protected $rule = [
'external_user_id' => 'require|max:50',
'staff_id' => 'require|integer',
'staff_name' => 'require|max:50',
'add_time' => 'require|datetime',
'user_info' => 'require',
'source' => 'require|max:20',
];
// 错误信息
protected $message = [
'external_user_id.require' => '外部用户ID不能为空',
'external_user_id.max' => '外部用户ID不能超过50个字符',
'staff_id.require' => '员工ID不能为空',
'staff_id.integer' => '员工ID必须是整数',
'staff_name.require' => '员工姓名不能为空',
'staff_name.max' => '员工姓名不能超过50个字符',
'add_time.require' => '添加时间不能为空',
'add_time.datetime' => '添加时间格式不正确',
'user_info.require' => '用户信息不能为空',
'source.require' => '来源不能为空',
'source.max' => '来源不能超过20个字符',
];
/**
* @notes 获取员工加粉统计
*/
public static function getStaffAddCount($staffId, $startDate, $endDate)
{
return self::where('staff_id', $staffId)
->where('add_time', '>=', $startDate)
->where('add_time', '<=', $endDate)
->count();
}
/**
* @notes 获取所有员工加粉统计
*/
public static function getStaffAddCountList($startDate, $endDate)
{
return self::field('staff_id, staff_name, count(*) as add_count')
->where('add_time', '>=', $startDate)
->where('add_time', '<=', $endDate)
->group('staff_id, staff_name')
->select();
}
}
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace app\common\model;
use think\Model;
/**
* 客户操作日志模型
*/
class QywxCustomerOperationLog extends Model
{
protected $table = 'zyt_qywx_customer_operation_log';
protected $autoWriteTimestamp = true;
// 字段类型
protected $type = [
'operator_id' => 'integer',
'staff_id' => 'integer',
'created_at' => 'datetime',
];
// 隐藏字段
protected $hidden = [];
// 验证规则
protected $rule = [
'operation_type' => 'require|max:20',
'operator_id' => 'require|integer',
'operator_name' => 'require|max:50',
];
// 错误信息
protected $message = [
'operation_type.require' => '操作类型不能为空',
'operation_type.max' => '操作类型不能超过20个字符',
'operator_id.require' => '操作人ID不能为空',
'operator_id.integer' => '操作人ID必须是整数',
'operator_name.require' => '操作人姓名不能为空',
'operator_name.max' => '操作人姓名不能超过50个字符',
];
/**
* @notes 记录操作日志
*/
public static function record($operationType, $operatorId, $operatorName, $externalUserId = null, $staffId = null, $content = null)
{
$log = new self();
$log->operation_type = $operationType;
$log->operator_id = $operatorId;
$log->operator_name = $operatorName;
$log->external_user_id = $externalUserId;
$log->staff_id = $staffId;
$log->content = $content;
$log->save();
return $log;
}
}
@@ -4,16 +4,14 @@ declare(strict_types=1);
namespace app\common\model;
use think\model\concern\SoftDelete;
/**
* 企业微信外部联系人模型
*/
class QywxExternalContact extends BaseModel
{
use SoftDelete;
protected $name = 'qywx_external_contact';
protected $autoWriteTimestamp = 'datetime';
protected $createTime = 'created_at';
protected $updateTime = 'updated_at';
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace app\common\model;
use think\Model;
/**
* 员工二维码模型
*/
class QywxStaffQrcode extends Model
{
protected $table = 'zyt_qywx_staff_qrcode';
protected $autoWriteTimestamp = true;
// 字段类型
protected $type = [
'staff_id' => 'integer',
'expire_time' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
// 隐藏字段
protected $hidden = [];
// 验证规则
protected $rule = [
'staff_id' => 'require|integer',
'staff_name' => 'require|max:50',
'scene' => 'require|max:100|unique:qywx_staff_qrcode',
'qrcode_url' => 'require|max:255',
'expire_time' => 'require|datetime',
];
// 错误信息
protected $message = [
'staff_id.require' => '员工ID不能为空',
'staff_id.integer' => '员工ID必须是整数',
'staff_name.require' => '员工姓名不能为空',
'staff_name.max' => '员工姓名不能超过50个字符',
'scene.require' => '场景值不能为空',
'scene.max' => '场景值不能超过100个字符',
'scene.unique' => '场景值已存在',
'qrcode_url.require' => '二维码URL不能为空',
'qrcode_url.max' => '二维码URL不能超过255个字符',
'expire_time.require' => '过期时间不能为空',
'expire_time.datetime' => '过期时间格式不正确',
];
}
+1 -1
View File
@@ -9,5 +9,5 @@ namespace app\common\model;
*/
class QywxSyncSettings extends BaseModel
{
protected $name = 'qywx_sync_settings';
protected $table = 'zyt_qywx_sync_settings';
}