作者 ZhengBing He

Merge remote-tracking branch 'origin/master' into workorder

... ... @@ -23,6 +23,7 @@ use App\Models\Project\ProjectWhiteHatAffix;
use App\Models\Template\BTemplateMain;
use App\Models\Template\TemplateTypeMain;
use App\Models\WebSetting\WebSetting;
use App\Models\WorkOrder\TicketLog;
use App\Models\WorkOrder\Tickets;
use App\Services\AiBlogService;
use App\Services\CosService;
... ... @@ -51,11 +52,11 @@ class lyhDemo extends Command
public function handle(){
echo 'start.'. PHP_EOL;
$ticketModel = new Tickets();
$list = $ticketModel->list(['end_at'=>['!=',null]],'id',['id','created_at','end_at']);
$list = $ticketModel->list(['id'=>['!=',0]],'id',['id','plan_end_at']);
foreach ($list as $item){
echo '执行的任务id:'.$item['id'].PHP_EOL;
$end_time = diffInHours($item['created_at'],$item['end_at']);
$ticketModel->edit(['end_time'=>$end_time],['id'=>$item['id']]);
echo '执行数据id:'.$item['id'].PHP_EOL;
$ticketLogModel = new TicketLog();
$ticketLogModel->edit(['plan_end_at'=>$item['plan_end_at']],['ticket_id'=>$item['id']]);
}
return true;
}
... ...
... ... @@ -46,12 +46,11 @@ class RankDataLog extends BaseCommands
{
while (true) {
$log_id = Redis::rpop('rank_data_task');
if (!$log_id) {
$log = RankDataLogModel::where('status', 0)->first();
}else{
$log = RankDataLogModel::where('id', $log_id)->where('status', 0)->first();
$log_id = RankDataLogModel::where('status', 0)->value('id');
}
$log = RankDataLogModel::where('id', $log_id)->where('status', 0)->first();
if(!$log){
sleep(10);
continue;
... ...
... ... @@ -59,14 +59,15 @@ class RerunSeoTdk extends Command
*/
public function handle()
{
$where = [
'id' => 624
];
$project_ids = Project::where('type', Project::TYPE_TWO)->where($where)->pluck('id')->toArray();
$project_ids = Project::where('type', Project::TYPE_TWO)->where('site_status',0)->where('extend_type',0)->where('delete_status',0)->where('tag_page_version', '>' ,1)->where('uptime', '<=', date('Y-m-d H:i:s'))->pluck('id')->toArray();
foreach ($project_ids as $project_id){
try {
ProjectServer::useProject($project_id);
$this->changeCompanyName($project_id);
$project = ProjectServer::useProject($project_id);
//小语种
if($project['main_lang_id'] != 1){
$this->needTransKeywordPage($project_id);
}
DB::disconnect('custom_mysql');
}catch (\Exception $e){
dump($e->getMessage());
... ... @@ -74,6 +75,13 @@ class RerunSeoTdk extends Command
}
}
public function needTransKeywordPage($project_id)
{
$row = Keyword::whereNotNull('sale_title')->update(['sale_title' => null, 'sale_content' => null, 'count_title'=>null, 'table_html'=>null, 'count_html' => null]);
dump($project_id .' - ' .$row);
}
/**
* 换了公司英文名的
* @author zbj
... ...
... ... @@ -9,12 +9,17 @@
namespace App\Console\Commands\Ticket;
use App\Models\Manage\BelongingGroup;
use App\Models\Manage\ManageHr;
use App\Models\Ticket\TicketDailyCount;
use App\Models\Ticket\TicketDailyDeptCount;
use App\Models\Ticket\TicketDailyManageCount;
use App\Models\WorkOrder\TicketLog;
use App\Models\WorkOrder\TicketProject;
use App\Models\WorkOrder\Tickets;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
class TicketCount extends Command
{
... ... @@ -32,6 +37,11 @@ class TicketCount extends Command
*/
protected $description = '日统计工单';
public $belong = [
1 => [1,2,3,4,5,6,7,8,9],
2 => [10,11,12],
];
/**
* @remark :统计脚本
* @name :handle
... ... @@ -40,7 +50,16 @@ class TicketCount extends Command
* @time :2025/8/7 17:45
*/
public function handle(){
$action = $this->argument('action');
if($action == 'manage_action'){
$this->manage_action();
}
if($action == 'dept_action'){
$this->dept_action();
}
if($action == 'yesterday_daily_action'){
$this->yesterday_daily_action();
}
}
/**
... ... @@ -56,26 +75,132 @@ class TicketCount extends Command
$date = date('Y-m-d');
$ticketManageCountModel = new TicketDailyManageCount();
foreach ($manageList as $item){
$this->output('按人员统计:执行的人员名称/id:'.$item['name'].'/'.$item['manage_id']);
$ticketLogModel = new TicketLog();
$ticket_num = $ticketLogModel->counts(['engineer_id'=>$item['manage_id'],'is_engineer'=>1]);
//工单总时长
$timeCount = $ticketLogModel->formatQuery(['engineer_id'=>$item['manage_id'],'is_engineer'=>1])->sum('end_time');
$ticket_end_num = $ticketLogModel->counts(['engineer_id'=>$item['manage_id'],'is_engineer'=>1,'end_at'=>['!=',null]]);
if(!empty($timeCount)){
$average_time = round($timeCount / $ticket_end_num, 2);
}
//最快完成的时间
$fastest_time = $ticketLogModel->formatQuery(['engineer_id'=>$item['manage_id'],'is_engineer'=>1,'end_at'=>['!=',null]])->min('end_time');
//超时工单数量
$timeout_num = $ticketLogModel->counts(['end_at'=>null,'plan_end_at'=>['>',date('Y-m-d H:i:s')]]);
$complete_num = $ticketLogModel->counts(['end_at'=>['!=',null]]);
$data = [
'date'=>$date,
'manage_id'=>$item['id'],
'manage_name'=>$item['name'],
'ticket_num'=>$ticket_num,//工单总数量
'average_time'=>'',//平均完成工单时长
'fastest_time'=>'',//最快完成工单时间
'timeout_num'=>'',//超时工单数量
'complete_num'=>'',//完成工单数量
'average_time'=>$average_time ?? '',//平均完成工单时长
'fastest_time'=>$fastest_time,//最快完成工单时间
'timeout_num'=>$timeout_num,//超时工单数量
'complete_num'=>$complete_num,//完成工单数量
];
//查询当前用户是否当日已有记录
$ticketManageInfo = $ticketManageCountModel->read(['date'=>$date,'manage_id'=>$item['id']],['id']);
if($ticketManageInfo === false){
//TODO::执行新增
$ticketManageCountModel->addReturnId($data);
}else{
//TODO::执行编辑
$ticketManageCountModel->edit($data,['id'=>$ticketManageInfo['id']]);
}
}
return true;
}
/**
* @remark :按技术组统计数据
* @name :dept_action
* @author :lyh
* @method :post
* @time :2025/8/8 11:48
*/
public function dept_action(){
$belongingGroupModel = new BelongingGroup();
$groupList = $belongingGroupModel->list(['id'=>['in',[1,2,3,4,5,6,7,8,9]]],'id',['id','name']);
$manageHrModel = new ManageHr();
$ticketLogModel = new TicketLog();
$ticketDailyDeptModel = new TicketDailyDeptCount();
$date = date('Y-m-d');
foreach ($groupList as $item){
$this->output('组统计:执行的组/id:'.$item['name'].'/'.$item['id']);
$manageIdArr = $manageHrModel->selectField(['belong_group'=>$item['id'],'status'=>1],'manage_id');
$ticket_num = $ticketLogModel->counts(['engineer_id'=>['in',$manageIdArr],'is_engineer'=>1]);
$timeCount = $ticketLogModel->formatQuery(['engineer_id'=>['in',$manageIdArr],'is_engineer'=>1])->sum('end_time');
if(!empty($timeCount)){
$average_time = round($timeCount / $ticket_num, 2);
}
$data = [
'date'=>$date,
'dept_id'=>$item['id'],
'dept_name'=>$item['name'],
'ticket_num'=>$ticket_num ?? 0,
'average_time'=>$average_time
];
$deptInfo = $ticketDailyDeptModel->read(['date'=>$date,'dept_id'=>$item['id']],['id']);
if($deptInfo === false){
$ticketDailyDeptModel->addReturnId($data);
}else{
$ticketDailyDeptModel->edit($data,['id'=>$deptInfo['id']]);
}
}
return true;
}
/**
* @remark :
* @name :daily_action
* @author :lyh
* @method :post
* @time :2025/8/8 14:33
*/
public function yesterday_daily_action(){
$ticketModel = new Tickets();
$date = Carbon::yesterday()->toDateString(); // "2025-08-07"
$ticket_num = $ticketModel->counts(['id'=>['!=',0]]);
$time_end_num = $ticketModel->counts(['end_at'=>['!=',null]]);//已完成的工单
$time_end_count = $ticketModel->formatQuery(['end_at'=>['!=',null]])->sum('end_time');//已完成工单时长
if(!empty($time_end_count)){
$average_time = round($time_end_count / $time_end_num, 2);
}
$add_num = $ticketModel->counts(['created_at'=>['between',[$date.' 00:00:00',$date.' 23:59:59']]]);
$untreated_num = $ticketModel->counts(['end_at'=>null]);
$processed_num = $ticketModel->counts(['end_at'=>['between',[$date.' 00:00:00',$date.' 23:59:59']]]);
$submit_a_side = $ticketModel->formatQuery(['submit_side'=>1])->sum('submit_side');
$submit_b_side = $ticketModel->formatQuery(['submit_side'=>2])->sum('submit_side');
$data = [
'date' => $date,
'ticket_num'=>$ticket_num,
'add_num'=>$add_num,
'untreated_num'=>$untreated_num,
'processed_num'=>$processed_num,
'average_time'=>$average_time ?? '',
'source'=>json_encode(['a'=>$submit_a_side,'b'=>$submit_b_side],true),
];
$ticketDailyModel = new TicketDailyCount();
$ticketDailyInfo = $ticketDailyModel->read(['date'=>$date],['id']);
if($ticketDailyInfo === false){
$ticketDailyModel->addReturnId($data);
}else{
$ticketDailyModel->edit($data,['id'=>$ticketDailyInfo['id']]);
}
return true;
}
/**
* @remark :日志
* @name :output
* @author :lyh
* @method :post
* @time :2025/8/8 11:43
*/
public function output($message)
{
// Log::channel('ticket_log')->info($message);
echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
}
}
... ...
... ... @@ -143,7 +143,11 @@ class ProjectController extends BaseController
* @time :2023/12/29 17:14
*/
public function orderByList($query){
$query = $query->orderBy('gl_project.uptime', 'desc')->orderBy('gl_project.id', 'desc');
if(isset($this->map['seo_plan']) && $this->map['seo_plan'] == 1){
$query = $query->orderBy('gl_project.cooperate_date', 'desc')->orderBy('gl_project.id', 'desc');
}else{
$query = $query->orderBy('gl_project.uptime', 'desc')->orderBy('gl_project.id', 'desc');
}
return $query;
}
... ...
... ... @@ -84,6 +84,7 @@ class Tickets extends Base
if ($log && $log->is_engineer != in_array($engineer_id, $engineer_ids))
{
$log->is_engineer = in_array($engineer_id, $engineer_ids);
$log->plan_end_at = $this->plan_end_at; // 新增时写入 plan_end_at
$log->save();
}else
{
... ... @@ -91,6 +92,7 @@ class Tickets extends Base
$log = new TicketLog();
$log->engineer_id = $engineer_id;
$log->is_engineer = in_array($engineer_id, $engineer_ids);
$log->plan_end_at = $this->plan_end_at; // 新增时写入 plan_end_at
$this->logs()->save($log);
}
}catch (\Exception $exception){
... ...