WeMall微信商城源码插件代金券部分代码


发布者 wemallshop  发布时间 1476083562941
关键字 Html5 
WeMall微信商城源码插件Coupon代金券代码是用于商业推广的比较有效的方式,分享了部分比较重要的代码,供技术员学习参考
 
AdminController.class.php
 
<?php  
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’, "<ul class=’pagination no-margin pull-right’></li><li>%FIRST%</li><li>%UP_PAGE%</li><li>%LINK_PAGE%</li><li>%DOWN_PAGE%</li><li>%END%</li><li><a> %HEADER%  %NOW_PAGE%/%TOTAL_PAGE% 页</a></ul>");  
        $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’, "<ul class=’pagination no-margin pull-right’></li><li>%FIRST%</li><li>%UP_PAGE%</li><li>%LINK_PAGE%</li><li>%DOWN_PAGE%</li><li>%END%</li><li><a> %HEADER%  %NOW_PAGE%/%TOTAL_PAGE% 页</a></ul>");  
        $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’);  
        }  
    }  
}  

 
AddonCouponMenuModel.class.php
 
<?php  
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
 
<section class="content-header">  
    <h1>  
        优惠券管理  
        <small></small>  
    </h1>  
</section>  
  
<!-- Main content -->  
<section class="content">  
    <div class="row">  
        <!-- /.col -->  
        <div class="col-md-12">  
            <div class="box box-danger">  
                <div class="box-header with-border">  
                    <h3 class="box-title">优惠券管理</h3>  
                    <!-- /.box-tools -->  
                </div>  
                <!-- /.box-header -->  
                <div class="box-body no-padding">  
                    <div class="mailbox-controls">  
                        <div class="btn-group">  
                            <a href="{:u_addons(\’Coupon://Admin/Admin/index\’)}" class="btn btn-danger ">  
                                返回优惠券列表页  
                            </a>  
                        </div>  
                        <!-- /.btn-group -->  
                    </div>  
                    <div class="table-responsive" style="overflow-x: visible;">  
                        <table class="table table-bordered table-hover">  
                            <tbody>  
                            <tr>  
                                <!--<th class="hidden-xs">-->  
                                    <!--<label><input onchange="checkAll()" type="checkbox" value=""></label>-->  
                                <!--</th>-->  
                                <th>ID</th>  
                                <th>优惠码</th>  
                                <th>金额</th>  
                                <th>状态</th>  
                                <th>截止时间</th>  
                                <th>操作</th>  
                            </tr>  
                            <volist name="coupon" id="coupon">  
                                <tr>  
                                    <!--<td class="hidden-xs">-->  
                                        <!--<label><input name="checkbox" class="check" type="checkbox"-->  
                                                      <!--value="{$coupon.id}"></label>-->  
                                    <!--</td>-->  
                                    <td>  
                                        {$coupon.id}  
                                    </td>  
                                    <td>  
                                        {$coupon.code}  
                                    </td>  
                                    <td>  
                                        {$coupon.price}  
                                    </td>  
                                    <td>  
                                        {$coupon.status}  
                                    </td>  
                                    <td>  
                                        {:date(’Y-m-d H:i:s’,$coupon[’last_time’])}  
                                    </td>  
                                    <td class="table-action"><a  
                                            href="{:u_addons(\’Coupon://Admin/Admin/detail_del\’,array(’id’=>$coupon[’id’]))}">删除</a></td>  
                                </tr>  
                            </volist>  
                            </tbody>  
                        </table>  
                        <div class="box-footer no-padding">  
                            <div class="mailbox-controls">  
                                <!--<div class="btn-group">-->  
                                    <!--<button type="button" class="btn btn-danger"-->  
                                            <!--onclick="batchUrl(’{:U(\’Admin/coupon/delcoupon\’)}’)">全部删除-->  
                                    <!--</button>-->  
                                <!--</div>-->  
                                <div class="pull-right" style="margin-bottom: 6px">  
                                    {$page}  
                                    <!-- /.btn-group -->  
                                </div>  
                            </div>  
                        </div>  
                    </div>  
                    <!-- /.mail-box-messages -->  
                </div>  
            </div>  
            <!-- /. box -->  
        </div>  
        <!-- /.col -->  
    </div>  
</section>  

 代码来源: www.wemallshop.com









  开源的 OurJS
OurJS开源博客已经迁移到 OnceOA 平台。

  关注我们
扫一扫即可关注我们:
OnceJS

OnceOA