<?php

namespace Cas\Module;

use KIF\Data\Convert;
use KIF\Data\ResultWrapper;
use KIF\Db\Transaction;
use KIF\Cache\Memcached;

use Cas\Dao\LotteryEventsLog;
use Cas\Dao\LotteryUserParticipateLog;

/**
 * 抽奖模型
 * 
 * @author lihuanchun
 *        
 */
class LotteryLog {
	
	private $objDLotteryEventsLog;
	private $objDLotteryUserParticipateLog;
	private $uid;
	private $eventsId;
	
	
	/**
	 * 初始化
	 */
	public function __construct($uid=null , $eventsId=null ) {
		$this->objDLotteryEventsLog = new LotteryEventsLog();// 活动日志
		$this->objDLotteryUserParticipateLog = new LotteryUserParticipateLog();// 用户"参与"活动日志
		$this->uid = $uid;
		$this->eventsId = $eventsId;
	}
	
	
	/**
	 * 获取行为类型
	 */
	public function getType(){
		return $this->objDLotteryEventsLog->getType();
	}
	
	/**
	 *  添加日志
	 */
	public function addLog($type,$other){
		$events_id = $this->eventsId?$this->eventsId:0;
		$uid = $this->uid?$this->uid:0;
		$info = array(
			'events_id' => $events_id,
			'uid' => $uid,
			'type' => $type,
			'other' => $other		
		);
		return $this->objDLotteryEventsLog  -> addOne($info);
	}
	
	/**
	 * 获取虚拟数据【条数】
	 */
	public function getLogNum($condition){
		return  $this->objDLotteryEventsLog->totals($condition);
	}
	
	/**
	 * 获取一条日志
	 */
	public function getOneData($id){
		return $this->objDLotteryEventsLog->get($id);
	}
	
	/**
	 * 获取多条日志
	 */
	public function getDatas($ids){
		return $this->objDLotteryEventsLog->gets($ids);
	}
	
	/**
	 * 获取日志列表IDs
	 */
	public function findByIds ($condition , $limit , $order){
		return  $this->objDLotteryEventsLog->findIdsBy($condition , $limit , $order);
	}
	
	/**
	 * 获取日志信息
	 */
	public function findData($condition , $limit , $order){
		$ids = $this->findByIds($condition, $limit, $order);
		return $this->getDatas($ids);
	}
	
	
	/**
	 *  添加"用户参与"日志
	 */
	public function addUserParticipateLog($other){
		$events_id = $this->eventsId?$this->eventsId:0;
		$uid = $this->uid?$this->uid:0;
		$info = array(
				'events_id' => $events_id,
				'uid' => $uid,
				'other' => $other
		);
	
		return $this->objDLotteryUserParticipateLog->add($info);
	}
	
	
	/**
	 * 获取"用户参与"虚拟数据【条数】
	 */
	public function getUserParticipateLogNum($condition){
		return  $this->objDLotteryUserParticipateLog->totals($condition);
	}
	
	/**
	 * 获取一条"用户参与"日志
	 */
	public function getUserParticipateOneData($id){
		return $this->objDLotteryUserParticipateLog->get($id);
	}
	
	/**
	 * 获取多条"用户参与"日志
	 */
	public function getUserParticipateDatas($ids){
		return $this->objDLotteryUserParticipateLog->gets($ids);
	}
	
	/**
	 * 获取"用户参与"日志列表IDs
	 */
	public function findByUserParticipateIds ($condition , $limit , $order){
		
		return  $this->objDLotteryUserParticipateLog->findIdsBy($condition , $limit , $order);
	}
	
	/**
	 * 获取"用户参与"日志信息
	 */
	public function findUserParticipateData($condition , $limit , $order){
		$ids = $this->findByUserParticipateIds($condition, $limit, $order);
		return $this->getUserParticipateDatas($ids);
	}
	
	/**
	 * 获取 "用户参与" 用户排重日志信息
	 */
	public function findUserParticipateDataGroupByUid( $limit , $order){
		
		return  $this->objDLotteryUserParticipateLog->findUserParticipateDataGroupByUid($this->eventsId,$limit,$order);
	}
	
	/**
	 * 获取"用户参与"用户排重虚拟数据【条数】
	 */
	public function getUserParticipateLogNumGroupByUid(){
		return  $this->objDLotteryUserParticipateLog->getUserParticipateLogNumGroupByUid($this->eventsId);
	}
	
	
	
}