Commit baf04151 by TingSong-Syu

implement static useful functions for Feature

parent 76395f16
...@@ -10,6 +10,7 @@ namespace neoteched\rpc\pay_center; ...@@ -10,6 +10,7 @@ namespace neoteched\rpc\pay_center;
use x2ts\IAssignable; use x2ts\IAssignable;
use x2ts\rpc\RPCWrapper;
class Feature implements IAssignable { class Feature implements IAssignable {
use AssignTrait; use AssignTrait;
...@@ -20,6 +21,8 @@ class Feature implements IAssignable { ...@@ -20,6 +21,8 @@ class Feature implements IAssignable {
self::TYPE_CARD, self::TYPE_CARD,
]; ];
private static $userBought = [];
public $name = ''; public $name = '';
public $description = ''; public $description = '';
...@@ -29,4 +32,28 @@ class Feature implements IAssignable { ...@@ -29,4 +32,28 @@ class Feature implements IAssignable {
public $ctime = 0; public $ctime = 0;
public $mtime = 0; public $mtime = 0;
public static function boughtFeatureNames(int $userId): array {
return array_keys(self::userBought($userId));
}
public static function userBought(int $userId) {
if (!array_key_exists($userId, self::$userBought)) {
self::$userBought[$userId] = RPCWrapper::rpc('pay_center')
->call('boughtFeatureHash', $userId);
}
return self::$userBought[$userId];
}
public static function boughtFeatures(int $userId): array {
return RPCWrapper::rpc('pay_center')->call('boughtFeatures', $userId);
}
public static function boughtFeatureCount(int $userId): int {
return count(self::userBought($userId));
}
public static function hasBought(string $name, int $userId): bool {
return array_key_exists($name, self::userBought($userId));
}
} }
\ No newline at end of file
...@@ -14,6 +14,8 @@ use x2ts\rpc\RPCWrapper; ...@@ -14,6 +14,8 @@ use x2ts\rpc\RPCWrapper;
class Product implements IAssignable { class Product implements IAssignable {
use AssignTrait; use AssignTrait;
private static $userBought = [];
public $name = ''; public $name = '';
public $price = 0; public $price = 0;
...@@ -28,7 +30,9 @@ class Product implements IAssignable { ...@@ -28,7 +30,9 @@ class Product implements IAssignable {
public $mtime = 0; public $mtime = 0;
private static $userBought = []; public static function boughtProductNames(int $userId): array {
return array_keys(self::userBought($userId));
}
public static function userBought(int $userId) { public static function userBought(int $userId) {
if (!array_key_exists($userId, self::$userBought)) { if (!array_key_exists($userId, self::$userBought)) {
...@@ -38,11 +42,7 @@ class Product implements IAssignable { ...@@ -38,11 +42,7 @@ class Product implements IAssignable {
return self::$userBought[$userId]; return self::$userBought[$userId];
} }
public static function boughtProductNames(int $userId): array { public static function boughtProducts(int $userId): array {
return array_keys(self::userBought($userId));
}
public static function boughtProducts(int $userId) {
return RPCWrapper::rpc('pay_center')->call('boughtProducts', $userId); return RPCWrapper::rpc('pay_center')->call('boughtProducts', $userId);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment