ReInquiryCost.php 1.4 KB
<?php

namespace App\Models\Inquiry;

use App\Models\Base;
use Illuminate\Support\Facades\Cache;

/**
 * Class ReInquiryCost
 * @package App\Models\Inquiry
 * @author zbj
 * @date 2024/12/4
 */
class ReInquiryCost extends Base
{

    //设置关联表名
    /**
     * @var mixed
     */
    protected $table = 'gl_re_inquiry_cost';


    public static function saveData($ad_id, $spend, $lead, $single_cost, $start_date, $end_date){
        $cost = self::where('ad_id', $ad_id)->first();
        if(!$cost){
            $cost = new self();
        }

        $cost->ad_id = $ad_id;
        $cost->spend = $spend;
        $cost->lead = $lead;
        $cost->single_cost = $single_cost;
        $cost->start_date = $start_date;
        $cost->end_date = $end_date;
        $cost->save();
    }

    public static function getCostByAdIds($ad_ids){
        if(is_string($ad_ids)){
            $ad_ids = explode(',',$ad_ids);
        }
        $cache_key = 'GET_COST_BY_AD_IDS_' . implode(',', $ad_ids);
        $data = Cache::get($cache_key);
        if(!$data){
            $data = [];
            $list = self::whereIn('ad_id', $ad_ids)->get();
            foreach ($list as $item){
                $data['cost'][] = '$' . $item['spend'];
                $data['single_cost'][] = '$' . $item['single_cost'];
            }
            Cache::set($cache_key, $data);
        }
        return $data;
    }

}