ConfigApis.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. * 所有第三方接口配置表 Table<ai_config_apis>
  7. */
  8. namespace app\common\model;
  9. use think\Model;
  10. class ConfigApis extends Model{
  11. protected $pk = 'id';
  12. /**
  13. * 读取接口信息
  14. */
  15. public static function Config($name){
  16. $info = self::where(['name' => $name])->find();
  17. if(empty($info)){
  18. return;
  19. }else{
  20. $data = empty($info->apikey) ? [] : $info->apikey;
  21. return json_decode($data,true);
  22. }
  23. }
  24. /**
  25. * 修改配置或新增
  26. */
  27. public static function edit($name,array $apikey = []){
  28. $apikey = json_encode($apikey);
  29. $info = self::where(['name' => $name])->find();
  30. if(empty($info)){
  31. $data['name'] = trim($name);
  32. $data['apikey'] = $apikey;
  33. return self::insert($data);
  34. }else{
  35. $info->apikey = $apikey;
  36. return $info->save();
  37. }
  38. }
  39. }