由于处于开发阶段,可能需要更多的参数需要进行填写.暂时写的先贴上
默认需要有个install()安装控制器方法和uninstall()卸载方法
附上控制器和模型的类方法:
class ControllerPaymentCkzalipay extends Controller {
function index()
{
$this->load->language(‘payment/ckzalipay’); //默认配置语言包
$this->document->setTitle($this->language->get(‘heading_title’)); //页面标题头
$this->load->model(‘setting/setting’); //模块/插件的启用和关闭状态表
$this->load->model(‘payment/ckzalipay’); //模型配置模型包
/**
* 开始导入语言包
*/
$data[‘heading_title’] = $this->language->get(‘heading_title’);
$data[‘ckz_id’]=$this->language->get(‘ckz_id’);
$data[‘ckz_key’]=$this->language->get(‘ckz_key’);
$data[‘ckz_account’]=$this->language->get(‘ckz_account’);
$data[‘ckz_save’]=$this->language->get(‘ckz_save’);
$data[‘ckz_false’]=$this->language->get(‘ckz_false’);
$data[‘text_enabled’]=$this->language->get(‘text_enabled’);
$data[‘text_disabled’]=$this->language->get(‘text_disabled’);
$data[‘zhuangtai’]=$this->language->get(‘zhuangtai’);
$data[‘ckz_jishi_text’]=$this->language->get(‘ckz_jishi_text’);
$data[‘ckz_danbao_text’]=$this->language->get(‘ckz_danbao_text’);
$data[‘ckz_alipay_moshi’]=$this->language->get(‘ckz_alipay_moshi’);
/**
* 导入其他栏
*/
$data[‘header’] = $this->load->controller(‘common/header’);
$data[‘column_left’] = $this->load->controller(‘common/column_left’);
$data[‘footer’] = $this->load->controller(‘common/footer’);
/**
* 导入支付宝配置的参数
*/
$data[‘config’]=array();
if(isset($this->request->post[‘ckz_id’])
&& isset($this->request->post[‘ckz_key’])
&& isset($this->request->post[‘ckz_account’])
&& isset($this->request->post[‘ckz_zhuangtai’])
&& isset($this->request->post[‘ckz_moshi’])
)
{
//var_dump($_POST);die();
$data[‘config’][‘ckzalipay_id’]=$this->request->post[‘ckz_id’];
$data[‘config’][‘ckzalipay_key’]=$this->request->post[‘ckz_key’];
$data[‘config’][‘ckzalipay_account’]=$this->request->post[‘ckz_account’];
$data[‘config’][‘ckzalipay_type’]=$this->request->post[‘ckz_moshi’];
//以上三个参数为获取POST数据
$this->model_payment_ckzalipay->setckzalipayconfig($this->request->post[‘ckz_id’],
$this->request->post[‘ckz_key’],
$this->request->post[‘ckz_account’],
$this->request->post[‘ckz_moshi’]);
//执行更新用户的模型数据
$this->model_payment_ckzalipay->update_setting_value($this->request->post[‘ckz_zhuangtai’]);
//更新setting模块状态
$data[‘status_value’]=$this->request->post[‘ckz_zhuangtai’];
//获取当前模块的启用/关闭值得
}
else
{
$data[‘config’]=$this->model_payment_ckzalipay->getckzalipayconfig();
if (empty($data[‘config’]))
{
$data[‘config’][‘ckzalipay_id’]=’this is id’;
$data[‘config’][‘ckzalipay_key’]=’this is key’;
$data[‘config’][‘ckzalipay_account’]=’this is account’;
$data[‘config’][‘ckzalipay_type’]=’0′;
}
if($this->model_payment_ckzalipay->getckzalipayconfig_setting())
{
$data[‘status_value’]=1;
}
else
{
$data[‘status_value’]=0;
}
}
$data[‘action’] = $this->url->link(‘payment/ckzalipay’, ‘token=’ . $this->session->data[‘token’], ‘SSL’); //保存的时候请求的方法
$data[‘cancel’] = $this->url->link(‘extension/payment’, ‘token=’ . $this->session->data[‘token’], ‘SSL’); //取消的时候返回的页面
$this->response->setOutput($this->load->view(‘payment/ckzalipay.tpl’, $data));
}
function install()
{
/**
* 加载语言模型文件
*/
$this->load->model(‘payment/ckzalipay’);
$this->load->model(‘setting/setting’);
$this->model_payment_ckzalipay->install();
}
function uninstall()
{
$this->load->model(‘payment/ckzalipay’);
$this->model_payment_ckzalipay->uninstall();
}
}
/**
* model file
*
* 由于是支付模块,属于extension
* 所以默认调用了安装,会给extension表内添加对应的字段
*
* */
class ModelPaymentCkzalipay extends Model
{
function install()
{
/**
$this->db->query(”
CREATE TABLE `” . DB_PREFIX . “order_ckzalipay` (
`order_id` int(11) NOT NULL,
`ckzalipay_order_id` varchar(255) NOT NULL,
`free_shipping` tinyint NOT NULL DEFAULT 0,
KEY `ckzalipay_order_id` (`ckzalipay_order_id`),
PRIMARY KEY `order_id` (`order_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
“);
$this->db->query(”
CREATE TABLE `” . DB_PREFIX . “order_ckzalipay_product` (
`order_product_id` int NOT NULL ,
`ckzalipay_order_item_code` varchar(255) NOT NULL,
PRIMARY KEY (`order_product_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
“);
*/
/**
* 创建支付宝支付配置
* 参数为:
* 验证ID,验证KEY,用户帐户及支付类型(即使到帐和担保交易)
* 其中type=1时为即时到帐
* type=0时为担保交易
*/
$this->db->query(”
CREATE TABLE `” . DB_PREFIX . “order_ckzalipay_config` (
`ckzalipay_id` varchar(255) NOT NULL ,
`ckzalipay_key` varchar(255) NOT NULL ,
`ckzalipay_account` varchar(255) NOT NULL ,
`ckzalipay_type` varchar(32) NOT NULL,
PRIMARY KEY (`ckzalipay_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
“);
//添加系统模块/插件配置开关
$this->db->query(”
INSERT INTO `” . DB_PREFIX . “setting`
(`store_id`, `code`, `key`, `value`, `serialized`)
VALUES (‘0’, ‘config’, ‘ckzalipay_status’, ‘0’, ‘0’);
“);
}
function uninstall()
{
//以下两个参数暂时不执行
// $this->db->query(“DROP TABLE IF EXISTS `” . DB_PREFIX . “order_ckzalipay`;”);
// $this->db->query(“DROP TABLE IF EXISTS `” . DB_PREFIX . “order_ckzalipay_product`;”);
$this->db->query(“DROP TABLE IF EXISTS `” . DB_PREFIX . “order_ckzalipay_config`;”);
$this->db->query(“DELETE FROM `” . DB_PREFIX . “setting` WHERE `key`=’ckzalipay_status’;”);
}
/**
* 获取清心醉-支付宝的参数配置
* 返回一行数据(只有一行)
* @return unknown
*/
function getckzalipayconfig()
{
$config=$this->db->query(“SELECT * FROM `” . DB_PREFIX . “order_ckzalipay_config`;”);
$config=$config->row; //提取一行数据 全部为rows;
return $config;
}
/**
* 用户写入的清心醉-支付宝数据进行写入保存
* @param unknown $id
* @param unknown $key
* @param unknown $account
*/
function setckzalipayconfig($id,$key,$account,$type)
{
$config=$this->getckzalipayconfig();//首先获取看看有没有数据
if (empty($config))
{
$this->db->query(”
INSERT INTO `” . DB_PREFIX . “order_ckzalipay_config`
(`ckzalipay_id`,`ckzalipay_key`,`ckzalipay_account`,`ckzalipay_type`)
VALUES(‘$id’,’$key’,’$account’,’$type’);
“);
}
else
{
$this->db->query(“UPDATE`” . DB_PREFIX . “order_ckzalipay_config` SET `ckzalipay_id`= ‘$id’, `ckzalipay_key`=’$key’, `ckzalipay_account`=’$account’, `ckzalipay_type`=’$type’;”);
}
}
/**
* 判断开起的模块/插件中key值中是否存在对应的
* $kye的值明确为 ckzalipay_status
* ckzalipay为插件的名称
* status为插件的启用状态
* @param unknown $key
* @return boolean
*/
function getckzalipayconfig_setting()
{
$keys=$this->db->query(“SELECT * FROM `” . DB_PREFIX . “setting` WHERE `key`=’ckzalipay_status'”);
$keys=$keys->row;
if (!empty($keys))
{
if ($keys[‘value’]==1)
{
return true;
}
else {
return false;
}
}
else {
return false;
}
}
function update_setting_value($value)
{
$this->db->query(“UPDATE`” . DB_PREFIX . “setting` SET `value`= ‘$value’ WHERE `key`=’ckzalipay_status’;”);
}
}
关于作者