| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\ActionLogModel;
- use App\Models\ApiKeyModel;
- use App\Models\MemberModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 接口账号管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Common
- */
- class ApiKeyService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new ApiKeyModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 获取接口配置
- * @param int $userId
- * @return array|false|mixed
- */
- public function getConfig($userId=0)
- {
- $cacheKey = "caches:apiKeys:user_{$userId}";
- $config = RedisService::get($cacheKey);
- if(empty($config)){
- $keyId = 0;
- if($userId){
- $keyId = MemberModel::where(['id'=>$userId])->value('api_key_id');
- }
- $config = $this->model->where(['mark'=>1])
- ->where(function($query) use($keyId){
- if($keyId){
- $query->where(['status'=>1,'id'=> $keyId]);
- }else{
- $query->where(['status'=>1]);
- }
- })
- ->select(['id','api_key','api_secret','passphrase','status'])
- ->first();
- $config = $config? $config->toArray() : [];
- if($config){
- RedisService::set($cacheKey, $config, rand(300, 600));
- }
- }
- return $config;
- }
- /**
- * 添加会编辑
- * @return array
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function edit()
- {
- // 请求参数
- $data = request()->all();
- ActionLogModel::setTitle("修改OK接口账号信息");
- ActionLogModel::record();
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- }
|