<?php

    /*******************************************************************\
    |                                                                   |
    |   房开源（综合房产ERP管理系统）                                   |
    |                                                                   |
    |   © 2019-2023 http://www.kaidandashi.com/ All rights reserved.    |
    |                                                                   |
    |   本系统由淮南市银泰软件科技有限公司提供技术支持                  |
    |                                                                   |
    |   QQ号：984784483                                                 |
    |                                                                   |
    \*******************************************************************/

namespace Admin\Controller;
use Think\Controller;
class OptionsController extends CommonController {
    public function chengjiao(){
        if (IS_POST) {
            $this->error('请联系客服（19965783436）获取正式版功能！');
        }else{
            $this->kyzt = get_peizhi("khzhuangtai",0,1);
            $this->fyzt = get_peizhi("zhuangtai",0,1);
            $options_arr = get_options('chengjiao_options',0);
            $this->arr = $options_arr;
            $fyfpzt=$options_arr['fyfengpan_zhuangtai'];
            $kyfpzt=$options_arr['kyfengpan_zhuangtai'];
            $this->fyfpzt=M('peizhi')->where("pzming = 'zhuangtai' and zhuangtai = 1 and lxid <> ".$options_arr['fygongpan_zhuangtai']." and lxid <> ".$options_arr['fysipan_zhuangtai'])->order('xsshunxu asc')->select();
            $this->kyfpzt=M('peizhi')->where("pzming = 'khzhuangtai' and zhuangtai = 1 and lxid <> ".$options_arr['kygongke_zhuangtai']." and lxid <> ".$options_arr['kysike_zhuangtai'])->order('xsshunxu asc')->select();
            $fyfpztids=explode(",",$fyfpzt);
            foreach ($fyfpztids as $key => $value) {
                $fyfpztid[$value]=$value;
            }
            $kyfpztids=explode(",",$kyfpzt);
            foreach ($kyfpztids as $key => $value) {
                $kyfpztid[$value]=$value;
            }
            $this->fyfpztid=$fyfpztid;
            $this->kyfpztid=$kyfpztid;
            $this->display();
        }
    }
    public function diaoqu(){
        if (IS_POST) {
            $data = I('data');
            $diaoqu_json = json_encode($data);
            $isok=M('options')->where(array('option_name'=>'diaoqu_options'))->setField('option_value',$diaoqu_json);
            if ($isok) {
                $id = M('options')->where(array('option_name'=>'diaoqu_options'))->getField('option_id');
                data_rizhi(6,2,$id,"","更新调取设置","","调取设置");
                $this->success('保存成功!');
            } else {
                $this->error('保存失败!');
            }
        }else{
            $this->arr = get_options('diaoqu_options',0);
            $this->role = M('role')->select();
            $this->display();
        }
    }
    //系统日志
    public function rizhi(){
        if (I('is_ajax')) {
            /*权限控制开始*/
            $condition = "e.gongsiid=".session('gongsiid');
            $x = _rbac_lists_where(1048,0);
            if ($x && $x != "all" && $x != "me") {
                $condition .= " and e.bumen in ({$x})";
            } elseif ($x == "me") {
                $condition .= " and e.id=".session('uid');
            } elseif ($x == false) {
                $condition .= " and e.id=0";
            }
            /*权限控制结束*/
            $sousuo = I('sousuo');
            $condition .= " and a.zy_type = 6";
            $shijian = I('shijian');
            if ($shijian) {
                $time_s = explode(' - ',$shijian);
                $time_s1 = strtotime($time_s[0]);
                $time_s2 = strtotime($time_s[1])+86400;
                $condition .= " and a.addtime>=".$time_s1." and a.addtime<".$time_s2;
            }
            if ($sousuo) {
                $condition .= " and (e.pinyinjs like '%$sousuo%' or e.ygmingcheng like '%$sousuo%' or a.zy_remark like '%$sousuo%')";
            }
            $field = I('field'); //排序字段名
            $order = I('order'); //排序方式
            $limit = I('limit',30,'int'); //每页条数
            $limit = $limit > 150 ? 150 : $limit;
            if ($field && $order) {
                $rzpx = "order by a.".$field." ".$order;
            } else {
                $rzpx = "order by a.addtime desc";
            }
            $Model = new \Think\Model();
            $count = $Model->query("select count(*) from __RIZHI__ a join __YONGHU__ e on a.uid=e.id where {$condition}");
            $Page = new \Think\Page($count['0']['count(*)'],$limit);
            $list = "select a.*,e.ygmingcheng,e.bumen from __RIZHI__ a join __YONGHU__ e on a.uid=e.id where {$condition} ".$rzpx." limit ".$Page->firstRow.','.$Page->listRows;
            $data = $Model->query($list);
            foreach ($data as $key => $value) {
                switch ($value['cz_type']) {
                    case '1':
                        $data[$key]['cz_type'] = "新增";
                        break;
                    case '2':
                        $data[$key]['cz_type'] = "基础修改";
                        break;
                    case '8':
                        $data[$key]['cz_type'] = "删除";
                        break;
                    case '20':
                        $data[$key]['cz_type'] = "下载";
                        break;
                    case '39':
                        $data[$key]['cz_type'] = "优化";
                        break;
                    case '40':
                        $data[$key]['cz_type'] = "修复";
                        break;
                    case '41':
                        $data[$key]['cz_type'] = "备份";
                        break;
                    case '42':
                        $data[$key]['cz_type'] = "还原";
                        break;
                    default:
                        $data[$key]['cz_type'] = "——";
                        break;
                }
                $data[$key]['bumen'] = zym($value['bumen'],6);
                $data[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);
            }
            $return_data = array(
                'code'=>0,
                'count'=>$count['0']['count(*)'],
                'data'=>$data
            );
            $this->ajaxReturn($return_data);
        } else {
            $this->display();// 输出模板
        }
    }
}