|
|
<?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 implements UserInfoServiceInterface{
/** * 更新 * @param $userId * @param $iv * @param $encryptedData * @return array * @throws DecryptException */ public function do($userId, $iv, $encryptedData) {
try { $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; } 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) { 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 getEmployeesByUID($userId) { $employees = Employees::where('user_id',$userId)->where(function ($query){ $query->whereJsonContains('position', '29')->orWhereJsonContains('position', '30'); })->first(); return $employees; } }
|