You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
6.3 KiB
184 lines
6.3 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\service_logs;
|
|
|
|
use app\job\schedule\ServiceLogsDistribution;
|
|
use app\model\service_logs\ServiceLogs;
|
|
use app\model\personnel\Personnel;
|
|
use core\base\BaseAdminService;
|
|
use think\facade\Log;
|
|
|
|
/**
|
|
* 服务记录分发管理服务层
|
|
* Class ServiceLogsDistributionService
|
|
* @package app\service\admin\service_logs
|
|
*/
|
|
class ServiceLogsDistributionService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 手动执行分发任务
|
|
* @return array
|
|
*/
|
|
public function executeDistribution()
|
|
{
|
|
try {
|
|
$job = new ServiceLogsDistribution();
|
|
$result = $job->doJob();
|
|
|
|
if ($result) {
|
|
return ['code' => 1, 'msg' => '分发任务执行成功'];
|
|
} else {
|
|
return ['code' => 0, 'msg' => '分发任务执行失败'];
|
|
}
|
|
} catch (\Exception $e) {
|
|
Log::write('手动执行分发任务异常: ' . $e->getMessage());
|
|
return ['code' => 0, 'msg' => '分发任务执行异常:' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取分发统计信息
|
|
* @return array
|
|
*/
|
|
public function getDistributionStats()
|
|
{
|
|
try {
|
|
$job = new ServiceLogsDistribution();
|
|
$stats = $job->getDistributionStats();
|
|
|
|
return [
|
|
'code' => 1,
|
|
'data' => $stats,
|
|
'msg' => '获取统计信息成功'
|
|
];
|
|
} catch (\Exception $e) {
|
|
Log::write('获取分发统计信息异常: ' . $e->getMessage());
|
|
return ['code' => 0, 'msg' => '获取统计信息失败:' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取待分发的服务记录列表
|
|
* @param array $where
|
|
* @return array
|
|
*/
|
|
public function getPendingDistributionList(array $where = [])
|
|
{
|
|
$field = 'id,service_id,staff_id,status,service_remark,feedback,score,created_at,updated_at,is_distributed_to_academic,is_distributed_to_coach,distribution_time';
|
|
|
|
$search_model = ServiceLogs::alias("a")
|
|
->join(['school_service' => 'b'], 'a.service_id = b.id', 'left')
|
|
->join(['school_personnel' => 'c'], 'a.staff_id = c.id', 'left')
|
|
->where('a.status', 1) // 已完成状态
|
|
->field("a.{$field},b.service_name,c.name as staff_name")
|
|
->order('a.created_at desc');
|
|
|
|
// 添加筛选条件
|
|
if (isset($where['distribution_status'])) {
|
|
switch ($where['distribution_status']) {
|
|
case 'pending_academic':
|
|
$search_model->where('a.is_distributed_to_academic', 0);
|
|
break;
|
|
case 'pending_coach':
|
|
$search_model->where('a.is_distributed_to_coach', 0);
|
|
break;
|
|
case 'distributed':
|
|
$search_model->where('a.is_distributed_to_academic', 1)
|
|
->where('a.is_distributed_to_coach', 1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (isset($where['date_range']) && !empty($where['date_range'])) {
|
|
$search_model->whereTime('a.created_at', $where['date_range']);
|
|
}
|
|
|
|
$list = $this->pageQuery($search_model);
|
|
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 重置分发状态
|
|
* @param array $ids 服务记录ID数组
|
|
* @param string $type 重置类型 (academic|coach|both)
|
|
* @return array
|
|
*/
|
|
public function resetDistributionStatus(array $ids, string $type = 'both')
|
|
{
|
|
try {
|
|
$updateData = [];
|
|
|
|
if ($type === 'academic' || $type === 'both') {
|
|
$updateData['is_distributed_to_academic'] = 0;
|
|
}
|
|
|
|
if ($type === 'coach' || $type === 'both') {
|
|
$updateData['is_distributed_to_coach'] = 0;
|
|
}
|
|
|
|
if ($type === 'both') {
|
|
$updateData['distribution_time'] = 0;
|
|
}
|
|
|
|
$result = ServiceLogs::whereIn('id', $ids)->update($updateData);
|
|
|
|
if ($result) {
|
|
Log::write("重置分发状态成功,记录ID: " . implode(',', $ids) . ",类型: {$type}");
|
|
return ['code' => 1, 'msg' => '重置分发状态成功'];
|
|
} else {
|
|
return ['code' => 0, 'msg' => '重置分发状态失败'];
|
|
}
|
|
} catch (\Exception $e) {
|
|
Log::write('重置分发状态异常: ' . $e->getMessage());
|
|
return ['code' => 0, 'msg' => '重置分发状态异常:' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取教务和教练人员列表
|
|
* @return array
|
|
*/
|
|
public function getStaffList()
|
|
{
|
|
try {
|
|
$academicStaff = Personnel::where('status', Personnel::STATUS_NORMAL)
|
|
->where('position', 'like', '%教务%')
|
|
->field('id,name,position,phone')
|
|
->select()
|
|
->toArray();
|
|
|
|
$coaches = Personnel::where('status', Personnel::STATUS_NORMAL)
|
|
->where('position', 'like', '%教练%')
|
|
->field('id,name,position,phone')
|
|
->select()
|
|
->toArray();
|
|
|
|
return [
|
|
'code' => 1,
|
|
'data' => [
|
|
'academic_staff' => $academicStaff,
|
|
'coaches' => $coaches
|
|
],
|
|
'msg' => '获取人员列表成功'
|
|
];
|
|
} catch (\Exception $e) {
|
|
Log::write('获取人员列表异常: ' . $e->getMessage());
|
|
return ['code' => 0, 'msg' => '获取人员列表失败:' . $e->getMessage()];
|
|
}
|
|
}
|
|
}
|