HEX
Server: Apache
System: Linux 4485441ca2e2 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 11:03:07 UTC 2025 aarch64
User: (1000)
PHP: 8.2.24
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/ganryu_shop/model/Point.php.bak20160930
<?php

require_once dirname(__FILE__).'/Abstract.php';

class ganryu_shop_model_Point extends ganryu_shop_model_Abstract{
	
	function checkPointType($category, $type){
		$checkar = array(
			'shopping'=>array(
				'shopping_buy'
			),
			'pointuse'=>array(
				'pointuse_shopping'
			),
			'pointbonus'=>array(
				'pointbonus_first'
			),
			'share'=>array(
				'share_articlesns'
			),
			'system'=>array(
				'system_adjust'
			),
		);
		if (!array_key_exists($category, $checkar)){
			return false;
		}
		if (!in_array($type, $checkar[$category])){
			return false;
		}
		return true;
	}
	
	
	function addPoint($userid, $data){
		$res = $this->checkPointType($data['point_category'],$data['point_type']);
		if (!$res){
			return false;
		}
		
		$tbll = $this->tablename('user_point_log');
		$tblu = $this->tablename('user_point');
		$sql = "
			insert into $tbll(
				userid,
				point_category,
				point_type,
				point_value,
				point_name,
				extent_info,
				create_date
			)
			values(
				:userid,
				:point_category,
				:point_type,
				:point_value,
				:point_name,
				:extent_info,
				now()
			)
		";
		$bind = array(
			'userid'=>$userid,
			'point_category'=>$data['point_category'],
			'point_type'=>$data['point_type'],
			'point_value'=>$data['point_value'],
			'point_name'=>$data['point_name'],
			'extent_info'=>$data['extent_info'],
		);
		$res = $this->query($sql, $bind);
		
		if (!$res){
			return false;
		}
		
		$sql = "
			select
				userid
			from
				$tblu
			where
				userid = :userid
		";
		$bind = array(
			'userid'=>$userid
		);
		$res=  $this->selectRow($sql, $bind);
		if ($res === false){
			return false;
		}
		
		if (!$res){
			$sql = "
				insert into $tblu(
					userid,
					current_point
				)
				values(
					:userid,
					:pt
				)
			";
			$bind = array(
				'userid'=>$userid,
				'pt'=>$data['point_value']
			);
			$res = $this->query($sql, $bind);
			if (!$res){
				return false;
			}
		}
		else{
			$sql = "
				update $tblu set
					current_point = current_point + (:pt)
				where
					userid = :userid
			";
			$bind = array(
				'userid'=>$userid,
				'pt'=>$data['point_value']
			);
			$res = $this->query($sql, $bind);
			if (!$res){
				return false;
			}
		}
		return true;
	}
	
	function getUserPoint($userid){
		$tbl = $this->tablename('user_point');
		$sql = "
			select
				current_point
			from
				$tbl
			where
				userid = :userid
		";
		$bind = array('userid'=>$userid);
		$res = $this->selectRow($sql, $bind);
		if ($res === false){
			return false;
		}
		if (!$res){
			return array('current_point'=>0);
		}
		return $res;
	}
	
	
	function searchPointLog($pg, $num, $data){
		$tbl = $this->tablename('user_point_log');
		
		$wsql = "";
		$b = array();
		if (isset($data['userid']) && $data['userid']){
			$wsql = " and userid = :userid";
			$b['userid'] = $data['userid'];
		}
		if (isset($data['point_category']) && $data['point_category']){
			$wsql = " and point_category = :point_category";
			$b['point_category'] = $data['point_category'];
		}
		
		$wblock = "
			from
				$tbl
			where
				1 $wsql
		";
		$sql = "
			select
				count(*) ct
			$wblock
		";
		$bind = $b;
		$res = $this->selectRow($sql, $bind);
		if ($res === false){
			return false;
		}
		$ct = $res?$res['ct']+0:0;
		if (!$ct){
			return $this->searchResult0();
		}
		
		$sql = "
			select
				logid,
				point_category,
				point_type,
				point_name,
				point_value,
				extent_info,
				date_format(create_date, '%Y%m%d%H%i%s') create_date
			$wblock
			order by create_date desc
		";
		$sql .= $this->searchLimit($pg, $num);
		$res = $this->selectAll($sql, $bind);
		if ($res === false){
			return false;
		}
		
		return $this->searchResult($res, $pg, $num, $ct);
	}

}