作者 赵彬吉
... ... @@ -33,8 +33,9 @@ class UpgradeProjectCount extends Command
protected $description = '升级项目统计';
public function handle(){
ProjectServer::useProject(439);
$this->count();
$project_id = 555;
ProjectServer::useProject($project_id);
$this->count($project_id);
DB::disconnect('custom_mysql');
}
... ... @@ -45,18 +46,18 @@ class UpgradeProjectCount extends Command
* @method :post
* @time :2024/1/8 9:05
*/
public function count(){
public function count($project_id){
$list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date')
->groupBy('updated_date')->get()->toArray();
$project = new Project();
$projectInfo = $project->read(['id'=>439]);
$projectInfo = $project->read(['id'=>$project_id]);
if(!empty($list)){
$arr = [];
foreach ($list as $k=>$v){
$v = (array)$v;
echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL;
$count = new Count();
$arr['project_id'] = 439;
$arr['project_id'] = $project_id;
$arr['date'] = $v['updated_date'];
$arr['pv_num'] = $this->pv_num($v['updated_date']);
$arr['ip_num'] = $this->ip_num($v['updated_date']);
... ... @@ -65,9 +66,9 @@ class UpgradeProjectCount extends Command
$arr['compliance_day'] = $projectInfo['finish_remain_day'];
//剩余服务时常
$arr['service_day'] = $projectInfo['remain_day'];
$arr['country'] = '{"也门": 4, "印度": 3, "埃及": 4, "巴西": 1, "约旦": 2, "美国": 3, "伊拉克": 4, "利比亚": 2, "墨西哥": 5, "摩洛哥": 8, "新加坡": 1, "突尼斯": 3, "巴勒斯坦": 2, "巴基斯坦": 1, "罗马尼亚": 1, "非洲地区": 2, "马来西亚": 5, "印度尼西亚": 2, "沙特阿拉伯": 3, "阿尔及利亚": 2}';
$arr['country'] = json_encode([]);
//查询当天数据是否存在 存在则更新
$info = $count->read(['date'=>$v['updated_date']]);
$info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]);
if($info === false){
$arr['created_at'] = $v['updated_date'].' 01:00:00';
$arr['updated_at'] = $v['updated_date'].' 01:00:00';
... ...
... ... @@ -35,8 +35,10 @@ class UpgradeProjectCount extends Command
protected $description = '升级项目统计';
public function handle(){
ProjectServer::useProject(439);
$this->count();
$project_id = 555;
$url = 'www.sincoherenaesthetics.com';
ProjectServer::useProject($project_id);
$this->count($project_id,$url);
DB::disconnect('custom_mysql');
}
... ... @@ -48,35 +50,36 @@ class UpgradeProjectCount extends Command
* @method :post
* @time :2024/1/8 9:05
*/
public function count(){
public function count($project_id,$url){
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
->groupBy('month')->get()->toArray();
foreach ($list as $k=>$v){
$v = (array)$v;
$monthCountModel = new MonthCount();
$info = $monthCountModel->read(['month'=>$v['month']]);
$info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
// 获取当月开始时间
$start = date('Y-m-01', strtotime($v['month']));
// 获取当月结束时间
$end = date('Y-m-t', strtotime($v['month']));
$arr['project_id'] = 439;
$res = $this->inquiry('www.cnzyl.com',$v['month']);
$arr['project_id'] = $project_id;
$res = $this->inquiry($url,$v['month']);
$arr['month_total'] = 0;
if(isset($res['data']['count'])){
$arr['month_total'] = $res['data']['count'];
}
if(isset($res['data']['data'])){
$arr['country'] = $res['data']['data'];
$arr['country'] = json_encode($res['data']['data']);
}
$arr['month'] = $v['month'];
$arr = $this->pv_ip($arr,$start,$end);
$arr = $this->pv_ip($arr,$start,$end,$project_id);
$arr = $this->sourceCount($arr,$start,$end);
if($info === false){
$selectedDate = $start;
$firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
$arr['created_at'] = $firstDayOfNextMonth;
$arr['updated_at'] = $firstDayOfNextMonth;
// echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL;
$monthCountModel->insert($arr);
}else{
$monthCountModel->edit($arr,['id'=>$info['id']]);
... ... @@ -92,9 +95,9 @@ class UpgradeProjectCount extends Command
* @method :post
* @time :2024/1/8 11:02
*/
public function pv_ip(&$arr,$start,$end){
public function pv_ip(&$arr,$start,$end,$project_id){
$pv_ip = DB::table('gl_count')
->where(['project_id'=>439])
->where(['project_id'=>$project_id])
->where('date','>=',$start.' 00:00:00')
->where('date','<=',$end.' 23:59:59')
->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'),DB::raw('SUM(inquiry_num) as inquiry_num'))
... ...
... ... @@ -153,9 +153,12 @@ class HtmlCollect extends Command
case 'blog':
$source = RouteMap::SOURCE_BLOG;
break;
default:
case 'post':
$source = RouteMap::SOURCE_PRODUCT;
break;
default:
$source = RouteMap::SOURCE_MODULE;
break;
}
$complete = false;
... ...
... ... @@ -155,9 +155,12 @@ class HtmlLanguageCollect extends Command
case 'blog':
$source = RouteMap::SOURCE_BLOG;
break;
default:
case 'post':
$source = RouteMap::SOURCE_PRODUCT;
break;
default:
$source = RouteMap::SOURCE_MODULE;
break;
}
$complete = false;
... ...
... ... @@ -10,6 +10,9 @@ use App\Models\Collect\CollectSource;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateOldInfo;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
... ... @@ -187,6 +190,7 @@ class ProjectUpdate extends Command
if (isset($data['code']) && $data['code'] == 200) {
$phones = $data['data']['phones'] ?? '';
$emails = $data['data']['emails'] ?? '';
$custom_types = $data['data']['customposttypes'] ?? '';
$model = new WebSettingReceiving();
if ($phones) {
... ... @@ -229,6 +233,25 @@ class ProjectUpdate extends Command
}
}
}
if ($custom_types) {
$custom_model = new CustomModule();
foreach ($custom_types as $v_custom) {
try {
$custom_info = $custom_model->read(['route' => $v_custom]);
if (!$custom_info) {
$custom_model->add([
'name' => $v_custom,
'project_id' => $project_id,
'route' => $v_custom
]);
}
UpdateLog::createLog($project_id, $v_custom, $task->api_url);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
}
}
}
} else {
return true;
}
... ... @@ -392,7 +415,7 @@ class ProjectUpdate extends Command
$category_id = $logic->getCategory(array_column($category_arr, 'id'));
}
//图片
if (is_array($item['images'])) {
if (is_array($item['images'] ?? '')) {
$image = $item['images'][0] ?? '';
} else {
$image = $item['images'] ?? '';
... ... @@ -448,7 +471,7 @@ class ProjectUpdate extends Command
} else {
return true;
}
} else {
} elseif ($api_type == 'page') {
//单页
$url = $api_url . '?' . http_build_query(['w' => 'page', 'page' => 1, 'pagesize' => 0]);
$data = curl_c($url);
... ... @@ -510,6 +533,79 @@ class ProjectUpdate extends Command
} else {
return true;
}
} else {
//自定义模块
$custom_model = new CustomModule();
$custom_info = $custom_model->read(['route' => $api_type]);
if ($custom_info) {
$url = $api_url . '?' . http_build_query(['w' => $api_type, 'page' => 1, 'pagesize' => 0]);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$category = $data['data']['category'] ?? [];
$this->category_custom_insert($project_id, $custom_info['id'], $category, 0);
$count = $data['data']['count'] ?? 0;
$total_page = ceil($count / $page_size);
for ($page = 1; $page <= $total_page; $page++) {
$url_page = $api_url . '?' . http_build_query(['w' => $api_type, 'page' => $page, 'pagesize' => $page_size]);
$data_page = curl_c($url_page);
if (isset($data_page['code']) && $data_page['code'] == 200) {
$items = $data_page['data']['data'] ?? [];
$model = new CustomModuleContent();
$category_model = new CustomModuleCategory();
foreach ($items as $item) {
$route = $this->get_url_route($item['url'] ?? '');
if ($route) {
//分类
$category_id = '';
if ($item['category'] ?? []) {
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
$category_id = implode(',', array_column($category_arr, 'id'));
}
//名称去掉特殊符号
$item['title'] = $this->special2str($item['title'] ?? '');
try {
$custom_content = $model->read(['route' => $route], 'id');
if (!$custom_content) {
$id = $model->insertGetId([
'project_id' => $project_id,
'name' => $item['title'],
'module_id' => $custom_info['id'],
'category_id' => $category_id,
'content' => $item['content'] ?? '',
'created_at' => $item['post_time'] ?? date('Y-m-d H:i:s'),
'updated_at' => $item['post_time'] ?? date('Y-m-d H:i:s'),
'is_upgrade' => 1,
'six_read' => 1,
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_MODULE, $id, $project_id);
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_MODULE, $id, $domain_arr['host'], $link_type, $language_list, $page_list);
} else {
$id = $custom_content['id'];
$model->edit([
'name' => $item['title'],
'category_id' => $category_id,
'content' => $item['content'] ?? '',
], ['id' => $id]);
}
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
}
}
}
}
}
} else {
return true;
}
}
}
}
//关闭数据库
... ... @@ -595,7 +691,7 @@ class ProjectUpdate extends Command
$parent_id = $parent['id'];
}
if (!empty($item['children'])) {
if (!empty($item['children'] ?? [])) {
$this->category_insert($project_id, $item['children'], $parent_id);
}
}
... ... @@ -629,13 +725,48 @@ class ProjectUpdate extends Command
$parent_id = $parent['id'];
}
if (!empty($item['children'])) {
if (!empty($item['children'] ?? [])) {
$this->category_news_insert($project_id, $item['children'], $parent_id);
}
}
}
}
//扩展模块多级分类入库
protected function category_custom_insert($project_id, $module_id, $items, $pid = 0)
{
$model = new CustomModuleCategory();
foreach ($items as $item) {
$route = $this->get_url_route($item['url'] ?? '');
if ($route) {
$parent = $model->read(['pid' => $pid, 'route' => $route], 'id');
if (!$parent) {
try {
$item['name'] = $this->special2str($item['name'] ?? '');
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'module_id' => $module_id,
'name' => $item['name'],
'pid' => $pid,
'original_id' => $item['id'],
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_MODULE_CATE, $parent_id, $project_id);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_custom_insert error: ' . $e->getMessage() . PHP_EOL;
continue;
}
} else {
$parent_id = $parent['id'];
}
if (!empty($item['children'] ?? [])) {
$this->category_custom_insert($project_id, $module_id, $item['children'], $parent_id);
}
}
}
}
//特殊字符转换
protected function special2str($str)
{
... ...