InquiryFormData.php
1.6 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
<?php
namespace App\Models\Inquiry;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
/**
* Class InquiryFormData
* @package App\Models\Inquiry
* @author zbj
* @date 2023/12/4
*/
class InquiryFormData extends Base
{
use SoftDeletes;
//设置关联表名
/**
* @var mixed
*/
protected $connection = "custom_mysql";
protected $table = 'gl_inquiry_form_data';
public function getDataAttribute($value)
{
return json_decode($value, true);
}
/**
* 非默认表单的数量统计
* @author zbj
* @date 2023/12/12
*/
public static function getCount($submit_at = []){
return self::leftjoin('gl_inquiry_form', 'gl_inquiry_form.id', '=', 'gl_inquiry_form_data.form_id')
->where('gl_inquiry_form.is_default', 0)
->when($submit_at, function ($query, $submit_at) {
$query->whereBetween('submit_at',[$submit_at[0], $submit_at[1]]);
})
->count();
}
/**
* 非默认表单的国家统计
* @author zbj
* @date 2023/12/12
*/
public static function getCountryCount($submit_at = []){
return self::leftjoin('gl_inquiry_form', 'gl_inquiry_form.id', '=', 'gl_inquiry_form_data.form_id')
->where('gl_inquiry_form.is_default', 0)
->when($submit_at, function ($query, $submit_at) {
$query->whereBetween('submit_at',[$submit_at[0], $submit_at[1]]);
})
->select("country",DB::raw('COUNT(*) as count'))->groupBy('country')->get()->toArray();
}
}