<?php
// +----------------------------------------------------------------------
// | 推送配置控制器
// +----------------------------------------------------------------------
// | ThinkOAO （Online And Offline）
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.hanchao9999.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: xiaogg <xiaogg@sina.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
class PushSetController extends BaseController {

	public function _initialize() {
		parent::_initialize();
		$this->model = D('PushSet');
	}
    /**
     * 编辑推送配置
     */
    public function edit($id = 0){
        if(IS_POST){
            $data = $this->model->create();
            if($data){
                if($this->model->save()){
                    $this->success('配置成功');
                } else {
                    $this->error('配置失败');
                }
            } else {
                $this->error($this->model->getError());
            }
        } else {
            $info = array();
            /* 获取数据 */
            $info = $this->model->field(true)->find();
			$info['group'] = unserialize($info['group']);
			$this->assign($info);
            //$groupData = array('PushSetOrderSend'=>'订单发货','PushSetOrderRefund'=>'退款订单','PushSetOrderReturn'=>'退货订单');
			//$this->assign('groupData',$groupData);
            $this->display();
        }
    }
    /**
     * 批量保存配置
     */
    public function save($config){
        if($config && is_array($config)){
            foreach ($config as $name => $value) {
                $map = array('name' => $name);
                $this->model->where($map)->setField('value', $value);
            }
        }
        if($config['MEMBER_UC'] && $config['MEMBER_UCONFIG']){//更新ucenter配置
        $con = "<?php\n".$config['MEMBER_UCONFIG'].";\n?>";
        oaofile(APP_PATH.'Member/Conf/uc.php', $con);
        }
        S('DB_CONFIG_DATA',null);
        $this->success('保存成功！');
    }
}
?>