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
function activity_module_grant($uid, $exid)
{
    global $_W;
    $exchange = activity_exchange_info($exid, $_W['uniacid']);
    if (empty($exchange)) {
        return error(-1, '没有指定的活动参与次数兑换');
    }
    if ($exchange['starttime'] > TIMESTAMP) {
        return error(-1, '该活动参与次数兑换尚未开始');
    }
    if ($exchange['endtime'] < TIMESTAMP) {
        return error(-1, '该活动参与次数兑换已经结束');
    }
    if ($exchange['pretotal'] > 0) {
        $activity_modules = pdo_fetch('SELECT * FROM ' . tablename('activity_modules') . ' WHERE uniacid = :uniacid AND uid = :uid AND exid = :exid AND module = :module', array(':uniacid' => $_W['uniacid'], ':uid' => $uid, 'exid' => $exid, 'module' => $exchange['extra']['name']));
        if ($activity_modules) {
            $starttime = strtotime(date('Y-m-d')) - intval($exchange['extra']['period']) * 3600 * 24;
            $pnum = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_modules_record') . ' WHERE mid = :mid AND num = 1 AND createtime > :createtime', array('mid' => $activity_modules['mid'], ':createtime' => $starttime));
            if ($pnum >= $exchange['pretotal']) {
                return error(-1, '每人每' . $exchange['extra']['period'] . '天内,只能兑换' . $exchange['pretotal'] . '次');
            }
            pdo_update('activity_modules', array('available' => $activity_modules['available'] + 1), array('mid' => $activity_modules['mid'], 'uid' => $uid));
        } else {
            $data = array('uniacid' => $_W['uniacid'], 'uid' => intval($uid), 'exid' => $exid, 'module' => trim($exchange['extra']['name']), 'available' => 1);
            pdo_insert('activity_modules', $data);
            $activity_modules['mid'] = pdo_insertid();
        }
        $data = array('mid' => $activity_modules['mid'], 'num' => 1, 'createtime' => TIMESTAMP);
        pdo_insert('activity_modules_record', $data);
        return true;
    } else {
        return error(-1, '该兑换活动每人可兑换' . intval($exchange['pretotal']));
    }
    return true;
}
Example #3
0
if ($do == 'display') {
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_exchange') . ' WHERE uniacid = :uniacid AND type = :type AND endtime > :endtime', array(':uniacid' => $_W['uniacid'], ':type' => 3, ':endtime' => TIMESTAMP));
    $pindex = max(1, intval($_GPC['page']));
    $psize = 10;
    $lists = pdo_fetchall('SELECT id,title,extra,thumb,type,credittype,endtime,description,credit FROM ' . tablename('activity_exchange') . ' WHERE uniacid = :uniacid AND type = :type AND endtime > :endtime ORDER BY endtime ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(':uniacid' => $_W['uniacid'], ':type' => 3, ':endtime' => TIMESTAMP));
    foreach ($lists as &$li) {
        $li['extra'] = iunserializer($li['extra']);
        if (!is_array($li['extra'])) {
            $li['extra'] = array();
        }
    }
    $pager = pagination($total, $pindex, $psize);
}
if ($do == 'post') {
    $id = intval($_GPC['id']);
    $goods = activity_exchange_info($id, $_W['uniacid']);
    if (empty($goods)) {
        message(error(-1, '没有指定的礼品兑换'), '', 'ajax');
    }
    $credit = mc_credit_fetch($_W['member']['uid'], array($goods['credittype']));
    if ($credit[$goods['credittype']] < $goods['credit']) {
        message(error(-1, "您的 {$creditnames[$token['credittype']]} 数量不够,无法兑换."), '', 'ajax');
    }
    $ret = activity_goods_grant($_W['member']['uid'], $id, 'system', '用户使用' . $goods['credit'] . $creditnames[$goods['credittype']] . '兑换');
    if (is_error($ret)) {
        message($ret, '', 'ajax');
    }
    mc_credit_update($_W['member']['uid'], $goods['credittype'], -1 * $goods['credit'], array($_W['member']['uid'], '礼品兑换:' . $goods['title'] . ' 消耗 ' . $creditnames[$goods['credittype']] . ':' . $goods['credit']));
    if ($goods['credittype'] == 'credit1') {
        mc_notice_credit1($_W['openid'], $_W['member']['uid'], -1 * $goods['credit'], '兑换礼品消耗积分');
    } else {
Example #4
0
defined('IN_IA') or exit('Access Denied');
$dos = array('display', 'post', 'mine', 'use', 'deliver', 'confirm');
$do = in_array($_GPC['do'], $dos) ? $_GPC['do'] : 'display';
if ($do == 'display') {
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('activity_exchange') . ' WHERE uniacid = :uniacid AND type = :type AND endtime > :endtime', array(':uniacid' => $_W['uniacid'], ':type' => 5, ':endtime' => TIMESTAMP));
    $pindex = max(1, intval($_GPC['page']));
    $psize = 10;
    $lists = pdo_fetchall('SELECT id,title,extra,thumb,type,credittype,endtime,description,credit FROM ' . tablename('activity_exchange') . ' WHERE uniacid = :uniacid AND type = :type AND endtime > :endtime ORDER BY endtime ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, array(':uniacid' => $_W['uniacid'], ':type' => 5, ':endtime' => TIMESTAMP));
    foreach ($lists as &$li) {
        $li['extra'] = iunserializer($li['extra']);
    }
    $pager = pagination($total, $pindex, $psize);
}
if ($do == 'post') {
    $id = intval($_GPC['id']);
    $partime = activity_exchange_info($id, $_W['uniacid']);
    if (empty($partime)) {
        message('没有指定的礼品兑换.');
    }
    $credit = mc_credit_fetch($_W['member']['uid'], array($partime['credittype']));
    if ($credit[$partime['credittype']] < $partime['credit']) {
        message('您的' . $creditnames[$partime['credittype']] . '数量不够,无法兑换.');
    }
    $ret = activity_module_grant($_W['member']['uid'], $id, 'system', '用户使用' . $partime['credit'] . $creditnames[$partime['credittype']] . '兑换');
    if (is_error($ret)) {
        message($ret['message']);
    }
    mc_credit_update($_W['member']['uid'], $partime['credittype'], -1 * $partime['credit'], array($_W['member']['uid'], '礼品兑换:' . $partime['title'] . ' 消耗 ' . $creditnames[$partime['credittype']] . ':' . $partime['credit']));
    message("兑换成功,您消费了 {$partime['credit']} {$creditnames[$partime['credittype']]}", url('activity/partimes/mine'));
}
if ($do == 'mine') {
 $type = in_array($type, array(1, 2, 3, 4, 5)) ? $type : 1;
 $page = intval($_GPC['__input']['page']);
 switch ($type) {
     case 1:
     case 2:
         break;
     case 3:
         $pindex = max(1, $page);
         $psize = 10;
         $where = ' WHERE uniacid=:uniacid AND uid=:uid';
         $params = array(':uniacid' => $uniacid, ':uid' => $uid);
         $sql = 'SELECT * FROM ' . tablename('activity_exchange_trades_shipping') . " {$where} ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize;
         $list = pdo_fetchall($sql, $params);
         if (!empty($list)) {
             foreach ($list as &$row) {
                 $row['exchange'] = activity_exchange_info($row['exid']);
                 $row['createtime_cn'] = date('Y-m-d', $row['createtime']);
                 if ($row['status'] == 1) {
                     $row['status_cn'] = "<a onclick=\"return confirm('确认收货吗?');\" class=\"btn btn-primary\"  href=\"" . url('activity/exchange/confirm', array('id' => $row['id'])) . "\">收货</a>";
                 } else {
                     $row['status_cn'] = activity_shipping_status_title($row['status']);
                 }
             }
         }
         if ($_W['isajax'] && $_W['ispost']) {
             $list = json_encode($list);
             exit($list);
         }
         break;
     case 4:
         break;
Example #6
0
        if (empty($shipping)) {
            message('未找到指定兑换礼品或已删除.');
        }
        if ($shipping['uniacid'] != $_W['uniacid'] || $shipping['status'] != 2) {
            message('没有权限删除当前兑换礼品.');
        }
        pdo_delete('activity_exchange_trades_shipping', array('id' => $id));
        message('礼品删除成功.', url('activity/exchange/shipping', array('op' => 'display')), 'success');
    } elseif ($op == 'post') {
        $id = intval($_GPC['id']);
        if (!empty($id)) {
            $shipping = activity_exchange_shipping($id);
        }
        if (empty($shipping)) {
            message('未找到指定兑换礼品或已删除.', url('activity/exchange/shipping'), 'error');
        }
        if (checksubmit('submit')) {
            $data = array('name' => $_GPC['realname'], 'mobile' => $_GPC['mobile'], 'province' => $_GPC['province'], 'city' => $_GPC['city'], 'district' => $_GPC['district'], 'address' => $_GPC['address'], 'zipcode' => $_GPC['zipcode']);
            pdo_update('activity_exchange_trades_shipping', $data, array('id' => $id));
            message('实物礼品邮递信息修改成功.', url('activity/exchange/shipping', array('op' => 'post', 'id' => $id)), 'success');
        } elseif (checksubmit('deliver')) {
            $data = array('name' => $_GPC['realname'], 'mobile' => $_GPC['mobile'], 'province' => $_GPC['province'], 'city' => $_GPC['city'], 'district' => $_GPC['district'], 'address' => $_GPC['address'], 'zipcode' => $_GPC['zipcode'], 'status' => 1);
            pdo_update('activity_exchange_trades_shipping', $data, array('id' => $id));
            message('实物礼品发货成功.', url('activity/exchange/shipping', array('op' => 'post', 'id' => $id)), 'success');
        } else {
            $exchange = activity_exchange_info($shipping['exid']);
            $member = mc_fetch($shipping['uid']);
        }
    }
    template('activity/exchange_shipping');
}