GoogleKeywordInsightDetail.php 2.6 KB
<?php
/**
 * @remark :
 * @name   :GoogleKeywordInsightDetail.php
 * @author :lyh
 * @method :post
 * @time   :2025/3/25 14:33
 */

namespace App\Models\GoogleKeywordInsight;

use App\Helper\Translate;
use App\Models\Base;

class GoogleKeywordInsightDetail extends Base
{
    protected $table = 'gl_google_insight_detail';

    /**
     * @remark :保存洞察数据详情
     * @name   :saveInsightDetail
     * @author :lyh
     * @method :post
     * @time   :2025/3/25 14:45
     */
    public function saveInsightDetail($project_id,$keyword,$data){
        $saveData = [];
        $textArr = array_column($data, 'text');
        $transData = Translate::tran($textArr, 'zh');
        if(!is_array($transData)){
            $transData = [$transData];
        }
        foreach ($data as $key => $val){
            $saveData[] = [
                'search'=>$keyword,
                'text'=>$val['text'],
                'zh_text'=>$transData[$key] ?? $val['text'],
                'project_id'=>$project_id,
                'volume'=>$val['volume'],
                'competition_level'=>$val['competition_level'],
                'competition_index'=>$val['competition_index'],
                'low_bid'=>$val['low_bid'],
                'high_bid'=>$val['high_bid'],
                'trend'=>$val['trend'],
            ];
        }
        return $this->insertAll($saveData);
    }

    /**
     * @remark :保存一条数据
     * @name   :saveInsightDetailOne
     * @author :lyh
     * @method :post
     * @time   :2025/4/1 11:32
     */
    public function saveInsightDetailOne($project_id,$keyword,$data){
        $transData = Translate::tran($data['text'], 'zh');
        $saveData = [
            'search'=>$keyword,
            'text'=>$data['text'],
            'zh_text'=>$transData ?? $data['text'],
            'project_id'=>$project_id,
            'volume'=>$data['volume'],
            'competition_level'=>$data['competition_level'],
            'competition_index'=>$data['competition_index'],
            'low_bid'=>$data['low_bid'],
            'high_bid'=>$data['high_bid'],
            'trend'=>$data['trend'],
        ];
        return $this->addReturnId($saveData);
    }

    /**
     * @remark :查看当前数据是否存在数组中
     * @name   :getSearchDetail
     * @author :lyh
     * @method :post
     * @time   :2025/4/1 9:56
     */
    public function getSearchDetail($keyword,$detailList){
        if(!empty($detailList)){
            foreach ($detailList as $value){
                if($keyword == $value['search']){
                    return $value;
                }
            }
        }
        return [];
    }
}