12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- use think\admin\model\SystemConfig;
- function systemConfig($name,$value=null){
- $nameArr=array_filter(explode('.',$name));
- if(is_null($value)){
- if(count($nameArr)==1) {
- $source = SystemConfig::where('type', $nameArr[0])->select();
- $data=[];
- foreach ($source as $model){
- $value=$model['value'];
- if($decode=json_decode($value,true)){
- $value=$decode;
- }
- $data[$model['name']]=$value;
- }
- return $data?:null;
- }else{
- $model = SystemConfig::where('type', $nameArr[0])->where('name',$nameArr[1])->find();
- $value=$model['value'];
- if($decode=json_decode($value,true)){
- $value=$decode;
- }
- return $value;
- }
- }else{
- SystemConfig::where('type', $nameArr[0])->delete();
- if(count($nameArr)==1) {
- if(is_array($value)){
- foreach ($value as $key=>$val){
- SystemConfig::insert([
- 'type'=>$nameArr[0],
- 'name'=>$key,
- 'value'=>is_array($val)?json_encode($val,256):$val,
- ]);
- }
- }
- }else{
- SystemConfig::insert([
- 'type'=>$nameArr[0],
- 'name'=>$nameArr[1],
- 'value'=>$value,
- ]);
- }
- }
- }
- /**
- * 生成??位随机数
- */
- function get32Str($length='32'){
- // $str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $str = 'abcdefghijklmnopqrstuvwxyz0123456789';
- $len = strlen($str)-1;
- $randstr = '';
- for ($i=0;$i<$length;$i++) {
- $num=mt_rand(0,$len);
- $randstr .= $str[$num];
- }
- return $randstr;
- }
|