<?php
class Miao extends pluginBase
{
//插件名字
public static function name(){
return "秒杀";
}
//插件介绍
public static function description(){
return "运用此插件吸引顾客,设置限时抢购。";
}
//新建数据库
public static function install(){
$miao = new IModel('miao');
if($miao->exists()){
return true;
}
//建立表
$data = array(
"comment" => self::name(),
"column" => array(
"id" => array("type" => "int(11) unsigned",'auto_increment' => 1),
"biao" => array("type" => "varchar(100)","comment" => "标题"),
"forea_time" => array("type" => "varchar(80)","comment"=>"秒杀开始时间"),
"end_time" => array("type" => "varchar(80)","comment"=>"秒杀结束时间"),
"jia" => array("type" => "varchar(20)","comment" => "价格"),
"num" => array("type" => "varchar(20)","comment" => "数量"),
"desc" => array("type" => "text","comment" => "描述"),
"goods_id"=>array("type"=>"int(11) unsigned"),
),
"index" => array("primary" => "id"),
);
$miao->setData($data);
return $miao->createTable();
}
//卸载数据表
public static function uninstall()
{
$ppt = new IModel('miao');
return $ppt->dropTable();
}
//钩子(显示到模块上)
public function reg(){
plugin::reg("onSystemMenuCreate", function () {
Menu::$menu['营销']['营销活动']['/plugins/seckill_list']=$this->name();
});
plugin::reg("onBeforeCreateAction@plugins@seckill_list", function () {
self::controller()->seckill_list = function () {
$this->seckill_list();
};
});
plugin::reg("onBeforeCreateAction@plugins@seckill_edit", function () {
self::controller()->seckill_edit = function () {
$this->seckill_edit();
};
});
plugin::reg("onBeforeCreateAction@plugins@seckilll_edit", function () {
self::controller()->seckilll_edit = function () {
$this->seckilll_edit();
};
});
plugin::reg("onBeforeCreateAction@plugins@seckill_del", function () {
self::controller()->seckill_del = function () {
$this->seckill_del();
};
});
plugin::reg("onBeforeCreateAction@plugins@seckill_upt", function () {
self::controller()->seckill_upt = function () {
$this->seckill_upt();
};
});
}
public function seckill_list(){
$testObj = new IModel("miao");
$arr = $testObj->query();
$this->list = $arr;
$this->redirect('seckill_list',$arr);
}
public function seckill_edit(){
$this->redirect('seckill_edit');
}
public function seckilll_edit(){
$is_close = IReq::get("is_close"); //是否开启
if($is_close==0) {
$goods_id = IReq::get("goods_id"); //商品id
$biao = IReq::get("title"); //标题
$forea_time = IReq::get("start_time"); //开始时间
$end_time = IReq::get("end_time"); //结束时间
$desc = IReq::get("intro"); //介绍
$jia = IReq::get("regiment_price"); //秒杀价格
$num = IReq::get("num"); //秒杀价格
$arr = array(
"biao" => $biao,
"forea_time" => $forea_time,
"end_time" => $end_time,
"desc" => $desc,
"jia" => $jia,
"goods_id" => $goods_id,
"num" => $num
);
$testObj = new IModel("miao");
$testObj->setData($arr);
$testObj->add();
$this->seckill_list();
}
}
public function seckill_del(){
$id = IReq::get("id");
$testObj = new IModel("miao");
$testObj->del("id=$id");
$this->seckill_list();
}
public function seckill_upt(){
$testObj = new IModel("miao");
$id = IFilter::act(IReq::get("id"), 'int');
$arr = $testObj->query("id=$id");
$this->list = $arr;
$this->redirect('seckill_edit');
}
}