ReInquiryCost.php
1.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
<?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;
}
}