php [积分和奖励]重新计算积分

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [积分和奖励]重新计算积分相关的知识,希望对你有一定的参考价值。

<?php

function ywpar_calculate_rewarded_points( $user_id ){
	global $wpdb;
	$table_name = $wpdb->prefix . 'yith_ywpar_points_log';


	$query = "SELECT SUM(ywpar_points.amount) as rewarded_points FROM $table_name as ywpar_points where user_id = $user_id AND action = 'redeemed_points'";
	$res   = $wpdb->get_row( $query );

	return ( empty( $res ) || $res->rewarded_points < 0 )  ? 0 : $res->rewarded_points;
}

function ywpar_calculate_total_points( $user_id ){
	global $wpdb;
	$table_name = $wpdb->prefix . 'yith_ywpar_points_log';


	$query = "SELECT SUM(ywpar_points.amount) as total FROM $table_name as ywpar_points where user_id = $user_id ";
	$res   = $wpdb->get_row( $query );

	return ( empty( $res ) || $res->total < 0 ) ? 0 : $res->total;
}

function ywpar_update_points(){
	global $wpdb;
	$table_name = $wpdb->prefix . 'yith_ywpar_points_log';
	$query = "SELECT user_id  FROM $table_name as ywpar_points  GROUP by user_id ";
	$res   = $wpdb->get_col( $query );

	if( $res){
		foreach ( $res as $customer_user ){
			$rewarded_points = ywpar_calculate_rewarded_points( $customer_user );
			$total_points    = ywpar_calculate_total_points( $customer_user );
			update_user_meta( $customer_user, '_ywpar_user_total_points',  $total_points);
			update_user_meta( $customer_user, '_ywpar_rewarded_points',  $rewarded_points);
		}

	}
}


if( isset($_GET['points_update'])){
	ywpar_update_points();
}

以上是关于php [积分和奖励]重新计算积分的主要内容,如果未能解决你的问题,请参考以下文章

php [积分和奖励]添加订单积分

php [积分和奖励]使用整点购物车的积分

php 动态+积分和奖励

SUMO 奖励积分 Wordpress 插件

php 在特定订单状态之后奖励积分(在本例中为“已完成”)

在 SQLite xp 系统上为奖励积分添加冷却时间