* @version : HUOSDK 8.0 */ namespace huoAccountDeal\controller; use huo\model\order\OrderModel; use huoAccountDeal\logic\MemGameLogic; use huolib\constant\OrderConst; use huolib\tool\StrUtils; class MemGameCache { public static function ins() { return new static(); } /** *获取玩家小号Key * * @param string $mg_mem_id * * @return string */ public function getMemGameIdKey($mg_mem_id) { return 'mem_game_id_key_'.$mg_mem_id; } /** * 获取玩家小号信息 * * @param string $mg_mem_id * * @return array|bool|mixed */ public function getInfoById($mg_mem_id) { // $_key = $this->getMemGameIdKey($mg_mem_id); // $_mem_game_data_json = Cache::get($_key); // $_mem_game_data = json_decode($_mem_game_data_json, true); // if (!is_array($_mem_game_data)) { // $_mem_game_data = $_mem_game_data_json; // } // if (!is_array($_mem_game_data) || empty($_mem_game_data)) { $_mem_game_data = (new MemGameLogic())->getInfoById($mg_mem_id); if (empty($_mem_game_data)) { return false; } // $this->saveMemGameCache($mg_mem_id, $_mem_game_data); // } //汇总玩家小号充值金额 $_sum_money = (new OrderModel())->getTotalAmount( [ 'mg_mem_id' => $mg_mem_id, 'status' => OrderConst::PAY_STATUS_SUC, ] ); $_mem_game_data['sum_money'] = StrUtils::formatNumber($_sum_money); return $_mem_game_data; } // /** // * 保存玩家小号 cache 数据 // * // * @param string $mg_mem_id // * @param array $mem_game_data // * @param int $ttl // */ // public function saveMemGameCache($mg_mem_id, $mem_game_data, $ttl = 3600) { // $_key = $this->getMemGameIdKey($mg_mem_id); // Cache::set($_key, json_encode($mem_game_data), $ttl); // } // // /** // * 更新玩家小号信息 // * // * @param string $mg_mem_id // * @param array $mem_game_data // * // * @return bool // */ // public function updateMemGame($mg_mem_id, $mem_game_data) { // $_key = $this->getMemGameIdKey($mg_mem_id); // Cache::rm($_key); // //移除数据表不存在的字段 // if (isset($mem_game_data['total_recharge'])) { // unset($mem_game_data['total_recharge']); // } // // return (new MemGameLogic())->updateMemGame($mg_mem_id, $mem_game_data); // } }