作者 lyh

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6

... ... @@ -6,6 +6,7 @@ use App\Http\Logic\Bside\Blog\BlogLogic;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Logic\Bside\Product\ProductLogic;
use App\Models\Import\ImportTask;
use App\Models\Mail\Mail;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
... ... @@ -56,6 +57,8 @@ class ProjectImport extends Command
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import fail, error: 文件编码格式错误' . PHP_EOL;
$task->status = ImportTask::STATUS_COM;//导入完成
$task->save();
$this->send_mail($task->user_id, $task->created_at, $task->type, 0, 0, '文件编码格式错误,仅支持UTF-8和GBK编码格式');
return true;
} elseif ($file_code_type === 'GBK') {
$is_gbk = 1;
... ... @@ -74,11 +77,14 @@ class ProjectImport extends Command
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import fail, error: ' . $e->getMessage() . PHP_EOL;
$task->status = ImportTask::STATUS_COM;//导入完成
$task->save();
$this->send_mail($task->user_id, $task->created_at, $task->type, 0, 0, '读取文件数据失败');
return true;
}
$total_count = 0; //总条数
$success_count = 0; //成功导入条数
$repeat_count = 0; //过滤已存在条数
if (count($line_of_text) > 1) {
$task->status = ImportTask::STATUS_ING;//导入中
$task->save();
... ... @@ -100,14 +106,20 @@ class ProjectImport extends Command
if ($task->type == ImportTask::TYPE_NEWS) {
if ((new NewsLogic())->importNews($task->project_id, $task->user_id, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
}
} elseif ($task->type == ImportTask::TYPE_BLOG) {
if ((new BlogLogic())->importBlog($task->project_id, $task->user_id, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
}
} else {
if ((new ProductLogic())->importProduct($task->project_id, $task->user_id, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
}
}
} catch (\Exception $e) {
... ... @@ -125,13 +137,15 @@ class ProjectImport extends Command
$task->success_count += $success_count;
$task->save();
$this->send_mail($task->user_id, $task->created_at, $task->type, $success_count, $repeat_count, '');
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import end, total count: ' . $total_count . ', success count: ' . $success_count . PHP_EOL;
sleep(2);
}
//判断编码格式
function get_code_type($file)
protected function get_code_type($file)
{
$list = array('GBK', 'UTF-8');
$str = file_get_contents($file);
... ... @@ -143,4 +157,27 @@ class ProjectImport extends Command
}
return false;
}
//发生站内通知
protected function send_mail($user_list, $time, $type, $success_count, $repeat_count, $reason)
{
if ($type == ImportTask::TYPE_NEWS) {
$type_content = '新闻';
} elseif ($type == ImportTask::TYPE_BLOG) {
$type_content = '博客';
} else {
$type_content = '产品';
}
$title = '导入结果通知';
$content = '您于 ' . $time . ' 添加的 ' . $type_content . ' 导入任务已执行完成, 成功导入数据:' . $success_count . ' 条';
$repeat_count && $content .= ',过滤已存在数据:' . $repeat_count . ' 条';
$reason && $content .= ',原因:' . $reason;
$mail_model = new Mail();
$mail_model->add([
'user_list' => $mail_model->setUserList($user_list),
'title' => $title,
'content' => $content
]);
}
}
... ...
<?php
/**
* @remark :
* @name :ImportChannel.php
* @author :lyh
* @method :post
* @time :2023/9/25 15:31
*/
namespace App\Console\Commands;
use App\Helper\OaGlobalsoApi;
use App\Models\Channel\Channel;
use App\Models\Project\Project;
use Illuminate\Console\Command;
class ImportChannel extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import_channel';
/**
* The console command description.
*
* @var string
*/
protected $description = '更新渠道信息';
/**
* @remark :导入5.0管理员数据
* @name :handle
* @author :lyh
* @method :post
* @time :2023/8/7 17:49
*/
public function handle(){
$projectModel = new Project();
$map = [
'channel'=>['like','%"user_id": "0"%'],
];
$lists = $projectModel->list($map);
// var_dump($lists);
// die();
foreach ($lists as $k => $v){
$order_id = $v['notice_order_id'];
$api = new OaGlobalsoApi();
$data = $api->order_info($order_id);
$data = $data['data'];
$channel = Channel::getProjectChannel($data['company_id'], $data['username_sales']);
$projectModel->edit(['channel'=>$channel],['id'=>$v['id']]);
}
return 1;
}
}
... ...
... ... @@ -75,8 +75,6 @@ class OptimizeController extends BaseController
$item['keyword_num'] = $item['key'] ?? 0;
$item['autologin_code'] = getAutoLoginCode($item['id']);
// $item['article_num'] = ($data['blog'] ?? 0) + ($data['news'] ?? 0);
// $item['task_finish_num'] = Task::getNumByProjectId($item['id'], Task::STATUS_DOWN);
// $item['task_pending_num'] = Task::getNumByProjectId($item['id'], [Task::STATUS_DONGING, Task::STATUS_WAIT]);
return $item;
}
/**
... ... @@ -122,6 +120,7 @@ class OptimizeController extends BaseController
'gl_project_deploy_optimize.domain AS domain',
'gl_project_deploy_optimize.quality_mid AS quality_mid',
'gl_project_deploy_optimize.design_mid AS design_mid',
'gl_project_deploy_optimize.special AS special',
];
return $select;
}
... ... @@ -135,9 +134,39 @@ class OptimizeController extends BaseController
*/
public function searchParam(&$query){
//搜索条件处理
if(isset($this->map['title'])){
if(isset($this->map['title']) && !empty($this->map['title'])){
$query = $query->where('gl_project.title','like','%'.$this->map['title'].'%');
}
if(isset($this->map['special']) && !empty($this->map['special'])){
$query = $query->where('gl_project_deploy_optimize.special','like','%'.$this->map['special'].'%');
}
if(isset($this->map['manager_mid']) && !empty($this->map['manager_mid'])){
$query = $query->where('gl_project_deploy_build.manager_mid','like','%'.$this->map['manager_mid'].'%');
}
if(isset($this->map['optimize_manager_mid']) && !empty($this->map['optimize_manager_mid'])){
$query = $query->where('gl_project_deploy_optimize.manager_mid','like','%'.$this->map['optimize_manager_mid'].'%');
}
if(isset($this->map['optimize_tech_mid']) && !empty($this->map['optimize_tech_mid'])){
$query = $query->where('gl_project_deploy_optimize.tech_mid','like','%'.$this->map['optimize_tech_mid'].'%');
}
if(isset($this->map['optimize_optimist_mid']) && !empty($this->map['optimize_optimist_mid'])){
$query = $query->where('gl_project_deploy_optimize.optimist_mid','like','%'.$this->map['optimize_optimist_mid'].'%');
}
if(isset($this->map['optimize_assist_mid']) && !empty($this->map['optimize_assist_mid'])){
$query = $query->where('gl_project_deploy_optimize.assist_mid','like','%'.$this->map['optimize_assist_mid'].'%');
}
if(isset($this->map['user_id']) && !empty($this->map['user_id'])){
$query->where(function ($subQuery) {
$subQuery->orWhere('gl_project.channel','like','%"user_id": "'.$this->map['user_id'].'"%')
->orWhere('gl_project.channel','like','%"user_id": '.$this->map['user_id'].'%');
});
}
if(isset($this->map['domain']) && !empty($this->map['domain'])){
$query = $query->where('gl_project_deploy_optimize.domain','like','%'.$this->map['domain'].'%');
}
if(isset($this->map['test_domain']) && !empty($this->map['test_domain'])){
$query = $query->where('gl_project_deploy_build.test_domain','like','%'.$this->map['test_domain'].'%');
}
$query = $query->whereIn('gl_project.type',[2,4]);//TODO::2,4代表优化项目
return $query;
}
... ...
... ... @@ -48,9 +48,9 @@ class Channel extends Model
$user['id'] = $userModel->addReturnId($data);
}
return [
'zone_id' => $channel['zone_id'] ?? 0,
'channel_id' => $channel['id'] ?? 0,
'user_id' => $user['id'] ?? 0,
'zone_id' => (string)$channel['zone_id'] ?? 0,
'channel_id' => (string)$channel['id'] ?? 0,
'user_id' => (string)$user['id'] ?? 0,
];
}
... ...