| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace App\Web\Models;
- use App\Models\BaseModel;
- use Illuminate\Support\Facades\DB;
- class SysGlobalConfigModel extends BaseModel
- {
- /**
- * 状态字段
- */
- const DELETED_AT = 'status';
- /**
- * @var string
- */
- protected $table = 'sys_global_config';
- /**
- * 获取全局配置列表
- * */
- public function getGlobalConfigList($params){
- $where=[];
- if(isset($params['status'])){
- $where[]=['a.status','=',$params['status']];
- }else{
- $where[]=['a.status','<',2];
- }
- $query= $this->newInstance()->alias('a')->where($where);
- $list= $query->selectRaw('a.*')
- ->orderBy('id')
- ->get();
- if(!empty($list)){
- $list=$list->toArray();
- }else{
- $list=[];
- }
- return $list;
- }
- /**
- * 文章全局配置数据保存
- * @param array $data
- * */
- public function saveGlobalConfigData($data){
- if (!empty($data['id'])) {
- $id = $data['id'];
- $this->newInstance()->where('id', $data['id'])->update($data);
- } else {
- $id = $this->newInstance()->insertGetId($data);
- }
- return $id;
- }
- /**
- * 获取全局配置详情
- * @param array $params
- * */
- public function getGlobalConfigInfo($params=[]){
- if(empty($params)){
- return [];
- }
- $where=[];
- $where[]=['status','<',2];
- if(!empty($params['id'])){
- $where['id']=$params['id'];
- }
- if(!empty($params['global_key'])){
- $where['global_key']=$params['global_key'];
- }
- $info= $this->newInstance()->where($where)->first();
- if(!empty($info)){
- return $info->toArray();
- }else{
- return [];
- }
- }
- /**
- * 检查 global_key是否唯一
- * */
- public function checkGlobalKeyUnique($globalKey,$id=0){
- $where=[];
- if(!empty($id)){
- $where[]=['id', '<>', $id];
- }
- $where[]=['status', '<', 2];
- $where[]=['global_key', '=', trim($globalKey)];
- return $this->checkFieldUnique('global_key',$where);
- }
- }
|