You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.9 KiB
98 lines
2.9 KiB
<?php
|
|
|
|
namespace App\Service\v3\Implementations;
|
|
|
|
use App\Constants\v3\ErrorCode;
|
|
use App\Constants\v3\SsdbKeys;
|
|
use App\Exception\ErrorCodeException;
|
|
use App\Model\v3\User;
|
|
use App\Model\v3\ServicePersonnel;
|
|
use App\Model\v3\Store;
|
|
use App\Service\v3\Interfaces\UserInfoServiceInterface;
|
|
use App\TaskWorker\SSDBTask;
|
|
use EasyWeChat\Factory;
|
|
use EasyWeChat\Kernel\Exceptions\DecryptException;
|
|
use Hyperf\Guzzle\CoroutineHandler;
|
|
use Hyperf\Utils\ApplicationContext;
|
|
|
|
class UserInfoService implements UserInfoServiceInterface
|
|
{
|
|
|
|
/**
|
|
* 更新
|
|
* @param $userId
|
|
* @param $iv
|
|
* @param $encryptedData
|
|
* @return array
|
|
* @throws DecryptException
|
|
*/
|
|
public function do($userId, $iv, $encryptedData)
|
|
{
|
|
|
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
|
|
$user = $ssdb->exec('hgetall', SsdbKeys::USER_INFO.$userId);
|
|
|
|
// 微信登录
|
|
$config = config('applet');
|
|
$app = Factory::miniProgram($config);
|
|
$app['guzzle_handler'] = CoroutineHandler::class;
|
|
$decryptedData = $app->encryptor->decryptData($user['session_key'], $iv, $encryptedData);
|
|
|
|
$data = [
|
|
'nick_name' => $decryptedData['nickName'],
|
|
'avatar' => $decryptedData['avatarUrl'],
|
|
'openid' => $decryptedData['openId'],
|
|
'unionid' => $decryptedData['unionId'],
|
|
'country' => $decryptedData['country'],
|
|
'province' => $decryptedData['province'],
|
|
'city' => $decryptedData['city'],
|
|
'gender' => $decryptedData['gender'],
|
|
'language' => $decryptedData['language'],
|
|
];
|
|
$user = User::query()->find($userId);
|
|
$res = $user->fill($data)->save();
|
|
|
|
if (!$res) {
|
|
$logArr = [
|
|
'userId' => $userId,
|
|
'iv' => $iv,
|
|
'encryptedData' => $encryptedData,
|
|
'$decryptedData' => $decryptedData
|
|
];
|
|
throw new ErrorCodeException(ErrorCode::USER_INFO_UPDATE_ERROR,'更新用户信息失败',$logArr);
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
public function check($userId)
|
|
{
|
|
return User::query()->where(['status' => 1, 'id' => $userId])->exists();
|
|
}
|
|
|
|
public function undo($userId)
|
|
{
|
|
// TODO: Implement undo() method.
|
|
}
|
|
|
|
public function detail($userId)
|
|
{
|
|
return User::query()
|
|
->select(['id', 'nick_name', 'avatar', 'openid', 'total_score', 'real_name'])
|
|
->where(['status' => 1, 'id' => $userId])
|
|
->first()->toArray();
|
|
}
|
|
|
|
public function getStoreByUID($userId)
|
|
{
|
|
$store = Store::where('user_id',$userId)->select(['id','name','user_id','market_id'])->first();
|
|
return $store;
|
|
}
|
|
|
|
public function getServicePersonnelByUID($userId)
|
|
{
|
|
$sp = ServicePersonnel::where('user_id',$userId)->select('id','user_id')->first();
|
|
return $sp;
|
|
}
|
|
|
|
}
|