where(['sjId' => $sjId, 'alipayId' => $alipayId])->one(); if (empty($alipay)) { $alipay = self::add(['sjId' => $sjId, 'alipayId' => $alipayId, 'alipayAccount' => $alipayAccount, 'addTime' => time(), 'createTime' => date("Y-m-d H:i:s")]); } if (empty($alipay['userId'])) { $user = xhUserService::generateUserByAlipay($alipayId, $sjId); $userId = $user['id']; xhUserAlipay::updateByCondition(['sjId' => $sjId, 'alipayId' => $alipayId], ['userId' => $userId]); }else{ $user = xhUserService::getById($alipay['userId']); } return $user; } public static function getByIds($alipayId, $sjId) { $user = xhUserAlipay::find()->where(['alipayId' => $alipayId, 'sjId' => $sjId])->asArray()->one(); return $user; } public static function add($data) { $return = xhUserAlipay::add($data); $sjId = $return['sjId']; $alipayId = $return['alipayId']; $cacheKey = dict::getCacheKey('xhUserAlipay') . '_' . $sjId . '_' . $alipayId; $params = [$cacheKey]; if (!empty($return)) { foreach ($return as $key => $val) { $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET', $params); return $return; } public static function updateByIds($alipayId, $sjId, $data) { xhUserAlipay::updateByCondition(['alipayId' => $alipayId, 'sjId' => $sjId], $data); self::getByIds($alipayId, $sjId); $cacheKey = dict::getCacheKey('xhUserAlipay') . '_' . $sjId . '_' . $alipayId; $params = [$cacheKey]; if (!empty($data)) { foreach ($data as $key => $val) { $params[] = $key; $params[] = $val; } } Yii::$app->redis->executeCommand('HMSET', $params); } public static function getAlipayAccount($alipayId, $sjId) { $user = self::getByIds($alipayId, $sjId); $account = isset($user['alipayAccount']) ? $user['alipayAccount'] : ''; return $account; } }