redis->executeCommand('HGETALL', [$cacheKey]); $data = []; $list = []; if(!empty($cacheData)){ if(!empty($cacheData)){ $x = 0; foreach($cacheData as $cKey => $cVal){ if($cKey%2 == 0){ $list[$x]['key'] = $cVal; }else{ $list[$x]['value'] = $cVal; $x++; } } foreach($list as $lKey => $lVal){ $data[$lVal['key']] = $lVal['value']; } } }else{ $condition = ['id' => $id]; $merchant = xhWxOpen::getByCondition($condition); if(!empty($merchant)){ $arr = [$cacheKey]; foreach($merchant as $key => $val){ $arr[] = $key; $arr[] = $val; } Yii::$app->redis->executeCommand('HMSET', $arr); } $data = $merchant; } return $data; } public static function updateById($id, $data) { xhWxOpen::updateById($id, $data); self::refresh($id); } public static function refresh($id) { $preKey = configDict::getCacheKey('wxOpen'); $cacheKey = $preKey.$id; Yii::$app->redis->executeCommand('DEL', [$cacheKey]); self::getById($id); } public static function add($data) { $data = xhWxOpen::add($data); $id = $data['id']; self::refresh($id); return $data; } /** * 取平台相应的商家 */ public static function getMerchant() { $wxOpenId = configDict::getConfig('openId'); $wxOpen = xhWxOpenService::getById($wxOpenId); $merchantId = $wxOpen['merchantId']; $merchant = xhMerchantService::getById($merchantId); return $merchant; } }