<?php
// +----------------------------------------------------------------------
// | Sunnyi 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.sunnyi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 商易网络(admin@sunnyi.cn)
// +----------------------------------------------------------------------

//会员日志
class UcLogModel extends MultiLangModel  {
	public function getLogList($user_id,$page)
	{
		$limit = (($page-1)*C("PAGE_LISTROWS")).",".(C("PAGE_LISTROWS"));
		$sql = "select *,'money' as log_type from ".C("DB_PREFIX")."user_money_log where user_id= ".$user_id.
				" union ".
			   "select *,'score' as log_type from ".C("DB_PREFIX")."user_score_log ".
			   "where user_id = ".$user_id." order by create_time desc limit ".$limit;
		
		$list = D()->query($sql);
		foreach($list as $k=>$v)
		{
			if($v['log_type'] == 'money')
			{
				$list[$k]['value'] = formatPrice(abs($v['money']));
			}
			if($v['log_type'] == 'score')
			{
				$list[$k]['value'] = formatScore($v['money']);
			}
			if($v['money']>=0)
			{
				$list[$k]['op_type'] = 0;
			}
			else
			{
				$list[$k]['op_type'] = 1;
			}
		}

		$result['list'] = $list;
		$sql_total_money = "select count(*) as total from ".C("DB_PREFIX")."user_money_log where user_id=".$user_id;
		$sql_total_score = "select count(*) as total from ".C("DB_PREFIX")."user_score_log where user_id =".$user_id;
		
	
		$total_res_money = D()->query($sql_total_money);
		$total_res_score = D()->query($sql_total_score);
		
		
		
		$total = $total_res_money[0]['total']+$total_res_score[0]['total'];
		
		$result['total'] = intval($total);
		return $result;
	}
}
?>