Example #1
0
 public function doMobileCheckprize()
 {
     global $_W, $_GPC;
     if (empty($_SERVER["HTTP_X_REQUESTED_WITH"]) || strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) != "xmlhttprequest") {
         exit('非法访问');
     }
     load()->model('activity');
     $id = $_GPC['id'];
     $reply = pdo_fetch("SELECT * FROM " . tablename($this->table_reply) . " WHERE id = :id", array(':id' => $id));
     if (!empty($reply)) {
         if (empty($_W['fans']['from_user'])) {
             //防止错误提交的数据
             $errorCode = 10999;
         } else {
             $from_user = $_W['fans']['from_user'];
             $fans = pdo_fetch("SELECT fanid,uid FROM " . tablename('mc_mapping_fans') . " WHERE `openid`='{$from_user}' LIMIT 1");
             $uid = '0';
             if ($fans['uid'] != '0') {
                 $uid = $fans['uid'];
             } else {
                 $uid = mc_update($uid, array('email' => md5($from_user) . '@wdlcms.com'));
                 if (!empty($fans['fanid']) && !empty($uid)) {
                     pdo_update('mc_mapping_fans', array('uid' => $uid), array('fanid' => $fans['fanid']));
                 }
             }
             $profile = mc_fetch($uid);
             $awardnum = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename($this->table_award) . " WHERE reply_id = '{$id}' AND uid = '{$uid}'");
             $awardfans = pdo_fetch("SELECT * FROM " . tablename($this->table_fans) . " WHERE reply_id = '{$id}' AND uid = '{$uid}'");
             $t = mktime(0, 0, 0, date("m", time()), date("d", time()), date("y", time()));
             if (empty($awardfans)) {
                 $data1 = array('reply_id' => $id, 'from_user' => $from_user, 'uid' => $uid, 'todaynum' => '0', 'totalnum' => '0', 'awardnum' => '0', 'last_time' => time(), 'createtime' => time());
                 pdo_insert($this->table_fans, $data1);
             } elseif ($awardfans['last_time'] < $t) {
                 $data2 = array('todaynum' => '0', 'last_time' => time());
                 pdo_update($this->table_fans, $data2, array('id' => $awardfans['id']));
             }
             if (time() <= $reply['starttime'] || time() >= $reply['endtime'] || $reply['status'] == 0) {
                 $errorCode = 1;
             } elseif ($reply['status'] == 2) {
                 $errorCode = 1;
             } elseif ($reply['groupid'] != 0 && $reply['groupid'] != $profile['groupid']) {
                 $errorCode = 1;
             } elseif ($reply['need_num'] > $profile[$reply['need_type']]) {
                 $errorCode = 1;
             } elseif ($awardnum >= $reply['awardnum']) {
                 $errorCode = 1;
             } elseif ($awardfans['totalnum'] >= $reply['playnum']) {
                 $errorCode = 1;
             } elseif ($awardfans['todaynum'] >= $reply['dayplaynum']) {
                 $errorCode = 1;
             } else {
                 mc_credit_update($uid, $reply['need_type'], '-' . $reply['need_num'], array('1', '幸运大抽奖 消耗 ' . $this->getcreditname($reply['need_type']) . ':' . $reply['need_num']));
                 $data3 = array('todaynum' => $awardfans['todaynum'] + 1, 'totalnum' => $awardfans['totalnum'] + 1, 'last_time' => time());
                 pdo_update($this->table_fans, $data3, array('id' => $awardfans['id']));
                 /*中奖部分代码开始*/
                 $rate = $reply['rate'];
                 $prizes = iunserializer($reply['prizes']);
                 $p_num = $prizes['p1_num'] + $prizes['p2_num'] + $prizes['p3_num'] + $prizes['p4_num'];
                 empty($p_num) && ($p_num = 1);
                 $arr['p1'] = round(100 * $rate * $prizes['p1_num'] / $p_num);
                 $arr['p2'] = round(100 * $rate * $prizes['p2_num'] / $p_num);
                 $arr['p3'] = round(100 * $rate * $prizes['p3_num'] / $p_num);
                 $arr['p4'] = round(100 * $rate * $prizes['p4_num'] / $p_num);
                 $arr['p5'] = 10000 - $arr['p1'] - $arr['p2'] - $arr['p3'] - $arr['p4'];
                 if ($awardnum >= $p_num) {
                     $result = 'p5';
                 } else {
                     $result = $this->get_rand($arr);
                     //返回结果为键值p1,p2,p3,p4
                 }
                 /*中奖部分代码结束*/
                 if ($result == 'p5') {
                     if ($reply['give_num'] != 0) {
                         mc_credit_update($uid, $reply['give_type'], $reply['give_num'], array('1', '幸运大抽奖 未中奖赠送 ' . $this->getcreditname($reply['give_type']) . ':' . $reply['give_num']));
                     }
                 } else {
                     if ($reply['give_num'] != 0 && $reply['onlynone'] != 1) {
                         $give_point = $reply['give_num'];
                         $give_name = $this->getcreditname($reply['give_type']);
                         mc_credit_update($uid, $reply['give_type'], $reply['give_num'], array('1', '幸运大抽奖 未中奖赠送 ' . $this->getcreditname($reply['give_type']) . ':' . $reply['give_num']));
                     }
                     $errorCode = 0;
                     if ($result == 'p1') {
                         if ($prizes['p1_type'] != 2 && $prizes['p1_type'] != 3 && $prizes['p1_type'] != 4) {
                             //积分类奖品
                             $point = $prizes['p1_score'];
                             $point_name = $this->getcreditname($prizes['p1_type']);
                             mc_credit_update($uid, $prizes['p1_type'], $point, array('1', '幸运大抽奖 中奖获得 ' . $this->getcreditname($prizes['p1_type']) . ':' . $point));
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=mc&a=bond&do=credits&credittype=' . $prizes['p1_type'];
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => $this->getcreditname($prizes['p1_type']) . ':' . $point, 'prizetype' => $prizes['p1_type'], 'level' => '1', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                         } elseif ($prizes['p1_type'] == 2) {
                             //非积分类奖品:折扣券
                             $point = 0;
                             $couponid = $prizes['p1_score'];
                             $coupon = activity_coupon_info($couponid, $_W['uniacid']);
                             $ret = activity_coupon_grant($uid, $couponid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($coupon['credittype']) . ':' . $coupon['credit'];
                                 mc_credit_update($uid, $coupon['credittype'], $coupon['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($coupon['credittype']) . ':' . $coupon['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=coupon&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $coupon['title'], 'prizetype' => 'coupon', 'level' => '1', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '折扣券';
                             $type = '折扣券';
                             $value = 1;
                         } elseif ($prizes['p1_type'] == 3) {
                             //非积分类奖品:代金券
                             $point = 0;
                             $tokenid = $prizes['p1_score'];
                             $token = activity_token_info($tokenid, $_W['uniacid']);
                             $ret = activity_token_grant($uid, $tokenid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($token['credittype']) . ':' . $token['credit'];
                                 mc_credit_update($uid, $token['credittype'], $token['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($token['credittype']) . ':' . $token['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=token&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $token['title'], 'prizetype' => 'token', 'level' => '1', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '代金券';
                             $type = '代金券';
                             $value = 1;
                         } elseif ($prizes['p1_type'] == 4) {
                             //非积分类奖品:真实物品
                             $point = 0;
                             $goodsid = $prizes['p1_score'];
                             $goods = activity_exchange_info($goodsid, $_W['uniacid']);
                             $ret = activity_goods_grant($uid, $goodsid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($goods['credittype']) . ':' . $goods['credit'];
                                 mc_credit_update($uid, $goods['credittype'], $goods['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($goods['credittype']) . ':' . $goods['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=goods&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $goods['title'], 'prizetype' => 'goods', 'level' => '1', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '真实物品券';
                             $type = '真实物品券';
                             $value = 1;
                         }
                         $award = array('title' => $title, 'value' => $value, 'type' => $type, 'remsg' => $remsg, 'point' => $point, 'point_name' => $point_name, 'give_point' => $give_point, 'give_name' => $give_name, 'level' => '1', 'detail_url' => $detail_url);
                     } elseif ($result == 'p2') {
                         if ($prizes['p2_type'] != 2 && $prizes['p2_type'] != 3 && $prizes['p2_type'] != 4) {
                             //积分类奖品
                             $point = $prizes['p2_score'];
                             $point_name = $this->getcreditname($prizes['p2_type']);
                             mc_credit_update($uid, $prizes['p2_type'], $point, array('1', '幸运大抽奖 中奖获得 ' . $this->getcreditname($prizes['p2_type']) . ':' . $point));
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=mc&a=bond&do=credits&credittype=' . $prizes['p2_type'];
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => $this->getcreditname($prizes['p2_type']) . ':' . $point, 'prizetype' => $prizes['p2_type'], 'level' => '2', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                         } elseif ($prizes['p2_type'] == 2) {
                             //非积分类奖品:折扣券
                             $point = 0;
                             $couponid = $prizes['p2_score'];
                             $coupon = activity_coupon_info($couponid, $_W['uniacid']);
                             $ret = activity_coupon_grant($uid, $couponid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($coupon['credittype']) . ':' . $coupon['credit'];
                                 mc_credit_update($uid, $coupon['credittype'], $coupon['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($coupon['credittype']) . ':' . $coupon['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=coupon&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $coupon['title'], 'prizetype' => 'coupon', 'level' => '2', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '折扣券';
                             $type = '折扣券';
                             $value = 1;
                         } elseif ($prizes['p2_type'] == 3) {
                             //非积分类奖品:代金券
                             $point = 0;
                             $tokenid = $prizes['p2_score'];
                             $token = activity_token_info($tokenid, $_W['uniacid']);
                             $ret = activity_token_grant($uid, $tokenid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($token['credittype']) . ':' . $token['credit'];
                                 mc_credit_update($uid, $token['credittype'], $token['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($token['credittype']) . ':' . $token['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=token&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $token['title'], 'prizetype' => 'token', 'level' => '2', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '代金券';
                             $type = '代金券';
                             $value = 1;
                         } elseif ($prizes['p2_type'] == 4) {
                             //非积分类奖品:真实物品
                             $point = 0;
                             $goodsid = $prizes['p2_score'];
                             $goods = activity_exchange_info($goodsid, $_W['uniacid']);
                             $ret = activity_goods_grant($uid, $goodsid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($goods['credittype']) . ':' . $goods['credit'];
                                 mc_credit_update($uid, $goods['credittype'], $goods['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($goods['credittype']) . ':' . $goods['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=goods&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $goods['title'], 'prizetype' => 'goods', 'level' => '2', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '真实物品券';
                             $type = '真实物品券';
                             $value = 1;
                         }
                         $award = array('title' => $title, 'value' => $value, 'type' => $type, 'remsg' => $remsg, 'point' => $point, 'point_name' => $point_name, 'give_point' => $give_point, 'give_name' => $give_name, 'level' => '2', 'detail_url' => $detail_url);
                     } elseif ($result == 'p3') {
                         if ($prizes['p3_type'] != 2 && $prizes['p3_type'] != 3 && $prizes['p3_type'] != 4) {
                             //积分类奖品
                             $point = $prizes['p3_score'];
                             $point_name = $this->getcreditname($prizes['p3_type']);
                             mc_credit_update($uid, $prizes['p3_type'], $point, array('1', '幸运大抽奖 中奖获得 ' . $this->getcreditname($prizes['p3_type']) . ':' . $point));
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=mc&a=bond&do=credits&credittype=' . $prizes['p3_type'];
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => $this->getcreditname($prizes['p3_type']) . ':' . $point, 'prizetype' => $prizes['p3_type'], 'level' => '3', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                         } elseif ($prizes['p3_type'] == 2) {
                             //非积分类奖品:折扣券
                             $point = 0;
                             $couponid = $prizes['p3_score'];
                             $coupon = activity_coupon_info($couponid, $_W['uniacid']);
                             $ret = activity_coupon_grant($uid, $couponid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($coupon['credittype']) . ':' . $coupon['credit'];
                                 mc_credit_update($uid, $coupon['credittype'], $coupon['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($coupon['credittype']) . ':' . $coupon['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=coupon&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $coupon['title'], 'prizetype' => 'coupon', 'level' => '3', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '折扣券';
                             $type = '折扣券';
                             $value = 1;
                         } elseif ($prizes['p3_type'] == 3) {
                             //非积分类奖品:代金券
                             $point = 0;
                             $tokenid = $prizes['p3_score'];
                             $token = activity_token_info($tokenid, $_W['uniacid']);
                             $ret = activity_token_grant($uid, $tokenid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($token['credittype']) . ':' . $token['credit'];
                                 mc_credit_update($uid, $token['credittype'], $token['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($token['credittype']) . ':' . $token['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=token&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $token['title'], 'prizetype' => 'token', 'level' => '3', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '代金券';
                             $type = '代金券';
                             $value = 1;
                         } elseif ($prizes['p3_type'] == 4) {
                             //非积分类奖品:真实物品
                             $point = 0;
                             $goodsid = $prizes['p3_score'];
                             $goods = activity_exchange_info($goodsid, $_W['uniacid']);
                             $ret = activity_goods_grant($uid, $goodsid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($goods['credittype']) . ':' . $goods['credit'];
                                 mc_credit_update($uid, $goods['credittype'], $goods['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($goods['credittype']) . ':' . $goods['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=goods&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $goods['title'], 'prizetype' => 'goods', 'level' => '3', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '真实物品券';
                             $type = '真实物品券';
                             $value = 1;
                         }
                         $award = array('title' => $title, 'value' => $value, 'type' => $type, 'remsg' => $remsg, 'point' => $point, 'point_name' => $point_name, 'give_point' => $give_point, 'give_name' => $give_name, 'level' => '3', 'detail_url' => $detail_url);
                     } elseif ($result == 'p4') {
                         if ($prizes['p4_type'] != 2 && $prizes['p4_type'] != 3 && $prizes['p4_type'] != 4) {
                             //积分类奖品
                             $point = $prizes['p4_score'];
                             $point_name = $this->getcreditname($prizes['p4_type']);
                             mc_credit_update($uid, $prizes['p4_type'], $point, array('1', '幸运大抽奖 中奖获得 ' . $this->getcreditname($prizes['p4_type']) . ':' . $point));
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=mc&a=bond&do=credits&credittype=' . $prizes['p4_type'];
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => $this->getcreditname($prizes['p4_type']) . ':' . $point, 'prizetype' => $prizes['p4_type'], 'level' => '4', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                         } elseif ($prizes['p4_type'] == 2) {
                             //非积分类奖品:折扣券
                             $point = 0;
                             $couponid = $prizes['p4_score'];
                             $coupon = activity_coupon_info($couponid, $_W['uniacid']);
                             $ret = activity_coupon_grant($uid, $couponid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($coupon['credittype']) . ':' . $coupon['credit'];
                                 mc_credit_update($uid, $coupon['credittype'], $coupon['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($coupon['credittype']) . ':' . $coupon['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=coupon&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $coupon['title'], 'prizetype' => 'coupon', 'level' => '4', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '折扣券';
                             $type = '折扣券';
                             $value = 1;
                         } elseif ($prizes['p4_type'] == 3) {
                             //非积分类奖品:代金券
                             $point = 0;
                             $tokenid = $prizes['p4_score'];
                             $token = activity_token_info($tokenid, $_W['uniacid']);
                             $ret = activity_token_grant($uid, $tokenid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($token['credittype']) . ':' . $token['credit'];
                                 mc_credit_update($uid, $token['credittype'], $token['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($token['credittype']) . ':' . $token['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=token&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $token['title'], 'prizetype' => 'token', 'level' => '4', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '代金券';
                             $type = '代金券';
                             $value = 1;
                         } elseif ($prizes['p4_type'] == 4) {
                             //非积分类奖品:真实物品
                             $point = 0;
                             $goodsid = $prizes['p4_score'];
                             $goods = activity_exchange_info($goodsid, $_W['uniacid']);
                             $ret = activity_goods_grant($uid, $goodsid, 'hx_lottery', '幸运大转盘中奖获得');
                             if (is_error($ret)) {
                                 //领取错误做等值处理
                                 $remsg = ' 由于' . $ret['message'] . ' 奖品转换为等值' . $this->getcreditname($goods['credittype']) . ':' . $goods['credit'];
                                 mc_credit_update($uid, $goods['credittype'], $goods['credit'], array('1', '幸运大抽奖 等价 ' . $this->getcreditname($goods['credittype']) . ':' . $goods['credit'] . '原因:' . $ret['message']));
                             }
                             $detail_url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=activity&a=goods&do=mine';
                             $awarddata = array('reply_id' => $id, 'uid' => $uid, 'name' => '折扣券:' . $goods['title'], 'prizetype' => 'goods', 'level' => '4', 'createtime' => time(), 'consumetime' => time(), 'status' => 1);
                             $title = '真实物品券';
                             $type = '真实物品券';
                             $value = 1;
                         }
                         $award = array('title' => $title, 'value' => $value, 'type' => $type, 'remsg' => !empty($remsg) ? $remsg : ' ', 'point' => $point, 'point_name' => $point_name, 'give_point' => $give_point, 'give_name' => $give_name, 'level' => '4', 'detail_url' => $detail_url);
                     }
                     pdo_insert($this->table_award, $awarddata);
                     pdo_update($this->table_fans, array('awardnum' => $awardfans['awardnum'] + 1), array('id' => $awardfans['id']));
                 }
             }
         }
     }
     $data['code'] = $errorCode;
     $data['msg'] = $errorMsg;
     $data['data'] = $award;
     echo json_encode($data);
 }
Example #2
0
if ($do == 'display') {
    $is_card = pdo_fetchall("SELECT name FROM " . tablename('modules') . " WHERE issystem = 0 AND iscard = 0", array(), 'name');
    $condition = ' AND use_module = 0 ';
    if (!empty($is_card)) {
        $is_card_str = "'" . implode("','", array_keys($is_card)) . "'";
        $condition = " AND (use_module = 0 OR (use_module = 1 AND couponid IN (SELECT couponid FROM " . tablename('activity_coupon_modules') . " WHERE uniacid = {$_W['uniacid']} AND module IN ({$is_card_str}))))";
    }
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_coupon') . " WHERE uniacid = :uniacid AND type = :type AND endtime > :endtime {$condition}", array(':uniacid' => $_W['uniacid'], ':type' => 1, ':endtime' => TIMESTAMP));
    $pindex = max(1, intval($_GPC['page']));
    $psize = 10;
    $lists = pdo_fetchall('SELECT couponid,title,thumb,type,credittype,credit,endtime,description FROM ' . tablename('activity_coupon') . " WHERE uniacid = :uniacid AND type = :type AND endtime > :endtime {$condition} ORDER BY endtime ASC LIMIT " . ($pindex - 1) * $psize . ',' . $psize, array(':uniacid' => $_W['uniacid'], ':type' => 1, ':endtime' => TIMESTAMP));
    $pager = pagination($total, $pindex, $psize);
}
if ($do == 'post') {
    $id = intval($_GPC['id']);
    $coupon = activity_coupon_info($id, $_W['uniacid']);
    if (empty($coupon)) {
        message(error(-1, '没有指定的礼品兑换'), '', 'ajax');
    }
    $credit = mc_credit_fetch($_W['member']['uid'], array($coupon['credittype']));
    if ($credit[$coupon['credittype']] < $coupon['credit']) {
        message(error(-1, "您的 {$creditnames[$token['credittype']]} 数量不够,无法兑换."), '', 'ajax');
    }
    $ret = activity_coupon_grant($_W['member']['uid'], $id, '', '用户使用' . $coupon['credit'] . $creditnames[$coupon['credittype']] . '兑换');
    if (is_error($ret)) {
        message($ret, '', 'ajax');
    }
    mc_credit_update($_W['member']['uid'], $coupon['credittype'], -1 * $coupon['credit'], array($_W['member']['uid'], '礼品兑换:' . $coupon['title'] . ' 消耗 ' . $creditnames[$coupon['credittype']] . ':' . $coupon['credit']));
    if ($coupon['credittype'] == 'credit1') {
        mc_notice_credit1($_W['openid'], $_W['member']['uid'], -1 * $coupon['credit'], '兑换折扣券消耗积分');
    } else {