123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace refill;
- use Cache;
- class rlock
- {
- //分配策略 1, 关闭 2,预留,3 分配
- const CLOSE = 1;
- const RETAIN = 2;
- const ASSIGN = 3;
- const sys_storage_name = 'system_storage';
- const mch_storage_name = 'merchant_storage';
- const locked_open_name = 'oil_amount_lock_turn';
- //system storage
- public static function set_open($card_type,$opened)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::sys_storage_name;
- $key = "{$card_type}-open";
- $ins->hset($name, '', [$key => $opened]);
- }
- public static function get_open($card_type)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::sys_storage_name;
- $key = "{$card_type}-open";
- $value = $ins->hget($name,'',$key);
- return $value;
- }
- public static function incr_sys_storage($card_type,$spec,$count)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::sys_storage_name;
- $key = "{$card_type}-{$spec}";
- return $ins->hIncrBy($name, $key, $spec * $count);
- }
- public static function decr_sys_storage($card_type,$spec,$count)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::sys_storage_name;
- $key = "{$card_type}-{$spec}";
- return $ins->hIncrBy($name, $key, -1 * $spec * $count);
- }
- public static function hget_sys_storage($card_type,$spec)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::sys_storage_name;
- $key = "{$card_type}-{$spec}";
- $value = $ins->hget($name, '', $key);
- return $value;
- }
- public static function get_sys()
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::sys_storage_name;
- $value = $ins->hget($name,'');
- return $value;
- }
- public static function clear_all()
- {
- $ins = Cache::getInstance('cacheredis');
- $ins->hdel(self::sys_storage_name,'');
- $ins->hdel(self::mch_storage_name,'');
- }
- //merchant 总金额分配策略开关,及剩余金额变动和获取
- public static function incr_mch_total_storage($mchid,$card_type,$amount)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-total";
- return $ins->hIncrBy($name, $key, $amount);
- }
- public static function decr_mch_total_storage($mchid,$card_type,$amount)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-total";
- return $ins->hIncrBy($name, $key, -1 * $amount);
- }
- public static function hget_mch_total_storage($mchid,$card_type)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-total";
- $value = $ins->hget($name, '', $key);
- return $value;
- }
- public static function hset_mch_total_storage_turn($mchid,$card_type,$val)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-turn";
- $ins->hset($name, '', [$key => $val]);
- }
- public static function hget_mch_total_storage_turn($mchid,$card_type)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-turn";
- return $ins->hget($name, '', $key);
- }
- //mchid storage count-lock
- public static function incr_mch_storage($mchid,$card_type,$spec,$count)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-{$spec}";
- return $ins->hIncrBy($name, $key, $spec * $count);
- }
- public static function decr_mch_storage($mchid,$card_type,$spec,$count)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-{$spec}";
- return $ins->hIncrBy($name, $key, -1 * $spec * $count);
- }
- public static function hget_mch_storage($mchid,$card_type,$spec)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-{$spec}";
- $value = $ins->hget($name, '', $key);
- return $value;
- }
- public static function hset_mch_storage_turn($mchid,$card_type,$spec,$val)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-{$spec}-turn";
- $ins->hset($name, '', [$key => $val]);
- }
- public static function hget_mch_storage_turn($mchid,$card_type,$spec)
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $key = "{$mchid}-{$card_type}-{$spec}-turn";
- return $ins->hget($name, '', $key);
- }
- public static function get_merchant()
- {
- $ins = Cache::getInstance('cacheredis');
- $name = self::mch_storage_name;
- $value = $ins->hget($name,'');
- return $value;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- }
|