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.
129 lines
4.0 KiB
129 lines
4.0 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\Employees;
|
|
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
|
|
{
|
|
|
|
/**
|
|
* 更新
|
|
* @param $data
|
|
* @return array
|
|
* @throws DecryptException
|
|
*/
|
|
public function do($data)
|
|
{
|
|
|
|
try {
|
|
$userId = $data['userId'];
|
|
$iv = $data['iv'];
|
|
$encryptedData = $data['encryptedData'];
|
|
|
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
|
|
$user = $ssdb->exec('hgetall', SsdbKeys::USER_INFO.$userId);
|
|
|
|
if(empty($user)) {
|
|
return ['找不到缓存的用户信息'];
|
|
}
|
|
|
|
// 微信登录
|
|
$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;
|
|
} catch (\Exception $e) {
|
|
throw new ErrorCodeException(ErrorCode::USER_INFO_UPDATE_ERROR,'更新用户信息失败',['error_msg' => $e->getMessage()]);
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
{
|
|
$result = User::query()
|
|
->select(['id', 'nick_name', 'avatar', 'openid', 'unionid', 'total_score', 'real_name'])
|
|
->where(['status' => 1, 'id' => $userId])
|
|
->first();
|
|
if(!$result) {
|
|
return [];
|
|
}else{
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
public function getStoreByUID($userId)
|
|
{
|
|
$store = Store::where('user_id',$userId)->select(['id','name','user_id','market_id'])->first();
|
|
return $store;
|
|
}
|
|
|
|
public function getEmployeesByUID($userId)
|
|
{
|
|
$employees = Employees::where('user_id',$userId)->where(function ($query){
|
|
$query->whereJsonContains('position', '29')->orWhereJsonContains('position', '30');
|
|
})->first();
|
|
return $employees;
|
|
}
|
|
|
|
public function getPaidUnionId($openid, $options = [])
|
|
{
|
|
$config = config('applet');
|
|
$app = Factory::miniProgram($config);
|
|
$app['guzzle_handler'] = CoroutineHandler::class;
|
|
$res = $app->base->getPaidUnionid($openid, $options);
|
|
if (isset($res['unionid']) && $res['unionid']) {
|
|
return $res['unionid'];
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|