| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace common\services;
- use common\components\util;
- use Yii;
- use common\components\stringUtil;
- use common\components\dict;
- use common\components\wxUtil;
- use common\models\xhUserAlipay;
- class xhUserAlipayService
- {
-
- public static function replaceInfo($arr)
- {
- $sjId = $arr['sjId'];
- $alipayId = $arr['alipayId'];
- $alipayAccount = $arr['alipayAccount'];
- $alipay = xhUserAlipay::find()->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;
- }
-
- }
|