码迷,mamicode.com
首页 > 其他好文 > 详细

接口3

时间:2014-10-20 21:01:14      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:des   android   style   blog   http   color   os   ar   使用   

抽奖  领取奖项

bubuko.com,布布扣
<?php
//抽奖   中奖
    require dirname(__FILE__)./../includes/common.inc.php;
    
    $_clean = array();
    $_clean[userId] = _check($_POST[userId]);//用户ID 
    $_clean[prizeId] = _check($_POST[prizeId]);//奖品id
    
    $_info = array();
    $_data = array();
    
    if ( $_clean[userId] > 0 && $_clean[prizeId] > 0 ) {
        $_info[state] = 0;
        $_info[info] = ‘‘;
        
        mysql_query("BEGIN");
        $flag=0;
        //插入中奖记录
        _query("INSERT INTO tb_thePrizeLog VALUES (null,‘{$_clean[‘userId‘]}‘,now(),‘来自Android‘,‘{$_clean[‘prizeId‘]}‘,1)");
        //通过中将ID查找  商家ID 
        $_sql = "SELECT * FROM tb_thePrize WHERE id = ‘{$_clean[‘prizeId‘]}‘ AND State = 1";
        $_result = _query($_sql);
        $_rows = _fetch_array($_result);
        $_html = array();
        $_html[company] = $_rows[company];
        $_html[useIntegral] = $_rows[useIntegral];//在线抽奖中官方奖品抽奖需要的积分
        $_html[thePrizeType] = $_rows[thePrizeType];//奖品类型
        $_html[oneReward] = $_rows[oneReward];//单条奖励的分数
        $_html[goodsId] = $_rows[goodsId];//商品ID
        $_html = _html($_html);
        
        if ( $_html[company] == 0 ) {
        //如果商家id等于0      更新账户易币   插入记录集
            _query("UPDATE tb_user SET integral_easyhunt = integral_easyhunt - ‘{$_html[‘useIntegral‘]}‘ WHERE id = ‘{$_clean[‘userId‘]}‘");
            _query("INSERT INTO tb_cashAndebLog VALUES (null,1,‘{$_clean[‘userId‘]}‘,now(),‘来自Android‘,‘在线抽奖‘,‘{$_html[‘useIntegral‘]}‘,0)");
        }
        //如果中奖的是易币       更新账户易币   插入记录集
        if ( $_html[thePrizeType] == 1 ) {
            _query("UPDATE tb_user SET integral_easyhunt = integral_easyhunt + ‘{$_html[‘oneReward‘]}‘ WHERE id = ‘{$_clean[‘userId‘]}‘");
            _query("INSERT INTO tb_cashAndebLog VALUES (null,1,‘{$_clean[‘userId‘]}‘,now(),‘来自Android‘,‘在线抽奖‘,‘{$_html[‘oneReward‘]}‘,1)");
        } elseif ( $_html[thePrizeType] == 2 ) {
            _query("UPDATE tb_user SET cash_easyhunt = cash_easyhunt + ‘{$_html[‘oneReward‘]}‘ WHERE id = ‘{$_clean[‘userId‘]}‘");
            _query("INSERT INTO tb_cashAndebLog VALUES (null,2,‘{$_clean[‘userId‘]}‘,now(),‘来自Android‘,‘在线抽奖‘,‘{$_html[‘oneReward‘]}‘,1)");
            //如果是物品  查出商品现价   可使用易币    商品邮费
        } elseif ( $_html[thePrizeType] == 3 ) {
            $_sql1 = "SELECT * FROM tb_easyGoods WHERE id = ‘{$_html[‘goodsId‘]}‘";
            $_result1 = _query($_sql1);
            $_rows1 = _fetch_array($_result1);
            $_html1 = array();
            $_html1[goodsMoneyPrice] = $_rows1[goodsMoneyPrice];
            $_html1[goodsIntegralPrice] = $_rows1[goodsIntegralPrice];
            $_html1[goodsPostage] = $_rows1[goodsPostage];
            $_html1 = _html($_html1);
            
            $year_code = array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
            $_orderNumber = $year_code[intval(date(Y))-2014].strtoupper(dechex(date(m))).date(d).substr(time(),-5).substr(microtime(),2,5).sprintf(d,rand(0,99));
            
            //如果都大于0       插入订单
            if ( $_html1[goodsMoneyPrice] > 0 or $_html1[goodsIntegralPrice] > 0 or $_html1[goodsPostage] > 0 ) {
                _query("INSERT INTO tb_easyGoodsOrder VALUES (null,5,now(),‘来自Android‘,‘{$_html[‘company‘]}‘,‘{$_clean[‘userId‘]}‘,‘$_orderNumber‘,‘{$_html[‘goodsId‘]}‘,‘{$_html1[‘goodsMoneyPrice‘]}‘,‘{$_html1[‘goodsIntegralPrice‘]}‘,‘{$_html1[‘goodsPostage‘]}‘,1,‘抽奖中奖‘,0,0,0,‘抽奖‘,0,‘‘,‘‘,‘‘,‘‘,‘‘,‘‘)");
            } else {
                _query("INSERT INTO tb_easyGoodsOrder VALUES (null,5,now(),‘来自Android‘,‘{$_html[‘company‘]}‘,‘{$_clean[‘userId‘]}‘,‘$_orderNumber‘,‘{$_html[‘goodsId‘]}‘,0,0,0,1,‘抽奖中奖‘,0,0,1,‘抽奖‘,1,‘‘,‘‘,‘‘,‘‘,‘‘,‘‘)");
            }
        }
        //更新抽奖商品的易币数
        _query("UPDATE tb_thePrize SET totalReward = totalReward - oneReward WHERE id = ‘{$_clean[‘prizeId‘]}‘");
        
        $flag=1;
        if($flag==1){
            mysql_query("COMMIT");
            $_data["state"] = 0;
            $_data[info] = 领取成功;
        }else{
            mysql_query("ROLLBACK");
            $_data[state] = 1;
            $_data[info] = 领取失败;
        }
        
        $_info[data] = $_data;
    } else {
        $_info[state] = 1;
        $_info[info] = 参数有误!;
    }
    
    echo _json($_info);
    
    _free_result($_result);
    _free_result($_result1);
    
    _close();

?>
View Code

 

接口3

标签:des   android   style   blog   http   color   os   ar   使用   

原文地址:http://www.cnblogs.com/qiuyang1/p/4038431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!