作者 lyh

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

... ... @@ -74,15 +74,15 @@ class ProjectFilePDF extends Command
public function dataPush(array $items)
{
foreach ($items as $item) {
$project_id = $item->project_id;
$application_id = $item->wx_id;
$wx_user_id = $item->wx_user_id;
$project_id = $item->project_id;
$user_id = $item->user_id;
$friend_id = $item->friend_id;
// todo 根据项目查询数据
$project_data = [];
$html = $this->html($project_data);
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $application_id);
$filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
$file_path = $this->savePDF($html, $filename);
$this->DataFile->saveData(compact('project_id', 'application_id', 'file_path') + ['time' => $this->time]);
$this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
}
}
... ...
... ... @@ -63,7 +63,7 @@ class HtmlLanguageCollect extends Command
//设置数据库
$project = ProjectServer::useProject($project_id);
if ($project) {
$collect_info = CollectTask::select(['id', 'domain', 'route'])->where('id', $collect_id)->where('status', CollectTask::STATUS_UN)->where('language', '!=', '')->first();
$collect_info = CollectTask::select(['id', 'domain', 'route', 'language'])->where('id', $collect_id)->where('status', CollectTask::STATUS_UN)->where('language', '!=', '')->first();
if (!$collect_info) {
sleep(2);
... ... @@ -75,10 +75,18 @@ class HtmlLanguageCollect extends Command
$collect_info->status = CollectTask::STATUS_ING;
$collect_info->save();
$web_url_domain = $collect_info->domain;
$home_url = $collect_info->domain;
$url_web_config = 'https://' . $collect_info->domain . '/wp-content/cache/user_config.text';
$data_config = http_get($url_web_config, ['charset' => 'UTF-8']);
//获取英文站域名
$domain = $collect_info->domain;
if (strpos($domain, '/') !== false) {
$domain = substr($domain, 0, strpos($domain, '/'));
} else {
$domain = str_replace($collect_info->language, 'www', $domain);
}
$web_url_domain = $domain;
$home_url = $domain;
$url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';
$data_config = curl_c($url_web_config);
if ($data_config) {
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
if (isset($web_url_arr['host'])) {
... ... @@ -93,20 +101,11 @@ class HtmlLanguageCollect extends Command
//采集html页面,下载资源到本地并替换
try {
$opts = [
'http' => [
'header' => 'User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0'
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
];
$html = file_get_contents('https://' . $collect_info->domain . $collect_info->route, false, stream_context_create($opts));
$html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
$source_list = $this->html_preg($html, $project_id, $collect_info->domain, $web_url_domain, $home_url);
if ($source_list) {
$html = $this->upload_source($html, $source_list, $project_id, $opts);
$html = $this->upload_source($html, $source_list, $project_id);
}
} catch (\Exception $e) {
$collect_info->status = CollectTask::STATUS_FAIL;
... ... @@ -279,7 +278,7 @@ class HtmlLanguageCollect extends Command
}
//下载并替换资源
protected function upload_source($html, $source, $project_id, $opts)
protected function upload_source($html, $source, $project_id)
{
foreach ($source as $vs) {
... ... @@ -297,7 +296,7 @@ class HtmlLanguageCollect extends Command
if (substr($new_source, -3, 3) == 'css') {
// 下载css文件中的资源
$css_html = file_get_contents($vs['url_complete'], false, stream_context_create($opts));
$css_html = curl_c($vs['url_complete'], false);
preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $css_html, $result_css_source);
$css_source = $result_css_source[1] ?? [];
... ...
... ... @@ -140,7 +140,7 @@ class ProjectUpdate extends Command
'seo_keywords' => $item['seo_keywords'] ?? '',
'seo_description' => $item['seo_description'] ?? '',
]);
$route = RouteMap::setRoute($this->get_url_route($item['url']) ?: $item['name'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
$route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
$model->edit(['route' => $route], ['id' => $id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
... ... @@ -273,7 +273,7 @@ class ProjectUpdate extends Command
]),
'status' => Product::STATUS_ON
]);
$route = RouteMap::setRoute($this->get_url_route($item['url']) ?: $item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);
$route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT, $id, $project_id);
$model->edit(['route' => $route], ['id' => $id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
... ... @@ -328,7 +328,7 @@ class ProjectUpdate extends Command
'image' => $item['images'][0] ?? '',
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE
]);
$route = RouteMap::setRoute($this->get_url_route($item['url']) ?: $item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
$route = $this->set_map($this->get_url_route($item['url']), $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
$model->edit(['url' => $route], ['id' => $id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
... ... @@ -377,7 +377,7 @@ class ProjectUpdate extends Command
'html' => $item['content'] ?? '',
'status' => 1
]);
$route = RouteMap::setRoute($this->get_url_route($item['url']) ?: $item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
$route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PAGE, $id, $project_id);
$model->edit(['url' => $route], ['id' => $id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
... ... @@ -465,7 +465,7 @@ class ProjectUpdate extends Command
'keywords' => $item['keywords'] ?? '',
'describe' => $item['description'] ?? ''
]);
$route = RouteMap::setRoute($this->get_url_route($item['url']) ?: $item['name'], RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
$route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
$model->edit(['route' => $route], ['id' => $parent_id]);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
... ... @@ -516,4 +516,28 @@ class ProjectUpdate extends Command
return $str;
}
//路由入库
protected function set_map($route, $source, $source_id, $project_id)
{
if (empty($route)) {
return '';
}
$route_map = new RouteMap();
$route_map->project_id = $project_id;
$route_map->source = $source;
$route_map->source_id = $source_id;
$route_map->route = $route;
if ($source == RouteMap::SOURCE_NEWS) {
$route_map->path = RouteMap::SOURCE_NEWS;
} elseif ($source == RouteMap::SOURCE_BLOG) {
$route_map->path = RouteMap::SOURCE_BLOG;
}
$route_map->save();
return $route;
}
}
... ...
... ... @@ -58,7 +58,8 @@ class WebsiteData extends Command
public function post_data($data)
{
$url = env('AICC_URL');
return http_post("{$url}/api/save_file_data", json_encode(compact('data')));
$msg = http_post("{$url}/api/save_file_data", json_encode(compact('data')));
print_r($msg);
}
}
... ...
... ... @@ -111,11 +111,12 @@ if (!function_exists('http_get')) {
if (!function_exists('curl_c')) {
/**
* @param $url
* @param $is_array
* @return []
* @author Akun
* @date 2023/11/22 11:33
*/
function curl_c($url){
function curl_c($url,$is_array=true){
$header = array(
'Expect:',
'Content-Type: application/json; charset=utf-8'
... ... @@ -130,11 +131,12 @@ if (!function_exists('curl_c')) {
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$content = curl_exec($ch);
curl_close($ch);
return json_decode($content, true);
return $is_array ? json_decode($content, true) : $content;
}
}
... ...
... ... @@ -116,7 +116,13 @@ class NavController extends BaseController
* @author zbj
* @date 2023/11/21
*/
public function import(){
public function import(NavLogic $navLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'ID不能为空',
]);
$navLogic->importNav();
$this->response('success');
}
}
... ...
... ... @@ -92,10 +92,11 @@ class KeywordController extends BaseController
*/
public function batchAdd(KeywordLogic $logic){
$this->request->validate([
'title'=>['required','array']
'title'=>['required','array', 'max:1000']
],[
'title.required' => 'title不能为空',
'title.array' => 'title为数组'
'title.array' => 'title为数组',
'title.max' => '批量操作不能超过1000条数据'
]);
$logic->batchAdd();
$this->response('success');
... ... @@ -119,4 +120,22 @@ class KeywordController extends BaseController
$this->response('success');
}
/**
* 批量删除
* @param KeywordLogic $logic
* @author zbj
* @date 2023/11/22
*/
public function batchDel(KeywordLogic $logic){
$this->request->validate([
'title'=>['required','array', 'max:1000']
],[
'title.required' => 'title不能为空',
'title.array' => 'title为数组',
'title.max' => '批量操作不能超过1000条数据'
]);
$logic->batchDel();
$this->response('success');
}
}
... ...
... ... @@ -31,19 +31,20 @@ class ProjectAssociationController extends BaseController
if (empty($project_id)) {
$this->fail('请选择项目!', Code::USER_PARAMS_ERROE);
}
$status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
$wx_user_id = (int)request()->post('user_id', 0);
if (empty($wx_user_id) && $status) {
$status = (bool)request()->post('status', 1); # 1 - 正常, 0 - 禁用
$user_id = (int)request()->post('user_id', 0);
if (empty($user_id) && $status) {
$this->fail('请选择要绑定的AICC用户!', Code::USER_PARAMS_ERROE);
}
$wx_id = (int)request()->post('wx_id', 0);
if (empty($wx_id) && $status) {
$this->fail('请选择要绑定的AICC项目!', Code::USER_PARAMS_ERROE);
$friend_id = (int)request()->post('friend_id', 0);
if (empty($friend_id) && $status) {
$this->fail('请选择要绑定的AICC用户列表!', Code::USER_PARAMS_ERROE);
}
$wx_nickname = request()->post('nickname', '');
$wx_user_name = request()->post('user_name', '');
$wx_image = request()->post('image', '');
$data = compact('project_id', 'wx_id', 'wx_nickname', 'wx_user_id', 'wx_user_name', 'wx_image');
$nickname = request()->post('nickname', '');
$user_name = request()->post('user_name', '');
$image = request()->post('image', '');
$data = compact('project_id', 'user_id', 'friend_id', 'nickname', 'user_name', 'image');
$this->ProjectAssociationLogic->saveWeChatData($data);
$this->response('success');
}
... ...
... ... @@ -116,4 +116,82 @@ class NavLogic extends BaseLogic
}
return $this->success();
}
/**
* 一键导入 对应分类
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
*/
public function importNav(){
$nav = $this->getInfo($this->param['id']);
if(!in_array($nav['url'], array_keys(BNav::ableImportMap()))){
$this->fail('该菜单不支持一键导入');
}
$class = BNav::ableImportMap($nav['url']);
$category = new $class();
$fields = ['id', 'name', 'pid', 'alias'];
if($nav['url'] == 'products'){
$fields = ['id', 'title as name', 'pid', 'route as alias'];
}
$this->addByPid($category, $nav, $fields);
return $this->success();
}
/**
* 一级一级的加
* @author zbj
* @date 2023/11/22
*/
protected function addByPid($category, $nav, $fields, $pid = 0)
{
$nav_pid = $nav['id'];
if($pid){
$p_cate = $category->where('id', $pid)->select($fields)->first();
if($p_cate){
$nav_pid = $this->model->where('import_id', $nav['id'])->where('url', $p_cate['alias'])->value('id');
}
}
$list = $category->list(['pid' => $pid], 'id', $fields, 'asc');
$data = [];
$time = date('Y-m-d H:i:s');
foreach ($list as $item) {
if(in_array($item['alias'], array_keys(BNav::ableImportMap()))){
continue;
}
$exists_info = $this->model->where('import_id', $nav['id'])->where('url', $item['alias'])->first();
if($exists_info){
continue;
}
$data[] = [
'pid' => $nav_pid,
'name' => $item['name'],
'url' => $item['alias'],
'project_id' => $this->project['id'],
'location' => $nav['location'],
'group_id' => $nav['group_id'],
'status' => BNav::STATUS_ACTIVE,
'import_id' => $nav['id'],
'created_at' => $time,
'updated_at' => $time,
];
}
//每500条更一次
$data_chunk = array_chunk($data,500);
foreach ($data_chunk as $chunk){
$this->model->insert($chunk);
}
foreach ($list as $item) {
$this->addByPid($category, $nav, $fields, $item['id']);
}
}
}
... ...
... ... @@ -6,6 +6,7 @@ use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\News;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
... ... @@ -38,6 +39,8 @@ class KeywordLogic extends BaseLogic
{
$info = $this->model->read($this->param);
$info['url'] = $this->user['domain'] . $info['route'];
$info['related_news_info'] = News::whereIn('id', $info['related_news_ids'])->select(['id', 'name'])->get();
return $this->success($info);
}
... ... @@ -209,4 +212,29 @@ class KeywordLogic extends BaseLogic
Common::del_user_cache('product_keyword',$project_id);
return ','.implode(',',$return).',';
}
/**
* 批量删除
* @return array
* @throws BsideGlobalException
* @throws \App\Exceptions\AsideGlobalException
* @author zbj
* @date 2023/11/22
*/
public function batchDel(){
try {
foreach ($this->param['title'] as $v){
$info = $this->model->read(['title'=>$v]);
if($info){
$this->delRoute($info['id']);
$this->model->del(['id'=>$info['id']]);
}
}
//清除缓存
Common::del_user_cache('product_keyword',$this->user['project_id']);
}catch (\Exception $e){
$this->fail('error');
}
return $this->success();
}
}
... ...
... ... @@ -10,14 +10,19 @@ class DataFile extends Base
public function saveData(array $data): bool
{
# v6项目ID
$project_id = (int)$data['project_id'] ?? 0;
$isRes = self::query()->where('project_id', $project_id)->where('created_at', 'like', $data['time'] . '%')->first();
if (!$isRes) {
$isRes = new self();
$isRes->project_id = $project_id;
}
$isRes->file_path = $data['file_path'];
$isRes->application_id = $data['application_id'];
# AICC用户ID
$isRes->user_id = $data['user_id'];
# 第三方朋友ID
$isRes->friend_id = $data['friend_id'];
# 生成文件路径
$isRes->file_path = $data['file_path'];
return $isRes->save();
}
... ...
... ... @@ -35,6 +35,21 @@ class BNav extends Base
const STATUS_DISABLED = 0;
/**
* @author zbj
* @date 2023/11/22
*/
public static function ableImportMap($url=''){
$map = [
'products' => '\\App\\Models\\Product\\Category',
'news' => '\\App\\Models\\News\\NewsCategory',
'blog' => '\\App\\Models\\Blog\\BlogCategory',
];
if ($url){
return $map[$url] ?:"";
}
return $map;
}
/**
... ... @@ -85,7 +100,7 @@ class BNav extends Base
*/
public function getAbleImportAttribute($value)
{
if(in_array($this->url, ['products','news','blogs'])){
if(in_array($this->url, array_keys(self::ableImportMap()))){
return 1;
}
return 0;
... ...
... ... @@ -67,7 +67,7 @@ class Keyword extends Base
if(!empty($value)){
$value = Arr::setToArr($value);
}
return $value;
return $value ?: [];
}
/**
... ... @@ -80,6 +80,6 @@ class Keyword extends Base
if(!empty($value)){
$value = Arr::setToArr($value);
}
return $value;
return $value ?: [];
}
}
... ...
... ... @@ -16,17 +16,23 @@ class ProjectAssociation extends Model
*/
public function saveData(array $data): bool
{
# V6项目ID
$project_id = (int)$data['project_id'] ?? 0;
$isRes = self::query()->where('project_id', $project_id)->first();
if (!$isRes) {
$isRes = new self();
$isRes->project_id = $project_id;
}
$isRes->wx_id = $data['wx_id'];
$isRes->wx_nickname = $data['wx_nickname'];
$isRes->wx_user_id = $data['wx_user_id'];
$isRes->wx_user_name = $data['wx_user_name'];
$isRes->wx_image = $data['wx_image'];
# AICC朋友ID
$isRes->friend_id = $data['friend_id'] ?? 0;
# AICC朋友昵称
$isRes->nickname = $data['nickname'] ?? 0;
# AICC用户ID
$isRes->user_id = $data['user_id'] ?? 0;
# AICC用户姓名
$isRes->user_name = $data['user_name'] ?? '';
# AICC朋友头像
$isRes->image = $data['image'] ?? '';
return $isRes->save();
}
... ... @@ -50,8 +56,9 @@ class ProjectAssociation extends Model
$status = 1; # 1 - 正常, 0 - 禁用
$lists = self::query()->where('status', $status)
->whereNotNull('project_id')
->whereNotNull('wx_user_id')
->paginate($perPage, ['project_id', 'wx_id', 'wx_user_id'], 'page', $page);
->whereNotNull('friend_id')
->whereNotNull('user_id')
->paginate($perPage, ['project_id', 'friend_id', 'user_id'], 'page', $page);
$items = $lists->Items();
$totalPage = $lists->lastPage();
$total = $lists->total();
... ...
... ... @@ -219,6 +219,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::get('keyword/info', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'info'])->name('product_keyword_info');
Route::post('keyword/save', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'save'])->name('product_keyword_save');
Route::post('keyword/batchAdd', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchAdd'])->name('product_keyword_batchAdd');
Route::post('keyword/batchDel', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'batchDel'])->name('product_keyword_batchDel');
Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete');
//产品参数
... ... @@ -365,6 +366,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::delete('/delete', [\App\Http\Controllers\Bside\Nav\NavController::class, 'delete'])->name('nav_delete');
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');
});
//排名数据
... ...