AdminConfig.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace addons\qingdongams\model;
  3. use think\Model;
  4. /**
  5. * 后台配置
  6. */
  7. class AdminConfig extends Model {
  8. const TYPE_SEAS = 'seas';
  9. const TYPE_WECHAT = 'wechat';
  10. const TYPE_DING = 'dingding';
  11. const TYPE_LEAD = 'lead';
  12. const TYPE_BAIDU = 'baidu';//百度API
  13. const TYPE_TEXTIN = 'textin'; //https://www.textin.com/
  14. const TYPE_JUHE = 'juhe';//聚合数据
  15. const TYPE_USER = 'user';//客户端设置
  16. // 表名,不含前缀
  17. protected $name = 'qingdongams_admin_config';
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = 'int';
  20. // 定义时间戳字段名
  21. protected $createTime = 'createtime';
  22. protected $updateTime = 'updatetime';
  23. //设置配置值
  24. public static function setConfig($name, $value, $type) {
  25. $find=self::where(['type'=>$type,'field'=>$name])->find();
  26. if($find){
  27. return self::where(['id'=>$find['id']])->update(['value'=>$value]);
  28. }
  29. $model=new self();
  30. return $model->save(['type'=>$type,'field'=>$name,'value'=>$value]);
  31. }
  32. //设置配置值
  33. public static function getConfigValue($name, $type) {
  34. $find = self::where(['type' => $type, 'field' => $name])->find();
  35. return $find ? $find['value'] : 0;
  36. }
  37. }