APublicModel.php
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @remark :
* @name :APublicModel.php
* @author :lyh
* @method :post
* @time :2023/8/10 18:16
*/
namespace App\Models\ASide;
use App\Helper\AyrShare as AyrShareHelper;
use App\Helper\FormGlobalsoApi;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use App\Models\Base;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class APublicModel extends Base
{
const STATUS_ON = 1;
/**
* @remark :查询对应项目对应产品博客新闻数量
* @name :getNumByProjectId
* @author :lyh
* @method :post
* @time :2023/8/30 9:35
*/
public static function getNumByProjectId($project_id){
ProjectServer::useProject($project_id);
try {
$data = Cache::get('product_blog_news_'.$project_id);
if(!$data){
$productNumber = DB::connection('custom_mysql')->table('gl_product')
->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
$blogNumber = DB::connection('custom_mysql')->table('gl_blog')
->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
$newsNumber = DB::connection('custom_mysql')->table('gl_news')
->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
$aiBlogNumber = DB::connection('custom_mysql')->table('gl_ai_blog')->where('project_id', $project_id)->count();
$keyNumber = DB::connection('custom_mysql')->table('gl_product_keyword')
->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
//获取项目的询盘数量
$inquiryNumber = 0;
$countInfo = DB::table('gl_count')->where('project_id', $project_id)->orderBy('id', 'desc')->first();
if(!empty($countInfo)){
$inquiryNumber = $countInfo->inquiry_num ?? 0;
}
$data = ['product'=>$productNumber,'blog'=>($blogNumber + $aiBlogNumber),'news'=>$newsNumber,'key'=>$keyNumber,'inquiry'=>$inquiryNumber];
Cache::add('product_blog_news_'.$project_id,$data,30 * 60);
}
}catch (\Exception $e){
return [];
}
DB::disconnect('custom_mysql');
return $data;
}
}