AdminConfig.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace addons\qingdong\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_KU = 'ku';
  12. const TYPE_LEAD = 'lead';
  13. // 表名,不含前缀
  14. protected $name = 'qingdong_admin_config';
  15. // 开启自动写入时间戳字段
  16. protected $autoWriteTimestamp = 'int';
  17. // 定义时间戳字段名
  18. protected $createTime = 'createtime';
  19. protected $updateTime = 'updatetime';
  20. //设置配置值
  21. public static function setConfig($name, $value, $type) {
  22. $find=self::where(['type'=>$type,'field'=>$name])->find();
  23. if($find){
  24. return self::where(['id'=>$find['id']])->update(['value'=>$value]);
  25. }
  26. $model=new self();
  27. return $model->save(['type'=>$type,'field'=>$name,'value'=>$value]);
  28. }
  29. //设置配置值
  30. public static function getConfigValue($name, $type) {
  31. $find = self::where(['type' => $type, 'field' => $name])->find();
  32. return $find ? $find['value'] : 0;
  33. }
  34. }