You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.2 KiB

4 days ago
<?php
/**
*
*/
include_once(SERVER_ROOT . "/model/mBase.php");
class mWeiboBehavior extends mBase {
private $tbl_data;
private $tbl_delta;
public function __construct() {
$this->obj = new dWeiboBehavior();
$this->tbl_data = 'spider_behavior_data';
$this->tbl_delta = 'spider_behavior_delta';
}
public function saveBehaviorData($data) {
return $this->obj->replace($this->tbl_data, $data);
}
public function getBehaviorByDate($date) {
return $this->obj->selectAll($this->tbl_data, array('sql' => "`date`=?", 'vals' => array($date)), 'id desc', array(0, 10000));
}
public function deleteExpireBehaviorData($date) {
return $this->obj->delete($this->tbl_data, array('sql' => "`date`<?", 'vals' => array($date)));
}
public function saveBehaviorDelta($data) {
return $this->obj->replace($this->tbl_delta, $data);
}
public function deleteExpireBehaviorDelta($date) {
return $this->obj->delete($this->tbl_delta, array('sql' => "`date`<?", 'vals' => array($date)));
}
public function getHotBehavior($type, $sdate, $edate, $page_num, $page_size) {
$offset = ($page_num - 1) * $page_size;
if (!$sdate) {
$this->setError('参数错误');
return false;
}
$sdate = date('Y-m-d', strtotime($sdate));
$where = " date = '{$sdate}' ";
if ($edate) {
$edate = date('Y-m-d', strtotime($edate));
$where = " date >= '{$sdate}' AND date <= '{$edate}' ";
}
$row = "";
if ($type == BEHAVIOR_TYPE_REPOSTS) $row = " SUM(reposts_delta) as num";
if ($type == BEHAVIOR_TYPE_COMMENTS) $row = " SUM(comments_delta) as num";
if ($type == BEHAVIOR_TYPE_ATTITUDES) $row = " SUM(attitudes_delta) as num";
$sql = "SELECT wid,{$row} FROM spider_behavior_delta WHERE {$where} GROUP BY wid ORDER BY num DESC LIMIT {$offset}, {$page_size}";
$res = $this->obj->execute($sql, true, true);
$mobj = new mWeibo();
$wids = array_column($res, 'wid');
$weibos = $mobj->getWeiboByWids($wids);
$weibo_list = array_column($weibos, null, 'wid');
$weibo_user = $GLOBALS['WEIBO_USER_LIST'];
foreach ($res as &$re){
$weibo = isset($weibo_list[$re['wid']]) ? $weibo_list[$re['wid']] : array();
$re['uname'] = empty($weibo)? $weibo_user[WEIBO_USER_ZHANG] : $weibo_user[$weibo['uid']];
$re['title'] = empty($weibo)? '无文字展示' : $weibo['text'];
$re['url'] = sprintf(WEIBO_DETAIL_URL, $re['wid']);
4 days ago
}
return $res;
}
public function getHotBehaviorTotal($sdate, $edate) {
if (!$sdate) {
$this->setError('参数错误');
return false;
}
$sdate = date('Y-m-d', strtotime($sdate));
$where = " date = '{$sdate}' ";
if ($edate) {
$edate = date('Y-m-d', strtotime($edate));
$where = " date >= '{$sdate}' AND date <= '{$edate}' ";
}
$sql = "SELECT count(*) as total FROM spider_behavior_delta WHERE {$where}";
$res = $this->obj->execute($sql, false, true);
return $res['total'];
}
}