2022-11-14 17:31:15 +00:00
< ? php
if ( ! defined ( 'IN_ECS' ))
{
die ( 'Hacking attempt' );
}
/**
* 获取某用户的缺货登记列表
*
* @ access public
* @ param int $goods_id 商品ID
*
* @ return array $info
*/
function get_goodsinfo ( $goods_id )
{
$info = array ();
$sql = " SELECT goods_name FROM " . $GLOBALS [ 'ecs' ] -> table ( 'goods' ) . " WHERE goods_id = ' $goods_id ' " ;
$info [ 'goods_name' ] = $GLOBALS [ 'db' ] -> getOne ( $sql );
$info [ 'goods_number' ] = 1 ;
$info [ 'id' ] = $goods_id ;
if ( ! empty ( $_SESSION [ 'user_id' ]))
{
$row = array ();
$sql = " SELECT ua.consignee, ua.email, ua.tel, ua.mobile " .
" FROM " . $GLOBALS [ 'ecs' ] -> table ( 'user_address' ) . " AS ua, " . $GLOBALS [ 'ecs' ] -> table ( 'users' ) . " AS u " .
" WHERE u.address_id = ua.address_id AND u.user_id = ' $_SESSION[user_id] ' " ;
$row = $GLOBALS [ 'db' ] -> getRow ( $sql ) ;
$info [ 'consignee' ] = empty ( $row [ 'consignee' ]) ? '' : $row [ 'consignee' ];
$info [ 'email' ] = empty ( $row [ 'email' ]) ? '' : $row [ 'email' ];
$info [ 'tel' ] = empty ( $row [ 'mobile' ]) ? ( empty ( $row [ 'tel' ]) ? '' : $row [ 'tel' ]) : $row [ 'mobile' ];
}
return $info ;
}
/**
* 验证删除某个收藏商品
*
* @ access public
* @ param int $booking_id 缺货登记的ID
* @ param int $user_id 会员的ID
* @ return boolen $bool
*/
function delete_booking ( $booking_id , $user_id )
{
$sql = 'DELETE FROM ' . $GLOBALS [ 'ecs' ] -> table ( 'booking_goods' ) .
" WHERE rec_id = ' $booking_id ' AND user_id = ' $user_id ' " ;
return $GLOBALS [ 'db' ] -> query ( $sql );
}
/**
* 添加缺货登记记录到数据表
* @ access public
* @ param array $booking
*
* @ return void
*/
function add_booking ( $booking )
{
$sql = " INSERT INTO " . $GLOBALS [ 'ecs' ] -> table ( 'booking_goods' ) .
" VALUES ('', ' $_SESSION[user_id] ', ' $booking[email] ', ' $booking[linkman] ', " .
" ' $booking[tel] ', ' $booking[goods_id] ', ' $booking[desc] ', " .
" ' $booking[goods_amount] ', ' " . gmtime () . " ', 0, '', 0, '') " ;
$GLOBALS [ 'db' ] -> query ( $sql ) or die ( $GLOBALS [ 'db' ] -> errorMsg ());
return $GLOBALS [ 'db' ] -> insert_id ();
}
function add_user_real ( $real )
{
$sql = " INSERT INTO " . $GLOBALS [ 'ecs' ] -> table ( 'user_real' ) .
" VALUES (' $_SESSION[user_id] ', ' $real[user_name] ', ' $real[user_idno] ', " .
" ' $real[apply_date] ', ' $real[site] ', ' $real[apply_reason] ' , '0') " ;
$GLOBALS [ 'db' ] -> query ( $sql ) or die ( $GLOBALS [ 'db' ] -> errorMsg ());
return true ;
}
/**
* 插入会员账目明细
*
* @ access public
* @ param array $surplus 会员余额信息
* @ param string $amount 余额
*
* @ return int
*/
function insert_user_account ( $surplus , $amount )
{
$sql = 'INSERT INTO ' . $GLOBALS [ 'ecs' ] -> table ( 'user_account' ) .
' (user_id, admin_user, amount, add_time, expire_time,paid_time, admin_note, user_note, process_type, payment, tran_out , tran_in , is_paid)' .
" VALUES (' $surplus[user_id] ', '', ' $amount ', ' " . gmtime () . " ', ' " . ( gmtime () + 43200 ) . " ', 0, '', ' $surplus[user_note] ', ' $surplus[process_type] ', ' $surplus[payment] ', $surplus[tran_out] , $surplus[tran_in] , 0) " ;
$GLOBALS [ 'db' ] -> query ( $sql );
return $GLOBALS [ 'db' ] -> insert_id ();
}
/**
* 更新会员账目明细
*
* @ access public
* @ param array $surplus 会员余额信息
*
* @ return int
*/
function update_user_account ( $surplus )
{
$sql = 'UPDATE ' . $GLOBALS [ 'ecs' ] -> table ( 'user_account' ) . ' SET ' .
" amount = ' $surplus[amount] ', " .
" user_note = ' $surplus[user_note] ', " .
" payment = ' $surplus[payment] ' " .
" WHERE id = ' $surplus[rec_id] ' " ;
$GLOBALS [ 'db' ] -> query ( $sql );
return $surplus [ 'rec_id' ];
}
/**
* 将支付LOG插入数据表
*
* @ access public
* @ param integer $id 订单编号
* @ param float $amount 订单金额
* @ param integer $type 支付类型
* @ param integer $is_paid 是否已支付
*
* @ return int
*/
function insert_pay_log ( $id , $amount , $type = PAY_SURPLUS , $is_paid = 0 )
{
$sql = 'INSERT INTO ' . $GLOBALS [ 'ecs' ] -> table ( 'pay_log' ) . " (order_id, order_amount, order_type, is_paid) " .
" VALUES (' $id ', ' $amount ', ' $type ', ' $is_paid ') " ;
$GLOBALS [ 'db' ] -> query ( $sql );
return $GLOBALS [ 'db' ] -> insert_id ();
}
/**
* 取得上次未支付的pay_lig_id
*
* @ access public
* @ param array $surplus_id 余额记录的ID
* @ param array $pay_type 支付的类型:预付款 / 订单支付
*
* @ return int
*/
function get_paylog_id ( $surplus_id , $pay_type = PAY_SURPLUS )
{
$sql = 'SELECT log_id FROM' . $GLOBALS [ 'ecs' ] -> table ( 'pay_log' ) .
" WHERE order_id = ' $surplus_id ' AND order_type = ' $pay_type ' AND is_paid = 0 " ;
return $GLOBALS [ 'db' ] -> getOne ( $sql );
}
/**
* 根据ID获取当前余额操作信息
*
* @ access public
* @ param int $surplus_id 会员余额的ID
*
* @ return int
*/
function get_surplus_info ( $surplus_id )
{
$sql = 'SELECT * FROM ' . $GLOBALS [ 'ecs' ] -> table ( 'user_account' ) .
" WHERE id = ' $surplus_id ' " ;
return $GLOBALS [ 'db' ] -> getRow ( $sql );
}
/**
* 取得已安装的支付方式 ( 其中不包括线下支付的 )
* @ param bool $include_balance 是否包含余额支付(冲值时不应包括)
* @ return array 已安装的配送方式列表
*/
function get_online_payment_list ( $pay_group = 0 )
{
$sql = 'SELECT pay_id, pay_code, pay_name, pay_fee, pay_desc ,target ' .
'FROM ' . $GLOBALS [ 'ecs' ] -> table ( 'payment' ) .
" WHERE enabled = 1 " ;
$sql .= " AND pay_group = " . $pay_group ;
$modules = $GLOBALS [ 'db' ] -> getAll ( $sql );
include_once ( ROOT_PATH . 'includes/lib_compositor.php' );
return $modules ;
}
/**
* 查询会员余额的操作记录
*
* @ access public
* @ param int $user_id 会员ID
* @ param int $num 每页显示数量
* @ param int $start 开始显示的条数
* @ return array
*/
function get_account_log ( $user_id , $num , $start )
{
$account_log = array ();
$sql = 'SELECT * FROM ' . $GLOBALS [ 'ecs' ] -> table ( 'user_account' ) .
" WHERE user_id = ' $user_id ' " .
" AND process_type " . db_create_in ( array ( SURPLUS_SAVE , SURPLUS_RETURN , 2 , 5 )) .
" ORDER BY add_time DESC " ;
$res = $GLOBALS [ 'db' ] -> selectLimit ( $sql , $num , $start );
if ( $res )
{
while ( $rows = $GLOBALS [ 'db' ] -> fetchRow ( $res ))
{
$rows [ 'add_time' ] = local_date ( $GLOBALS [ '_CFG' ][ 'time_format' ], $rows [ 'add_time' ]);
$rows [ 'admin_note' ] = nl2br ( htmlspecialchars ( $rows [ 'admin_note' ]));
$rows [ 'short_admin_note' ] = ( $rows [ 'admin_note' ] > '' ) ? sub_str ( $rows [ 'admin_note' ], 30 ) : '' ;
$rows [ 'user_note' ] = nl2br ( htmlspecialchars ( $rows [ 'user_note' ]));
$rows [ 'short_user_note' ] = ( $rows [ 'user_note' ] > '' ) ? sub_str ( $rows [ 'user_note' ], 30 ) : '' ;
if ( $rows [ 'expire_time' ] == 0 && $rows [ 'is_paid' ] == 0 ){
$rows [ 'pay_status' ] = '未確認' ;
} else {
if ( $rows [ 'is_paid' ] == 1 ){
$rows [ 'pay_status' ] = $GLOBALS [ '_LANG' ][ 'is_confirm' ];
} elseif ( $rows [ 'is_paid' ] == 0 ){
$rows [ 'pay_status' ] = '等待付款' ;
} elseif ( $rows [ 'is_paid' ] == 2 ){
$rows [ 'pay_status' ] = '取消' ;
} elseif ( $rows [ 'is_paid' ] == 3 ){
$rows [ 'pay_status' ] = '等待付款' ; //付款會到凍結帳戶中
} elseif ( $rows [ 'is_paid' ] == 4 ){
$rows [ 'pay_status' ] = '等待付款' ; //付款會到凍結帳戶中
} elseif ( $rows [ 'is_paid' ] == 5 ){
$rows [ 'pay_status' ] = $GLOBALS [ '_LANG' ][ 'is_confirm' ]; //付款會到凍結帳戶中
}
}
$rows [ 'amount' ] = price_format ( abs ( $rows [ 'amount' ]), false );
$rows [ 'tran_out' ] = get_gamename_by_id ( $rows [ 'tran_out' ]);
$rows [ 'tran_in' ] = get_gamename_by_id ( $rows [ 'tran_in' ]);
/* 会员的操作类型: 冲值,提现 */
if ( $rows [ 'process_type' ] == 0 )
{
$rows [ 'type' ] = $GLOBALS [ '_LANG' ][ 'surplus_type_0' ];
}
elseif ( $rows [ 'process_type' ] == 1 )
{
$rows [ 'type' ] = $GLOBALS [ '_LANG' ][ 'surplus_type_1' ];
} elseif ( $rows [ 'process_type' ] == 2 ){
$rows [ 'type' ] = $GLOBALS [ '_LANG' ][ 'surplus_type_2' ];
} elseif ( $rows [ 'process_type' ] == 5 ){
$rows [ 'type' ] = '返水紅利' ;
}
/* 支付方式的ID */
$sql = 'SELECT pay_id FROM ' . $GLOBALS [ 'ecs' ] -> table ( 'payment' ) .
" WHERE pay_name = ' $rows[payment] ' AND enabled = 1 " ;
$pid = $GLOBALS [ 'db' ] -> getOne ( $sql );
/* 如果是预付款而且还没有付款, 允许付款 */
if (( $rows [ 'is_paid' ] == 0 ) && ( $rows [ 'process_type' ] == 0 ))
{
$rows [ 'handle' ] = '<a href="user.php?act=pay&id=' . $rows [ 'id' ] . '&pid=' . $pid . '">' . $GLOBALS [ '_LANG' ][ 'pay' ] . '</a>' ;
}
/* 處理內容 */
if ( $rows [ 'process_type' ] == 0 )
{
$rows [ 'payment' ] = $rows [ 'payment' ];
}
elseif ( $rows [ 'process_type' ] == 1 )
{
$rows [ 'payment' ] = '電子錢包' ;
}
elseif ( $rows [ 'process_type' ] == 2 ){
$rows [ 'payment' ] = $rows [ 'tran_out' ] . " 到 " . $rows [ 'tran_in' ];
}
$account_log [] = $rows ;
}
return $account_log ;
}
else
{
return false ;
}
}
/**
* 删除未确认的会员帐目信息
*
* @ access public
* @ param int $rec_id 会员余额记录的ID
* @ param int $user_id 会员的ID
* @ return boolen
*/
function del_user_account ( $rec_id , $user_id )
{
$sql = 'DELETE FROM ' . $GLOBALS [ 'ecs' ] -> table ( 'user_account' ) .
" WHERE is_paid = 0 AND id = ' $rec_id ' AND user_id = ' $user_id ' " ;
return $GLOBALS [ 'db' ] -> query ( $sql );
}
/**
* 查询会员余额的数量
* @ access public
* @ param int $user_id 会员ID
* @ return int
*/
function get_user_surplus ( $user_id )
{
// $sql = "SELECT SUM(user_money) FROM " .$GLOBALS['ecs']->table('account_log').
// " WHERE user_id = '$user_id'";
$sql = " SELECT user_money FROM " . $GLOBALS [ 'ecs' ] -> table ( 'users' ) .
" WHERE user_id = ' $user_id ' " ;
return $GLOBALS [ 'db' ] -> getOne ( $sql );
}
/**
* 获取用户中心默认页面所需的数据
*
* @ access public
* @ param int $user_id 用户ID
*
* @ return array $info 默认页面所需资料数组
*/
function get_user_default ( $user_id )
{
$user_bonus = get_user_bonus ();
$sql = " SELECT pay_points, user_money, credit_line, last_login, is_validated,status,reason,rolling,total_rolling FROM " . $GLOBALS [ 'ecs' ] -> table ( 'users' ) . " WHERE user_id = ' $user_id ' " ;
$row = $GLOBALS [ 'db' ] -> getRow ( $sql );
$info = array ();
$info [ 'username' ] = stripslashes ( $_SESSION [ 'user_name' ]);
$info [ 'shop_name' ] = $GLOBALS [ '_CFG' ][ 'shop_name' ];
$info [ 'integral' ] = $row [ 'pay_points' ] . $GLOBALS [ '_CFG' ][ 'integral_name' ];
/* 增加是否开启会员邮件验证开关 */
$info [ 'is_validate' ] = ( $GLOBALS [ '_CFG' ][ 'member_email_validate' ] && ! $row [ 'is_validated' ]) ? 0 : 1 ;
$info [ 'credit_line' ] = $row [ 'credit_line' ];
$info [ 'formated_credit_line' ] = price_format ( $info [ 'credit_line' ], false );
$info [ 'rolling' ] = intval ( $row [ 'rolling' ]);
$info [ 'total_rolling' ] = intval ( $row [ 'total_rolling' ]);
$info [ 'reason' ] = $row [ 'reason' ];
$info [ 'status' ] = $row [ 'status' ];
//如果$_SESSION中时间无效说明用户是第一次登录。取当前登录时间。
$last_time = ! isset ( $_SESSION [ 'last_time' ]) ? $row [ 'last_login' ] : $_SESSION [ 'last_time' ];
if ( $last_time == 0 )
{
$_SESSION [ 'last_time' ] = $last_time = gmtime ();
}
$info [ 'last_time' ] = local_date ( $GLOBALS [ '_CFG' ][ 'time_format' ], $last_time );
$info [ 'surplus' ] = price_format ( $row [ 'user_money' ], false );
$info [ 'bonus' ] = sprintf ( $GLOBALS [ '_LANG' ][ 'user_bonus_info' ], $user_bonus [ 'bonus_count' ], price_format ( $user_bonus [ 'bonus_value' ], false ));
// $sql = "SELECT COUNT(*) FROM " .$GLOBALS['ecs']->table('order_info').
// " WHERE user_id = '" .$user_id. "' AND add_time > '" .local_strtotime('-1 months'). "'";
// $info['order_count'] = $GLOBALS['db']->getOne($sql);
// include_once(ROOT_PATH . 'includes/lib_order.php');
// $sql = "SELECT order_id, order_sn ".
// " FROM " .$GLOBALS['ecs']->table('order_info').
// " WHERE user_id = '" .$user_id. "' AND shipping_time > '" .$last_time. "'". order_query_sql('shipped');
// $info['shipped_order'] = $GLOBALS['db']->getAll($sql);
return $info ;
}
/**
* 添加商品标签
*
* @ access public
* @ param integer $id
* @ param string $tag
* @ return void
*/
function add_tag ( $id , $tag )
{
if ( empty ( $tag ))
{
return ;
}
$arr = explode ( ',' , $tag );
foreach ( $arr AS $val )
{
/* 检查是否重复 */
$sql = " SELECT COUNT(*) FROM " . $GLOBALS [ 'ecs' ] -> table ( " tag " ) .
" WHERE user_id = ' " . $_SESSION [ 'user_id' ] . " ' AND goods_id = ' $id ' AND tag_words = ' $val ' " ;
if ( $GLOBALS [ 'db' ] -> getOne ( $sql ) == 0 )
{
$sql = " INSERT INTO " . $GLOBALS [ 'ecs' ] -> table ( " tag " ) . " (user_id, goods_id, tag_words) " .
" VALUES (' " . $_SESSION [ 'user_id' ] . " ', ' $id ', ' $val ') " ;
$GLOBALS [ 'db' ] -> query ( $sql );
}
}
}
/**
* 标签着色
*
* @ access public
* @ param array
* @ author Xuan Yan
*
* @ return none
*/
function color_tag ( & $tags )
{
$tagmark = array (
array ( 'color' => '#666666' , 'size' => '0.8em' , 'ifbold' => 1 ),
array ( 'color' => '#333333' , 'size' => '0.9em' , 'ifbold' => 0 ),
array ( 'color' => '#006699' , 'size' => '1.0em' , 'ifbold' => 1 ),
array ( 'color' => '#CC9900' , 'size' => '1.1em' , 'ifbold' => 0 ),
array ( 'color' => '#666633' , 'size' => '1.2em' , 'ifbold' => 1 ),
array ( 'color' => '#993300' , 'size' => '1.3em' , 'ifbold' => 0 ),
array ( 'color' => '#669933' , 'size' => '1.4em' , 'ifbold' => 1 ),
array ( 'color' => '#3366FF' , 'size' => '1.5em' , 'ifbold' => 0 ),
array ( 'color' => '#197B30' , 'size' => '1.6em' , 'ifbold' => 1 ),
);
$maxlevel = count ( $tagmark );
$tcount = $scount = array ();
foreach ( $tags AS $val )
{
$tcount [] = $val [ 'tag_count' ]; // 获得tag个数数组
}
$tcount = array_unique ( $tcount ); // 去除相同个数的tag
sort ( $tcount ); // 从小到大排序
$tempcount = count ( $tcount ); // 真正的tag级数
$per = $maxlevel >= $tempcount ? 1 : $maxlevel / ( $tempcount - 1 );
foreach ( $tcount AS $key => $val )
{
$lvl = floor ( $per * $key );
$scount [ $val ] = $lvl ; // 计算不同个数的tag相对应的着色数组key
}
$rewrite = intval ( $GLOBALS [ '_CFG' ][ 'rewrite' ]) > 0 ;
/* 遍历所有标签,根据引用次数设定字体大小 */
foreach ( $tags AS $key => $val )
{
$lvl = $scount [ $val [ 'tag_count' ]]; // 着色数组key
$tags [ $key ][ 'color' ] = $tagmark [ $lvl ][ 'color' ];
$tags [ $key ][ 'size' ] = $tagmark [ $lvl ][ 'size' ];
$tags [ $key ][ 'bold' ] = $tagmark [ $lvl ][ 'ifbold' ];
if ( $rewrite )
{
if ( strtolower ( EC_CHARSET ) !== 'utf-8' )
{
$tags [ $key ][ 'url' ] = 'tag-' . urlencode ( urlencode ( $val [ 'tag_words' ])) . '.html' ;
}
else
{
$tags [ $key ][ 'url' ] = 'tag-' . urlencode ( $val [ 'tag_words' ]) . '.html' ;
}
}
else
{
$tags [ $key ][ 'url' ] = 'search.php?keywords=' . urlencode ( $val [ 'tag_words' ]);
}
}
shuffle ( $tags );
}
/**
* 取得用户等级信息
* @ access public
* @ author Xuan Yan
*
* @ return array
*/
function get_rank_info ()
{
global $db , $ecs ;
if ( ! empty ( $_SESSION [ 'user_rank' ]))
{
$sql = " SELECT rank_name, special_rank FROM " . $ecs -> table ( 'user_rank' ) . " WHERE rank_id = ' $_SESSION[user_rank] ' " ;
$row = $db -> getRow ( $sql );
if ( empty ( $row ))
{
return array ();
}
$rank_name = $row [ 'rank_name' ];
if ( $row [ 'special_rank' ])
{
return array ( 'rank_name' => $rank_name );
}
else
{
$user_rank = $db -> getOne ( " SELECT rank_points FROM " . $ecs -> table ( 'users' ) . " WHERE user_id = ' $_SESSION[user_id] ' " );
$sql = " SELECT rank_name,min_points FROM " . $ecs -> table ( 'user_rank' ) . " WHERE min_points > ' $user_rank ' ORDER BY min_points ASC LIMIT 1 " ;
$rt = $db -> getRow ( $sql );
$next_rank_name = $rt [ 'rank_name' ];
$next_rank = $rt [ 'min_points' ] - $user_rank ;
return array ( 'rank_name' => $rank_name , 'next_rank_name' => $next_rank_name , 'next_rank' => $next_rank );
}
}
else
{
return array ();
}
}
/**
* 获取用户参与活动信息
*
* @ access public
* @ param int $user_id 用户id
*
* @ return array
*/
function get_user_prompt ( $user_id )
{
$prompt = array ();
$now = gmtime ();
/* 夺宝奇兵 */
$sql = " SELECT act_id, goods_name, end_time " .
" FROM " . $GLOBALS [ 'ecs' ] -> table ( 'goods_activity' ) .
" WHERE act_type = ' " . GAT_SNATCH . " ' " .
" AND (is_finished = 1 OR (is_finished = 0 AND end_time <= ' $now ')) " ;
$res = $GLOBALS [ 'db' ] -> query ( $sql );
while ( $row = $GLOBALS [ 'db' ] -> fetchRow ( $res ))
{
$act_id = $row [ 'act_id' ];
$result = get_snatch_result ( $act_id );
if ( isset ( $result [ 'order_count' ]) && $result [ 'order_count' ] == 0 && $result [ 'user_id' ] == $user_id )
{
$prompt [] = array (
'text' => sprintf ( $GLOBALS [ '_LANG' ][ 'your_snatch' ], $row [ 'goods_name' ], $row [ 'act_id' ]),
'add_time' => $row [ 'end_time' ]
);
}
if ( isset ( $auction [ 'last_bid' ]) && $auction [ 'last_bid' ][ 'bid_user' ] == $user_id && $auction [ 'order_count' ] == 0 )
{
$prompt [] = array (
'text' => sprintf ( $GLOBALS [ '_LANG' ][ 'your_auction' ], $row [ 'goods_name' ], $row [ 'act_id' ]),
'add_time' => $row [ 'end_time' ]
);
}
}
/* 竞拍 */
$sql = " SELECT act_id, goods_name, end_time " .
" FROM " . $GLOBALS [ 'ecs' ] -> table ( 'goods_activity' ) .
" WHERE act_type = ' " . GAT_AUCTION . " ' " .
" AND (is_finished = 1 OR (is_finished = 0 AND end_time <= ' $now ')) " ;
$res = $GLOBALS [ 'db' ] -> query ( $sql );
while ( $row = $GLOBALS [ 'db' ] -> fetchRow ( $res ))
{
$act_id = $row [ 'act_id' ];
$auction = auction_info ( $act_id );
if ( isset ( $auction [ 'last_bid' ]) && $auction [ 'last_bid' ][ 'bid_user' ] == $user_id && $auction [ 'order_count' ] == 0 )
{
$prompt [] = array (
'text' => sprintf ( $GLOBALS [ '_LANG' ][ 'your_auction' ], $row [ 'goods_name' ], $row [ 'act_id' ]),
'add_time' => $row [ 'end_time' ]
);
}
}
/* 排序 */
$cmp = create_function ( '$a, $b' , 'if($a["add_time"] == $b["add_time"]){return 0;};return $a["add_time"] < $b["add_time"] ? 1 : -1;' );
usort ( $prompt , $cmp );
/* 格式化时间 */
foreach ( $prompt as $key => $val )
{
$prompt [ $key ][ 'formated_time' ] = local_date ( $GLOBALS [ '_CFG' ][ 'time_format' ], $val [ 'add_time' ]);
}
return $prompt ;
}
/**
* 获取用户评论
*
* @ access public
* @ param int $user_id 用户id
* @ param int $page_size 列表最大数量
* @ param int $start 列表起始页
* @ return array
*/
function get_comment_list ( $user_id , $page_size , $start )
{
$sql = " SELECT c.*, g.goods_name AS cmt_name, r.content AS reply_content, r.add_time AS reply_time " .
" FROM " . $GLOBALS [ 'ecs' ] -> table ( 'comment' ) . " AS c " .
" LEFT JOIN " . $GLOBALS [ 'ecs' ] -> table ( 'comment' ) . " AS r " .
" ON r.parent_id = c.comment_id AND r.parent_id > 0 " .
" LEFT JOIN " . $GLOBALS [ 'ecs' ] -> table ( 'goods' ) . " AS g " .
" ON c.comment_type=0 AND c.id_value = g.goods_id " .
" WHERE c.user_id=' $user_id ' " ;
$res = $GLOBALS [ 'db' ] -> SelectLimit ( $sql , $page_size , $start );
$comments = array ();
$to_article = array ();
while ( $row = $GLOBALS [ 'db' ] -> fetchRow ( $res ))
{
$row [ 'formated_add_time' ] = local_date ( $GLOBALS [ '_CFG' ][ 'time_format' ], $row [ 'add_time' ]);
if ( $row [ 'reply_time' ])
{
$row [ 'formated_reply_time' ] = local_date ( $GLOBALS [ '_CFG' ][ 'time_format' ], $row [ 'reply_time' ]);
}
if ( $row [ 'comment_type' ] == 1 )
{
$to_article [] = $row [ " id_value " ];
}
$comments [] = $row ;
}
if ( $to_article )
{
$sql = " SELECT article_id , title FROM " . $GLOBALS [ 'ecs' ] -> table ( 'article' ) . " WHERE " . db_create_in ( $to_article , 'article_id' );
$arr = $GLOBALS [ 'db' ] -> getAll ( $sql );
$to_cmt_name = array ();
foreach ( $arr as $row )
{
$to_cmt_name [ $row [ 'article_id' ]] = $row [ 'title' ];
}
foreach ( $comments as $key => $row )
{
if ( $row [ 'comment_type' ] == 1 )
{
$comments [ $key ][ 'cmt_name' ] = isset ( $to_cmt_name [ $row [ 'id_value' ]]) ? $to_cmt_name [ $row [ 'id_value' ]] : '' ;
}
}
}
return $comments ;
}
/**
* 扣除點數
*/
/**
* 增加點數
*/
function decrease_point ( $games_id , $user_id , $amount , $rec_id )
{
if ( $games_id != '0' ){
$sql = " SELECT games_code FROM " . $GLOBALS [ 'ecs' ] -> table ( 'games' ) . " WHERE games_id= " . $games_id ;
$games_code = $GLOBALS [ 'db' ] -> getOne ( $sql );
} else {
$games_code = 'HB' ;
}
switch ( $games_code )
{
case 'HB' :
log_account_change ( $user_id , $amount , 0 , 0 , 0 , $rec_id , '2' );
return 1 ;
break ;
default :
include_once ( ROOT_PATH . 'includes/modules/games/game_' . $games_code . '.php' );
$func = 'game_' . $games_code ;
$game_obj = new $func ;
$memberId = $GLOBALS [ 'db' ] -> getOne ( " SELECT account FROM " . $GLOBALS [ 'ecs' ] -> table ( 'user_game' ) . " WHERE game_id=' " . getGameId ( $games_code ) . " ' and user_id = ' " . $user_id . " ' " );
if ( strlen ( $memberId ) == 0 ){
$game_obj -> add_user ( $user_id );
}
//檢查領額
$blc = $game_obj -> get_balance ( $user_id );
if ( abs ( $amount ) > $blc [ 'amount' ]){
return false ;
}
$result = $game_obj -> trans_out ( $_SESSION [ 'user_id' ], abs ( $amount ), $rec_id );
return $result ;
break ;
}
}
/**
* 增加點數
*/
function increase_point ( $games_id , $user_id , $amount , $rec_id )
{
if ( $games_id != '0' ){
$sql = " SELECT games_code FROM " . $GLOBALS [ 'ecs' ] -> table ( 'games' ) . " WHERE games_id= " . $games_id ;
$games_code = $GLOBALS [ 'db' ] -> getOne ( $sql );
} else {
$games_code = 'HB' ;
}
switch ( $games_code )
{
case 'HB' :
log_account_change ( $user_id , $amount , 0 , 0 , 0 , $rec_id , '2' );
return 1 ;
break ;
default :
include_once ( ROOT_PATH . 'includes/modules/games/game_' . $games_code . '.php' );
$func = 'game_' . $games_code ;
$game_obj = new $func ;
$memberId = $GLOBALS [ 'db' ] -> getOne ( " SELECT account FROM " . $GLOBALS [ 'ecs' ] -> table ( 'user_game' ) . " WHERE game_id=' " . getGameId ( $games_code ) . " ' and user_id = ' " . $user_id . " ' " );
if ( strlen ( $memberId ) == 0 ){
$game_obj -> add_user ( $user_id );
}
$result = $game_obj -> trans_in ( $user_id , abs ( $amount ), $rec_id );
return $result ;
break ;
}
}
function check_trans ( $games_id , $user_id , $rec_id )
{
if ( $games_id != '0' ){
$sql = " SELECT games_code FROM " . $GLOBALS [ 'ecs' ] -> table ( 'games' ) . " WHERE games_id= " . $games_id ;
$games_code = $GLOBALS [ 'db' ] -> getOne ( $sql );
} else {
$games_code = 'HB' ;
}
include_once ( ROOT_PATH . 'includes/modules/games/game_' . $games_code . '.php' );
$func = 'game_' . $games_code ;
$game_obj = new $func ;
$result = $game_obj -> check_trans ( $user_id , $rec_id );
return $result ;
}
2022-11-14 15:49:28 +00:00
?>