SystemApis.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. *
  7. * 所有第三方接口配置表
  8. */
  9. namespace app\common\model;
  10. use think\Model;
  11. class SystemApis extends Model{
  12. protected $pk = 'id';
  13. /**
  14. * 读取接口信息
  15. */
  16. public static function Config($name){
  17. $info = self::where(['name' => $name])->find();
  18. if(empty($info)){
  19. return;
  20. }else{
  21. $data = empty($info->apikey) ? [] : $info->apikey;
  22. return json_decode($data,true);
  23. }
  24. }
  25. /**
  26. * 修改配置或新增
  27. */
  28. public static function edit($name,array $apikey = []){
  29. $apikey = json_encode($apikey);
  30. $info = self::where(['name' => $name])->find();
  31. if(empty($info)){
  32. $data['name'] = trim($name);
  33. $data['apikey'] = $apikey;
  34. return self::insert($data);
  35. }else{
  36. $info->apikey = $apikey;
  37. return $info->save();
  38. }
  39. }
  40. }