Commit 76395f16 by TingSong-Syu

implement some client side function to shadow Product

parent 5910ebe6
......@@ -9,6 +9,7 @@
namespace neoteched\rpc\pay_center;
use x2ts\IAssignable;
use x2ts\rpc\RPCWrapper;
class Product implements IAssignable {
use AssignTrait;
......@@ -26,4 +27,30 @@ class Product implements IAssignable {
public $ctime = 0;
public $mtime = 0;
private static $userBought = [];
public static function userBought(int $userId) {
if (!array_key_exists($userId, self::$userBought)) {
self::$userBought[$userId] = RPCWrapper::rpc('pay_center')
->call('boughtProductHash', $userId);
}
return self::$userBought[$userId];
}
public static function boughtProductNames(int $userId): array {
return array_keys(self::userBought($userId));
}
public static function boughtProducts(int $userId) {
return RPCWrapper::rpc('pay_center')->call('boughtProducts', $userId);
}
public static function boughtProductCount(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
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