博客> WeMall微信商城源码插件代金券部分代码
WeMall微信商城源码插件代金券部分代码
2018-10-21 04:08 评论:0 阅读:463 wemallshop
html php 商城源码

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></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></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

&lt;?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>  

&lt;!-- Main content --&gt;  
<section class="content">  
    <div class="row">  
        &lt;!-- /.col --&gt;  
        <div class="col-md-12">  
            <div class="box box-danger">  
                <div class="box-header with-border">  
                    <h3 class="box-title">优惠券管理</h3>  
                    &lt;!-- /.box-tools --&gt;  
                </div>  
                &lt;!-- /.box-header --&gt;  
                <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>  
                        &lt;!-- /.btn-group --&gt;  
                    </div>  
                    <div class="table-responsive" xss=removed>  
                        <table class="table table-bordered table-hover">  
                            <tbody>  
                            <tr>  
                                &lt;!--<th class="hidden-xs">--&gt;  
                                    &lt;!--<label>&lt;input onchange="checkAll()" type="checkbox" value=""&gt;</label>--&gt;  
                                &lt;!--</th>--&gt;  
                                <th>ID</th>  
                                <th>优惠码</th>  
                                <th>金额</th>  
                                <th>状态</th>  
                                <th>截止时间</th>  
                                <th>操作</th>  
                            </tr>  
                            <volist name="coupon" id="coupon">  
                                <tr>  
                                    &lt;!--<td class="hidden-xs">--&gt;  
                                        &lt;!--<label>&lt;input name="checkbox" class="check" type="checkbox"--&gt;  
                                                      &lt;!--value="{$coupon.id}"&gt;</label>--&gt;  
                                    &lt;!--</td>--&gt;  
                                    <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>$coupon[’id’]))}">删除</a></td>  
                                </tr>  
                            </volist>  
                            </tbody>  
                        </table>  
                        <div class="box-footer no-padding">  
                            <div class="mailbox-controls">  
                                &lt;!--<div class="btn-group">--&gt;  
                                    &lt;!--&lt;button type="button" class="btn btn-danger"--&gt;  
                                            &lt;!--onclick="batchUrl(’{:U(\\’Admin/coupon/delcoupon\\’)}’)"&gt;全部删除--&gt;  
                                    &lt;!--&lt;/button&gt;--&gt;  
                                &lt;!--</div>--&gt;  
                                <div class="pull-right" xss=removed>  
                                    {$page}  
                                    &lt;!-- /.btn-group --&gt;  
                                </div>  
                            </div>  
                        </div>  
                    </div>  
                    &lt;!-- /.mail-box-messages --&gt;  
                </div>  
            </div>  
            &lt;!-- /. box --&gt;  
        </div>  
        &lt;!-- /.col --&gt;  
    </div>  
</section>  

代码来源: www.wemallshop.com

收藏
0
sina weixin mail 回到顶部