Rumah > pembangunan bahagian belakang > tutorial php > PHP/THINKPHP创建优惠券码

PHP/THINKPHP创建优惠券码

WBOY
Lepaskan: 2016-07-29 09:08:00
asal
1888 orang telah melayarinya

<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>
Salin selepas log masuk
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

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

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan