namespace Addons\Coupon\Controller;
class AdminController extends InitController
{
public function index()
{
$num = 25;
$p = I("get.page") ? I("get.page") : 1;
$couponModel = D(’Addons://Coupon/AddonCouponMenu’);
$coupon = $couponModel->getPageConditionOrder($p, $num, "id desc");
$this->assign("couponList", $coupon);// 赋值数据集
$count = $couponModel->getCount();// 查询满足要求的总记录数
$Page = new \Think\Page($count, $num);// 实例化分页类 传入总记录数和每页显示的记录数
$Page->setConfig(’theme’, "- %FIRST%
- %UP_PAGE%
- %LINK_PAGE%
- %DOWN_PAGE%
- %END%
- %HEADER% %NOW_PAGE%/%TOTAL_PAGE% 页
");
$show = $Page->show();// 分页显示输出
$this->assign(’page’, $show);// 赋值分页输出
$this->display(); // 输出模板
}
public function add()
{
if (IS_POST) {
if (!I("post.name")) {
return;
}
$data = I("post.");
$data[’last_time’] = I(’post.last_time’, ’’, ’strtotime’);
$coupon_id = D(’Addons://Coupon/AddonCouponMenu’)->addCouponMenu($data);
isset($coupon_id) ? $this->success(’添加成功’, ’Admin/Admin/index/addon/Coupon’) : $this->error(’添加失败’, u_addons("Coupon://Admin/Admin/index"));
} else {
$this->display(); // 输出模板
}
}
public function detail()
{
$cdata[’coupon_menu_id’] = I(’get.id’);
$m = M(’AddonCoupon’);
$count = $m->where($cdata)->count(); // 查询满足要求的总记录数
$Page = new \Think\Page ($count, 15); // 实例化分页类 传入总记录数和每页显示的记录数
$Page->setConfig(’theme’, "- %FIRST%
- %UP_PAGE%
- %LINK_PAGE%
- %DOWN_PAGE%
- %END%
- %HEADER% %NOW_PAGE%/%TOTAL_PAGE% 页
");
$show = $Page->show(); // 分页显示输出
$detail = $m->where($cdata)->limit($Page->firstRow . ’,’ . $Page->listRows)->select();
$this->assign("page", $show); // 赋值分页输出
$this->assign(’coupon’, $detail);
$this->display();
}
public function export()
{
}
public function del()
{
$cdata[’coupon_menu_id’] = $data[’id’] = I(’get.id’);
$c = M(’AddonCouponMenu’)->where($data)->delete();
$m = M(’AddonCoupon’)->where($cdata)->delete();
if ($c != false && $m != false) {
$this->success(’删除成功’, ’Admin/Admin/index/addon/Coupon’);
} else {
$this->error(’操作失败’, ’Admin/Admin/index/addon/Coupon’);
}
}
public function detail_del()
{
$cdata[’id’] = I(’get.id’);
$m = M(’AddonCoupon’)->where($cdata)->delete();
if ($m != false) {
$this->success(’删除成功’, ’Admin/Admin/index/addon/Coupon’);
} else {
$this->error(’操作失败’, ’Admin/Admin/index/addon/Coupon’);
}
}
}
namespace Addons\Coupon\Model;
use Think\Model\RelationModel;
class AddonCouponMenuModel extends RelationModel
{
protected $_link = array();
public function getCount()
{
$count = $this->count();
return $count;
}
public function getPageConditionOrder($p = 1, $num = 1, $order)
{
// 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
$orderList = $this->page($p . ’,’ . $num . ’’)->order($order)->select();
return $orderList;
}
public function addCouponMenu($data)
{
$data[’ctime’] = time();
$number = $data[’num’] = intval($data[’num’]);
$data[’coupon_menu_id’] = $this->add($data);
for ($i = 0; $i < $number; $i++) {
$data[’code’] = rand_code(6);
$code = M(’AddonCoupon’)->where(array(’code’ => $data[’code’]))->find();
if (!isset($code)) {
$coupon_id = M(’AddonCoupon’)->add($data);
} else {
$number = $number + 1;
}
}
return $coupon_id;
}
}
Admin_detail.html
优惠券管理
优惠券管理
代码来源: www.wemallshop.com
Coupon代金券.rar
( 8.65 KB 下载:2 次 )
已抢16490个
抢已抢49432个
抢已抢16501个
抢已抢8713个
抢已抢4350个
抢已抢4240个
抢