weiphp中会员卡插件CardController控制器代码信息

<?php

namespace Addons\Card\Controller;        //ThinkPHP命名空间定义,且命名空间定义必须写在所有的PHP代码之前声明,否则会出错

use Addons\Card\Controller\BaseController;        //表示引入Addons\Card\Controller\BaseController命名空间便于直接使用

class CardController extends BaseController {        //继承命名空间对应目录下的基本控制器BaseController
    function config() {        //定义配置函数
        $normal_tips = '配置完保存后,在微信里回复: 会员卡,即可看到效果。';        //定义字符串变量normal_tips的值
        $this->assign ( 'normal_tips', $normal_tips );        //向前端输出变量normal_tips的值
        
        $this->getModel ();        //使用父类下的getModel函数
        
        
        if (IS_POST) {        //判读是否有POST传参
            if ($_POST ['config'] ['background'] == 11) {        //判断POST传入的二维数组中是否有值background等于11
                $_POST ['config'] ['background_custom'] = get_cover_url ( $_POST ['config'] ['bg'] );        //用get_cover_url方法给二维数组中background_custom赋值
            }
            $flag = D ( 'Common/AddonConfig' )->set ( _ADDONS, I ( 'config' ) );        //实例化Common分组的AddonConfig模型调用set方法返还值给$flag
            
            if ($flag !== false) {        //如果有返回值,则说明保存成功
                $this->success ( '保存成功', Cookie ( '__forward__' ) );        
            } else {        //如果没有返回值,抛出错误,保存失败
                $this->error ( '保存失败' );
            }
        }
        
        $map ['name'] = _ADDONS;    //设置数组map下name的值为插件标识名
        $addon = M ( 'Addons' )->where ( $map )->find ();    //实例化Addons模型,从数据库中查询当前插件名的数据交给数组addon
        if (! $addon)        //如果addon为空,说明插件为安装
            $this->error ( '插件未安装' );
        
        $addon_class = get_addon_class ( $addon ['name'] );        //获取插件类的类名交给$addon_class
        
        $data = new $addon_class ();        //实例化插件类
        $addon ['addon_path'] = $data->addon_path;        //给数组$addon 中addon_path赋值
        $addon ['custom_config'] = $data->custom_config;    //给数组$addon中custom_config赋值
        $db_config = D ( 'Common/AddonConfig' )->get ( _ADDONS );    //实例化Common下的AddonConfig类,获取插件配置交给$db_config
        $addon ['config'] = include $data->config_file;        //给数组$addon中config赋值
        if ($db_config) {        //如果$db_config不为空,循环该数组
            foreach ( $addon ['config'] as $key => $value ) {
                if ($value ['type'] != 'group') {
                    ! isset ( $db_config [$key] ) || $addon ['config'] [$key] ['value'] = $db_config [$key];
                } else {
                    foreach ( $value ['options'] as $gourp => $options ) {
                        foreach ( $options ['options'] as $gkey => $value ) {
                            ! isset ( $db_config [$key] ) || $addon ['config'] [$key] ['options'] [$gourp] ['options'] [$gkey] ['value'] = $db_config [$gkey];
                        }
                    }
                }
            }
        }
        $this->assign ( 'data', $addon );        //向前端模板传值
        
        $this->display ();        //显示模板
    }
    function show() {        //定义show方法
        $tpl = 'show';        //设置变量$tpl值为字符串‘show’
        
        $map ['uid'] = $this->mid;        //给$map ['uid'] 赋值
        $info = M ( 'card_member' )->where ( $map )->find ();        //获取info
        // dump($info);
        // dump(M ( 'card_member' )->getLastSql());
        if ($info) {        //如果$info不为空,将其值丢给show模板显示
            $tpl = 'show_card';
            $this->assign ( 'info', $info );
        }
        
        $this->display ( $tpl );    //调取show模板显示
    }
    // 使用介绍
    function introduction() {        //定义介绍函数
        $this->display ();
    }
    // 适用门店
    function storeList() {        //定义适用门店函数
        $this->display ();
    }
    // 填写会员卡资料
    function writeCardInfo() {        //定义会员卡信息的填写方法
        $map ['uid'] = $this->mid;        //设置uid
        $info = M ( 'card_member' )->where ( $map )->find ();        //查card_member表中对应的uid的信息交给$info
        
        if (IS_POST) {        //判读是否有POST传参
            $data ['username'] = I ( 'post.username' );        //将POST传过来的username值交给$data数组
            $data ['phone'] = I ( 'post.phone' );        //将POST传过来的phone值交给$data数组
            
            if ($info) {
                $res = M ( 'card_member' )->where ( $map )->save ( $data );        //更新card_member表中对应uid项的数据
            } else {
                $config = getAddonConfig ( 'Card' );        //获取card插件的配置信息
                $map_token ['token'] = get_token ();        //获取token交给map_token数组下的token
                $data ['number'] = M ( 'card_member' )->where ( $map_token )->getField ( "max(number) as number" );        //查表card_member,获取对应的卡号
                if (empty ( $data ['number'] )) {
                    $data ['number'] = $config ['length'];
                } else {
                    $data ['number'] += 1;
                }
                
                $data ['uid'] = $map2 ['id'] = $this->mid;     //关联用户身份
                $data ['cTime'] = time ();        //获取当前时间
                $data ['token'] = get_token ();        //获取token
                
                $res = M ( 'card_member' )->add ( $data );         //保存数据
                
                M ( 'follow' )->where ( $map2 )->setField ( 'status', 3 );
                
                // 增加积分
                add_credit ( 'card_bind' );
            }
            redirect ( addons_url ( 'Card://Card/showCard' ) );        //跳转到卡的预览界面
        }
        
        $this->assign ( 'info', $info );    //向前端模板传分配info信息
        $this->display ( 'write_cardinfo' );        //调用模板
    }
    function index() {
        $this->display ();
    }
    // 绑定实体会员卡
    function bindCard() {
        $this->display ( 'bind_card' );
    }
    // 积分
    function score() {
        $this->display ();
    }
    // 兑换
    function exchange() {
        $this->display ();
    }
    // 优惠券
    function ticket() {
        $this->display ();
    }
    // 领取后
    function showCard() {
        $map ['uid'] = $this->mid;
        $info = M ( 'card_member' )->where ( $map )->find ();
        $this->assign ( 'info', $info );
        
        $this->display ( 'show_card' );
    }
}

 

posted on 2015-06-24 01:04  dennr  阅读(720)  评论(0编辑  收藏  举报