/** * [WeEngine System] Copyright (c) 2014 WE7.CC * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details. */ defined('IN_IA') or exit('Access Denied'); $dos = array('display', 'change', 'qr', 'chat'); $do = !empty($_GPC['do']) && in_array($do, $dos) ? $do : 'display'; load()->model('account'); if ($do == 'display') { template('platform/url2qr'); } if ($do == 'change') { if ($_W['ispost']) { load()->func('communication'); $longurl = trim($_GPC['longurl']); $token = WeAccount::token(WeAccount::TYPE_WEIXIN); $url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$token}"; $send = array(); $send['action'] = 'long2short'; $send['long_url'] = $longurl; $response = ihttp_request($url, json_encode($send)); if (is_error($response)) { $result = error(-1, "访问公众平台接口失败, 错误: {$response['message']}"); } $result = @json_decode($response['content'], true); if (empty($result)) { $result = error(-1, "接口调用失败, 元数据: {$response['meta']}"); } elseif (!empty($result['errcode'])) { $result = error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']}"); } if (is_error($result)) {
public function doMobilepayweixin() { global $_W, $_GPC; $op = $_GPC['op']; $tid = $_GPC['tid']; $title = '二维码支付'; //获取商城标题 load()->model('account'); if (empty($op)) { if (empty($tid)) { message('订单错误, 请重新下单支付!', '', 'error'); } $value = $this->GetPrePayUrl($tid); ///44.生成扫描支付URL,模式一。 include $this->template('payweixin'); } if ($op == 'change') { if ($_W['ispost']) { load()->func('communication'); $longurl = trim($_GPC['longurl']); $token = WeAccount::token(WeAccount::TYPE_WEIXIN); $url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$token}"; $send = array(); $send['action'] = 'long2short'; $send['long_url'] = $longurl; $response = ihttp_request($url, json_encode($send)); if (is_error($response)) { $result = error(-1, "访问公众平台接口失败, 错误: {$response['message']}"); } $result = @json_decode($response['content'], true); if (empty($result)) { $result = error(-1, "接口调用失败, 元数据: {$response['meta']}"); } elseif (!empty($result['errcode'])) { $result = error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']}"); } if (is_error($result)) { exit(json_encode(array('errcode' => -1, 'errmsg' => $result['message']))); } exit(json_encode($result)); } else { exit('err'); } } if ($op == 'qr') { $url = $_GPC['url']; require IA_ROOT . '/framework/library/qrcode/phpqrcode.php'; $errorCorrectionLevel = "L"; $matrixPointSize = "5"; QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize); exit; } }
public function sendtempmsg($template_id, $url, $data, $topcolor, $tousers = '') { load()->func('communication'); load()->classs('weixin.account'); $access_token = WeAccount::token(); if (empty($access_token)) { return; } $postarr = '{"touser":"******","template_id":"' . $template_id . '","url":"' . $url . '","topcolor":"' . $topcolor . '","data":' . $data . '}'; $res = ihttp_post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token, $postarr); return true; }
public function payResult($params) { global $_W, $_GPC; $weid = $this->_weid; $orderid = $params['tid']; $fee = intval($params['fee']); $data = array('status' => $params['result'] == 'success' ? 1 : 0); $paytype = array('credit' => '1', 'wechat' => '2', 'alipay' => '2', 'delivery' => '3'); $data['paytype'] = $paytype[$params['type']]; if ($params['type'] == 'wechat') { $data['dateline'] = TIMESTAMP; $paylog = pdo_fetch("SELECT plid FROM " . tablename('core_paylog') . " WHERE uniacid= :uniacid and tid = :tid", array(':uniacid' => $weid, ':tid' => $orderid)); if (!empty($paylog)) { $data['transid'] = $paylog['plid']; } // $data['transid'] = $params['tag']['transaction_id']; } if ($params['type'] == 'delivery') { $data['status'] = 1; } $order = pdo_fetch("SELECT * FROM " . tablename($this->table_order) . " WHERE id = '{$orderid}'"); $storeid = $order['storeid']; pdo_update($this->table_order, $data, array('id' => $orderid)); if ($params['from'] == 'return') { //邮件提醒 $goods_str = ''; //本订单产品 $goods = pdo_fetchall("SELECT a.*,b.title,b.unitname FROM " . tablename($this->table_order_goods) . " as a left join " . tablename($this->table_goods) . " as b on a.goodsid=b.id WHERE a.weid = '{$weid}' and a.orderid={$orderid}"); $goods_str = ''; $goods_tplstr = ''; $flag = false; foreach ($goods as $key => $value) { if (!$flag) { $goods_str .= "{$value['title']} 价格:{$value['price']} 数量:{$value['total']}{$value['unitname']}"; $goods_tplstr .= "{$value['title']} {$value['total']}{$value['unitname']}"; $flag = true; } else { $goods_str .= "<br/>{$value['title']} 价格:{$value['price']} 数量:{$value['total']}{$value['unitname']}"; $goods_tplstr .= ",{$value['title']} {$value['total']}{$value['unitname']}"; } } //发送邮件提醒 $emailSetting = pdo_fetch("SELECT * FROM " . tablename($this->table_email_setting) . " WHERE weid=:weid AND storeid=:storeid LIMIT 1", array(':weid' => $weid, ':storeid' => $storeid)); $email_tpl = $emailSetting['email_business_tpl']; //您有新的订单:[sn],收货人:[name],菜单:[goods],电话:[tel],请及时确认订单! $email_tpl = "\r\n 您有新订单:<br/>\r\n 所属门店:[store]<br/>\r\n 单号[sn] 总数量:[totalnum] 总价:[totalprice]<br/>\r\n 菜单:[goods]<br/>\r\n 姓名:[name]<br/>\r\n 电话:[tel]<br/>\r\n 桌号:[tables]<br/>\r\n 备注:[remark]\r\n "; if ($order['dining_mode'] == 2) { $email_tpl = "\r\n 您有新订单:<br/>\r\n 所属门店:[store]<br/>\r\n 单号[sn] 总数量:[totalnum] 总价:[totalprice]<br/>\r\n 收货人:[name]<br/>\r\n 送达时间:[mealtime]<br/>\r\n 菜单:<br/>[goods]<br/>\r\n 电话:[tel]<br/>\r\n 地址:[address]<br>\r\n 备注:[remark]\r\n "; } $smsStatus = ''; //发送短信提醒 $smsSetting = pdo_fetch("SELECT * FROM " . tablename($this->table_sms_setting) . " WHERE weid=:weid AND storeid=:storeid LIMIT 1", array(':weid' => $weid, ':storeid' => $storeid)); $sendInfo = array(); if (!empty($smsSetting)) { if ($smsSetting['sms_enable'] == 1 && !empty($smsSetting['sms_mobile'])) { //模板 if (empty($smsSetting['sms_business_tpl'])) { $smsSetting['sms_business_tpl'] = '您有新的订单:[sn],收货人:[name],电话:[tel],请及时确认订单!'; } //订单号 $smsSetting['sms_business_tpl'] = str_replace('[sn]', $order['ordersn'], $smsSetting['sms_business_tpl']); //用户名 $smsSetting['sms_business_tpl'] = str_replace('[name]', $order['username'], $smsSetting['sms_business_tpl']); //就餐时间 $smsSetting['sms_business_tpl'] = str_replace('[date]', $order['meal_time'], $smsSetting['sms_business_tpl']); //电话 $smsSetting['sms_business_tpl'] = str_replace('[tel]', $order['tel'], $smsSetting['sms_business_tpl']); $smsSetting['sms_business_tpl'] = str_replace('[totalnum]', $order['totalnum'], $smsSetting['sms_business_tpl']); $smsSetting['sms_business_tpl'] = str_replace('[totalprice]', $order['totalprice'], $smsSetting['sms_business_tpl']); $smsSetting['sms_business_tpl'] = str_replace('[address]', $order['address'], $smsSetting['sms_business_tpl']); $smsSetting['sms_business_tpl'] = str_replace('[remark]', $order['remark'], $smsSetting['sms_business_tpl']); $smsSetting['sms_business_tpl'] = str_replace('[goods]', $goods_str, $smsSetting['sms_business_tpl']); $sendInfo['username'] = $smsSetting['sms_username']; $sendInfo['pwd'] = $smsSetting['sms_pwd']; $sendInfo['mobile'] = $smsSetting['sms_mobile']; $sendInfo['content'] = $smsSetting['sms_business_tpl']; //debug if ($data['status'] == 1) { if ($order['issms'] == 0) { pdo_update($this->table_order, array('issms' => 1), array('id' => $orderid)); $return_result_code = $this->_sendSms($sendInfo); $smsStatus = $this->sms_status[$return_result_code]; } } } } $store = pdo_fetch("SELECT * FROM " . tablename($this->table_stores) . " WHERE weid=:weid AND id=:id LIMIT 1", array(':weid' => $weid, ':id' => $storeid)); if (!empty($emailSetting) && !empty($emailSetting['email'])) { $email_tpl = str_replace('[store]', $store['title'], $email_tpl); $email_tpl = str_replace('[sn]', $order['ordersn'], $email_tpl); $email_tpl = str_replace('[name]', $order['username'], $email_tpl); //用户名 $email_tpl = str_replace('[name]', $order['username'], $email_tpl); //就餐时间 $email_tpl = str_replace('[mealtime]', $order['meal_time'], $email_tpl); //电话 $email_tpl = str_replace('[tel]', $order['tel'], $email_tpl); $email_tpl = str_replace('[tables]', $order['tables'], $email_tpl); $email_tpl = str_replace('[goods]', $goods_str, $email_tpl); $email_tpl = str_replace('[totalnum]', $order['totalnum'], $email_tpl); $email_tpl = str_replace('[totalprice]', $order['totalprice'], $email_tpl); $email_tpl = str_replace('[address]', $order['address'], $email_tpl); $email_tpl = str_replace('[remark]', $order['remark'], $email_tpl); if ($emailSetting['email_host'] == 'smtp.qq.com' || $emailSetting['email_host'] == 'smtp.gmail.com') { $secure = 'ssl'; $port = '465'; } else { $secure = 'tls'; $port = '25'; } $mail_config = array(); $mail_config['host'] = $emailSetting['email_host']; $mail_config['secure'] = $secure; $mail_config['port'] = $port; $mail_config['username'] = $emailSetting['email_user']; $mail_config['sendmail'] = $emailSetting['email_send']; $mail_config['password'] = $emailSetting['email_pwd']; $mail_config['mailaddress'] = $emailSetting['email']; $mail_config['subject'] = '订单提醒'; $mail_config['body'] = $email_tpl; if ($data['status'] == 1) { if ($order['isemail'] == 0) { pdo_update($this->table_order, array('isemail' => 1), array('id' => $orderid)); $result = $this->sendmail($mail_config); } } } $setting = pdo_fetch("select * from " . tablename($this->table_setting) . " where weid =:weid LIMIT 1", array(':weid' => $weid)); if (!empty($setting) && $setting['istplnotice'] == 1) { $templateid = $setting['tplneworder']; $noticeuser = $setting['tpluser']; $template = array('touser' => $noticeuser, 'template_id' => $templateid, 'url' => '', 'topcolor' => "#FF0000", 'data' => array('first' => array('value' => urlencode("您有一个新的订单"), 'color' => '#000'), 'keyword1' => array('value' => urlencode($order['ordersn']), 'color' => '#000'), 'keyword2' => array('value' => urlencode($order['username'] . ' ' . $order['tel']), 'color' => '#000'), 'keyword3' => array('value' => urlencode($goods_tplstr), 'color' => '#000'), 'keyword4' => array('value' => urlencode($order['address']), 'color' => '#000'), 'keyword5' => array('value' => urlencode($order['meal_time']), 'color' => '#000'), 'remark' => array('value' => urlencode('总金额:' . $order['totalprice'] . '元'), 'color' => '#f00'))); if ($data['status'] == 1) { if ($order['istpl'] == 0) { pdo_update($this->table_order, array('istpl' => 1), array('id' => $orderid)); $templateMessage = new class_templateMessage($this->_appid, $this->_appsecret); $access_token = WeAccount::token(); $templateMessage->send_template_message($template, $access_token); } } } $this->feiyinSendFreeMessage($orderid); $setting = uni_setting($_W['uniacid'], array('creditbehaviors')); $credit = $setting['creditbehaviors']['currency']; if ($params['type'] == $credit) { message('支付成功!' . $smsStatus, $this->createMobileUrl('order', array('storeid' => $storeid, 'status' => 1), true), 'success'); } else { message('支付成功!' . $smsStatus, '../../app/' . $this->createMobileUrl('order', array('storeid' => $storeid), true), 'success'); } } }
} } else { if (isset($avatar) && isset($nickname) && isset($from_user)) { $shareuserdata = $_W['siteroot'] . 'app/' . $this->createMobileUrl('shareuserdata', array('rid' => $rid, 'fromuser' => $fromuser, 'duli' => $_GPC['duli'], 'tfrom_user' => $tfrom_user)); header("location:{$shareuserdata}"); exit; } else { $from_user = $_W['openid']; if ($from_user) { //取得openid后查询是否为高级号 if ($serverapp == 4) { //认证服务号查询是否关注 $profile = pdo_fetch("SELECT follow FROM " . tablename('mc_mapping_fans') . " WHERE uniacid = :uniacid and openid = :from_user", array(':uniacid' => $uniacid, ':from_user' => $from_user)); if ($_W['fans']['follow'] || $profile['follow']) { //已关注直接获取信息 $access_token = WeAccount::token(); $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?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], 请稍后重试! 公众平台返回原始数据为: <br />' . $content['meta'] . '<h1>'; exit; } else { $avatar = $info['headimgurl']; $nickname = $info['nickname']; $sex = $info['sex']; //设置cookie信息 setcookie("user_oauth2_avatar", $avatar, time() + 3600 * 24 * 7); setcookie("user_oauth2_nickname", $nickname, time() + 3600 * 24 * 7); setcookie("user_oauth2_sex", $sex, time() + 3600 * 24 * 7); setcookie("user_oauth2_openid", $from_user, time() + 3600 * 24 * 7);
/** * 模板消息 * 接口已开放 * */ private function SendTpl($openid, $info, $type, $res) { load()->func('communication'); require_once 'template_conf_ap.php'; require_once 'template_conf_auth.php'; require_once 'template_conf_re.php'; require_once 'template_conf_cd.php'; require_once 'template_conf_fl.php'; global $_W; $access_token = WeAccount::token(); $apply = json_decode($apply, true); // $this->saveSettings($apply); $auth = json_decode($auth, true); // $this->saveSettings(auth); $refu = json_decode($refu, true); // $this->saveSettings($refu); $credit = json_decode($credit, true); // $this->saveSettings($credit); $full = json_decode($full, true); // $this->saveSettings($full); //post URL $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token; //POST data if ($type == 'apply') { $data = array('touser' => $openid, 'template_id' => $apply['apply_tid'], 'url' => $_W['siteroot'] . 'app/index.php?i=1&c=entry&do=ptjindex&m=hypernet_iptj', 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => $apply['apply_first'], 'color' => $apply['apply_fcolor']), 'keynote1' => array('value' => $apply['apply_keynote1'], 'color' => $apply['apply_kfcolor']), 'keynote2' => array('value' => '请联系雇主确认....', 'color' => '#000'), 'remark' => array('value' => $apply['apply_remark'], 'color' => $apply['apply_mkcolor']))); } else { if ($type == 'auth') { $date = date('Y-m-d H:i'); $data = array('touser' => $openid, 'template_id' => $auth['auth_tid'], 'url' => $_W['siteroot'] . 'app/index.php?i=1&c=entry&do=ptjindex&m=hypernet_iptj', 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => $auth['auth_first'], 'color' => $apply['auth_first']), 'keyword1' => array('value' => $info['name'], 'color' => '#000'), 'keyword2' => array('value' => $info['phone'], 'color' => '#000'), 'keyword3' => array('value' => $date, 'color' => '#000'), 'remark' => array('value' => $auth['auth_remark'], 'color' => $auth['auth_mkcolor']))); } else { if ($type == 'refuse') { $date = date('Y-m-d H:i'); $data = array('touser' => $openid, 'template_id' => $refu['refu_tid'], 'url' => $_W['siteroot'] . 'app/index.php?i=1&c=entry&do=ptjindex&m=hypernet_iptj', 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => $refu['refu_first'], 'color' => $refu['refu_fcolor']), 'keyword1' => array('value' => $info['name'], 'color' => '#000'), 'keyword2' => array('value' => $info['phone'], 'color' => '#000'), 'keyword3' => array('value' => $date, 'color' => '#000'), 'remark' => array('value' => $refu['refu_remark'], 'color' => $refu['refu_mkcolor']))); } else { if ($type == 'credit1') { $date = date('Y-m-d H:i:s'); $data = array('touser' => $openid, 'template_id' => $credit['credit_tid'], 'url' => $_W['siteroot'] . 'app/index.php?i=1&c=entry&do=ptjindex&m=hypernet_iptj', 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => $credit['credit_first'], 'color' => $credit['credit_fcolor']), 'account' => array('value' => $info['name'], 'color' => '#000'), 'time' => array('value' => $date, 'color' => '#000'), 'type' => array('value' => $credit['credit_type'], 'color' => $credit['credit_tpcolor']), 'creditChange' => array('value' => '支出', 'color' => '#000'), 'number' => array('value' => '100', 'color' => '#000'), 'creditName' => array('value' => '账户积分', 'color' => '#000'), 'amount' => array('value' => $res, 'color' => '#000'), 'remark' => array('value' => $credit['credit_remark'], 'color' => $credit['crefit_mkcolor']))); } else { if ($type == 'full') { $data = array('touser' => $openid, 'template_id' => $full['full_tid'], 'url' => $_W['siteroot'] . 'app/index.php?i=1&c=entry&do=ptjmyinfo&m=hypernet_iptj', 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => $full['full_first'], 'color' => $full['full_fcolor']), 'keyword1' => array('value' => $info['title'], 'color' => '#000'), 'keyword2' => array('value' => "待办", 'color' => 'red'), 'remark' => array('value' => $full['full_remark'], 'color' => $full['full_mkcolor']))); } else { if ($type == 'first_third') { $data = array('touser' => $openid, 'template_id' => $full['full_tid'], 'url' => $_W['siteroot'] . 'app/index.php?i=1&c=entry&do=ptjmyinfo&m=hypernet_iptj', 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => '请尽快去录取应答者,完成本次招募。', 'color' => '#000'), 'keyword1' => array('value' => $info['title'], 'color' => '#000'), 'keyword2' => array('value' => '待办', 'color' => 'red'), 'remark' => array('value' => '帖子有人认领啦,快去看看.', 'color' => '#0542FA'))); } else { if ($type == 'second_third') { $data = array('touser' => $openid, 'template_id' => $full['full_tid'], 'url' => $_W['siteroot'] . 'app/index.php?i=1&c=entry&do=ptjmyinfo&m=hypernet_iptj', 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => '请尽快去录取应聘者,完成本次招聘。', 'color' => '#000'), 'keyword1' => array('value' => $info['title'], 'color' => '#000'), 'keyword2' => array('value' => '待办', 'color' => 'red'), 'remark' => array('value' => '招聘帖子人数快满了,请速去验收.', 'color' => '#0542FA'))); } else { if ($type == 'admit') { $data = array('touser' => $openid, 'template_id' => $apply['apply_tid'], 'url' => $_W['siteroot'] . 'app/index.php?i=1&c=entry&do=ptjindex&m=hypernet_iptj', 'topcolor' => '#FF0000', 'data' => array('first' => array('value' => 'congrats!你已被' . $info['name'] . '招募', 'color' => '#FF0000'), 'keynote1' => array('value' => $info['name'] . '欢迎你的加入~', 'color' => '#000'), 'keynote2' => array('value' => '请联系雇主确认....', 'color' => '#000'), 'remark' => array('value' => '要愉快地玩耍哦~~~~', 'color' => '#000'))); } } } } } } } } return ihttp_post($url, json_encode($data)); }
public function payResult($params) { global $_W, $_GPC; $fee = intval($params['fee']); $data = array('status' => $params['result'] == 'success' ? 1 : 0); $paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 2, 'delivery' => 3); $data['pay_type'] = $paytype[$params['type']]; if ($params['type'] == 'wechat') { $data['transid'] = $params['tag']['transaction_id']; } $goodsId = pdo_fetchcolumn("SELECT `g_id` FROM" . tablename('tg_order') . "WHERE `orderno` = :orderid ", array(':orderid' => $params['tid'])); $goodsInfo = pdo_fetch("SELECT * FROM" . tablename('tg_goods') . "WHERE `id` = :id ", array(':id' => $goodsId)); // //货到付款 if ($params['type'] == 'delivery') { $data['status'] = 1; $data['starttime'] = TIMESTAMP; $data['ptime'] = TIMESTAMP; } if ($params['result'] == 'success') { $data['ptime'] = TIMESTAMP; $data['starttime'] = TIMESTAMP; } $tuan_id = pdo_fetch("select * from" . tablename('tg_order') . "where orderno = '{$params['tid']}'"); $goods = pdo_fetch("select * from" . tablename('tg_order') . "where id = '{$tuan_id['g_id']}'"); if ($params['from'] == 'return') { $pay_suc = $this->module['config']['pay_suc']; $pay_remark = $this->module['config']['pay_remark']; $m_pay = $this->module['config']['m_pay']; //支付成功模板消息提醒 $content = ""; if ($tuan_id['tuan_first'] == 1) { $content .= "您已成功付款开团,恭喜您荣升团长,组团成功才会享受优惠哦"; } else { $content .= "您已成功付款参团,组团成功才会享受优惠哦"; } load()->func('communication'); load()->model('account'); $access_token = WeAccount::token(); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $url2 = $_W['siteroot'] . 'app/' . $this->createMobileUrl('orderdetails', array('id' => $params['tid'])); //点击模板详情跳转的地址url2 $time = date("Y-m-d H:i:s", time()); $openid = trim($_W['openid']); $msg_json = '{ "touser":"******", "template_id":"' . $m_pay . '", "url":"' . $url2 . '", "topcolor":"#FF0000", "data":{ "first":{ "value":"\\n' . $pay_suc . '\\n", "color":"#000000" }, "orderProductName":{ "value":"' . $goodsInfo['gname'] . '\\n", "color":"#000000" }, "orderMoneySum":{ "value":"' . $tuan_id['price'] . '\\n", "color":"#000000" }, "remark":{ "value":"\\n\\n' . $pay_remark . '", "color":"#0099FF" } } }'; include_once 'message.php'; $sendmessage = new WX_message(); $res = $sendmessage->WX_request($url, $msg_json); $setting = uni_setting($_W['uniacid'], array('creditbehaviors')); $credit = $setting['creditbehaviors']['currency']; if ($tuan_id['status'] != 1) { pdo_update('tg_order', $data, array('orderno' => $params['tid'])); // 更改库存 if (!empty($goodsInfo['gnum'])) { pdo_update('tg_goods', array('gnum' => $goodsInfo['gnum'] - 1, 'salenum' => $goodsInfo['salenum'] + 1), array('id' => $goodsId)); } } $order_out = pdo_fetch("select * from" . tablename('tg_order') . "where orderno = '{$params['tid']}'"); //判断人数,是否团购成功 $sql = "SELECT * FROM" . tablename('tg_order') . "where tuan_id=:tuan_id and status =:status "; $params = array(':tuan_id' => $tuan_id['tuan_id'], ':status' => 1); $alltuan = pdo_fetchall($sql, $params); $item = array(); foreach ($alltuan as $num => $all) { $item[$num] = $all['id']; if ($all['tuan_first'] == 1) { $tuan_firstopenid = $all['openid']; } } $profile = pdo_fetch("SELECT * FROM " . tablename('tg_member') . " WHERE uniacid ='{$_W['uniacid']}' and from_user = '******'"); $n = $goodsInfo['groupnum'] - count($item); if ($n == 0) { pdo_update('tg_order', array('success' => 0), array('tuan_id' => $tuan_id['tuan_id'], 'status' => 1)); //组团成功模板消息提醒 $m_tuan = $this->module['config']['m_tuan']; $tuan_suc = $this->module['config']['tuan_suc']; $tuan_remark = $this->module['config']['tuan_remark']; $content = "组团成功!!!"; load()->func('communication'); load()->model('account'); $access_token = WeAccount::token(); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $url2 = ""; //点击模板详情跳转的地址url2 $time = date("Y-m-d H:i:s", time()); foreach ($alltuan as $num => $all) { $openid = trim($all['openid']); $msg_json = '{ "touser":"******", "template_id":"' . $m_tuan . '", "url":"' . $url2 . '", "topcolor":"#FF0000", "data":{ "first":{ "value":"\\n' . $tuan_suc . '\\n", "color":"#000000" }, "Pingou_ProductName":{ "value":"' . $goodsInfo['gname'] . '\\n", "color":"#000000" }, "Weixin_ID":{ "value":"' . $profile['nickname'] . '\\n", "color":"#000000" }, "remark":{ "value":"\\n\\n' . $tuan_remark . '", "color":"#0099FF" } } }'; $sendme = new WX_message(); $res = $sendme->WX_request($url, $msg_json); //获取所有打印机 $prints = pdo_fetchall('SELECT * FROM ' . tablename('tg_print') . ' WHERE uniacid = :aid AND status = 1', array(':aid' => $_W['uniacid'])); if (!empty($prints)) { include_once 'wprint.class.php'; //遍历所有打印机 foreach ($prints as $li) { if (!empty($li['print_no']) && !empty($li['key'])) { $wprint = new wprint(); if ($li['mode'] == 1) { $orderinfo .= "<CB>组团成功</CB><BR>"; $orderInfo .= "商品信息:<BR>"; $orderinfo .= '------------------------------<BR>'; $orderinfo .= "商品名称:{$goodsInfo['gname']}<BR>"; $orderinfo .= '------------------------------<BR>'; $orderinfo .= "用户信息:<BR>"; $orderinfo .= '------------------------------<BR>'; foreach ($alltuan as $row) { $user = pdo_fetch("select * from" . tablename('tg_address') . "where id='{$row['addressid']}'"); $orderinfo .= "用户名:{$user['cname']}<BR>"; $orderinfo .= "手机号:{$user['tel']}<BR>"; $orderinfo .= "地址:{$user['province']}{$user['city']}{$user['county']}{$user['detailed_address']}<BR>"; $orderinfo .= '------------------------------<BR>'; } $status = $wprint->StrPrint($li['print_no'], $li['key'], $orderinfo, $li['print_nums']); } else { $orderinfo .= "组团成功"; $orderInfo .= "商品信息:"; $orderinfo .= '------------------------------'; $orderinfo .= "商品名称:{$goodsInfo['gname']}"; $orderinfo .= '------------------------------'; $orderinfo .= "用户信息:"; $orderinfo .= '------------------------------'; foreach ($alltuan as $row) { $user = pdo_fetch("select * from" . tablename('tg_address') . "where id='{$row['addressid']}'"); $orderinfo .= "用户名:{$user['cname']}"; $orderinfo .= "手机号:{$user['tel']}"; $orderinfo .= "地址:{$user['province']}{$user['city']}{$user['county']}{$user['detailed_address']}"; $orderinfo .= '------------------------------'; } $status = $wprint->testSendFreeMessage($li['member_code'], $li['print_no'], $li['key'], $orderinfo); } if (!is_error($status)) { $i++; $data = array('uniacid' => $_W['uniacid'], 'sid' => $sid, 'pid' => $li['id'], 'oid' => $id, 'status' => 1, 'foid' => $status, 'addtime' => TIMESTAMP); pdo_insert('tg_order_print', $data); } } } } } } elseif ($n < 0) { echo "<script>location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('more_refund', array('transid' => $order_out['transid'])) . "';</script>"; exit; } if ($params['type'] == $credit) { if ($tuan_id['is_tuan'] == 0) { // message('支付成功!', $this->createMobileUrl('myorder'), 'success'); echo "<script>alert('支付成功!');location.href='" . $this->createMobileUrl('myorder') . "';</script>"; exit; } else { // message('支付成功!', $this->createMobileUrl('group',array('tuan_id' => $tuan_id['tuan_id'])), 'success'); echo "<script>alert('支付成功!');location.href='" . $this->createMobileUrl('group', array('tuan_id' => $tuan_id['tuan_id'])) . "';</script>"; exit; } } else { if ($tuan_id['is_tuan'] == 0) { // message('支付成功!', '../../app/' . $this->createMobileUrl('myorder'), 'success'); echo "<script>alert('支付成功!');location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('myorder') . "';</script>"; exit; } else { // message('支付成功!', '../../app/' . $this->createMobileUrl('group',array('tuan_id' => $tuan_id['tuan_id'])), 'success'); echo "<script>alert('支付成功!');location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('group', array('tuan_id' => $tuan_id['tuan_id'])) . "';</script>"; exit; } } } }
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' => '3', 'alipay' => '2'); $data['paytype'] = $paytype[$params['type']]; if ($params['type'] == 'wechat') { $data['transid'] = $params['tag']['transaction_id']; } if ($params['result'] == 'success' && $params['from'] == 'notify') { $order = pdo_fetch("SELECT * FROM " . tablename('feng_record') . " WHERE id ='{$params['tid']}'"); //获取商品ID if ($order['status'] != 1) { if ($params['result'] == 'success') { $data['status'] = 1; $codes = pdo_fetch("SELECT * FROM " . tablename('feng_goodscodes') . " WHERE s_id ='{$order['sid']}'"); //获取商品code $sidm = pdo_fetch("SELECT * FROM " . tablename('feng_goodslist') . " WHERE id ='{$order['sid']}'"); //获取商品详情 $s_codes = unserialize($codes['s_codes']); //转换商品code $c_number = intval($codes['s_len']); if ($c_number > 0) { if ($fee < $c_number) { //计算购买的夺宝码 $data['s_codes'] = array_slice($s_codes, 0, $fee); $data['s_codes'] = serialize($data['s_codes']); $r_codes['s_len'] = $c_number - $fee; $r_codes['s_codes'] = array_slice($s_codes, $fee, $r_codes['s_len']); $r_codes['s_codes'] = serialize($r_codes['s_codes']); $sid_mess['canyurenshu'] = $sidm['canyurenshu'] + $fee; $sid_mess['shengyurenshu'] = $sidm['shengyurenshu'] - $fee; $sid_mess['scale'] = round($sid_mess['canyurenshu'] / $sidm['zongrenshu'] * 100); //执行数据库更新 pdo_update('feng_goodscodes', $r_codes, array('id' => $codes['id'])); pdo_update('feng_goodslist', $sid_mess, array('id' => $sidm['id'])); $result_mess = '支付成功!'; } elseif ($fee >= $c_number) { $data['s_codes'] = $codes['s_codes']; /*$data['s_codes']=serialize($data['s_codes']);*/ $r_codes['s_len'] = 0; $r_codes['s_codes'] = NULL; //计算获奖的code和获奖人 $s_record = pdo_fetchall("SELECT * FROM " . tablename('feng_record') . " WHERE uniacid = '{$_W['uniacid']}' and sid ='{$order['sid']}'"); //获取商品所有交易记录 if (empty($sidm['q_user_code'])) { $wincode = mt_rand(1, $sidm['zongrenshu']); $wincode = $wincode + 1000000; } else { $wincode = $sidm['q_user_code']; } //计算获奖人 foreach ($s_record as $value) { $ss_codes = unserialize($value['s_codes']); //转换商品code for ($i = 0; $i < count($ss_codes); $i++) { if ($ss_codes[$i] == $wincode) { $sid_mess['q_user'] = $value['from_user']; break; } } } if (empty($sid_mess['q_user'])) { $ss_codes = unserialize($data['s_codes']); //转换商品code for ($i = 0; $i < count($ss_codes); $i++) { if ($ss_codes[$i] == $wincode) { $sid_mess['q_user'] = $_W['fans']['from_user']; break; } } } $sid_mess['canyurenshu'] = $sidm['zongrenshu']; $sid_mess['shengyurenshu'] = 0; $sid_mess['q_user_code'] = $wincode; $pro_m = pdo_fetch("SELECT * FROM " . tablename('feng_member') . " WHERE uniacid = '{$_W['uniacid']}' and from_user ='******'q_user']}'"); //用户信息 $sid_mess['q_uid'] = $pro_m['nickname']; $sid_mess['status'] = 1; $sid_mess['q_end_time'] = TIMESTAMP; $sid_mess['scale'] = 100; //模板消息推送 load()->model('account'); $access_token = WeAccount::token(); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $json_data = array('touser' => $sid_mess['q_user'], 'template_id' => $this->module['config']['win_mess'], 'url' => $_W['siteroot'] . 'app/' . $this->createMobileUrl('prize'), 'topcolor' => '#FF0000', "data" => array("title" => array('value' => '尊敬的客户', 'color' => '#173177'), "headinfo" => array('value' => '恭喜您,中奖啦!', 'color' => '#FF0000'), "program" => array('value' => '一元夺宝', 'color' => '#FF0000'), "result" => array('value' => '获得了我们的大奖', 'color' => '#FF0000'), "remark" => array('value' => '点击进入查看中奖详情,祝你生活愉快!', 'color' => '#173177'))); $msg_json = json_encode($json_data); include_once 'message.php'; $sendmessage = new WX_message(); $res = $sendmessage->WX_request($url, $msg_json); //生成新一期商品 if ($sidm['periods'] <= $sidm['maxperiods']) { $new_sid = array('uniacid' => $_W['uniacid'], 'sid' => $sidm['sid'], 'title' => $sidm['title'], 'price' => $sidm['price'], 'zongrenshu' => $sidm['zongrenshu'], 'canyurenshu' => 0, 'shengyurenshu' => $sidm['zongrenshu'], 'periods' => $sidm['periods'] + 1, 'maxperiods' => $sidm['maxperiods'], 'picarr' => $sidm['picarr'], 'content' => $sidm['content'], 'createtime' => TIMESTAMP, 'pos' => $sidm['pos'], 'status' => $sidm['status']); pdo_insert('feng_goodslist', $new_sid); $id = pdo_insertid(); $CountNum = intval($sidm['price']); $new_codes = array(); for ($i = 1; $i <= $CountNum; $i++) { $new_codes[$i] = 1000000 + $i; } shuffle($new_codes); $new_codes = serialize($new_codes); $data1['uniacid'] = $_W['uniacid']; $data1['s_id'] = $id; $data1['s_len'] = $CountNum; $data1['s_codes'] = $new_codes; $data1['s_codes_tmp'] = $new_codes; $ret = pdo_insert('feng_goodscodes', $data1); unset($new_codes); } if ($fee == $c_number) { //执行数据库操作 pdo_update('feng_goodscodes', $r_codes, array('id' => $codes['id'])); pdo_update('feng_goodslist', $sid_mess, array('id' => $sidm['id'])); $result_mess = '支付成功!'; } else { $data['count'] = $c_number; $reprice = $fee - $c_number; load()->model('mc'); $result_c = mc_credit_update($_W['member']['uid'], 'credit2', $reprice); //执行数据库操作 pdo_update('feng_goodscodes', $r_codes, array('id' => $codes['id'])); pdo_update('feng_goodslist', $sid_mess, array('id' => $sidm['id'])); $result_mess = '支付成功!'; } } } else { $reprice = $fee; $data['status'] = 0; load()->model('mc'); $result_c = mc_credit_update($_W['member']['uid'], 'credit2', $reprice); $result_mess = '支付失败,已退款!'; } } load()->model('account'); $access_token = WeAccount::token(); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $url2 = $_W['siteroot'] . 'app/' . $this->createMobileUrl('myorder'); //点击模板详情跳转的地址url2 $time = date("Y-m-d H:i:s", time()); $openid = trim($_W['openid']); $msg_json = '{ "touser":"******", "template_id":"' . $this->module['config']['succ_mess'] . '", "url":"' . $url2 . '", "topcolor":"#FF0000", "data":{ "first":{ "value":"恭喜您,成功参与一元夺宝!", "color":"#0099FF" }, "orderMoneySum":{ "value":"' . $fee . '元", "color":"#0099FF" }, "orderProductName":{ "value":"' . $sidm['title'] . '", "color":"#0099FF" }, "Remark":{ "value":"点击查看订单详情", "color":"#0099FF" } } }'; include_once 'message.php'; $sendmessage = new WX_message(); $res = $sendmessage->WX_request($url, $msg_json); pdo_update('feng_record', $data, array('id' => $params['tid'])); } } if ($params['from'] == 'return') { $order = pdo_fetch("SELECT * FROM " . tablename('feng_record') . " WHERE id ='{$params['tid']}'"); //获取商品ID if ($order['status'] != 1) { if ($params['result'] == 'success') { $data['status'] = 1; $codes = pdo_fetch("SELECT * FROM " . tablename('feng_goodscodes') . " WHERE s_id ='{$order['sid']}'"); //获取商品code $sidm = pdo_fetch("SELECT * FROM " . tablename('feng_goodslist') . " WHERE id ='{$order['sid']}'"); //获取商品详情 $s_codes = unserialize($codes['s_codes']); //转换商品code $c_number = intval($codes['s_len']); if ($c_number > 0) { if ($fee < $c_number) { //计算购买的夺宝码 $data['s_codes'] = array_slice($s_codes, 0, $fee); $data['s_codes'] = serialize($data['s_codes']); $r_codes['s_len'] = $c_number - $fee; $r_codes['s_codes'] = array_slice($s_codes, $fee, $r_codes['s_len']); $r_codes['s_codes'] = serialize($r_codes['s_codes']); $sid_mess['canyurenshu'] = $sidm['canyurenshu'] + $fee; $sid_mess['shengyurenshu'] = $sidm['shengyurenshu'] - $fee; $sid_mess['scale'] = round($sid_mess['canyurenshu'] / $sidm['zongrenshu'] * 100); //执行数据库更新 pdo_update('feng_goodscodes', $r_codes, array('id' => $codes['id'])); pdo_update('feng_goodslist', $sid_mess, array('id' => $sidm['id'])); $result_mess = '支付成功!'; } elseif ($fee >= $c_number) { $data['s_codes'] = $codes['s_codes']; /*$data['s_codes']=serialize($data['s_codes']);*/ $r_codes['s_len'] = 0; $r_codes['s_codes'] = NULL; //计算获奖的code和获奖人 $s_record = pdo_fetchall("SELECT * FROM " . tablename('feng_record') . " WHERE uniacid = '{$_W['uniacid']}' and sid ='{$order['sid']}'"); //获取商品所有交易记录 if (empty($sidm['q_user_code'])) { $wincode = mt_rand(1, $sidm['zongrenshu']); $wincode = $wincode + 1000000; } else { $wincode = $sidm['q_user_code']; } //计算获奖人 foreach ($s_record as $value) { $ss_codes = unserialize($value['s_codes']); //转换商品code for ($i = 0; $i < count($ss_codes); $i++) { if ($ss_codes[$i] == $wincode) { $sid_mess['q_user'] = $value['from_user']; break; } } } if (empty($sid_mess['q_user'])) { $ss_codes = unserialize($data['s_codes']); //转换商品code for ($i = 0; $i < count($ss_codes); $i++) { if ($ss_codes[$i] == $wincode) { $sid_mess['q_user'] = $_W['fans']['from_user']; break; } } } $sid_mess['canyurenshu'] = $sidm['zongrenshu']; $sid_mess['shengyurenshu'] = 0; $sid_mess['q_user_code'] = $wincode; $pro_m = pdo_fetch("SELECT * FROM " . tablename('feng_member') . " WHERE uniacid = '{$_W['uniacid']}' and from_user ='******'q_user']}'"); //用户信息 $sid_mess['q_uid'] = $pro_m['nickname']; $sid_mess['status'] = 1; $sid_mess['q_end_time'] = TIMESTAMP; $sid_mess['scale'] = 100; //模板消息推送 load()->model('account'); $access_token = WeAccount::token(); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $json_data = array('touser' => $sid_mess['q_user'], 'template_id' => $this->module['config']['win_mess'], 'url' => $_W['siteroot'] . 'app/' . $this->createMobileUrl('prize'), 'topcolor' => '#FF0000', "data" => array("title" => array('value' => '尊敬的客户', 'color' => '#173177'), "headinfo" => array('value' => '恭喜您,中奖啦!', 'color' => '#FF0000'), "program" => array('value' => '一元夺宝', 'color' => '#FF0000'), "result" => array('value' => '获得了我们的大奖', 'color' => '#FF0000'), "remark" => array('value' => '点击进入查看中奖详情,祝你生活愉快!', 'color' => '#173177'))); $msg_json = json_encode($json_data); include_once 'message.php'; $sendmessage = new WX_message(); $res = $sendmessage->WX_request($url, $msg_json); //生成新一期商品 if ($sidm['periods'] <= $sidm['maxperiods']) { $new_sid = array('uniacid' => $_W['uniacid'], 'sid' => $sidm['sid'], 'title' => $sidm['title'], 'price' => $sidm['price'], 'zongrenshu' => $sidm['zongrenshu'], 'canyurenshu' => 0, 'shengyurenshu' => $sidm['zongrenshu'], 'periods' => $sidm['periods'] + 1, 'maxperiods' => $sidm['maxperiods'], 'picarr' => $sidm['picarr'], 'content' => $sidm['content'], 'createtime' => TIMESTAMP, 'pos' => $sidm['pos'], 'status' => $sidm['status']); pdo_insert('feng_goodslist', $new_sid); $id = pdo_insertid(); $CountNum = intval($sidm['price']); $new_codes = array(); for ($i = 1; $i <= $CountNum; $i++) { $new_codes[$i] = 1000000 + $i; } shuffle($new_codes); $new_codes = serialize($new_codes); $data1['uniacid'] = $_W['uniacid']; $data1['s_id'] = $id; $data1['s_len'] = $CountNum; $data1['s_codes'] = $new_codes; $data1['s_codes_tmp'] = $new_codes; $ret = pdo_insert('feng_goodscodes', $data1); unset($new_codes); } if ($fee == $c_number) { //执行数据库操作 pdo_update('feng_goodscodes', $r_codes, array('id' => $codes['id'])); pdo_update('feng_goodslist', $sid_mess, array('id' => $sidm['id'])); $result_mess = '支付成功!'; } else { $data['count'] = $c_number; $reprice = $fee - $c_number; load()->model('mc'); $result_c = mc_credit_update($_W['member']['uid'], 'credit2', $reprice); //执行数据库操作 pdo_update('feng_goodscodes', $r_codes, array('id' => $codes['id'])); pdo_update('feng_goodslist', $sid_mess, array('id' => $sidm['id'])); $result_mess = '支付成功!'; } } } else { $reprice = $fee; $data['status'] = 0; load()->model('mc'); $result_c = mc_credit_update($_W['member']['uid'], 'credit2', $reprice); $result_mess = '支付失败,已退款!'; } } load()->model('account'); $access_token = WeAccount::token(); $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $url2 = $_W['siteroot'] . 'app/' . $this->createMobileUrl('myorder'); //点击模板详情跳转的地址url2 $time = date("Y-m-d H:i:s", time()); $openid = trim($_W['openid']); $msg_json = '{ "touser":"******", "template_id":"' . $this->module['config']['succ_mess'] . '", "url":"' . $url2 . '", "topcolor":"#FF0000", "data":{ "first":{ "value":"恭喜您,成功参与一元夺宝!", "color":"#0099FF" }, "orderMoneySum":{ "value":"' . $fee . '元", "color":"#0099FF" }, "orderProductName":{ "value":"' . $sidm['title'] . '", "color":"#0099FF" }, "Remark":{ "value":"点击查看订单详情", "color":"#0099FF" } } }'; include_once 'message.php'; $sendmessage = new WX_message(); $res = $sendmessage->WX_request($url, $msg_json); pdo_update('feng_record', $data, array('id' => $params['tid'])); } $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 payResult($params) { global $_W, $_GPC; $fee = intval($params['fee']); $data = array('status' => $params['result'] == 'success' ? 1 : 0); $paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 2, 'delivery' => 3); $data['pay_type'] = $paytype[$params['type']]; if ($params['type'] == 'wechat') { $data['transid'] = $params['tag']['transaction_id']; } $data['ptime'] = TIMESTAMP; $data['starttime'] = TIMESTAMP; $order_out = pdo_fetch("select * from" . tablename('tg_order') . "where orderno = '{$params['tid']}'"); $goodsInfo = pdo_fetch("SELECT * FROM" . tablename('tg_goods') . "WHERE `id` = :id ", array(':id' => $order_out['g_id'])); $nowtuan = pdo_fetch("select * from" . tablename('tg_group') . "where groupnumber = '{$order_out['tuan_id']}'"); if (!empty($nowtuan)) { if ($nowtuan['lacknum'] == 0 && $order_out['status'] == 0) { $data['status'] = 6; $data['is_tuan'] = 2; echo "<script>location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('more_refund', array('data' => $data, 'orderno' => $params['tid'])) . "';</script>"; exit; } } //后台通知,修改状态 if ($params['result'] == 'success' && $params['from'] == 'notify') { /*支付成功消息模板*/ require_once MB_ROOT . '/source/Message.class.php'; load()->model('account'); $access_token = WeAccount::token(); $url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $url2 = $_W['siteroot'] . 'app/' . $this->createMobileUrl('myorder', array('id' => $order_out['id'])); $sendmessage = new Message(); $res = $sendmessage->pay_success($order_out['openid'], $order_out['orderno'], $goodsInfo['gname'], $this, $url1, $url2); /*支付成功模板消息*/ if ($order_out['status'] == 0) { pdo_update('tg_order', $data, array('orderno' => $params['tid'])); if ($order_out['is_tuan'] == 0) { pdo_update('tg_order', array('status' => 2), array('orderno' => $params['tid'])); } else { if ($nowtuan['lacknum'] > 0) { pdo_update('tg_group', array('lacknum' => $nowtuan['lacknum'] - 1), array('groupnumber' => $order_out['tuan_id'])); } } // 更改库存 if ($goodsInfo['gnum'] == 1) { pdo_update('tg_goods', array('gnum' => $goodsInfo['gnum'] - 1, 'salenum' => $goodsInfo['salenum'] + 1, 'isshow' => 0), array('id' => $order_out['g_id'])); } elseif (!empty($goodsInfo['gnum'])) { pdo_update('tg_goods', array('gnum' => $goodsInfo['gnum'] - 1, 'salenum' => $goodsInfo['salenum'] + 1), array('id' => $order_out['g_id'])); } } $now = pdo_fetch("select * from" . tablename('tg_group') . "where groupnumber = '{$order_out['tuan_id']}'"); if (!empty($now) && $now['lacknum'] == 0) { pdo_update('tg_group', array('groupstatus' => 2), array('groupnumber' => $now['groupnumber'])); pdo_update('tg_order', array('status' => 2), array('tuan_id' => $now['groupnumber'], 'status' => 1)); /*组团成功成功消息模板*/ require_once MB_ROOT . '/source/Message.class.php'; load()->model('account'); $access_token = WeAccount::token(); $url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $url2 = ''; $sendmessage = new Message(); $res = $sendmessage->group_success($order_out['tuan_id'], $this, $url1, $url2); /*组团成功模板消息*/ //获取所有打印机 $prints = pdo_fetchall('SELECT * FROM ' . tablename('tg_print') . ' WHERE uniacid = :aid AND status = 1', array(':aid' => $_W['uniacid'])); if (!empty($prints)) { include_once MB_ROOT . '/source/wprint.class.php'; //遍历所有打印机 foreach ($prints as $li) { if (!empty($li['print_no']) && !empty($li['key'])) { $wprint = new wprint(); $alltuan = pdo_fetchall("select * from" . tablename('tg_order') . "where tuan_id = '{$now['groupnumber']}' and status = 2 "); if ($li['mode'] == 1) { $orderinfo .= "<CB>组团成功</CB><BR>"; $orderInfo .= "商品信息:<BR>"; $orderinfo .= '------------------------------<BR>'; $orderinfo .= "商品名称:{$goodsInfo['gname']}<BR>"; $orderinfo .= '------------------------------<BR>'; $orderinfo .= "用户信息:<BR>"; $orderinfo .= '------------------------------<BR>'; foreach ($alltuan as $row) { $orderinfo .= "用户名:{$row['addname']}<BR>"; $orderinfo .= "手机号:{$row['mobile']}<BR>"; $orderinfo .= "地址:{$row['address']}<BR>"; $orderinfo .= '------------------------------<BR>'; } $status = $wprint->StrPrint($li['print_no'], $li['key'], $orderinfo, $li['print_nums']); } else { $orderinfo .= "组团成功"; $orderInfo .= "商品信息:"; $orderinfo .= '------------------------------'; $orderinfo .= "商品名称:{$goodsInfo['gname']}"; $orderinfo .= '------------------------------'; $orderinfo .= "用户信息:"; $orderinfo .= '------------------------------'; foreach ($alltuan as $row) { $orderinfo .= "用户名:{$row['addname']}"; $orderinfo .= "手机号:{$row['mobile']}"; $orderinfo .= "地址:{$row['address']}"; $orderinfo .= '------------------------------'; } $status = $wprint->testSendFreeMessage($li['member_code'], $li['print_no'], $li['key'], $orderinfo); } } } } } } //前台通知 if ($params['from'] == 'return') { $setting = uni_setting($_W['uniacid'], array('creditbehaviors')); $credit = $setting['creditbehaviors']['currency']; if ($params['type'] == $credit) { if ($order_out['is_tuan'] == 0) { echo "<script> location.href='" . $this->createMobileUrl('myorder', array('payreslut' => 'success')) . "';</script>"; exit; } else { echo "<script> location.href='" . $this->createMobileUrl('group', array('tuan_id' => $order_out['tuan_id'], 'payreslut' => 'success')) . "';</script>"; exit; } } else { if ($order_out['is_tuan'] == 0) { echo "<script> location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('myorder', array('payreslut' => 'success')) . "';</script>"; exit; } else { echo "<script> location.href='" . $_W['siteroot'] . 'app/' . $this->createMobileUrl('group', array('tuan_id' => $order_out['tuan_id'], 'payreslut' => 'success')) . "';</script>"; exit; } } } }
public function doMobilet() { global $_W, $_GPC, $codeca, $codeset, $luckset, $ckey, $settings, $webset; $settings = $this->module['config']; $batch = array(); load()->classs('weixin.account'); $access_token = WeAccount::token(); load()->func('communication'); if (strlen($settings['wapcss']) < 1) { $settings['wapcss'] = 'default'; } if (empty($_W['openid'])) { $appid = $_W['account']['key']; $oauth2_code = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . urlencode($_W['siteurl']) . "&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect"; header("location:{$oauth2_code}"); exit; } if (empty($_W['fans']['follow'])) { $oauth2_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $_W['openid'] . "&lang=zh_CN"; $content = ihttp_get($oauth2_url); $info = @json_decode($content['content'], true); if (empty($info) || !is_array($info) || empty($info['openid'])) { $_W['fans']['follow'] = 0; } else { $_W['fans']['follow'] = $info['subscribe']; $_W['fans']['nickname'] = $info['nickname']; } } if (empty($_W['fans']['follow'])) { if (empty($settings['link'])) { $settings['link'] = $_W['account']['qrcode']; } else { $settings['link'] = $_W['attachurl'] . $settings['link']; } include $this->template($settings['wapcss'] . '/comeon'); exit; } $content = $_GPC['co']; $openid = $_W['openid']; if ($_GPC['u'] == 'i') { $casel = "微站"; $ctapy = 6; } else { $casel = "扫一扫"; $ctapy = 3; } $fans = pdo_fetch("SELECT * FROM " . tablename('mc_mapping_fans') . " WHERE uniacid=:uniacid AND openid=:openid", array(':uniacid' => $_W['uniacid'], ':openid' => $openid)); $member = pdo_fetch("SELECT * FROM " . tablename('mc_members') . " WHERE uniacid=:uniacid AND uid=:uid", array(':uniacid' => $_W['uniacid'], ':uid' => $fans['uid'])); if (empty($member['resideprovince']) && !empty($info['province'])) { $member['resideprovince'] = $info['province']; } if (empty($member['residecity']) && !empty($info['city'])) { $member['residecity'] = $info['city']; } if (empty($member['gender']) && !empty($info['sex'])) { $member['gender'] = $info['sex']; } if ((int) $settings['ischuanhuo'] > 0 && !empty($_W['clientip'])) { } $fgltxt = "查询失败,你输入的不是有效的防伪码!"; $mm = strtoupper($content); $mm = str_replace("-", "", str_replace(" ", "", str_replace("-", "", str_replace(" ", "", str_replace(".", "", $mm))))); $fglact = 0; $fglnum = 0; $fglttt = 0; $a = substr($mm, 2, $codeset['m'][5] - 2); if (empty($settings['welcome'])) { $settings['welcome'] = '欢迎您进入本公司商品防伪查询!'; } if (empty($settings['con_msg'])) { $settings['con_msg'] = '查询失败,查不到该防伪码!请仔细核对!'; } if (empty($settings['luckname'])) { $settings['luckname'] = "积分"; } if (empty($settings['welcometxt'])) { $settings['welcometxt'] = "现在请刮开防伪标上的涂层,\n直接在微信回复" . $codeset['m'][5] . "位防伪密码\n(英文字母要区分大小写,不要输入空格),\n您将可以参加" . $settings['luckname'] . "活动!\n"; } if ($mm == "微信防伪") { $fgltle = $settings['welcome']; $fgltxt = $settings['welcometxt']; $fglurl = ""; $fglttt = 1; } elseif ($mm == $codeset['m'][1] . "000") { $fgltle = $settings['welcome']; $fgltxt = $settings['welcometxt']; $fglurl = ""; $fglttt = 1; } elseif (strlen($mm) != (int) $codeset['m'][5] && strlen($mm) != 18) { $fgltxt = $settings['con_msg'] . "\n"; $fglttt = 1; } elseif (!is_numeric($a)) { $fgltxt = $settings['con_msg'] . "\n"; $fglttt = 1; } if ($fglttt == 0) { $insert = array('cid' => $_W['uniacid'], 'cod' => $mm); $a = ihttp_post($codeca . '&ac=5', $insert); if (strlen($a['content']) > 5) { $a = @json_decode($a['content'], true); } if ($a['content'] == '3') { if ($a['isok'] == '8') { if (strlen($a['mm']) == (int) $codeset['m'][5]) { $mm = $a['mm']; } $batchid = substr($mm, strlen($codeset['m'][1]), (int) $codeset['m'][2]); $batch = pdo_fetch("SELECT * FROM " . tablename('zmcn_fw_batch') . " WHERE uniacid=:uniacid AND batch=:batch", array(':uniacid' => $_W['uniacid'], ':batch' => $batchid)); if (!empty($batch['id'])) { $codeset['m'][1] = substr($mm, 0, 2); $fgltxt = "1密码正确!"; $record = pdo_fetch("SELECT COUNT(*) AS number ,id , num , addtime , userid ,isvalid FROM " . tablename('zmcn_fw_chai') . " WHERE uniacid=:uniacid AND code=:code", array(':uniacid' => $_W['uniacid'], ':code' => $mm)); $fglact = 1; $fglcong = 0; if (empty($record['number'])) { $fglnum = 1; $fglcong = 1; $fglpp = 2; $data = array('uniacid' => $_W['uniacid'], 'code' => $mm, 'type' => $ctapy, 'num' => 1, 'addtime' => $_W['timestamp'], 'userna' => $openid, 'userid' => $fans['uid'], 'ip' => $_W['clientip'], 'gender' => $member['gender'], 'province' => $member['resideprovince'], 'city' => $member['residecity'], 'os' => $_W['os'], 'container' => $_W['container']); pdo_insert('zmcn_fw_chai', $data); } else { $fglnum = $record['num'] + 1; } $history = pdo_fetch("SELECT COUNT(*) AS number,id FROM " . tablename('zmcn_fw_history') . " WHERE uniacid=:uniacid AND summary=:summary AND type=0 AND uid=:uid AND addtime>:addtime", array(':uniacid' => $_W['uniacid'], ':summary' => $mm, ':uid' => $fans['uid'], ':addtime' => $_W['timestamp'] - 21)); if (empty($history['number'])) { $data1 = array('uniacid' => $_W['uniacid'], 'type' => 0, 'summary' => $mm, 'uid' => $fans['uid'], 'addtime' => $_W['timestamp'], 'ip' => $_W['clientip'], 'remark' => "第" . $fglnum . "次" . $casel . ":" . $member['resideprovince'] . "·" . $member['residecity']); pdo_insert('zmcn_fw_history', $data1); $data = array('num' => $fglnum); pdo_update('zmcn_fw_chai', $data, array('id' => $record['id'])); $fglpp = 1; } elseif ($fglnum == 2) { $fglcong = 1; } } else { $fgltxt = "查询失败,查不到些商品,这可能商家还未录入相关商品资料!\n"; $fglttt = 1; } } else { $fgltxt = $settings['con_msg'] . "\n"; $fglttt = 1; } } else { $fgltxt = "查询中断,防伪码数据库连接失败(" . $a . "),这是网通信故障,与商品真伪无关,请稍候再查询!"; $fglttt = 1; } } if ($fglact == 1) { if ($fglcong == 1) { if (empty($settings['suc_one'])) { $settings['suc_one'] = '查询成功,该码为首次查询,请放心使用!'; } $fgltxt = "查询结果:" . $settings['suc_one'] . "\n"; $fgltle = $settings['suc_one']; } elseif ((int) $_W['timestamp'] > (int) $batch['validity'] || $record['isvalid'] == 1) { if (empty($settings['suc_three'])) { $settings['suc_three'] = $settings['con_msg'] . "\n"; } $fgltxt = "查询结果:" . $settings['suc_three'] . "\n"; $fgltle = $settings['suc_three']; $fglact = 0; } else { if ((int) $settings['upperlimit'] > 0 && (int) $record['num'] > (int) $settings['upperlimit']) { if (empty($settings['suc_three'])) { $settings['suc_three'] = '查询失败,该码因查询次数过多,已经失效!'; } $fgltxt = "查询结果:" . $settings['suc_three'] . "\n"; $fgltle = $settings['suc_three']; $fglact = 0; } else { if (empty($settings['suc_two'])) { $settings['suc_two'] = '查询成功,该码为非首次查询,谨防假冒!'; } $fgltxt = "查询结果:该码为多次查询,\n首次时间:" . date('Y-m-d H:i:s', $record['addtime']) . "\n"; $fgltle = $settings['suc_two']; } } } if ($fglact == 1) { $params = iunserializer($batch['param']); if ($batch['product'] != "") { $fgltxt .= "产品名称:" . $batch['product'] . "\n"; } if ($batch['factory'] != "") { $fgltxt .= "企业名称:" . $batch['factory'] . "\n"; } if ($batch['brand'] != "") { $fgltxt .= "产品品牌:" . $batch['brand'] . "\n"; } if ($settings['ischuanhuo'] > 0) { if ($batch['ischuanhuo'] == 0) { } } foreach ($params as $param) { $fgltxt .= $param['title'] . ":" . $param['value'] . "\n"; } if ($settings['ftel'] != "") { $fgltxt .= "客服电话:" . $settings['ftel'] . "\n"; } if ($settings['dtel'] != "") { $fgltxt .= "打假电话:" . $settings['dtel'] . "\n"; } if ($settings['script'] != "") { $fgltxt .= $settings['script'] . "\n"; } if ($batch['buylink'] != "") { $fglurl = $batch['buylink']; } else { $fglurl = $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=mc"; } } if ($fglnum == 1) { pdo_query("update " . tablename('zmcn_fw_batch') . " set rcon = rcon + 1 where id=" . $batch['id']); if ($batch['inttype'] == 0 && $settings['isluck'] == 1) { $luckno = mt_rand(10000, 99999); $list = pdo_fetch("SELECT * FROM " . tablename('zmcn_fw_set') . " WHERE uniacid=" . $_W['uniacid']); $luckset = iunserializer($list['luck']); $jj = 0; $tt = ""; for ($i = 1; $i < 6; ++$i) { $tmparray = explode($luckset[$i]['m'], $luckno); if (count($tmparray) > 1) { $jj = $luckset[$i]['i']; $tt = $luckset[$i]['t']; break; } } if (empty($settings['luckname'])) { $settings['luckname'] = '码上抽奖'; } if ($jj == 0) { $jj = $luckset[0]['i']; $tt = $luckset[0]['t']; } $fgltxt .= $settings['luckname'] . "活动:抽奖码(" . $luckno . ")奖励:" . zmcn_get_int($settings['inttype'], $jj) . "\n"; mc_credit_update($fans['uid'], 'credit' . $settings['inttype'], $jj, array(0 => $fans['uid'], 1 => '微防伪:' . $settings['luckname'] . '活动')); $fgltxt .= $tt . "\n"; } else { if ($batch['integral'] > 0) { if ($batch['inttype'] == 0) { $batch['inttype'] = 1; } mc_credit_update($fans['uid'], 'credit' . $batch['inttype'], $batch['integral'], array(0 => $fans['uid'], 1 => '微防伪:查询' . $mm . '奖励')); $fgltxt .= "防伪码查询奖励:" . zmcn_get_int($batch['inttype'], $batch['integral']) . "\n"; } } } elseif ($fglcong == 1) { $record = pdo_fetch("SELECT num,remark,credittype,createtime FROM " . tablename('mc_credits_record') . " WHERE uniacid=:uniacid AND uid=:uid AND operator=:operator AND remark LIKE '微防伪:%' ORDER BY id DESC", array(':uniacid' => $_W['uniacid'], ':uid' => $fans['uid'], ':operator' => $fans['uid'])); $fgltxt .= $record['remark'] . zmcn_get_int(substr($record['credittype'], -1), $record['num']) . "\n"; } elseif ($fglact == 1) { if ($settings['ishistory'] >= 1) { $fgltxt .= "近期查询记录:\n"; $history = pdo_fetchall("SELECT * FROM " . tablename('zmcn_fw_history') . " WHERE uniacid=:uniacid AND type = 0 AND summary=:summary ORDER BY id DESC LIMIT " . $settings['ishistory'], array(':uniacid' => $_W['uniacid'], ':summary' => $mm)); for ($i = 0; $i < count($history); ++$i) { $fgltxt .= $history[$i]['remark'] . "(" . date('y-m-d h:i:s', $history[$i]['addtime']) . ")\n"; } } } if (strlen($batch['banner']) < 5) { $batch['banner'] = $settings['banner']; } if (strlen($batch['logo']) < 5) { $batch['logo'] = $settings['logo']; } if ($fglact == 1) { if ($settings['islink'] == 1) { $toshop = iunserializer($batch['toshop']); if (strlen($batch['buylink']) > 20) { $fglurl = $batch['buylink']; } elseif ($toshop['shioip'] == 0) { $fglurl = $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=mc&a=bond&do=credits&credittype=credit1&wxref=mp.weixin.qq.com#wechat_redirect"; } elseif ($toshop['shioip'] == 1) { $fglurl = $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&do=detail&m=ewei_shopping&id=" . $toshop['proid']; } elseif ($toshop['shioip'] == 2) { $fglurl = $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=mc&a=bond&do=credits&credittype=credit1&wxref=mp.weixin.qq.com#wechat_redirect"; } $abcd = array('title' => $fgltle, 'description' => $fgltxt, 'picUrl' => $fglpic, 'url' => $fglurl); $articles = array($abcd); $kfxx = array('touser' => $_W['openid'], 'msgtype' => "news", 'news' => array('articles' => $articles)); $postarr = encode_json($kfxx); if ($fglpp == 1 && !empty($access_token)) { $res = ihttp_post('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token, $postarr); $res = @json_decode($res['content'], true); if ((int) $res['errcode'] > 0) { $abcd = array('first' => array('value' => $settings['welcome'], 'color' => '#173177'), 'keyword1' => array('value' => '商品防伪鉴别', 'color' => '#173177'), 'keyword2' => array('value' => $fgltle, 'color' => '#000000'), 'remark' => array('value' => '亲!可能是因为你太长时间没来活动,所以系统发不出更详细的资料,请点菜单或回复几个字后再查!', 'color' => '#173177')); $kfxx = array('touser' => $_W['openid'], 'template_id' => $settings['template_id'], 'url' => $fglurl, 'topcolor' => '#FF0000', 'data' => $abcd); $postarr = encode_json($kfxx); $res = ihttp_post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token, $postarr); } } header('location:' . $fglurl); exit; } else { $fgltxt = str_replace(chr(10), '<br>', $fgltxt); $fgltxt = str_replace(chr(13), '<br>', $fgltxt); include $this->template($settings['wapcss'] . '/authentic'); } } else { include $this->template($settings['wapcss'] . '/err'); } }