public function payResult($params) { load()->model('mc'); $status = pdo_fetchcolumn("SELECT status FROM " . tablename('mc_credits_recharge') . " WHERE tid = :tid", array(':tid' => $params['tid'])); if (empty($status)) { $fee = $params['fee']; $data = array('status' => $params['result'] == 'success' ? 1 : -1); if ($params['type'] == 'wechat') { $data['transid'] = $params['tag']['transaction_id']; $params['user'] = mc_openid2uid($params['user']); } pdo_update('mc_credits_recharge', $data, array('tid' => $params['tid'])); if ($params['result'] == 'success' && $params['from'] == 'notify') { $setting = uni_setting($_W['uniacid'], array('creditbehaviors')); $credit = $setting['creditbehaviors']['currency']; if (empty($credit)) { message('站点积分行为参数配置错误,请联系服务商', '', 'error'); } else { $paydata = array('wechat' => '微信', 'alipay' => '支付宝'); $record[] = $params['user']; $record[] = '用户通过' . $paydata[$params['type']] . '充值' . $fee; mc_credit_update($params['user'], $credit, $fee, $record); } } } if ($params['from'] == 'return') { if ($params['result'] == 'success') { message('支付成功!', '../../app/' . url('mc/home'), 'success'); } else { message('支付失败!', '../../app/' . url('mc/home'), 'error'); } } }
public function respond() { global $_W; $rid = $this->rule; //$content = $this->message['content']; $openid = $this->message['from']; load()->model('mc'); $uid = mc_openid2uid($openid); $row = pdo_fetch("SELECT awardprompt,currentprompt,floorprompt,setting FROM " . tablename('superman_floor') . " WHERE rid={$rid}"); $rule_name = pdo_fetchcolumn("SELECT name FROM " . tablename('rule') . " WHERE id={$rid}"); if ($row) { $setting = unserialize($row['setting']); if (!$setting['repeat_floor']) { $floor = $this->get_floor(); if ($floor) { $result = str_replace('{RULENAME}', $rule_name, $row['floorprompt']); $result = str_replace('{FLOOR}', $floor['id'], $result); $result = str_replace('{TIME}', date('Y-m-d H:i:s', $floor['dateline']), $result); $winninginfo = $_W['siteroot'] . 'app/' . $this->createMobileUrl('winninginfo', array('rid' => $rid)); //return $this->respText($result); $news = array(array('title' => '您已参与过本活动!', 'description' => $result, 'picurl' => '', 'url' => $winninginfo)); return $this->respNews($news); } } } $new_data = array('dateline' => $_W['timestamp'], 'openid' => $openid); pdo_insert("superman_floor_{$rid}", $new_data, false); $new_id = pdo_insertid(); if ($new_id <= 0) { return $this->respText('系统异常,请稍后重试!'); } $awards = pdo_fetchall("SELECT * FROM " . tablename('superman_floor_award') . " WHERE rid={$rid}"); $prompt = pdo_fetch("SELECT awardprompt,currentprompt,floorprompt,setting FROM " . tablename('superman_floor') . " WHERE rid={$rid}"); if ($awards) { foreach ($awards as $item) { $floors = explode(',', $item['floors']); if (in_array($new_id, $floors)) { $new_data = array('rid' => $rid, 'floor' => $new_id, 'uid' => $uid, 'uniacid' => $_W['uniacid'], 'openid' => $openid, 'award_id' => $item['id'], 'ip' => $_W['clientip'], 'dateline' => $_W['timestamp']); pdo_insert('superman_floor_winner', $new_data); $winner_id = pdo_insertid(); $result = str_replace('{RULENAME}', $rule_name, $row['awardprompt']); $result = str_replace('{FLOOR}', $new_id, $result); $result = str_replace('{AWARD}', $item['title'], $result); $result = str_replace('{DESCRIPTION}', $item['description'], $result); $url = $_W['siteroot'] . 'app/' . $this->createMobileUrl('infosubmit', array('_x' => superman_authcode("{$rid}|{$winner_id}|{$openid}", 'ENCODE'), 'rid' => $rid)); $winninginfo = $_W['siteroot'] . 'app/' . $this->createMobileUrl('winninginfo', array('rid' => $rid)); $news = array(array('title' => '恭喜您,获得' . $item['title'] . '!', 'description' => $result, 'picurl' => '', 'url' => $url)); return $this->respNews($news); } } } $result = str_replace('{RULENAME}', $rule_name, $row['currentprompt']); $result = str_replace('{FLOOR}', $new_id, $result); $winninginfo = $_W['siteroot'] . 'app/' . $this->createMobileUrl('winninginfo', array('rid' => $rid)); $news = array(array('title' => '未中奖,再接再厉!', 'description' => $result, 'picurl' => '', 'url' => $winninginfo)); return $this->respNews($news); }
public static function fans_search($from_user, $fields = array()) { // $uid = pdo_fetchcolumn("SELECT a.uid FROM " // . tablename('mc_mapping_fans') . " a inner join " // . tablename('mc_members') . " b on a.uid=b.uid " // . " WHERE a.openid='{$from_user}' LIMIT 1"); // return fans_search($uid, $fields); load()->model('mc'); $uid = mc_openid2uid($from_user); return mc_fetch($uid, $fields); }
private function getUserInfo($uid = null) { global $_W; load()->model('mc'); if (empty($uid)) { $uid = $_W['member']['uid']; } else { $uid = mc_openid2uid($uid); } $userInfo = array(); $filter = array(); $filter['status'] = 1; $userInfo['coupons'] = activity_coupon_owned($uid, $filter); $userInfo['tokens'] = activity_token_owned($uid, $filter); $userInfo['credits'] = mc_credit_fetch($_W['member']['uid'], '*'); return $userInfo; }
public function receive() { global $_W; load()->model('mc'); $type = $this->message['type']; $event = $this->message['event']; $openid = $this->message['from']; $config = $this->module['config']; $acc = WeAccount::create($_W['acid']); if ($event == 'subscribe' && $config['sub_num'] != 0 && !empty($config['sub_type'])) { $log = pdo_fetch("SELECT id FROM " . tablename('ju_credit_log') . " WHERE uniacid=:uniacid and openid=:openid", array(':uniacid' => $_W['uniacid'], ':openid' => $openid)); if (empty($log)) { $uid = mc_openid2uid($openid); $result = mc_credit_update($uid, $config['sub_type'], $config['sub_num'], array('0' => '1', '1' => '关注平台奖励')); if ($result) { $insert = array('uniacid' => $_W['uniacid'], 'openid' => $openid, 'subscribetime' => time(), 'unsubscribetime' => 0, 'follow' => 1); pdo_insert('ju_credit_log', $insert); $this->sendText($acc, $this->message['from'], '感谢您的关注,赠送您' . $config['sub_num'] . '!'); } } else { pdo_update('ju_credit_log', array('follow' => 1, 'subscribetime' => time()), array('id' => $log['id'])); } } elseif ($event == 'unsubscribe' && $config['unsub_num'] != 0) { $log = pdo_fetch("SELECT id FROM " . tablename('ju_credit_log') . " WHERE uniacid=:uniacid and openid=:openid", array(':uniacid' => $_W['uniacid'], ':openid' => $openid)); $uid = mc_openid2uid($openid); if (empty($log)) { $result = mc_credit_update($uid, $config['unsub_type'], '-' . $config['unsub_num'], array('0' => '1', '1' => '取消关注平台扣除')); if ($result) { $insert = array('uniacid' => $_W['uniacid'], 'openid' => $openid, 'subscribetime' => 0, 'unsubscribetime' => time(), 'follow' => 0); pdo_insert('ju_credit_log', $insert); } } else { $result = mc_credit_update($uid, $config['unsub_type'], '-' . $config['unsub_num'], array('0' => '1', '1' => '取消关注平台扣除')); pdo_update('ju_credit_log', array('follow' => 0, 'subscribetime' => 0, 'unsubscribetime' => time()), array('id' => $log['id'])); } } }
public function payResult($params) { global $_W, $_GPC; load()->model('mc'); load()->func('communication'); //调用http通信文件 $fee = $params['fee']; $data = array('status' => $params['result'] == 'success' ? 1 : -1); $paydata = array('wechat' => '微信', 'alipay' => '支付宝', 'credit' => '余额支付'); $params['user'] = mc_openid2uid($params['user']); if ($params['type'] == 'wechat' || $params['type'] == 'alipay') { $data['transid'] = $params['tag']['transaction_id']; } //查询有无充值订单 $status = pdo_fetch("SELECT * FROM " . tablename('mc_credits_recharge') . " WHERE tid = :tid", array(':tid' => $params['tid'])); //查询有无商品订单 $status2 = pdo_fetch("SELECT * FROM " . tablename('wwx_fxxt_order') . " WHERE id = :tid", array(':tid' => $params['tid'])); if (empty($status['status']) && !empty($status['id'])) { pdo_update('mc_credits_recharge', $data, array('tid' => $params['tid'])); if ($params['result'] == 'success') { $setting = uni_setting($_W['uniacid'], array('creditbehaviors')); $credit = $setting['creditbehaviors']['currency']; if (empty($credit)) { message('站点积分行为参数配置错误,请联系服务商', '', 'error'); } else { $record[] = $params['user']; $record[] = '用户通过' . $paydata[$params['type']] . '充值' . $fee; $this->pay_credit_update($params['user'], $credit, $fee, $record); ///47.余额充值微信数据返回调用。 } } } if (empty($status2['status']) && !empty($status2['id'])) { $data['zhifutime'] = time(); pdo_update('wwx_fxxt_order', $data, array('id' => $params['tid'])); if ($params['result'] == 'success') { $order = pdo_fetch("SELECT * FROM " . tablename('wwx_fxxt_order') . " WHERE id = '{$params['tid']}'"); $ordergoods = pdo_fetchall("SELECT * FROM " . tablename('wwx_fxxt_order_goods') . " WHERE orderid = '{$params['tid']}'", array(), 'goodsid'); $goods = pdo_fetchall("SELECT * FROM " . tablename('wwx_fxxt_goods') . " WHERE id IN ('" . implode("','", array_keys($ordergoods)) . "')"); $address = pdo_fetch("SELECT * FROM " . tablename('wwx_fxxt_address') . " WHERE id = :id", array(':id' => $order['addressid'])); if ($goods['totalcnf'] == 1 && empty($goods['total'])) { $this->setOrderStock($params['tid']); ///48.根据订单ID更新信息,false增加库存,无参数为减少库存。 } if (!empty($this->module['config']['noticeemail'])) { $body = "<h3>购买商品清单</h3> <br />"; if (!empty($goods)) { foreach ($goods as $row) { $body .= "名称:{$row['title']} ,数量:{$ordergoods[$row['id']]['total']} <br />"; $body .= "订单号:{$order['ordersn']}<br />"; $body .= "{$paydata[$params['type']]}订单号:{$data['transid']}<br />"; } } } $body .= "总金额:{$order['price']}元 (用户通过{$paydata[$params['type']]}付款)<br />"; $body .= "<h3>购买用户详情</h3> <br />"; $body .= "用户标识:{$params['user']} <br />"; $body .= "真实姓名:{$address['realname']} <br />"; $body .= "地区:{$address['province']} - {$address['city']} - {$address['area']}<br />"; $body .= "详细地址:{$address['address']} <br />"; $body .= "手机:{$address['mobile']} <br /> <br /> <br />"; ihttp_email($this->module['config']['noticeemail'], "{$_W['account']['name']}商城订单提醒", $body); } } if ($params['from'] == 'return') { if ($params['result'] == 'success') { $order = pdo_fetch("SELECT * FROM " . tablename('wwx_fxxt_order') . " WHERE id = '{$params['tid']}'"); $ordergoods = pdo_fetchall("SELECT goodsid,total,optionid FROM " . tablename('wwx_fxxt_order_goods') . " WHERE orderid = '{$order['id']}'", array(), 'goodsid'); if (!empty($ordergoods)) { $goods = pdo_fetchall("SELECT id, title, thumb, marketprice, unit, total,credit FROM " . tablename('wwx_fxxt_goods') . " WHERE id IN ('" . implode("','", array_keys($ordergoods)) . "')"); } $shopmember = pdo_fetch('SELECT shareid,realname FROM ' . tablename('wwx_fxxt_member') . " WHERE from_user = :from_user", array(':from_user' => $order['from_user'])); $shareopenid = pdo_fetch('SELECT from_user FROM ' . tablename('wwx_fxxt_member') . " WHERE `uniacid` = :uniacid AND id=:id ", array(':uniacid' => $_W['uniacid'], ':id' => $shopmember['shareid'])); //查询上级代理的OPENID以及ID if (empty($order['ordermessage'])) { $this->sendgmsptz($order['ordersn'], $order['price'], $shopmember['realname'], $shareopenid['from_user']); ///18.提醒:下级购买商品通知 $this->sendMobilePayMsg($order, $goods, "在线付款", $ordergoods); ///40.提交订单消息模板。 pdo_update('wwx_fxxt_order', array('ordermessage' => 1), array('id' => $params['tid'])); } message('支付成功!', '../../app/' . $this->createMobileUrl('FansIndex'), 'success'); } else { message('支付失败!', '../../app/' . $this->createMobileUrl('FansIndex'), 'error'); } } }
public function checkMember($openid = '') { global $_W; $acc = WeiXinAccount::create($_W['acid']); $userinfo = $acc->fansQueryInfo($openid); load()->model('mc'); $uid = mc_openid2uid($openid); pdo_update('mc_members', array('nickname' => $userinfo['nickname'], 'gender' => $userinfo['sex'], 'nationality' => $userinfo['country'], 'resideprovince' => $userinfo['province'], 'residecity' => $userinfo['city'], 'avatar' => $userinfo['headimgurl']), array('uid' => $uid)); pdo_update('mc_mapping_fans', array('nickname' => $userinfo['nickname']), array('uniacid' => $_W['uniacid'], 'openid' => $openid)); $model = m('member'); $member = $model->getMember($openid); if (empty($member)) { $mc = mc_fetch($uid, array('realname', 'nickname', 'mobile', 'avatar', 'resideprovince', 'residecity', 'residedist')); $member = array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'openid' => $openid, 'realname' => $mc['realname'], 'mobile' => $mc['mobile'], 'nickname' => $mc['nickname'], 'avatar' => $mc['avatar'], 'gender' => $mc['gender'], 'province' => $mc['residecity'], 'city' => $mc['residecity'], 'area' => $mc['resizedist'], 'createtime' => time(), 'status' => 0); pdo_insert('ewei_shop_member', $member); $member['id'] = pdo_insertid(); $member['isnew'] = true; } else { $member['nickname'] = $userinfo['nickname']; $member['avatar'] = $userinfo['headimgurl']; $member['province'] = $userinfo['province']; $member['city'] = $userinfo['city']; pdo_update('ewei_shop_member', $member, array('id' => $member['id'])); $member['isnew'] = false; } return $member; }
public function setOrderCredit($orderid, $add = true) { $order = pdo_fetch("SELECT * FROM " . tablename($this->table_order) . " WHERE id=:id LIMIT 1", array(':id' => $orderid)); if (empty($order)) { return false; } $ordergoods = pdo_fetchall("SELECT goodsid, total FROM " . tablename($this->table_order_goods) . " WHERE orderid = :orderid", array(':orderid' => $orderid)); if (!empty($ordergoods)) { $credit = 0.0; $sql = 'SELECT `credit` FROM ' . tablename($this->table_goods) . ' WHERE `id` = :id'; foreach ($ordergoods as $goods) { $goodsCredit = pdo_fetchcolumn($sql, array(':id' => $goods['goodsid'])); $credit += $goodsCredit * floatval($goods['total']); } } //增加积分 if (!empty($credit)) { load()->model('mc'); load()->func('compat.biz'); $uid = mc_openid2uid($order['from_user']); $fans = fans_search($uid, array("credit1")); if (!empty($fans)) { $uid = intval($fans['uid']); $remark = $add == true ? '微点餐积分奖励 订单ID:' . $orderid : '微点餐积分扣除 订单ID:' . $orderid; $log = array(); $log[0] = $uid; $log[1] = $remark; mc_credit_update($uid, 'credit1', $credit, $log); } } return true; }
public function doMobileSurvey() { checkauth(); global $_W, $_GPC; $sid = intval($_GPC['id']); $sql = 'SELECT * FROM ' . tablename('survey') . ' WHERE `weid`=:weid AND `sid`=:sid'; $params = array(); $params[':weid'] = $_W['uniacid']; $params[':sid'] = $sid; $activity = pdo_fetch($sql, $params); $activity['content'] = htmlspecialchars_decode($activity['content']); $title = $activity['title']; $mcard = pdo_fetch('SELECT * FROM ' . tablename('mc_card_members') . ' WHERE uniacid = :uniacid AND uid = :uid', array(':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid'])); $reregister = empty($mcard); //分享处理 $_share_img = $_W['attachurl'] . $activity['thumb']; if ($activity['status'] != '1') { message('当前调研活动已经停止.'); } if (!$activity) { message('非法访问.'); } if ($activity['starttime'] > TIMESTAMP) { message('当前调研活动还未开始!'); } if ($activity['endtime'] < TIMESTAMP) { message('当前调研活动已经结束!'); } $sql = 'SELECT * FROM ' . tablename('survey_fields') . ' WHERE `sid`=:sid ORDER BY `displayorder` ASC,sfid ASC'; $params = array(); $params[':sid'] = $sid; $ds = pdo_fetchall($sql, $params); $dscount = count($ds); if (!$ds) { message('非法访问.'); } $pertotal = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('survey_rows') . " WHERE sid = :sid AND openid = :openid", array(':sid' => $sid, ':openid' => $_W['fans']['from_user'])); $month_total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('survey_rows') . " WHERE sid = :sid AND openid = :openid AND FROM_UNIXTIME(createtime, '%Y%m') = DATE_FORMAT(NOW(), '%Y%m')", array(':sid' => $sid, ':openid' => $_W['fans']['from_user'])); $pererror = 0; if ($pertotal >= $activity['pertotal']) { $pererror = 1; } else { if ($activity['only_once'] == '1' && $month_total > 0) { $pererror = 2; } } $user = mc_fetch($_W['fans']['from_user'], array('realname', 'mobile')); if (empty($user['realname']) || empty($user['mobile'])) { $userinfo = 0; } if (checksubmit()) { if ($pertotal >= $activity['pertotal']) { message('抱歉!每人只能提交' . $activity['pertotal'] . "次!", referer(), 'error'); } //更新粉丝的手机号和姓名 if ($userinfo == '0') { //mc_update($_W['fans']['from_user'], array('realname' => trim($_GPC['username']), 'mobile' => trim($_GPC['telephone']))); } $row = array(); $row['sid'] = $sid; $row['openid'] = $_W['fans']['from_user']; $row['suggest'] = trim($_GPC['suggest']); $row['store'] = trim($_GPC['store']); $row['createtime'] = TIMESTAMP; $datas = array(); $fields = array(); foreach ($ds as $r) { $fields[$r['sfid']] = $r; } foreach ($_GPC as $key => $value) { if (strexists($key, 'field_')) { $sfid = intval(str_replace('field_', '', $key)); $field = $fields[$sfid]; if ($sfid && $field) { if (in_array($field['type'], array('textarea', 'radio'))) { $entry = array(); $entry['sid'] = $sid; $entry['srid'] = 0; $entry['sfid'] = $sfid; $entry['createtime'] = TIMESTAMP; $entry['data'] = strval($value); $datas[] = $entry; } if (in_array($field['type'], array('checkbox'))) { $value = explode("||", $value); if (!is_array($value)) { continue; } foreach ($value as $k => $v) { $entry['sid'] = $sid; $entry['srid'] = 0; $entry['sfid'] = $sfid; $entry['createtime'] = TIMESTAMP; $entry['data'] = strval($v); $datas[] = $entry; } } } } } if (empty($datas)) { message('非法访问.', '', 'error'); } if (pdo_insert('survey_rows', $row) != 1) { message('保存失败.'); } $srid = pdo_insertid(); if (empty($srid)) { message('保存失败.'); } else { if ($activity['credit'] > 0) { //if (!$reregister) { //只有领取了会员卡的,才有积分 $log = "参加调研问卷,赠送{$activity['credit']}积分"; $result = mc_credit_update(mc_openid2uid($row['openid']), 'credit1', $activity['credit'], array(mc_openid2uid($row['openid']), $log, 'ur_survey')); /* } else { //没有注册会员卡的,无积发 $log = "参加调研问卷,因未领卡获得0积分"; $result = mc_credit_update(mc_openid2uid($row['openid']), 'credit1', 0, array(mc_openid2uid($row['openid']), $log, 'ur_survey')); }*/ } } foreach ($datas as &$r) { $r['srid'] = $srid; pdo_insert('survey_data', $r); } if (empty($activity['starttime'])) { $record = array(); $record['starttime'] = TIMESTAMP; pdo_update('survey', $record, array('sid' => $sid)); } message($log . "</br>" . $activity['information'], url('mc/home')); //完成后跳转到会员中 } foreach ($ds as &$r) { if ($r['value']) { $r['options'] = explode("\r\n", $r['value']); } } load()->func('tpl'); $stores = pdo_fetchall('SELECT * FROM ' . tablename('activity_stores') . " WHERE uniacid = :uniacid", array(':uniacid' => $_W['uniacid'])); include $this->template('survey'); }
public function doMobileGetAnswer() { global $_GPC, $_W; $fid = intval($_GPC['fid']); $weid = $_W['uniacid']; $flight_setting = pdo_fetch("SELECT * FROM " . tablename('fighting_setting') . " WHERE id = '{$fid}' LIMIT 1"); if (empty($flight_setting)) { message('非法访问,请重新发送消息进入一战到底页面!'); } load()->model('mc'); load()->func('compat.biz'); $fromuser = $_GPC['openid']; $uid = mc_openid2uid($fromuser); $fans = fans_search($uid, array("credit1")); if (!empty($fans)) { $credit = $fans['credit1']; } $qid = intval($_GPC['qestionid']); $answer = $_GPC['answer']; $answerNum = $_GPC['answerNum']; $sql_fighting = pdo_fetch("SELECT * FROM " . tablename('fighting') . " WHERE `from_user`=:from_user AND `fid`=:fid ORDER BY id DESC LIMIT 1", array(':from_user' => $fromuser, ':fid' => $fid)); $question = pdo_fetch("SELECT * FROM " . tablename('fighting_question_bank') . " WHERE id = '{$qid}'"); $isupdate = pdo_fetch("SELECT * FROM " . tablename('fighting') . " WHERE fid = " . $fid . " and from_user='******'"); if ($answer == $question['answer']) { //正确答案 $figure = intval($question['figure']); //不存在false的情况,如果是false,则表明是非法 // pdo_update('mc_members', array("credit1" => $credit + $figure), array('uid' => $uid,'uniacid'=>$weid)); if ($isupdate == false) { $insert1 = array('weid' => $_W['uniacid'], 'fid' => $fid, 'answerNum' => $answerNum + 1, 'from_user' => $fromuser, 'nickname' => $member['nickname'], 'lastcredit' => $figure); $add = pdo_insert('fighting', $insert1); $flightid = pdo_insertid(); $awn = $insert1['$answerNum']; if ($awn >= $flight_setting['qnum']) { $updateData = array('lasttime' => time(), 'answerNum' => 0); pdo_update('fighting', $updateData, array('id' => $flightid)); return $this->fightJson(3, ''); exit; } } else { $updateData = array('answerNum' => $isupdate['answerNum'] + 1, 'lastcredit' => $isupdate['lastcredit'] + $figure); pdo_update('fighting', $updateData, array('id' => $isupdate['id'])); $awn = $updateData['answerNum']; if ($awn >= $flight_setting['qnum']) { $updateData = array('lasttime' => time(), 'lastcredit' => $isupdate['lastcredit'] + $figure, 'answerNum' => 0); pdo_update('fighting', $updateData, array('id' => $isupdate['id'])); return $this->fightJson(1, $answerNum); exit; } } pdo_update('mc_members', array("credit1" => $credit + $figure), array('uid' => $uid, 'uniacid' => $weid)); return $this->fightJson(1, ''); exit; } else { if ($isupdate == false) { $insert1 = array('weid' => $_W['uniacid'], 'fid' => $fid, 'answerNum' => $answerNum + 1, 'from_user' => $fromuser, 'nickname' => $member['nickname'], 'lastcredit' => 0); $addworng = pdo_insert('fighting', $insert1); $flightid = pdo_insertid(); $awn = $insert1['answerNum']; if ($awn >= $flight_setting['qnum']) { $updateData = array('lasttime' => time(), 'answerNum' => 0); pdo_update('fighting', $updateData, array('id' => $flightid)); return $this->fightJson(3, '答题满了'); exit; } else { return $this->fightJson(2, $question[answer]); exit; } } else { $updateData = array('answerNum' => $isupdate['answerNum'] + 1); pdo_update('fighting', $updateData, array('id' => $isupdate['id'])); $awn = $updateData['answerNum']; if ($awn >= $flight_setting['qnum']) { $updateData2 = array('lasttime' => time(), 'answerNum' => 0); pdo_update('fighting', $updateData2, array('id' => $isupdate['id'])); return $this->fightJson(3, '答题满了'); exit; } else { return $this->fightJson(2, $question[answer]); exit; } } //错误答案 回看答错的题目 $answer fighting_question_worng $insertworng = array('weid' => $_W['uniacid'], 'fightingid' => $isupdate['id'], 'wornganswer' => $answer ? $answer : '超时没选择答案', 'qname' => $question['question'], 'answer' => $question['answer'], 'optionA' => $question['optionA'], 'optionB' => $question['optionB'], 'optionC' => $question['optionC'], 'optionD' => $question['optionD'], 'optionE' => $question['optionE'], 'optionF' => $question['optionF']); pdo_insert('fighting_question_worng', $insertworng); return $this->fightJson(2, '答案错误'); exit; } }
/** * author: 微赞科技 * 兑换 */ public function doMobileDH() { global $_W, $_GPC; MonUtil::checkmobile(); $rid = $_GPC['rid']; $egid = $_GPC['egid']; $dpassword = $_GPC['dpassword']; $record = DBUtil::findById(DBUtil::$TABLE_EGG_RECORD, $rid); $res = array(); if (empty($record)) { $res['code'] = 500; $res['msg'] = "记录删除或不存在"; die(json_encode($res)); } $egg = DBUtil::findById(DBUtil::$TABLE_EGG, $egid); if ($record['status'] == self::$STATUS_DH) { $res['code'] = 500; $res['msg'] = "奖品已经兑换过"; die(json_encode($res)); } if ($egg['dpassword'] == $dpassword) { //密码正确 $prize = DBUtil::findById(DBUtil::$TABLE_EGG_PRIZE, $record['pid']); if ($prize['ptype'] == 2) { //积分类型 load()->model('mc'); $uid = mc_openid2uid($this->getOpenId()); $result = mc_credit_update($uid, 'credit1', $prize['jf'], array($uid, '砸金蛋手机端兑换积分')); if ($result) { DBUtil::updateById(DBUtil::$TABLE_EGG_RECORD, array("status" => self::$STATUS_DH, 'dhtime' => TIMESTAMP), $rid); $res['code'] = 200; die(json_encode($res)); } else { $res['code'] = 500; $res['msg'] = "兑换失败"; die(json_encode($res)); } } else { DBUtil::updateById(DBUtil::$TABLE_EGG_RECORD, array("status" => self::$STATUS_DH, 'dhtime' => TIMESTAMP), $rid); $res['code'] = 200; die(json_encode($res)); } } else { $res['code'] = 500; $res['msg'] = "密码错误"; die(json_encode($res)); } }
function mc_fetch($uid, $fields = array()) { global $_W; $uid = mc_openid2uid($uid); if (empty($uid)) { return array(); } $struct = (array) cache_load('usersfields'); if (empty($fields)) { $select = '*'; } else { foreach ($fields as $field) { if (!in_array($field, $struct)) { unset($fields[$field]); } if ($field == 'birth') { $fields[] = 'birthyear'; $fields[] = 'birthmonth'; $fields[] = 'birthday'; } if ($field == 'reside') { $fields[] = 'resideprovince'; $fields[] = 'residecity'; $fields[] = 'residedist'; } } unset($fields['birth'], $fields['reside']); $select = '`uid`, `' . implode('`,`', $fields) . '`'; } if (is_array($uid)) { $result = pdo_fetchall("SELECT {$select} FROM " . tablename('mc_members') . " WHERE uid IN ('" . implode("','", is_array($uid) ? $uid : array($uid)) . "')", array(), 'uid'); foreach ($result as &$row) { if (isset($row['avatar']) && !empty($row['avatar'])) { $row['avatar'] = tomedia($row['avatar']); } } } else { $result = pdo_fetch("SELECT {$select} FROM " . tablename('mc_members') . " WHERE `uid` = :uid", array(':uid' => $uid)); if (isset($result['avatar']) && !empty($result['avatar'])) { $result['avatar'] = tomedia($result['avatar']); } } return $result; }
public function payResult($params) { global $_W; load()->model('mc'); $order = pdo_fetch("SELECT * FROM " . tablename('mc_credits_recharge') . " WHERE tid = :tid", array(':tid' => $params['tid'])); if (empty($order['status'])) { $fee = $params['fee']; $total_fee = $fee; $data = array('status' => $params['result'] == 'success' ? 1 : -1); if ($params['type'] == 'wechat') { $data['transid'] = $params['tag']['transaction_id']; $params['user'] = mc_openid2uid($params['user']); } pdo_update('mc_credits_recharge', $data, array('tid' => $params['tid'])); if ($params['result'] == 'success' && $params['from'] == 'notify') { $paydata = array('wechat' => '微信', 'alipay' => '支付宝', 'baifubao' => '百付宝', 'unionpay' => '银联'); if (empty($order['type']) || $order['type'] == 'credit') { $setting = uni_setting($_W['uniacid'], array('creditbehaviors', 'recharge')); $credit = $setting['creditbehaviors']['currency']; if (empty($credit)) { message('站点积分行为参数配置错误,请联系服务商', '', 'error'); } else { $recharge = $setting['recharge']; $add_fee = 0; if (!empty($recharge)) { $back = -1; foreach ($recharge as $k => $li) { if ($li['recharge'] <= $fee) { $back = $k; } } if (!empty($recharge[$back])) { $add_fee = $recharge[$back]['back']; $total_fee = $add_fee + $fee; $add_str = ",满足 充{$recharge[$back]['recharge']}返{$recharge[$back]['back']},返余额{$recharge[$back]['back']}元,本次操作共增加余额{$total_fee}元"; } } $record[] = $params['user']; $record[] = '用户通过' . $paydata[$params['type']] . '充值' . $fee . $add_str; mc_credit_update($order['uid'], $credit, $total_fee, $record); $remark = '用户通过' . $paydata[$params['type']] . '充值' . $fee . $add_str; mc_notice_recharge($order['openid'], $order['uid'], $total_fee, '', $remark); } } if ($order['type'] == 'card_nums') { $member_card = pdo_get('mc_card_members', array('uniacid' => $order['uniacid'], 'uid' => $order['uid'])); $total_num = $member_card['nums'] + $order['tag']; pdo_update('mc_card_members', array('nums' => $total_num), array('uniacid' => $order['uniacid'], 'uid' => $order['uid'])); $log = array('uniacid' => $order['uniacid'], 'uid' => $order['uid'], 'type' => 'nums', 'fee' => $params['fee'], 'model' => '1', 'tag' => $order['tag'], 'note' => date('Y-m-d H:i') . "通过{$paydata[$params['type']]}充值{$params['fee']}元,返{$order['tag']}次,总共剩余{$total_num}次", 'addtime' => TIMESTAMP); pdo_insert('mc_card_record', $log); $type = pdo_fetchcolumn('SELECT nums_text FROM ' . tablename('mc_card') . ' WHERE uniacid = :uniacid', array(':uniacid' => $order['uniacid'])); $total_num = $member_card['nums'] + $order['tag']; mc_notice_nums_plus($order['openid'], $type, $order['tag'], $total_num); } if ($order['type'] == 'card_times') { $member_card = pdo_get('mc_card_members', array('uniacid' => $order['uniacid'], 'uid' => $order['uid'])); if ($member_card['endtime'] > TIMESTAMP) { $endtime = $member_card['endtime'] + $order['tag'] * 86400; } else { $endtime = strtotime($order['tag'] . 'days'); } pdo_update('mc_card_members', array('endtime' => $endtime), array('uniacid' => $order['uniacid'], 'uid' => $order['uid'])); $log = array('uniacid' => $order['uniacid'], 'uid' => $order['uid'], 'type' => 'times', 'model' => '1', 'fee' => $params['fee'], 'tag' => $order['tag'], 'note' => date('Y-m-d H:i') . "通过{$paydata[$params['type']]}充值{$params['fee']}元,返{$order['tag']}天,充值后到期时间:" . date('Y-m-d', $endtime), 'addtime' => TIMESTAMP); pdo_insert('mc_card_record', $log); $type = pdo_fetchcolumn('SELECT times_text FROM ' . tablename('mc_card') . ' WHERE uniacid = :uniacid', array(':uniacid' => $order['uniacid'])); $endtime = date('Y-m-d', $endtime); mc_notice_times_plus($order['openid'], $member_card['cardsn'], $type, $fee, $order['tag'], $endtime); } } } if ($order['type'] == 'credit' || $order['type'] == '') { $url = murl('mc/home'); } else { $url = murl('mc/bond/mycard'); } if ($params['from'] == 'return') { if ($params['result'] == 'success') { message('支付成功!', '../../app/' . $url, 'success'); } else { message('支付失败!', '../../app/' . $url, 'error'); } } }
public function setOrderCredit($orderid, $add = true) { global $_W; $order = pdo_fetch("SELECT * FROM " . tablename('shopping_order') . " WHERE id = :id limit 1", array(':id' => $orderid)); if (empty($order)) { return false; } $sql = 'SELECT `goodsid`, `total` FROM ' . tablename('shopping_order_goods') . ' WHERE `orderid` = :orderid'; $orderGoods = pdo_fetchall($sql, array(':orderid' => $orderid)); if (!empty($orderGoods)) { $credit = 0.0; $sql = 'SELECT `credit` FROM ' . tablename('shopping_goods') . ' WHERE `id` = :id'; foreach ($orderGoods as $goods) { $goodsCredit = pdo_fetchcolumn($sql, array(':id' => $goods['goodsid'])); $credit += $goodsCredit * floatval($goods['total']); } } //增加积分 if (!empty($credit)) { load()->model('mc'); load()->func('compat.biz'); $uid = mc_openid2uid($order['from_user']); $fans = fans_search($uid, array("credit1")); if (!empty($fans)) { if (!empty($add)) { mc_credit_update($_W['member']['uid'], 'credit1', $credit, array('0' => $_W['member']['uid'], '购买商品赠送')); } else { mc_credit_update($_W['member']['uid'], 'credit1', 0 - $credit, array('0' => $_W['member']['uid'], '微商城操作')); } } } }
public function doMobileGetAward() { global $_GPC, $_W; if (empty($_W['fans']['from_user'])) { message('非法访问,请重新发送消息进入砸蛋页面!'); } $fromuser = $_W['fans']['from_user']; $id = intval($_GPC['id']); $egg = pdo_fetch("SELECT id, periodlottery, maxlottery, default_tips, misscredit, hitcredit FROM " . tablename('egg_reply') . " WHERE rid = '{$id}' LIMIT 1"); if (empty($egg)) { message('非法访问,请重新发送消息进入砸蛋页面!'); } $result = array('status' => -1, 'message' => ''); if (!empty($egg['periodlottery'])) { $total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('egg_winner') . " WHERE createtime > '" . (strtotime(date('Y-m-d')) - 86400 * $egg['periodlottery']) . "' AND from_user = '******' AND status <> 3 AND rid = '{$id}'"); $lastdate = pdo_fetchcolumn("SELECT createtime FROM " . tablename('egg_winner') . " WHERE from_user = '******' AND status <> 3 ORDER BY createtime DESC"); if ($total >= intval($egg['maxlottery']) && strtotime(date('Y-m-d')) < strtotime(date('Y-m-d', $lastdate)) + $egg['periodlottery'] * 86400) { $result['message'] = '您还未到达可以再次砸蛋的时间。下次可砸时间为' . date('Y-m-d', strtotime(date('Y-m-d', $lastdate)) + $egg['periodlottery'] * 86400); message($result, '', 'ajax'); } } else { $total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('egg_winner') . " WHERE createtime > '" . strtotime(date('Y-m-d')) . "' AND from_user = '******' AND status <> 3"); if (!empty($egg['maxlottery']) && $total >= $egg['maxlottery']) { $result['message'] = $egg['periodlottery'] ? '您已经超过当日砸蛋次数' : '您已经超过最大砸蛋次数'; message($result, '', 'ajax'); } } $gifts = pdo_fetchall("SELECT id, probalilty,inkind,total FROM " . tablename('egg_award') . " WHERE rid = '{$id}' ORDER BY probalilty ASC"); //计算每个礼物的概率 $probability = 0; $rate = 1; $award = array(); $awardids = array(); //奖品ID (同时可中多个奖品,然后随机派奖) foreach ($gifts as $name => $gift) { if (empty($gift['probalilty'])) { continue; } $probability = $gift['probalilty']; if ($probability < 1) { $temp = explode('.', $probability); $temp = pow(10, strlen($temp[1])); $rate = $temp < $rate ? $rate : $temp; $probability = $probability * $rate; } $award[] = array('id' => $gift['id'], 'probalilty' => $probability, 'inkind' => $gift['inkind'], 'total' => $gift['total']); } $all = 100 * $rate; mt_srand((double) microtime() * 1000000); $rand = mt_rand(1, $all); foreach ($award as $gift) { if ($rand > 0 && $rand <= $gift['probalilty'] && $gift['total'] > 0) { // $awardid = $gift['id']; //break; //只要符合概率,都算中奖品,然后从奖品中随机 $awardids[] = $gift['id']; } } if (count($awardids) > 0) { mt_srand((double) microtime() * 1000000); $randid = mt_rand(0, count($awardids) - 1); $awardid = $awardids[$randid]; } $title = ''; $result['message'] = empty($egg['default_tips']) ? '很遗憾,您没能中奖!' : $egg['default_tips']; $data = array('rid' => $id, 'from_user' => $fromuser, 'status' => 0, 'createtime' => TIMESTAMP); $credit = array('rid' => $id, 'award' => (empty($awardid) ? '未中' : '中') . '奖奖励积分', 'from_user' => $fromuser, 'status' => 3, 'description' => empty($awardid) ? $egg['misscredit'] : $egg['hitcredit'], 'createtime' => TIMESTAMP); if (!empty($awardid)) { $gift = pdo_fetch("SELECT * FROM " . tablename('egg_award') . " WHERE rid = '{$id}' AND id = '{$awardid}'"); if ($gift['total'] > 0) { $data['award'] = $gift['title']; if (!empty($gift['inkind'])) { $data['description'] = $gift['description']; pdo_query("UPDATE " . tablename('egg_award') . " SET total = total - 1 WHERE rid = '{$id}' AND id = '{$awardid}'"); } else { $gift['activation_code'] = iunserializer($gift['activation_code']); $code = array_pop($gift['activation_code']); pdo_query("UPDATE " . tablename('egg_award') . " SET total = total - 1, activation_code = '" . iserializer($gift['activation_code']) . "' WHERE rid = '{$id}' AND id = '{$awardid}'"); $data['description'] = '兑换码:' . $code . '<br /> 兑换地址:' . $gift['activation_url']; } $result['message'] = '恭喜您,得到“' . $data['award'] . '”!'; $result['status'] = 0; } else { $credit['description'] = $egg['misscredit']; $credit['award'] = '未中奖奖励积分'; } } !empty($credit['description']) && ($result['message'] .= '<br />' . $credit['award'] . ':' . $credit['description']); $data['aid'] = $gift['id']; if (empty($awardid)) { $value = intval($egg['misscredit']); $uid = mc_openid2uid($fromuser); mc_credit_update($uid, 'credit1', $value, array(0, '使用砸蛋模块未中奖,赠送' . $value . '积分')); } else { $value = intval($egg['hitcredit']); $uid = mc_openid2uid($fromuser); mc_credit_update($uid, 'credit1', $value, array(0, '使用砸蛋模块中奖,赠送' . $value . '积分')); } if (!empty($credit['description'])) { pdo_insert('egg_winner', $credit); } pdo_insert('egg_winner', $data); $result['myaward'] = pdo_fetchall("SELECT award, description FROM " . tablename('egg_winner') . " WHERE from_user = '******' AND award <> '' AND rid = '{$id}' ORDER BY createtime DESC"); message($result, '', 'ajax'); }
public function checkMember($openid = '') { global $_W, $_GPC; if (strexists($_SERVER['REQUEST_URI'], '/web/')) { return; } if (empty($openid)) { $openid = m('user')->getOpenid(); } if (empty($openid)) { return; } $member = m('member')->getMember($openid); $userinfo = m('user')->getInfo(); $followed = m('user')->followed($openid); $uid = 0; $mc = array(); load()->model('mc'); if ($followed) { $uid = mc_openid2uid($openid); $mc = mc_fetch($uid, array('realname', 'mobile', 'avatar', 'resideprovince', 'residecity', 'residedist')); } if (empty($member)) { $member = array('uniacid' => $_W['uniacid'], 'uid' => $uid, 'openid' => $openid, 'realname' => !empty($mc['realname']) ? $mc['realname'] : '', 'mobile' => !empty($mc['mobile']) ? $mc['mobile'] : '', 'nickname' => !empty($mc['nickname']) ? $mc['nickname'] : $userinfo['nickname'], 'avatar' => !empty($mc['avatar']) ? $mc['avatar'] : $userinfo['avatar'], 'gender' => !empty($mc['gender']) ? $mc['gender'] : $userinfo['sex'], 'province' => !empty($mc['residecity']) ? $mc['resideprovince'] : $userinfo['province'], 'city' => !empty($mc['residecity']) ? $mc['residecity'] : $userinfo['city'], 'area' => !empty($mc['residedist']) ? $mc['residedist'] : '', 'createtime' => time(), 'status' => 0); pdo_insert('ewei_shop_member', $member); } else { if (!empty($uid)) { $upgrade = array(); if ($userinfo['nickname'] != $member['nickname']) { $upgrade['nickname'] = $userinfo['nickname']; } if ($userinfo['avatar'] != $member['avatar']) { $upgrade['avatar'] = $userinfo['avatar']; } if (empty($member['uid'])) { $upgrade['uid'] = $uid; } if ($member['credit1'] > 0) { mc_credit_update($uid, 'credit1', $member['credit1']); $upgrade['credit1'] = 0; } if ($member['credit2'] > 0) { mc_credit_update($uid, 'credit2', $member['credit2']); $upgrade['credit2'] = 0; } if (!empty($upgrade)) { pdo_update('ewei_shop_member', $upgrade, array('id' => $member['id'])); } } } if (p('commission')) { p('commission')->checkAgent(); } if (p('poster')) { p('poster')->checkScan(); } }
public function getfansinfo($openid) { global $_W; load()->model('mc'); $profile = pdo_fetch("SELECT * FROM " . tablename('tg_member') . " WHERE uniacid ='{$_W['uniacid']}' and openid = '{$openid}'"); if (empty($profile['nickname'])) { $uid = mc_openid2uid($openid); $result = mc_fetch($uid, array('credit1', 'credit2', 'avatar', 'nickname')); } else { $result['nickname'] = $profile['nickname']; $result['avatar'] = $profile['avatar']; } return $result; }
private function addCredit($from_user, $credit_value) { global $_GPC, $_W; load()->model('mc'); $uid = mc_openid2uid($from_user); mc_credit_update($uid, 'credit1', $credit_value, array($uid, '文章分享')); }
public function doMobileInfosubmit() { global $_W, $_GPC; $uid = mc_openid2uid($_W['openid']); $rid = intval($_GPC['rid']); if ($_W['openid']) { $member = mc_fetch($_W['openid'], array('realname', 'mobile', 'qq')); if ($member['realname'] && $member['mobile'] && $member['qq']) { message('您已提交过领奖信息,稍后自动跳转至已中奖品列表页面!', $this->createMobileUrl('winlist', array('op' => 'never', 'openid' => $_W['openid'], 'rid' => $rid))); } else { $title = '提交领奖信息'; list($rid, $winner_id, $openid) = explode('|', superman_authcode(trim($_GPC['_x']), 'DECODE')); if (empty($rid) || empty($winner_id) || empty($openid)) { message("非法请求"); } $active = pdo_fetch("SELECT * FROM " . tablename('rule') . " WHERE id = {$rid}"); if (!$active) { message('活动已结束'); } $success = false; if (checksubmit()) { $realname = trim($_GPC['realname']); if (empty($realname)) { message('请填写姓名!'); } $mobile = trim($_GPC['mobile']); if (empty($mobile)) { message('请填写电话号码!'); } $qq = trim($_GPC['qq']); if (empty($qq)) { message('请填写QQ号码!'); } $winner = $update_data = array('realname' => $realname, 'mobile' => $mobile, 'qq' => $qq); //pdo_update('superman_floor_winner', $update_data, array('id' => $winner_id)); mc_update($uid, $update_data); $success = true; message('提交个人中奖信息成功,稍后自动跳转至已中奖品列表页面!', $this->createMobileUrl('winlist', array('op' => 'never', 'openid' => $_W['openid'], 'rid' => $_GPC['rid']))); } include $this->template('infosubmit'); } } else { message('非法请求!'); } }
public function fetchUid($openid) { load()->model('mc'); $uid = mc_openid2uid($openid); return $uid; }
public function doMobileUserinfo() { global $_GPC, $_W; $weid = $_W['weid']; if ($_GPC['code'] == "authdeny") { $url = $_W['siteroot'] . "app/" . $this->createMobileUrl('index', array()); header("location:{$url}"); exit('authdeny'); } load()->func('communication'); if (isset($_GPC['code'])) { $appid = $_W['account']['key']; $secret = $_W['account']['secret']; $serverapp = $_W['account']['level']; if ($serverapp != 4) { $cfg = $this->module['config']; $appid = $cfg['appid']; $secret = $cfg['secret']; } $state = $_GPC['state']; $rid = $_GPC['rid']; $code = $_GPC['code']; $oauth2_code = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $appid . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code"; $content = ihttp_get($oauth2_code); $token = @json_decode($content['content'], true); if (empty($token) || !is_array($token) || empty($token['access_token']) || empty($token['openid'])) { echo '<h1>获取微信公众号授权' . $code . '失败[无法取得token以及openid], 请稍后重试! 公众平台返回原始数据为: <br />' . $content['meta'] . '<h1>'; exit; } $from_user = $token['openid']; //load()->model('mc'); ///$uid = mc_openid2uid($from_user); //$profile = mc_fetch($uid, 'follow'); $fans = pdo_fetch("select follow from " . tablename('mc_mapping_fans') . " where openid=:openid and uniacid=:uniacid limit 1", array(':openid' => $from_user, ':uniacid' => $_W['uniacid'])); if (!empty($fans) && !empty($fans['follow'])) { $state = 1; } else { $url = $_W['siteroot'] . "app/" . $this->createMobileUrl('userinfo', array()); $oauth2_code = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . urlencode($url) . "&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect"; header("location:{$oauth2_code}"); } if ($state == 1) { $oauth2_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . ""; $content = ihttp_get($oauth2_url); $token_all = @json_decode($content['content'], true); if (empty($token_all) || !is_array($token_all) || empty($token_all['access_token'])) { echo '<h1>获取微信公众号授权失败[无法取得access_token], 请稍后重试! 公众平台返回原始数据为: <br />' . $content['meta'] . '<h1>'; exit; } $access_token = $token_all['access_token']; $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN"; } else { $access_token = $token['access_token']; $oauth2_url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN"; } $content = ihttp_get($oauth2_url); $info = @json_decode($content['content'], true); if (empty($info) || !is_array($info) || empty($info['openid']) || empty($info['nickname'])) { echo '<h1>获取微信公众号授权失败[无法取得info], 请稍后重试!<h1>'; exit; } if (!empty($_W['fans']['from_user'])) { load()->model('mc'); $uid = mc_openid2uid($_W['fans']['from_user']); mc_update($uid, array('nickname' => $info['nickname'], 'realname' => $info['nickname'], 'avatar' => $info['headimgurl'])); } setcookie("wdl_hchighguess_fromuser" . $_W['weid'], $info['openid'], time() + 3600 * 240); $url = $this->createMobileUrl('index'); header("location:{$url}"); exit; } else { echo '<h1>网页授权域名设置出错!</h1>'; exit; } }
public function setOrderCredit($orderid, $add = true) { $order = pdo_fetch("SELECT * FROM " . tablename($this->modulename . '_order') . " WHERE id=:id LIMIT 1", array(':id' => $orderid)); if (empty($order)) { return false; } $ordergoods = pdo_fetchall("SELECT goodsid, total FROM " . tablename($this->modulename . '_order_goods') . " WHERE orderid = '{$orderid}'", array(), 'goodsid'); if (!empty($ordergoods)) { $goods = pdo_fetchall("SELECT * FROM " . tablename($this->modulename . '_goods') . " WHERE id IN ('" . implode("','", array_keys($ordergoods)) . "')"); } //增加积分 if (!empty($goods)) { $credits = 0; foreach ($goods as $g) { $credits += $g['credit'] * $g['total']; } load()->model('mc'); load()->func('compat.biz'); $uid = mc_openid2uid($order['from_user']); $fans = fans_search($uid, array("credit1")); if (!empty($fans)) { // if ($add) { // $new_credit = $credits + $fans['credit1']; // } else { // $new_credit = $fans['credit1'] - $credits; // if ($new_credit <= 0) { // $new_credit = 0; // } // } $uid = intval($fans['uid']); $remark = $add == true ? '微点餐积分奖励 订单ID:' . $orderid : '微点餐积分扣除 订单ID:' . $orderid; $log = array(); $log[0] = $uid; $log[1] = $remark; mc_credit_update($uid, 'credit1', $credits, $log); //pdo_update('mc_members', array("credit1" => $new_credit), array('uid' => $uid)); } } return true; }
public function saveUserInfo($info) { if (!isset($info['subscribe']) || $info['subscribe'] != 1) { return; } WeUtility::logging('saveUserInfo', $info); $from_user = $info['openid']; load()->model('mc'); $uid = mc_openid2uid($from_user); mc_update($uid, array('nickname' => $info['nickname'], 'gender' => $info['sex'], 'nationality' => $info['country'], 'resideprovince' => $info['province'], 'residecity' => $info['city'], 'avatar' => $info['headimgurl'])); }
public function doMobileGetAward() { global $_GPC, $_W; if (empty($_W['fans']['from_user']) || empty($_W['member']['uid'])) { message('非法访问,请重新发送消息进入砸蛋页面!'); } checkauth(); $fromuser = $_W['fans']['from_user']; $uid = intval($_W['member']['uid']); $id = intval($_GPC['id']); $sql = 'SELECT `id`, `periodlottery`, `maxlottery`, `default_tips`, `misscredit`, `hitcredit` FROM ' . tablename('egg_reply') . ' WHERE `rid` = :rid'; $params = array(':rid' => $id); $egg = pdo_fetch($sql, $params); if (empty($egg)) { message('非法访问,请重新发送消息进入砸蛋页面!'); } $result = array('status' => -1, 'message' => ''); $sql = 'SELECT COUNT(*) FROM ' . tablename('egg_winner') . ' WHERE `rid` = :rid AND `uid` = :uid'; $params[':uid'] = $uid; if (empty($egg['periodlottery'])) { $total = pdo_fetchcolumn($sql, $params); if ($total >= $egg['maxlottery']) { $result['message'] = '您已经超过最大砸蛋次数'; message($result, '', 'ajax'); } } else { $sql .= ' AND `createtime` > :createtime'; $params[':createtime'] = strtotime(date('Y-m-d')) - 86400 * $egg['periodlottery']; $total = pdo_fetchcolumn($sql, $params); if ($total >= $egg['maxlottery']) { $sql = 'SELECT `createtime` FROM ' . tablename('egg_winner') . ' WHERE `rid` = :rid AND `uid` = :uid ORDER BY `createtime` DESC'; $lastdate = pdo_fetchcolumn($sql, array(':rid' => $id, ':uid' => $uid)); $result['message'] = '您还未到达可以再次砸蛋的时间。下次可砸时间为' . date('Y-m-d', strtotime(date('Y-m-d', $lastdate)) + $egg['periodlottery'] * 86400); message($result, '', 'ajax'); } } $sql = 'SELECT * FROM ' . tablename('egg_award') . ' WHERE `rid` = :rid ORDER BY `probalilty`'; $gifts = pdo_fetchall($sql, array(':rid' => $id)); $awards = array(); foreach ($gifts as $key => $gift) { if (empty($gift['total']) || empty($gift['probalilty'])) { unset($gifts[$key]); continue; } $gifts[$key]['random'] = mt_rand(1, 100 / $gift['probalilty']); if (mt_rand(1, 100 / $gift['probalilty']) == mt_rand(1, 100 / $gift['probalilty'])) { $awards[] = $gift; } } if (count($awards) > 0) { $randid = mt_rand(0, count($awards) - 1); $awardid = $awards[$randid]; } $result['message'] = empty($egg['default_tips']) ? '很遗憾,您没能中奖!' : $egg['default_tips']; $credit = array('rid' => $id, 'uniacid' => $_W['uniacid'], 'uid' => $uid, 'from_user' => $fromuser, 'isaward' => empty($awardid) ? 0 : 1, 'award' => (empty($awardid) ? '未中' : '中') . '奖奖励积分', 'description' => empty($awardid) ? $egg['misscredit'] : $egg['hitcredit'], 'credit' => empty($awardid) ? $egg['misscredit'] : $egg['hitcredit'], 'createtime' => strtotime(date('Y-m-d H:i:s')), 'status' => 2); if (!empty($awardid)) { $sql = 'SELECT * FROM ' . tablename('egg_award') . ' WHERE `rid` = :rid AND `id` = :id'; $params = array(':rid' => $id, ':id' => $awardid['id']); $gift = pdo_fetch($sql, $params); if ($gift['total'] > 0) { $credit['status'] = 0; $credit['award'] = $gift['title']; if (!empty($gift['inkind'])) { $credit['description'] = $gift['description']; $sql = 'UPDATE ' . tablename('egg_award') . ' SET `total` = `total` - 1 WHERE `rid` = :rid AND `id` = :id'; pdo_query($sql, $params); } else { $gift['activation_code'] = (array) iunserializer($gift['activation_code']); $code = array_pop($gift['activation_code']); $activation_code = iserializer($gift['activation_code']); $sql = 'UPDATE ' . tablename('egg_award') . " SET `total` = `total` - 1, `activation_code` = '" . $activation_code . "' WHERE `rid` = :rid AND `id` = :id"; pdo_query($sql, $params); $credit['description'] = '兑换码:' . $code . '<br /> 兑换地址:' . $gift['activation_url']; } $result['message'] = '恭喜您,得到“' . $gift['title'] . '”!'; $result['status'] = 0; } else { $credit['description'] = $egg['misscredit']; $credit['award'] = '未中奖奖励积分'; } } !empty($credit['description']) && ($result['message'] .= '<br />' . $credit['award'] . ':' . $credit['description']); $credit['aid'] = $gift['id']; if (empty($awardid)) { $value = intval($egg['misscredit']); $uid = mc_openid2uid($fromuser); mc_credit_update($uid, 'credit1', $value, array(0, '使用砸蛋模块未中奖,赠送' . $value . '积分')); } else { $value = intval($egg['hitcredit']); $uid = mc_openid2uid($fromuser); mc_credit_update($uid, 'credit1', $value, array(0, '使用砸蛋模块中奖,赠送' . $value . '积分')); } pdo_insert('egg_winner', $credit); $result['myaward'] = pdo_fetchall("SELECT award, description FROM " . tablename('egg_winner') . " WHERE uid = '{$uid}' AND award <> '' AND rid = '{$id}' ORDER BY createtime DESC"); message($result, '', 'ajax'); }
public function payResult($params) { global $_W, $_GPC; $uniacid = $_W['uniacid']; $fee = intval($params['fee']); $data = array('status' => $params['result'] == 'success' ? 1 : 0); $paytype = array('credit' => '1', 'wechat' => '2', 'alipay' => '3'); $data['paytype'] = $paytype[$params['type']]; if ($params['type'] == 'wechat') { $data['transid'] = $params['tag']['transaction_id']; } if ($params['from'] == 'return') { $order = pdo_fetch("SELECT * FROM " . tablename('recharge_order') . " WHERE ordersn ='{$params['tid']}'"); //获取商品ID if ($order['status'] != 1) { if ($params['result'] == 'success') { $data['status'] = 1; } pdo_update('recharge_order', $data, array('ordersn' => $params['tid'])); $settingss = $this->settings; $profile = fans_search($_W['fans']['from_user'], array('nickname', 'credit1', 'credit2', 'avatar')); $uid = mc_openid2uid($_W['fans']['from_user']); if ($fee >= $settingss['marketprice1']) { pdo_update('mc_members', array('credit2' => $profile['credit2'] + $fee + $settingss['productprice1']), array('uid' => $uid)); } elseif ($fee >= $settingss['marketprice2']) { pdo_update('mc_members', array('credit2' => $profile['credit2'] + $fee + $settingss['productprice2']), array('uid' => $uid)); } elseif ($fee >= $settingss['marketprice3']) { pdo_update('mc_members', array('credit2' => $profile['credit2'] + $fee + $settingss['productprice3']), array('uid' => $uid)); } elseif ($fee >= $settingss['marketprice4']) { pdo_update('mc_members', array('credit2' => $profile['credit2'] + $fee + $settingss['productprice4']), array('uid' => $uid)); } else { pdo_update('mc_members', array('credit2' => $profile['credit2'] + $fee), array('uid' => $uid)); } } $setting = uni_setting($_W['uniacid'], array('creditbehaviors')); $credit = $setting['creditbehaviors']['currency']; if ($params['type'] == $credit) { message('充值成功!', $this->createMobileUrl('myorder'), 'success'); } else { message('充值成功!', '../../app/' . $this->createMobileUrl('myorder'), 'success'); } } }
public function disappear($weid, $from_user) { load()->model('mc'); $uid = mc_openid2uid($from_user); pdo_delete(self::$t_sys_fans, array('uniacid' => $weid, 'openid' => $from_user)); pdo_delete(self::$t_sys_member, array('uniacid' => $weid, 'uid' => $uid)); }
public function doMobileExchangeApi() { global $_GPC, $_W; $rid = $_GPC['rid']; $record = DBUtil::findById(DBUtil::$TABLE_EGG_RECORD, $rid); $res = array(); if (empty($record)) { $res['res'] = 'fail'; $res['msg'] = '砸金蛋记录删除或不存在'; die(json_encode($res)); } if ($record['status'] == $this::$STATUS_DH) { $res['res'] = 'fail'; $res['msg'] = '奖品已兑换,不能重复兑奖!'; die(json_encode($res)); } $tokenUrl = urldecode($_GPC['tokenUrl']); $token = $_GPC['token']; if (empty($tokenUrl) || empty($token)) { $res['res'] = 'fail'; $res['msg'] = '核销人员信息信息错误'; die(json_encode($res)); } load()->func('communication'); //验证核销人员 $result = ihttp_post($tokenUrl, array('token' => $token)); $resultJson = json_decode(substr($result['content'], 3), true); if (empty($resultJson)) { $res['res'] = 'fail'; $res['msg'] = '验证核销人员返回为空'; die(json_encode($res)); } else { if ($resultJson['code'] == 200) { //开始执行核销 $prize = DBUtil::findById(DBUtil::$TABLE_EGG_PRIZE, $record['pid']); if ($prize['ptype'] == 1) { //实物 DBUtil::updateById(DBUtil::$TABLE_EGG_RECORD, array("status" => self::$STATUS_DH, 'dhtime' => TIMESTAMP), $rid); $user = DBUtil::findById(DBUtil::$TABLE_EGG_USER, $record['uid']); $res['res'] = 'success'; $res['uname'] = $user['uname']; $res['unickname'] = $user['nickname']; $res['utel'] = $user['tel']; $res['pname'] = $prize['pname']; $res['remark'] = '兑换实物成功'; die(json_encode($res)); } else { if ($prize['ptype'] == 2) { //积分 $user = DBUtil::findById(DBUtil::$TABLE_EGG_USER, $record['uid']); if (empty($user['openid'])) { $res['res'] = 'fail'; $res['msg'] = '用户openid为空'; die(json_encode($res)); } else { load()->model('mc'); $uid = mc_openid2uid($user['openid']); $result = mc_credit_update($uid, 'credit1', $prize['jf'], array($uid, '二维码核销砸金蛋手机端兑换积分')); if ($result) { DBUtil::updateById(DBUtil::$TABLE_EGG_RECORD, array("status" => self::$STATUS_DH, 'dhtime' => TIMESTAMP), $rid); $res['res'] = 'success'; $res['uname'] = $user['uname']; $res['unickname'] = $user['nickname']; $res['utel'] = $user['tel']; $res['pname'] = $prize['pname']; $res['remark'] = '兑换积分成功'; die(json_encode($res)); } else { DBUtil::updateById(DBUtil::$TABLE_EGG_RECORD, array("status" => self::$STATUS_DH, 'dhtime' => TIMESTAMP), $rid); $res['res'] = 'success'; $res['uname'] = $user['uname']; $res['unickname'] = $user['nickname']; $res['utel'] = $user['tel']; $res['pname'] = $prize['pname']; $res['remark'] = '兑换积分成功'; die(json_encode($res)); //message($result, referer(), 'success'); } } } } } else { $res['res'] = 'fail'; $res['msg'] = '核销人员删除或不存在!'; die(json_encode($res)); } } }