<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Userpoints_model extends CI_Model
{
private $table ='userpoints';
private static $DB;
public function __construct()
{
parent::__construct();
self::$DB = $this->load->database('tanqinba', TRUE);
}
public function getUserCountRow($userId=0)
{
self::$DB->where('userId', $userId);
$result = self::$DB->get($this->table);
return $result->row_array();
}
public function insertData($userData)
{
self::$DB->insert('userpoints', $userData);
$bool = self::$DB->insert_id();
return $bool;
}
public function updateNum($data,$userId=0)
{
foreach ($data as $k => $v)
{
self::$DB->set($k, $v, FALSE);
}
self::$DB->where('userId', $userId)->update($this->table);
return self::$DB->affected_rows();
}
public function getTodayPointsNum( $userId ,$stime,$etime,$typeFlag=0)
{
self::$DB->select_sum('operandNum');
self::$DB->where('userId',$userId);
self::$DB->where('typeFlag',$typeFlag);
self::$DB->where('changeTime >',$stime);
self::$DB->where('changeTime <',$etime);
self::$DB->where('adminId' ,0);
$result = self::$DB->get($this->table);
return $result->row_array();
}
public function getUserPointsList($param,$userId,$limit=10,$start=0,$time=0)
{
$where = $this->_getWhere($param);
self::$DB->where($where);
self::$DB->where('userId',$userId);
if($time>0)
{
self::$DB->where('changeTime >',$time);
self::$DB->where('changeTime <',time());
}
self::$DB->limit($limit, $start);
self::$DB->order_by('changeTime','desc');
return self::$DB->get( $this->table )->result_array();
}
public function getUserPointsCount($param,$userId,$time=0)
{
$where = $this->_getWhere($param);
if(!empty($where))
{
self::$DB->where($where);
}
if($time>0)
{
self::$DB->where('changeTime >',$time);
self::$DB->where('changeTime <',time());
}
self::$DB->where('userId',$userId);
return self::$DB->count_all_results( $this->table );
}
public function getUsermoonsumPoints($param,$userId,$time=0)
{
self::$DB->select_sum('operandNum');
$where = $this->_getWhere($param);
if(!empty($where))
{
self::$DB->where($where);
}
if($time>0)
{
self::$DB->where('changeTime >',$time);
self::$DB->where('changeTime <',time());
}
self::$DB->where('userId',$userId);
return self::$DB->get($this->table)->row_array();
}
public function _getWhere($where=array() )
{
$param = array();
if (isset($where['status'])&& ($where['status']==1))
{
$param['operandNum >'] = 0;
}
else if (isset($where['status'])&& ($where['status']==2))
{
$param['operandNum <'] = 0;
}
return $param;
}
public function getUserPoints($userId,$stime=0,$etime)
{
self::$DB->where('userId',$userId);
if($stime>0)
{
self::$DB->where( 'changeTime >=' ,$stime );
self::$DB->where( 'changeTime <=' ,$etime );
}
self::$DB->order_by('changeTime','desc');
return self::$DB->get( $this->table )->result_array();
}
public function getLoginLastTime($userId=0,$flag=0,$typeFlag=5)
{
self::$DB->where('userId', $userId);
self::$DB->where('flag', $flag);
self::$DB->where('typeFlag', $typeFlag);
self::$DB->order_by('changeTime', 'desc');
$result = self::$DB->get($this->table);
return $result->row_array();
}
public function getTodayUserPoints($userId,$stime=0,$etime)
{
self::$DB->select_sum('operandNum');
self::$DB->where('userId',$userId);
if($stime>0)
{
self::$DB->where( 'changeTime >=' ,$stime );
self::$DB->where( 'changeTime <=' ,$etime );
}
self::$DB->where( 'operandNum >' ,0 );
return self::$DB->get( $this->table )->row_array();
}
}
?>