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
|
//计划任务批量刷新房源
public
function
allRefresh(){
$houseDb
=D(
"House"
);
$data
=
$houseDb
->get_list();
//dump($data);
}
下面的为model里的数据处理,上面的为控制器部分
//查询所有数据
public
function
getAll(
$where
,
$page
= 1,
$page_num
= 10){
$houseDb
=D(
"House"
);
$data
=
$this
->where(
$where
)->limit((
$page
- 1) *
$page_num
,
$page_num
)->select();
return
$data
;
}
//查询所有数据总数
public
function
get_list(){
$where
[
'isDel'
] =
'0'
;
$where
[
'status'
] =
'2'
;
$where
[
'auditstatus'
] =
'1'
;
//已审核
$where
[
'salestatus'
] =
'0'
;
//在售
$houseDb
=D(
"House"
);
$totalCount
=
$houseDb
->where(
$where
)->
count
();
$totalpage
=
ceil
(
$totalCount
/10);
for
(
$nowPage
=1;
$nowPage
<=
$totalpage
;
$nowPage
++){
$list
=
$houseDb
->getAll(
$where
,
$nowPage
,10);
// print_r($houseDb->getLastSql()) ;
$this
->refreshData(
$list
);
}
}
//批量刷新房源的停留时间和计算
public
function
refreshData(
$list
){
// echo '111';
foreach
(
$list
as
$key
=>
$value
){
//计算出来停留时间
$data
=
array
();
$where
[
'esfId'
]=
$value
[
'esfId'
];
$data
[
'stayTime'
]=(
$value
[
'publishScore'
]*
$value
[
'houseRatio'
])/100*3600+
$value
[
'verifyTime'
];
$houseRatio
=
$this
->where(
$where
)->save(
$data
);
//更新房源系数
//首页排序数量
$data
=
array
();
$where
=
array
();
//计算上周经济人日均发房源数量
$map
[
'esfId'
]=
$value
[
'esfId'
];
$start
=
mktime
(0,0,0,
date
(
'm'
),
date
(
'd'
)-
date
(
'w'
)+1-7,
date
(
'Y'
));
//上周起时间
$end
=
mktime
(23,59,59,
date
(
'm'
),
date
(
'd'
)-
date
(
'w'
)+7-7,
date
(
'Y'
));
//上周结束时间
$map
[
'verifyTime'
]=
array
(between,
array
(
$start
,
$end
));
$count
=
$this
->where(
$map
)->
count
();
//得到上周总发房源总数
$where
=
array
();
$data
=
array
();
$where
[
'esfId'
]=
$value
[
'esfId'
];
if
(
$count
){
$indexNum
=
$count
/6;
//日均发房源数量
}
$data
[
'indexNum'
]=
intval
(
$indexNum
);
//日均数量
$stayTime
=
$this
->where(
$where
)->save(
$data
);
//更新房源停留时间
//echo $this->getLastSql();die;
}
}
|
本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/1843760