作者 赵彬吉
正在显示 35 个修改的文件 包含 799 行增加546 行删除
... ... @@ -119,6 +119,8 @@ class ProjectImport extends Command
}
}
$v[0] = $this->special2str($v[0]);
$total_count += 1;
try {
if ($task->type == ImportTask::TYPE_NEWS) {
... ... @@ -200,6 +202,30 @@ class ProjectImport extends Command
return false;
}
//特殊字符转换
protected function special2str($str)
{
if (strpos($str, ';') === false) {
return $str;
}
$list = [
'&lt;' => '<',
'&gt;' => '>',
'&amp;' => '&',
'&acute;' => "'",
'&quot;' => '"',
'&nbsp;' => ' ',
'&#x27;' => "'"
];
foreach ($list as $k => $v) {
$str = str_replace($k, $v, $str);
}
return $str;
}
//发送站内通知
protected function send_mail($user_list, $time, $type, $success_count, $repeat_count, $fail_count, $reason, $fail_line = [])
{
... ...
... ... @@ -136,7 +136,7 @@ class HtmlCollect extends Command
}
$update_log = UpdateLog::where('project_id', '<', 799)->where('status', UpdateLog::STATUS_COM)->where('collect_status', UpdateLog::COLLECT_STATUS_UN)->orderBy('project_id', 'asc')->first();
$update_log = UpdateLog::whereNotIn('project_id', [626])->where('status', UpdateLog::STATUS_COM)->where('collect_status', UpdateLog::COLLECT_STATUS_UN)->orderBy('project_id', 'asc')->first();
if (!$update_log) {
return false;
}
... ...
... ... @@ -20,21 +20,21 @@ use Illuminate\Support\Facades\Redis;
* @author Akun
* @date 2023/11/10 16:04
*/
class HtmlCollectNew extends Command
class HtmlSpecialCollect extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project_html_collect_new';
protected $signature = 'project_html_special_collect';
/**
* The console command description.
*
* @var string
*/
protected $description = '执行项目html页面采集';
protected $description = '执行特殊项目html页面采集';
public function handle()
... ... @@ -129,14 +129,14 @@ class HtmlCollectNew extends Command
//获取任务
protected function get_task()
{
$key = 'console_html_collect_new_task';
$key = 'console_html_special_collect_task';
$task_id = Redis::rpop($key);
if ($task_id) {
return $task_id;
}
$update_log = UpdateLog::where('project_id', '>=', 799)->where('status', UpdateLog::STATUS_COM)->where('collect_status', UpdateLog::COLLECT_STATUS_UN)->orderBy('project_id', 'asc')->first();
$update_log = UpdateLog::whereIn('project_id', [626])->where('status', UpdateLog::STATUS_COM)->where('collect_status', UpdateLog::COLLECT_STATUS_UN)->orderBy('project_id', 'asc')->first();
if (!$update_log) {
return false;
}
... ... @@ -267,7 +267,8 @@ class HtmlCollectNew extends Command
&& (strpos($path_end, 'com') === false)
&& (strpos($path_end, 'xml') === false)
) {
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
$new_url = str_replace($home_url, $web_url_domain, $url);
$source = CollectSource::where('project_id', $project_id)->where('origin', $new_url)->first();
if (!$source) {
return [
'download' => true,
... ...
<?php
namespace App\Console\Commands\Update;
use App\Models\Com\UpdateVisit;
use App\Models\Visit\Visit;
use App\Models\Visit\VisitItem;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* 4.0,5.0升级到6.0,访问同步
* Class ProjectImport
* @package App\Console\Commands
* @author Akun
* @date 2023/12/18 15:52
*/
class ProjectVisit extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project_visit';
/**
* The console command description.
*
* @var string
*/
protected $description = '执行项目升级访问任务';
public function handle()
{
ini_set('memory_limit', '512M');
while (true) {
$this->start_visit();
}
}
protected function start_visit()
{
$task_id = $this->get_task();
if (!$task_id) {
sleep(60);
return true;
}
$task = UpdateVisit::where('id', $task_id)->where('status', UpdateVisit::STATUS_UN)->first();
if (!$task) {
sleep(2);
return true;
}
$project_id = $task->project_id;
$api_type = $task->api_type;
$api_url = $task->api_url;
$page_size = 1000;
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL;
$task->status = UpdateVisit::STATUS_ING;//同步中
$task->save();
//设置数据库
$project = ProjectServer::useProject($project_id);
if ($project) {
if ($api_type == 'visit_list') {
//访问列表
$url = $api_url . '?' . http_build_query(['w' => 'visit_list', 'page' => 1, 'pagesize' => 1]);
$data = curl_c($url);
if (isset($data['count']) && $data['count'] > 0) {
$count = $data['count'];
$max_id = $data['data'][0]['id'] ?? 0;
$is_stop = 0;
$total_page = ceil($count / $page_size);
for ($page = 1; $page <= $total_page; $page++) {
if ($is_stop) {
break;
}
$url_page = $api_url . '?' . http_build_query(['w' => 'visit_list', 'page' => $page, 'pagesize' => $page_size]);
$data_page = curl_c($url_page);
if (isset($data_page['data']) && $data_page['data']) {
$items = $data_page['data'];
$model = new Visit();
$insert = [];
foreach ($items as $item) {
if (isset($item['id']) && $item['id']) {
if ($item['id'] > $task->max_id) {
$url_arr = parse_url($item['request'] ?? '');
$insert[] = [
'url' => $item['request'] ?? '',
'referrer_url' => $item['referrer'] ?? '',
'device_port' => isset($item['is_moblie']) && $item['is_moblie'] == 1 ? 2 : 1,
'country' => $item['ip_area'] ?? '',
'ip' => $item['ip'] ?? '',
'depth' => $item['pv'],
'domain' => $url_arr['host'] ?? '',
'is_inquiry' => $item['is_cf'] ?? 0,
'created_at' => date('Y-m-d H:i:s', isset($item['update']) && $item['update'] ? $item['update'] : time()),
'updated_at' => date('Y-m-d H:i:s', isset($item['update']) && $item['update'] ? $item['update'] : time()),
'updated_date' => date('Y-m-d', isset($item['c_time']) && $item['c_time'] ? strtotime($item['c_time']) : time()),
'original_id' => $item['id'],
];
} else {
$is_stop = 1;
break;
}
}
}
if ($insert) {
try {
$model->insert($insert);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ',page: ' . $page . ' error: ' . $e->getMessage() . PHP_EOL;
continue;
}
}
}
}
if ($max_id) {
$task->max_id = $max_id;
}
} else {
return true;
}
} else {
//访问明细
$url = $api_url . '?' . http_build_query(['w' => 'visit_detail_list', 'page' => 1, 'pagesize' => 1]);
$data = curl_c($url);
if (isset($data['count']) && $data['count'] > 0) {
$count = $data['count'];
$max_id = $data['data'][0]['id'] ?? 0;
$is_stop = 0;
$total_page = ceil($count / $page_size);
for ($page = 1; $page <= $total_page; $page++) {
if ($is_stop) {
break;
}
$url_page = $api_url . '?' . http_build_query(['w' => 'visit_detail_list', 'page' => $page, 'pagesize' => $page_size]);
$data_page = curl_c($url_page);
if (isset($data_page['data']) && $data_page['data']) {
$items = $data_page['data'];
$model = new VisitItem();
$p_model = new Visit();
$insert = [];
foreach ($items as $item) {
if (isset($item['id']) && $item['id']) {
if ($item['id'] > $task->max_id) {
$p_info = $p_model->read(['ip' => $item['ip'] ?? '', 'updated_date' => $item['day_at'] ?? '']);
if ($p_info) {
$insert[] = [
'customer_visit_id' => $p_info['id'],
'url' => $p_info['url'],
'referrer_url' => $p_info['referrer_url'],
'device_port' => $p_info['device_port'],
'country' => $p_info['country'],
'ip' => $p_info['ip'],
'domain' => $p_info['domain'],
'created_at' => $item['time_str'] ?? $p_info['created_at'],
'updated_at' => $item['time_str'] ?? $p_info['updated_at'],
'updated_date' => $item['day_at'] ?? $p_info['updated_date'],
'original_id' => $item['id'],
];
}
} else {
$is_stop = 1;
break;
}
}
}
if ($insert) {
try {
$model->insert($insert);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ',page: ' . $page . ' error: ' . $e->getMessage() . PHP_EOL;
continue;
}
}
}
}
if ($max_id) {
$task->max_id = $max_id;
}
} else {
return true;
}
}
}
//关闭数据库
DB::disconnect('custom_mysql');
$task->status = UpdateVisit::STATUS_COM;//同步完成
$task->save();
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL;
sleep(2);
}
//获取任务
protected function get_task()
{
$key = 'console_visit_task';
$task_id = Redis::rpop($key);
if ($task_id) {
return $task_id;
}
$task_list = UpdateVisit::where('status', UpdateVisit::STATUS_UN)->orderBy('sort', 'asc')->orderBy('project_id', 'asc')->limit(20)->get();
if ($task_list->count() == 0) {
return false;
}
foreach ($task_list as $value) {
Redis::lpush($key, $value->id);
}
$task_id = Redis::rpop($key);
return $task_id;
}
}
... ...
... ... @@ -53,9 +53,13 @@ class UpdateRoute extends Command
* @time :2023/11/20 15:13
*/
public function handle(){
ProjectServer::useProject(75);
$this->getProductKeyword();
DB::disconnect('custom_mysql');
$projectModel = new Project();
$list = $projectModel->list(['type'=>['in',[1,2,3,4]]]);
foreach ($list as $v){
ProjectServer::useProject($v['id']);
$this->getProductKeyword();
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
... ... @@ -68,14 +72,18 @@ class UpdateRoute extends Command
*/
public function getProductKeyword(){
$keywordModel = new Keyword();
$lists = $keywordModel->list(['route'=>'']);
$lists = $keywordModel->list(['status'=>1]);
if(!empty($lists)){
foreach ($lists as $v){
echo date('Y-m-d H:i:s') . 'id :'.$v['id'] . PHP_EOL;
$route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']);
$this->curlDelRoute(['new_route'=>$route]);
$this->model->edit(['route'=>$route],['id'=>$v['id']]);
echo date('Y-m-d H:i:s') . 'end :'.$route . PHP_EOL;
$tag = "-tag";
if (!(substr($v['route'], -strlen($tag)) === $tag)) {
echo date('Y-m-d H:i:s') . '拼接'.$tag . PHP_EOL;
$route = $v['route'].$tag;
// 如果不是以 '-tag' 结尾,则拼接上 '-tag'
$routeModel = new RouteMap();
$routeModel->edit(['route'=>$route],['source'=>RouteMap::SOURCE_PRODUCT_KEYWORD,'source_id'=>$v['id']]);
$keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
}
}
}
}
... ...
... ... @@ -66,11 +66,11 @@ class Handler extends ExceptionHandler
'-------错误行数:' . $exception->getLine();
//A端错误
if ($exception instanceof AsideGlobalException) {
LogUtils::error("AsideGlobalException", [], $exceptionMessage);
// LogUtils::error("AsideGlobalException", [], $exceptionMessage);
}
//B端错误
elseif($exception instanceof BsideGlobalException) {
LogUtils::error("BsideGlobalException", [], $exceptionMessage);
// LogUtils::error("BsideGlobalException", [], $exceptionMessage);
}
//验证错误(非手动抛出)
elseif ($exception instanceof ValidationException) {
... ...
<?php
/**
* @remark :
* @name :CreateKeywordController.php
* @author :lyh
* @method :post
* @time :2023/12/19 9:14
*/
namespace App\Http\Controllers\Aside\Optimize;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Optimize\CreateKeywordLogic;
use App\Models\Com\CreateKeyword;
/**
* @remark :生成关键字
* @name :CreateKeywordController
* @author :lyh
* @method :post
* @time :2023/12/19 9:14
*/
class CreateKeywordController extends BaseController
{
/**
* @remark :根据类型获取对应的语种
* @name :lists
* @author :lyh
* @method :post
* @time :2023/12/19 9:31
*/
public function lists(CreateKeyword $createKeyword){
$list = $createKeyword->list($this->map);
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :保存数据
* @name :save
* @author :lyh
* @method :post
* @time :2023/12/19 9:35
*/
public function save(CreateKeywordLogic $logic){
$this->request->validate([
'type'=>'required|integer',
'name'=>'required',
],[
'type.required' => '类型不能为空',
'type.integer' => '类型必须为数字',
'name.required' => '名称不能为空',
]);
$logic->saveKeyword();
$this->response('success');
}
/**
* @remark :创建关键字
* @name :createKeyword
* @author :lyh
* @method :post
* @time :2023/12/19 10:12
*/
public function createKeyword(CreateKeywordLogic $logic){
$data = $logic->createKeyword();
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -46,23 +46,6 @@ class CNoticeController extends BaseController
];
http_post($url, json_encode($param));
$this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
// $updateProgressModel = new UpdateProgress();
// $progressInfo = $updateProgressModel->formatQuery(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']])->orderBy('id','desc')->first();
// if((!empty($progressInfo))){
// $progressInfo = $progressInfo->toArray();
// if(($progressInfo['total_num'] > $progressInfo['current_num'])){
// $this->response('当前页面正在生成了,请完成后再点击',Code::SUCCESS,$progressInfo);
// }
// }
// //通知更新
// if($this->param['type'] == UpdateNotify::TYPE_MASTER){
// $this->updateMaster();
// }else{
// $this->updateMinorLanguages();
// }
// $urlStr = $this->getString($this->param['type'],$this->param['page']);
// curlGet($urlStr);
// $this->response('更新成功');
}
/**
... ...
... ... @@ -35,14 +35,6 @@ class ComController extends BaseController
$this->map = $this->getAdminMenuCondition();
}
$lists = $projectMenuModel->list($this->map,'sort');
foreach ($lists as $k => $v){
$v = (array)$v;
if(empty($this->user['is_upload_manage'])){
if($v['rules'] == '/fileUpload'){
unset($lists[$k]);
}
}
}
$menu = array();
foreach ($lists as $k => $v){
$v = (array)$v;
... ... @@ -94,15 +86,24 @@ class ComController extends BaseController
* @time :2023/9/6 11:47
*/
public function getNoAdminMenuCondition(){
$code = $this->getIsHome();
$projectRoleModel = new ProjectRoleModel();
$info = $projectRoleModel->read(['id'=>$this->user['role_id']]);
if($info === false){
$this->fail('当前登录角色不存在');
}else{
$code = $this->getIsHome();
if($code != 1){
$info['role_menu'] = trim(str_replace(',11,',',',','.$info['role_menu'].','),',');
}
$blogCode = $this->getIsBlog();
if($blogCode != 1){
$info['role_menu'] = trim(str_replace(',16,',',',','.$info['role_menu'].','),',');
$info['role_menu'] = trim(str_replace(',17,',',',','.$info['role_menu'].','),',');
}
$uploadCode = $this->getIsUpload();
if($uploadCode != 1){
$info['role_menu'] = trim(str_replace(',41,',',',','.$info['role_menu'].','),',');
}
$this->map = [
'status'=>0,
'is_role'=>0,
... ... @@ -120,10 +121,23 @@ class ComController extends BaseController
* @time :2023/9/6 13:53
*/
public function getAdminMenuCondition(){
$data = [];
$this->map['status'] = 0;
$code = $this->getIsHome();
$code = $this->getIsHome();//是否开启首页
if($code != 1){
$this->map['id'] = ['!=',11];//排除菜单网站装修
$data[] = 11;
}
$blogCode = $this->getIsBlog();//是否开启blog
if($blogCode != 1){
$data[] = 16;
$data[] = 17;
}
$uploadCode = $this->getIsUpload();//是否开启上传
if($uploadCode != 1){
$data[] = 41;
}
if(!empty($data)){
$this->map['id'] = ['not in',$data];
}
return $this->map;
}
... ... @@ -152,6 +166,34 @@ class ComController extends BaseController
}
/**
* @remark :是否开启上传配置
* @name :getIsUpload
* @author :lyh
* @method :post
* @time :2023/12/19 17:22
*/
public function getIsUpload(){
if($this->user['is_upload_manage'] != 0){
return 1;
}
return 0;
}
/**
* @remark :是否显示博客
* @name :getIsBlog
* @author :lyh
* @method :post
* @time :2023/12/19 16:44
*/
public function getIsBlog(){
if($this->user['is_show_blog'] != 0){
return 1;//不显示
}
return 0;
}
/**
* @name :登录用户编辑资料/修改密码
* @author :liyuhang
* @method
... ...
... ... @@ -9,7 +9,6 @@ use App\Http\Requests\Bside\Blog\BlogRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\Product\Category;
use App\Models\RouteMap\RouteMap;
use App\Models\User\User;
... ... @@ -56,12 +55,8 @@ class BlogController extends BaseController
$query = $query->where('project_id',$this->user['project_id']);
if (isset($this->map['category_id']) && !empty($this->map['category_id'])) {
$str = [];
$this->getLastLevelIds($this->map['category_id'],$str);
$query->where(function ($subQuery) use ($str) {
foreach ($str as $v) {
$subQuery->orWhereRaw("FIND_IN_SET(?, category_id) > 0", [$v]);
}
});
$this->getAllSub($this->map['category_id'],$str);
$query = $query->whereIn('category_id',$str);
}
if(isset($this->map['status'])){
$query = $query->where('status',$this->map['status']);
... ... @@ -76,24 +71,22 @@ class BlogController extends BaseController
}
/**
* @remark :获取当前分类的最后一级id
* @name :getLastLevelIds
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/20 15:02
* @time :2023/10/18 15:10
*/
public function getLastLevelIds($id, &$str = []) {
$cateModel = new BlogCategoryModel();
$subList = $cateModel->where('pid', $id)->get();
if ($subList->isEmpty()) {
// 如果没有子集,将当前 ID 添加到最后一级 ID 数组
$str[] = $id;
} else {
// 如果有子集,继续向下遍历
foreach ($subList as $v) {
$this->getLastLevelIds($v->id, $str);
public function getAllSub($id,&$str = []){
$cateModel = new BlogCategory();
$list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
... ... @@ -158,7 +151,7 @@ class BlogController extends BaseController
public function get_category_list(){
$this->map['status'] = 0;
$this->map['project_id'] = $this->user['project_id'];
$blogCategoryModel = new BlogCategoryModel();
$blogCategoryModel = new BlogCategory();
$cate_list = $blogCategoryModel->list($this->map,'sort');
if($cate_list === false){
$this->fail('error',Code::USER_ERROR);
... ...
... ... @@ -299,5 +299,9 @@ class LoginController extends BaseController
}
return $data;
}
public function ceshi(){
$ceshi = Translate::tran('Полностью Сварной Пластинчатый Теплообменник', 'en');
return $ceshi;
}
}
... ...
... ... @@ -8,6 +8,7 @@ use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Nav\NavLogic;
use App\Http\Requests\Bside\Nav\NavRequest;
use App\Models\Nav\BNav;
use App\Models\Nav\BNavGroup;
/**
* 导航栏目 b端编辑 c端显示
... ... @@ -27,21 +28,53 @@ class NavController extends BaseController
* @method :post
* @time :2023/12/4 15:00
*/
public function index(BNav $nav){
public function index(BNav $nav,BNavGroup $navGroup){
$this->map['project_id'] = $this->user['project_id'];
$lists = $nav->list($this->map,$this->order = ['sort','id']);
$data = array();
foreach ($lists as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $lists);
$data[] = $v;
//获取菜单组排序字段
$groupInfo = $navGroup->read(['id'=>$this->param['group_id']]);
if(!empty($groupInfo['sort_list'])){
$sort_list = json_decode($groupInfo['sort_list']);
$data = $this->findDetailsList($sort_list,$lists);
}else{
$data = array();
foreach ($lists as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $lists);
$data[] = $v;
}
}
}
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :根据固定的数组排序
* @name :findDetailsInList
* @author :lyh
* @method :post
* @time :2023/12/18 14:54
*/
public function findDetailsList($data, $detailsList) {
$result = [];
foreach ($data as $item) {
$items = $item = (array)$item;
$id = $item['id'];
// 在给定的详情列表中查找匹配的id
$matchingDetail = array_filter($detailsList, function ($detail) use ($id) {
return $detail['id'] == $id;
});
if (!empty($matchingDetail)) {
$items = reset($matchingDetail);
}
if (!empty($item['sub'])) {
$items['sub'] = $this->findDetailsList((array)$item['sub'], $detailsList);
}
$result[] = $items;
}
return $result;
}
/**
* @remark :获取当前id下的所有子集
... ... @@ -137,4 +170,21 @@ class NavController extends BaseController
$navLogic->importNav();
$this->response('success');
}
/**
* @remark :菜单列表排序
* @name :setSortList
* @author :lyh
* @method :post
* @time :2023/12/18 13:44
*/
public function setSortList(NavLogic $navLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空',
]);
$navLogic->setSortList();
$this->response('success');
}
}
... ...
... ... @@ -58,12 +58,8 @@ class NewsController extends BaseController
$query = $query->where('project_id',$this->user['project_id']);
if (isset($this->map['category_id']) && !empty($this->map['category_id'])) {
$str = [];
$this->getLastLevelIds($this->map['category_id'],$str);
$query->where(function ($subQuery) use ($str) {
foreach ($str as $v) {
$subQuery->orWhereRaw("FIND_IN_SET(?, category_id) > 0", [$v]);
}
});
$this->getAllSub($this->map['category_id'],$str);
$query = $query->whereIn('category_id',$str);
}
if(isset($this->map['status'])){
$query = $query->where('status',$this->map['status']);
... ... @@ -78,24 +74,22 @@ class NewsController extends BaseController
}
/**
* @remark :获取当前分类的最后一级id
* @name :getLastLevelIds
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/20 15:02
* @time :2023/10/18 15:10
*/
public function getLastLevelIds($id, &$str = []) {
public function getAllSub($id,&$str = []){
$cateModel = new NewsCategory();
$subList = $cateModel->where('pid', $id)->get();
if ($subList->isEmpty()) {
// 如果没有子集,将当前 ID 添加到最后一级 ID 数组
$str[] = $id;
} else {
// 如果有子集,继续向下遍历
foreach ($subList as $v) {
$this->getLastLevelIds($v->id, $str);
$list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
... ...
... ... @@ -86,7 +86,7 @@ class CategoryController extends BaseController
}
/**
* @name :(添加/编辑时获取顶级分类)topList
* @name :(添加/编辑时获取分类)topList
* @author :lyh
* @method :post
* @time :2023/6/13 9:03
... ...
... ... @@ -79,12 +79,8 @@ class ProductController extends BaseController
$query = $query->where('project_id',$this->user['project_id']);
if (isset($this->map['category_id']) && !empty($this->map['category_id'])) {
$str = [];
$this->getLastLevelIds($this->map['category_id'],$str);
$query->where(function ($subQuery) use ($str) {
foreach ($str as $v) {
$subQuery->orWhereRaw("FIND_IN_SET(?, category_id) > 0", [$v]);
}
});
$this->getAllSub($this->map['category_id'],$str);
$query = $query->whereIn('category_id',$str);
}
if(isset($this->map['title']) && !empty($this->map['title'])){
$query = $query->where('title','like','%'.$this->map['title'].'%');
... ... @@ -99,24 +95,22 @@ class ProductController extends BaseController
}
/**
* @remark :获取当前分类的最后一级id
* @name :getLastLevelIds
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/20 15:02
* @time :2023/10/18 15:10
*/
public function getLastLevelIds($id, &$str = []) {
public function getAllSub($id,&$str = []){
$cateModel = new Category();
$subList = $cateModel->where('pid', $id)->get();
if ($subList->isEmpty()) {
// 如果没有子集,将当前 ID 添加到最后一级 ID 数组
$str[] = $id;
} else {
// 如果有子集,继续向下遍历
foreach ($subList as $v) {
$this->getLastLevelIds($v->id, $str);
$list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
... ...
<?php
/**
* @remark :
* @name :CreateKeywordLogic.php
* @author :lyh
* @method :post
* @time :2023/12/19 9:45
*/
namespace App\Http\Logic\Aside\Optimize;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Com\CreateKeyword;
class CreateKeywordLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new CreateKeyword();
$this->param = $this->requestAll;
}
/**
* @remark :保存关键字
* @name :saveCreateKeyword
* @author :lyh
* @method :post
* @time :2023/12/19 9:47
*/
public function saveKeyword(){
$data = $this->handleParam($this->param);
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->model->edit($data,['id'=>$this->param['id']]);
}else{
$this->model->add($data);
}
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
return $this->success();
}
/**
* @remark :请求参数处理
* @name :handleParam
* @author :lyh
* @method :post
* @time :2023/12/19 10:03
*/
public function handleParam($param){
$data = [
'type'=>$param['type'],
'name'=>$param['name'],
'language_id'=>$param['language_id'] ?? 0
];
if(!isset($param['id'])){
$info = $this->model->read($data);
if($info !== false){
$this->fail('当前名称已存在');
}
}
return $this->success($data);
}
/**
* @remark :创建关键词
* @name :createKeyword
* @author :lyh
* @method :post
* @time :2023/12/19 10:48
*/
public function createKeyword(){
$data = array();
if(empty($this->param['keyword'])){
return $this->success($data);
}
$prefix_keyword = $this->prefixKeyword($this->param['prefix'] ?? [],$this->param['keyword']);
$keyword_suffix = $this->keywordSuffix($this->param['suffix'] ?? [],$this->param['keyword']);
$prefix_keyword_suffix = $this->prefixKeywordSuffix($this->param['prefix'] ?? [],$this->param['suffix'] ?? [],$this->param['keyword']);
$data = [
'prefix_keyword'=>$prefix_keyword,
'keyword_suffix'=>$keyword_suffix,
'prefix_keyword_suffix'=>$prefix_keyword_suffix
];
return $this->success($data);
}
/**
* @remark :前缀+关键词
* @name :
* @author :lyh
* @method :post
* @time :2023/12/19 11:11
*/
public function prefixKeyword($prefix,$keyword){
$prefix_keyword = array();
if(!empty($prefix)){//前缀+关键词
foreach ($keyword as $keywordItem){
foreach ($prefix as $prefixItem) {
$prefix_keyword[] =$prefixItem.' '.$keywordItem;
}
}
}
return $this->success($prefix_keyword);
}
/**
* @remark :关键词+后缀
* @name :
* @author :lyh
* @method :post
* @time :2023/12/19 11:11
*/
public function keywordSuffix($suffix,$keyword){
$suffix_keyword = array();
if(!empty($suffix)){//前缀+关键词
foreach ($keyword as $keywordItem){
foreach ($suffix as $suffixItem) {
$suffix_keyword[] = $keywordItem.' '.$suffixItem;
}
}
}
return $this->success($suffix_keyword);
}
/**
* @remark :前缀+关键词+后缀
* @name :prefixKeywordSuffix
* @author :lyh
* @method :post
* @time :2023/12/19 11:59
*/
public function prefixKeywordSuffix($prefix,$suffix,$keyword){
$prefix_keyword_suffix = array();
if(!empty($prefix) && !empty($suffix)){
foreach ($keyword as $keywordItem){
foreach ($prefix as $prefixItem) {
foreach ($suffix as $suffixItem) {
$prefix_keyword_suffix[] = $prefixItem.' '.$keywordItem.' '.$suffixItem;
}
}
}
}
return $this->success($prefix_keyword_suffix);
}
}
... ...
... ... @@ -714,7 +714,7 @@ class ProjectLogic extends BaseLogic
'company_name'=>$projectInfo['company'],
'principal_mobile'=>$projectInfo['mobile'],
'remark'=>'',
'exclusive_aicc_day'=>$projectInfo['exclusive_aicc_day'] ?: 1,
'exclusive_aicc_day'=>$this->param['exclusive_aicc_day'] ?: 1,
'from_order_id'=>$projectInfo['from_order_id']
];
$this->toAicc($data);
... ... @@ -724,7 +724,7 @@ class ProjectLogic extends BaseLogic
$data = [
'company_name'=>$projectInfo['company'],
'principal_mobile'=>$projectInfo['mobile'],
'exclusive_hagro_day'=>$projectInfo['exclusive_hagro_day'] ?: 1,
'exclusive_hagro_day'=>$this->param['exclusive_hagro_day'] ?: 1,
'from_order_id'=>$projectInfo['from_order_id'],
'company_id'=>$projectInfo['channel']['channel_id']
];
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Aside\Template;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\RouteMap\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
... ... @@ -222,6 +223,7 @@ class ATemplateLogic extends BaseLogic
];
$bCommonTemplateModel->add($commonData);
}
RouteMap::setRoute('index', RouteMap::SOURCE_PAGE, 0, $project_id);
DB::disconnect('custom_mysql');
return $this->success();
}
... ...
... ... @@ -667,15 +667,20 @@ class BTemplateLogic extends BaseLogic
* @method :any
* @time :2023/7/17 16:03
*/
/**
* @remark :获取类型
* @name :getModuleType
* @author :lyh
* @method :any
* @time :2023/7/17 16:03
*/
public function getModuleType(): array
{
//定义数据结构
$data = $this->model->product_type;
//产品,新闻,博客,一级分类数据
$map = ['pid'=>0, 'project_id'=>$this->user['project_id']];
$productCategory = Category::where($map)->get();
$newCategory = NewsCategory::where($map)->get();
$blogCategory = BlogCategory::where($map)->get();
$productCategory = $this->getCategoryList((new Category()),1);
$newCategory = $this->getCategoryList((new NewsCategory()));
$blogCategory = $this->getCategoryList((new BlogCategory()));
if (!empty($productCategory)){
foreach ($productCategory as $item){$data["products"]["category"][] =$item;}
}
... ... @@ -690,6 +695,26 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :获取1级+2级
* @name :getCategoryList
* @author :lyh
* @method :post
* @time :2023/12/20 10:26
*/
public function getCategoryList($categoryModel,$status = 0){
$data = array();
$list = $categoryModel->list(['pid'=>0,'status'=>$status]);
foreach ($list as $v){
$data[] = $v;
$son_list = $categoryModel->list(['pid'=>$v['id'],'status'=>$status]);
foreach ($son_list as $v1){
$data[] = $v1;
}
}
return $this->success($data);
}
/**
* @remark :保存html
* @name :savePublicTemplateHtml
* @author :lyh
... ...
... ... @@ -34,7 +34,6 @@ class BlogCategoryLogic extends BaseLogic
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']);
$route = $this->param['alias'];
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
... ... @@ -47,8 +46,6 @@ class BlogCategoryLogic extends BaseLogic
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
$this->edit(['alias'=>$route],['id'=>$id]);
//处理子集
$this->addProcessingSon($id);
}
DB::commit();
}catch (\Exception $e){
... ... @@ -61,48 +58,6 @@ class BlogCategoryLogic extends BaseLogic
}
/**
* @remark :编辑分类,处理博客数据
* @name :editCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:32
*/
public function editHandleCategory($id,$pid){
$info = $this->model->read(['id'=>$id],['id','pid']);
if($info['pid'] != $pid){
//修改勒上级,先查看上级是否拥有博客
$blogModel = new BlogModel();
$blogCount = $blogModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
if($blogCount > 0){
//随机获取最后一级id
$replacement = $this->getLastId($id);
//存在博客时,移动所有博客到当前分类最后一级
$blogModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
$blogModel->where('category_id', 'like', '%,' . $pid . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
}
}
return $this->success();
}
/**
* @remark :随机获取当前id下最后一级的id
* @name :getLastId
* @author :lyh
* @method :post
* @time :2023/10/20 9:45
*/
public function getLastId($id){
$info = $this->model->read(['pid'=>$id],['id']);
if($info !== false){
return $this->getLastId($info['id']);
}else{
return $id;
}
}
/**
* @name :详情
* @return array
* @author :liyuhang
... ... @@ -122,7 +77,7 @@ class BlogCategoryLogic extends BaseLogic
public function status_blog_category(){
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
if($rs === false){
$this->fail('error');
}
return $this->success();
... ... @@ -248,37 +203,6 @@ class BlogCategoryLogic extends BaseLogic
}
/**
* @param $cate_id
* @name :(处理子集)addProcessingSon
* @author :lyh
* @method :post
* @time :2023/6/13 11:59
*/
public function addProcessingSon($cate_id){
if(!isset($this->param['pid'])){
$this->param['pid'] = 0;
}
//判断为子分类时
if($this->param['pid'] != 0){
//查看当前上级分类下是否有其他子分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$blogModel = new BlogModel();
$blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($blog_count > 0) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$blogModel->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
return $this->success();
}
/**
* @remark :删除路由
* @name :delRoute
* @author :lyh
... ... @@ -322,7 +246,7 @@ class BlogCategoryLogic extends BaseLogic
$pid = $id;
}
}
return $this->getLastCategory($return);
return $this->getCategory($return);
}
/**
... ... @@ -332,15 +256,12 @@ class BlogCategoryLogic extends BaseLogic
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
public function getCategory($category){
$str = '';
foreach ($category as $v){
$info = $this->model->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...
... ... @@ -133,12 +133,9 @@ class CustomModuleCategoryLogic extends BaseLogic
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_MODULE_CATE,
$id, $this->user['project_id']);
$this->handleAddSon($id);
$this->addUpdateNotify(RouteMap::SOURCE_MODULE_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->edit(['route' => $route], ['id' => $id]);
//处理上级分类商品
$this->handleAddSon($id);
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
... ... @@ -155,7 +152,6 @@ class CustomModuleCategoryLogic extends BaseLogic
public function categoryEdit(){
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_MODULE_CATE,
$this->param['id'], $this->user['project_id']);
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->editRoute($this->param['id'],$route);
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
... ... @@ -165,48 +161,6 @@ class CustomModuleCategoryLogic extends BaseLogic
}
/**
* @remark :编辑分类,处理博客数据
* @name :editCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:32
*/
public function editHandleCategory($id,$pid){
$info = $this->model->read(['id'=>$id],['id','pid']);
if($info['pid'] != $pid){
//修改勒上级,先查看上级是否拥有产品
$contentModel = new CustomModuleContent();
$contentCount = $contentModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
if($contentCount > 0){
//随机获取最后一级id
$replacement = $this->getLastId($id);
//存在博客时,移动所有博客到当前分类最后一级
$contentModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
$contentModel->where('category_id', 'like', '%,' . $pid . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
}
}
return $this->success();
}
/**
* @remark :随机获取当前id下最后一级的id
* @name :getLastId
* @author :lyh
* @method :post
* @time :2023/10/20 9:45
*/
public function getLastId($id){
$info = $this->model->read(['pid'=>$id],['id']);
if($info !== false){
return $this->getLastId($info['id']);
}else{
return $id;
}
}
/**
* @remark :查看是否编辑路由
* @name :editCategoryRoute
* @author :lyh
... ... @@ -225,46 +179,6 @@ class CustomModuleCategoryLogic extends BaseLogic
}
/**
* @name :(添加分类时处理子集分类)addProcessingSon
* @author :lyh
* @method :post
* @time :2023/6/13 11:34
*/
public function handleAddSon($cate_id){
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
$this->param['pid'] = 0;
}
//判断为子分类时
if($this->param['pid'] != 0) {
//查看当前上级分类下是否有其他分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]],['id']);
if ($cate_info === false) {
//查看当前上一级分类下是否有关联模块内容
$contentModel = new CustomModuleContent();
$news_count = $contentModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($news_count > 0) {
$replacement = $this->handleStr($cate_id);
$old = $this->handleStr($this->param['pid']);
//更新所有商品到当前分类
$contentModel->where('category_id', 'like', '%' . $old . '%')->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
return $this->success();
}
/**
* @remark :处理字符串
* @name :handleStr
* @author :lyh
* @method :post
* @time :2023/12/5 18:03
*/
public function handleStr($str){
return ',' . $str . ',';
}
/**
* @remark :删除数据
* @name :ModuleDel
* @author :lyh
... ...
... ... @@ -192,7 +192,7 @@ class CustomModuleContentLogic extends BaseLogic
$param['project_id'] = $this->user['project_id'];
}
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = $this->getLastCategory($param['category_id']);
$param['category_id'] = $this->getCategory($param['category_id']);
}
if(isset($param['image']) && !empty($param['image'])){
$param['image'] = str_replace_url($param['image']);
... ... @@ -219,22 +219,18 @@ class CustomModuleContentLogic extends BaseLogic
}
/**
* @remark :获取最后一级分类id
* @remark :处理分类
* @name :getLastCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
public function getCategory($category){
$str = '';
$cateModel = new CustomModuleCategory();
foreach ($category as $v){
$info = $cateModel->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...
... ... @@ -29,12 +29,21 @@ class ImportLogic extends BaseLogic
if (end($ext) != 'csv') {
$this->fail('导入文件格式必须为csv');
}
$domain = $this->param['domain'];
if (strpos($domain, 'https') === false || strpos($domain, 'http') == false) {
$this->fail('请输入完整的采集页面地址');
}
$domain_arr = parse_url($domain);
if (!isset($domain_arr['host'])) {
$this->fail('采集页面地址输入有误');
}
$this->param['domain'] = $domain_arr['host'];
$this->param['project_id'] = $this->user['project_id'];
$this->param['user_id'] = $this->user['id'];
$this->param['status'] = 9;
$rs = $this->model->add($this->param);
if($rs === false){
if ($rs === false) {
$this->fail('error');
}
return $this->success();
... ...
... ... @@ -250,7 +250,21 @@ class NavLogic extends BaseLogic
}
}
/**
* @remark :排序字段
* @name :setSortList
* @author :lyh
* @method :post
* @time :2023/12/18 13:47
*/
public function setSortList(){
$navGroupModel = new BNavGroup();
if(!empty($this->param['sort_list'])){
$this->param['sort_list'] = json_encode($this->param['sort_list']);
}
$navGroupModel->edit(['sort_list'=>$this->param['sort_list']],['id'=>$this->param['id']]);
return $this->success();
}
... ...
... ... @@ -46,7 +46,6 @@ class NewsCategoryLogic extends BaseLogic
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']);
$route = $this->param['alias'];
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
... ... @@ -57,8 +56,6 @@ class NewsCategoryLogic extends BaseLogic
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
$this->model->edit(['alias'=>$route],['id'=>$id]);
//当父级分类拥有产品时,处理子集
$this->addProcessingSon($id);
}
DB::commit();
}catch (\Exception $e){
... ... @@ -71,49 +68,6 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @remark :编辑分类,处理博客数据
* @name :editCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:32
*/
public function editHandleCategory($id,$pid){
$info = $this->model->read(['id'=>$id],['id','pid']);
if($info['pid'] != $pid){
//修改勒上级,先查看上级是否拥有博客
$newsModel = new NewsModel();
$newsCount = $newsModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
//随机获取最后一级id
$replacement = $this->getLastId($id);
if($newsCount > 0){
//存在博客时,移动所有博客到当前分类最后一级
$newsModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
$newsModel->where('category_id', 'like', '%,' . $pid . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
}
}
return $this->success();
}
/**
* @remark :随机获取当前id下最后一级的id
* @name :getLastId
* @author :lyh
* @method :post
* @time :2023/10/20 9:45
*/
public function getLastId($id){
$info = $this->model->read(['pid'=>$id],['id']);
if($info !== false){
return $this->getLastId($info['id']);
}else{
return $id;
}
}
/**
* @remark :修改状态
* @name :status_news_category
* @author :lyh
... ... @@ -231,36 +185,6 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @name :(添加分类时处理子集分类)addProcessingSon
* @author :lyh
* @method :post
* @time :2023/6/13 11:34
*/
public function addProcessingSon($cate_id){
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
$this->param['pid'] = 0;
}
//判断为子分类时
if($this->param['pid'] != 0) {
//查看当前上级分类下是否有其他分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$newsModel = new NewsModel();
$news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($news_count > 0) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$newsModel->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
return $this->success();
}
/**
* @remark :删除路由
* @name :delRoute
* @author :lyh
... ... @@ -303,7 +227,7 @@ class NewsCategoryLogic extends BaseLogic
$pid = $id;
}
}
return $this->getLastCategory($return);
return $this->getCategory($return);
}
/**
... ... @@ -313,15 +237,12 @@ class NewsCategoryLogic extends BaseLogic
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
public function getCategory($category){
$str = '';
foreach ($category as $v){
$info = $this->model->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...
... ... @@ -167,36 +167,32 @@ class NewsLogic extends BaseLogic
if(isset($this->param['id'])){
$param['operator_id'] = $this->user['id'];
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = $this->getLastCategory($param['category_id']);
$param['category_id'] = $this->getCategory($param['category_id']);
}
}else{
$param['create_id'] = $this->user['id'];
$param['operator_id'] = $this->user['id'];
$param['project_id'] = $this->user['project_id'];
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = $this->getLastCategory($param['category_id']);
$param['category_id'] = $this->getCategory($param['category_id']);
}
}
return $this->success($param);
}
/**
* @remark :获取最后一级分类id
* @remark :获取分类(字符串)
* @name :getLastCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
public function getCategory($category){
$str = '';
$cateModel = new NewsCategoryModel();
foreach ($category as $v){
$info = $cateModel->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...
... ... @@ -115,16 +115,12 @@ class CategoryLogic extends BaseLogic
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $this->param['id'], $this->user['project_id']);
$route = $this->param['route'];
//处理子集
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
$this->edit(['route'=>$route],['id'=>$id]);
//处理子集
$this->addProcessingSon($id);
}
//清除缓存
Common::del_user_cache('product_category',$this->user['project_id']);
... ... @@ -139,90 +135,6 @@ class CategoryLogic extends BaseLogic
}
/**
* @param $cate_id
* @name :(处理子集)addProcessingSon
* @author :lyh
* @method :post
* @time :2023/6/13 11:59
*/
public function addProcessingSon($cate_id){
if(!isset($this->param['pid'])){
$this->param['pid'] = 0;
}
//判断为子分类时
if($this->param['pid'] != 0){
//查看当前上级分类下是否有其他子分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
$productModel = new Product();
$blog_count = $productModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($blog_count > 0) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$productModel->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
//同步更新关联表
$categoryRelatedModel = new CategoryRelated();
$categoryRelatedModel->edit(['category_id'=>$cate_id],['category_id'=>$this->param['pid']]);
}
}
}
return $this->success();
}
/**
* @remark :编辑分类,处理博客数据
* @name :editCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:32
*/
public function editHandleCategory($id,$pid){
$info = $this->model->read(['id'=>$id],['id','pid']);
if($info['pid'] != $pid){
//修改勒上级,先查看上级是否拥有博客
$productModel = new Product();
$blogCount = $productModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
if($blogCount > 0){
//随机获取最后一级id
$replacement = $this->getLastId($id);
//存在博客时,移动所有博客到当前分类最后一级
$productModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
$productModel->where('category_id', 'like', '%,' . $pid . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
//同步更新关联表
$categoryRelatedModel = new CategoryRelated();
$cateRelateList = $categoryRelatedModel->list(['category_id'=>$pid]);
if(!empty($cateRelateList)){
foreach ($cateRelateList as $v){
$categoryRelatedModel->del(['category_id'=>$replacement,'product_id'=>$v['product_id']]);
}
}
$categoryRelatedModel->edit(['category_id'=>$replacement],['category_id'=>$pid]);
}
}
return $this->success();
}
/**
* @remark :随机获取当前id下最后一级的id
* @name :getLastId
* @author :lyh
* @method :post
* @time :2023/10/20 9:45
*/
public function getLastId($id){
$info = $this->model->read(['pid'=>$id],['id']);
if($info !== false){
return $this->getLastId($info['id']);
}else{
return $id;
}
}
/**
* @remark :删除
* @name :delete
* @author :lyh
... ... @@ -309,13 +221,10 @@ class CategoryLogic extends BaseLogic
$str = '';
if(isset($category) && !empty($category)){
foreach ($category as $v){
$info = $this->model->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...
... ... @@ -95,7 +95,7 @@ class ProductLogic extends BaseLogic
public function handleCategory(){
$category_ids = [];
if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
$category_ids = $this->getLastCategoryArr($this->param['category_id']);
$category_ids = $this->param['category_id'];
$this->param['category_id'] = ','.implode(',',$category_ids).',';
}else{
$this->param['category_id'] = '';
... ... @@ -176,7 +176,7 @@ class ProductLogic extends BaseLogic
* @time :2023/10/26 9:49
*/
public function editList(){
$this->param['category_id'] = $this->getLastCategory($this->param['category_id']);
$this->param['category_id'] = $this->handleListCategory($this->param['category_id']);
$this->param['keyword_id'] = $this->saveKeyword($this->param['keyword_id']);
if(isset($this->param['gallery']) && !empty($this->param['gallery'])){
foreach ($this->param['gallery'] as $k => $v){
... ... @@ -186,7 +186,7 @@ class ProductLogic extends BaseLogic
$this->param['thumb'] = Arr::a2s($this->param['gallery'][0] ?? []);
$this->param['gallery'] = Arr::a2s($this->param['gallery'] ?? []);
}else{
$this->param['thumb'] = Arr::a2s([]);
unset($this->param['thumb']);
}
try {
if(isset($this->param['route']) && !empty($this->param['route'])){
... ... @@ -195,7 +195,7 @@ class ProductLogic extends BaseLogic
}
$this->model->edit($this->param,['id'=>$this->param['id']]);
}catch (\Exception $e){
$this->fail('系统错误,请连续管理员');;
$this->fail('系统错误,请连续管理员');
}
return $this->success();
}
... ... @@ -276,24 +276,20 @@ class ProductLogic extends BaseLogic
}
/**
* @remark :获取最后一级分类id(字符串)
* @remark :列表标记处理分类(字符串)
* @name :getLastCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
public function handleListCategory($category){
$str = '';
if(isset($category) && !empty($category)){
$cateModel = new Category();
foreach ($category as $v){
$info = $cateModel->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ... @@ -306,12 +302,8 @@ class ProductLogic extends BaseLogic
public function getLastCategoryArr($category){
$arr = [];
if(isset($category) && !empty($category)){
$cateModel = new Category();
foreach ($category as $v){
$info = $cateModel->read(['pid'=>$v]);
if($info === false){
$arr[] = $v;
}
$arr[] = $v;
}
}
return $arr;
... ...
... ... @@ -165,7 +165,9 @@ class UserLoginLogic
$info['domain'] = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ($project['deploy_build']['test_domain'] ?? ''));
$info['is_customized'] = $project['is_customized'];
$info['is_upload_manage'] = $project['is_upload_manage'];
$info['is_show_blog'] = $project['is_show_blog'];
$info['upload_config'] = $project['upload_config'];
$info['main_lang_id'] = $project['main_lang_id'];
$info['image_max'] = $project['image_max'];
$info['is_update_language'] = $project['is_update_language'];
$info['configuration'] = $project['deploy_build']['configuration'];
... ... @@ -199,7 +201,9 @@ class UserLoginLogic
((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ($project['deploy_build']['test_domain'] ?? ''));
$info['is_customized'] = $project['is_customized'];
$info['is_upload_manage'] = $project['is_upload_manage'];
$info['is_show_blog'] = $project['is_show_blog'];
$info['upload_config'] = $project['upload_config'];
$info['main_lang_id'] = $project['main_lang_id'];
$info['image_max'] = $project['image_max'];
$info['is_update_language'] = $project['is_update_language'];
$info['configuration'] = $project['deploy_build']['configuration'];
... ...
... ... @@ -35,6 +35,7 @@ class ImportTaskRequest extends FormRequest
return [
'type' => ['required', Rule::in([ImportTask::TYPE_PROJECT, ImportTask::TYPE_NEWS, ImportTask::TYPE_BLOG])],
'file_url' => ['required'],
'domain' => ['required'],
];
}
... ... @@ -44,6 +45,7 @@ class ImportTaskRequest extends FormRequest
'type.required' => '导入类型必须',
'type.in' => '导入类型错误',
'file_url.required' => '文件地址必须',
'domain.required' => '采集页面地址必须填写',
];
}
}
... ...
<?php
/**
* @remark :
* @name :CreateKeyword.php
* @author :lyh
* @method :post
* @time :2023/12/19 9:34
*/
namespace App\Models\Com;
use App\Models\Base;
/**
* @remark :关键字
* @name :CreateKeyword
* @author :lyh
* @method :post
* @time :2023/12/19 9:34
*/
class CreateKeyword extends Base
{
protected $table = 'gl_create_keyword';
}
... ...
<?php
namespace App\Models\Com;
use Illuminate\Database\Eloquent\Model;
class UpdateVisit extends Model
{
//设置关联表名
protected $table = 'gl_update_visit';
const STATUS_UN = 0;//未开始
const STATUS_ING = 1;//导入中
const STATUS_COM = 2;//导入完成
}
... ...
... ... @@ -58,15 +58,14 @@ class RouteMap extends Base
$i=1;
$sign = generateRoute($title);
$info = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
if($info === false){
$suffix = '';
if(empty($info)){
if($source == self::SOURCE_PRODUCT_KEYWORD){
$suffix = '-tag';
}
if($source == self::SOURCE_PRODUCT){
$suffix = '-product';
}
}else{
$suffix = '';
}
$route = $sign.$suffix;
while(self::isExist($route, $source_id, $project_id)){
... ... @@ -140,45 +139,6 @@ class RouteMap extends Base
return $route;
}
// /**
// * @remark :产品新增单独处理路由
// * @name :setProductRoute
// * @author :lyh
// * @method :post
// * @time :2023/11/21 18:48
// */
// public static function setProductRoute($route,$i = 0){
// $routes = $route.'-'.$i.'-product';
// $routeMapModel = new RouteMap();
// $routeInfo = $routeMapModel->read(['route'=>$routes]);
// if($routeInfo === false){
// return $routes;
// }else{
// $i = $i + 1;
// return self::setProductRoute($route,$i);
// }
// }
//
// /**
// * @remark :关键字新增单独处理路由
// * @name :setProductRoute
// * @author :lyh
// * @method :post
// * @time :2023/11/21 18:48
// */
// public static function setKeywordRoute($route,$i = 0){
// $routes = $route.'-'.$i.'-tag';
// $routeMapModel = new RouteMap();
// $routeInfo = $routeMapModel->read(['route'=>$routes]);
// if($routeInfo === false){
// return $routes;
// }else{
// $i = $i + 1;
// return self::setKeywordRoute($route,$i);
// }
// }
/**
* @param $route
* @param $project_id
... ...
... ... @@ -259,6 +259,13 @@ Route::middleware(['aloginauth'])->group(function () {
Route::any('/saveAiPrefix', [Aside\Optimize\OptimizeController::class, 'saveAiPrefix'])->name('admin.optimize_saveAiPrefix');//保存Ai前后缀
Route::any('/setRobots', [Aside\Optimize\OptimizeController::class, 'setRobots'])->name('admin.optimize_setRobots');//设置robots开关
});
//生成关键字
Route::prefix('create_keyword')->group(function () {
Route::any('/', [Aside\Optimize\CreateKeywordController::class, 'lists'])->name('admin.create_keywords_lists');//创建关键字获取语种+前后缀
Route::any('/save', [Aside\Optimize\CreateKeywordController::class, 'save'])->name('admin.create_keywords_save');//保存关键字获取语种+前后缀
Route::any('/createKeyword', [Aside\Optimize\CreateKeywordController::class, 'createKeyword'])->name('admin.create_keywords_createKeyword');//保存关键字获取语种+前后缀
});
//优化中台
Route::prefix('keyword')->group(function () {
... ...
... ... @@ -373,6 +373,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::get('/default-urls', [\App\Http\Controllers\Bside\Nav\NavController::class, 'urls'])->name('nav_default-urls');
Route::post('/sort', [\App\Http\Controllers\Bside\Nav\NavController::class, 'sort'])->name('nav_sort');
Route::post('/import', [\App\Http\Controllers\Bside\Nav\NavController::class, 'import'])->name('nav_import');
Route::post('/setSortList', [\App\Http\Controllers\Bside\Nav\NavController::class, 'setSortList'])->name('nav_setSortList');
});
//排名数据
... ...