<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Pay extends Admin_Controller{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('Pay_model','pay');
        $this->load->library('pagination');
    }
    
    public function edit($appid = '')
    {
        $data['keyInfo'] = $this->pay->get();
        $data['title'] = '支付管理'; 
		
		$this->load->view('common/innerheader',$data);
		$this->load->view('admin/payment',$data);
        $this->load->view('common/footer');

    }

    public function addkey()
    {
        $rules_config = array(
            array(
                'field' => 'key',
                'label' => '支付key',
                'rules' => 'trim|required'
            ),
            array(
                'field' => 'id',
                'label' => '应用ID',
                'rules' => 'trim|required'
            ),
            array(
                'field' => 'publickey',
                'label' => '支付公钥',
                'rules' => 'trim|required'
            )
        );
        $this->load->library('form_validation', $rules_config);
        $this->form_validation->set_data($_POST);
        if($this->form_validation->run() == FALSE)
        {
            print_r($this->form_validation->error_array());
        }
        else
        {
            $data = array(
                'key' => $this->input->post('key'),
                'appid' => $this->input->post('id'),
                'publickey' => $this->input->post('publickey')
            );
            $old_key = $this->input->post('old_key');
            if(!empty($old_key))
            {
                $this->pay->update($data, array('key' => $old_key));
            }
            else
            {
                 $this->pay->add($data);
            }

            redirect('admin/card/view');
        }       
    }
}