首页 >后端开发 >php教程 >PHP/THINKPHP创建优惠券码

PHP/THINKPHP创建优惠券码

WBOY
WBOY原创
2016-07-29 09:08:001885浏览

<code><span><span><?php </span><span>namespace</span><span>Addons</span>\<span>Coupon</span>\<span>Controller</span>;
<span>use</span><span>Home</span>\<span>Controller</span>\<span>AddonsController</span>;

<span><span>class</span><span>WapController</span><span>extends</span><span>AddonsController</span>{</span><span>protected</span><span>$model</span>;
    <span>public</span><span><span>function</span><span>__construct</span><span>()</span> {</span><span>$GLOBALS</span> [<span>'is_wap'</span>] = <span>true</span>;

        <span>parent</span>::__construct ();
        <span>$uid</span>= get_uid_by_openid();
        <span>$this</span>->model = getModelByName (<span>'coupon'</span>);
        <span>$this</span>->model || <span>$this</span>->error ( <span>'model is not found!'</span> );
    }

    <span>/*
     * Create coupon code
     * 
     *<span> @param</span>  $namespace string
     *<span> @return</span> $guid string 
     *<span> @author</span> sun
     */</span><span>private</span><span><span>function</span><span>create_guid</span><span>(<span>$namespace</span> = <span>''</span>)</span> {</span><span>static</span><span>$guid</span> = <span>''</span>;
        <span>$uid</span> = uniqid(<span>""</span>, <span>true</span>);
        <span>$data</span> = <span>$namespace</span>;
        <span>$data</span> .= <span>$_SERVER</span>[<span>'REQUEST_TIME'</span>];
        <span>$data</span> .= <span>$_SERVER</span>[<span>'HTTP_USER_AGENT'</span>];
        <span>$data</span> .= <span>$_SERVER</span>[<span>'LOCAL_ADDR'</span>];
        <span>$data</span> .= <span>$_SERVER</span>[<span>'LOCAL_PORT'</span>];
        <span>$data</span> .= <span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>];
        <span>$data</span> .= <span>$_SERVER</span>[<span>'REMOTE_PORT'</span>];
        <span>$hash</span> = strtoupper(hash(<span>'ripemd128'</span>, <span>$uid</span> . <span>$guid</span> . md5(<span>$data</span>)));
        <span>// test str combination</span><span>$guid</span> =
        substr(<span>$hash</span>, <span>0</span>, <span>6</span>) .
        <span>'-'</span> .
        substr(<span>$hash</span>, <span>8</span>, <span>4</span>) .
        <span>'-'</span> .
        substr(<span>$hash</span>, <span>12</span>, <span>4</span>) .
        <span>'-'</span> .
        substr(<span>$hash</span>, <span>16</span>, <span>4</span>) .
        <span>'-'</span> .
        substr(<span>$hash</span>, <span>20</span>, <span>8</span>);
        <span>return</span><span>$guid</span>;
    }

}


<span>// end</span></span></span></code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了PHP/THINKPHP创建优惠券码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn