public function payResult($params) { global $_W; $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['result'] == 'success') { $data['pay_time'] = TIMESTAMP; } pdo_update('daijia_orders', $data, array('ordersn' => $params['tid'])); if ($params['from'] == 'return') { $setting = uni_setting($_W['uniacid'], array('creditbehaviors')); $credit = $setting['creditbehaviors']['currency']; //支付成功,打印订单 $order = pdo_fetch("SELECT * FROM " . tablename('daijia_orders') . "where ordersn={$params['tid']}"); //获取所有打印机 $prints = pdo_fetchall('SELECT * FROM ' . tablename('daijia_print') . ' WHERE uniacid = :aid AND status = 1', array(':aid' => $_W['uniacid'])); if (empty($prints)) { // exit('没有有效的打印机'); } $paytype = $order['paytype'] == '3' ? '货到付款' : '已付款'; $ordertype = $order['type'] == 'daijia' ? '代驾' : '代劳、代步'; //邮件提醒 $orderinfo = ''; $orderinfo .= '订单编号 起始地址 目的地址 价格 备注<BR>'; $orderinfo .= '--------------------------------<BR>'; $orderInfo .= "{$order['ordersn']}{$order['start_address']}{$order['end_address']}{$order['price']}{$order['remark']}<br />"; $orderInfo .= '--------------------------------<BR>'; $orderinfo .= "合计:{$order['price']}元<BR>"; $orderinfo .= "联系电话:{$order['mobile']}<BR>"; $orderinfo .= "支付方式:{$paytype}<BR>"; //微信提醒 $sendinfo = '您的订单支付成功,请等待处理:\\n'; $sendinfo .= '--------------------\\n'; $sendinfo .= "{$ordertype}详情:\n"; $sendinfo .= '--------------------\\n'; $sendinfo .= "订单编号:{$order['ordersn']}\n"; $sendinfo .= "起始地址: {$order['start_address']}\n"; $sendinfo .= "目的地址: {$order['end_address']}\n"; $sendinfo .= "备注: {$order['remark']}\n"; $sendinfo .= '--------------------\\n'; $sendinfo .= "合计:{$order['price']}元\n"; $sendinfo .= "联系电话:{$order['mobile']}\n"; $sendinfo .= "支付方式:{$paytype}\n"; //发送微信提醒 $send['msgtype'] = 'text'; $send['text'] = array('content' => urlencode($sendinfo)); $acc = WeAccount::create($_W['account']['acid']); $send['touser'] = trim($_W['openid']); $s_mess = $acc->sendCustomNotice($send); include 'wprint.class.php'; //遍历所有打印机 foreach ($prints as $li) { if (!empty($li['qrcode_link'])) { $orderinfo .= "<QR>{$li['qrcode_link']}</QR>"; } if (!empty($li['print_no']) && !empty($li['key'])) { $wprint = new wprint(); $status = $wprint->StrPrint($li['print_no'], $li['key'], $orderinfo, 1); if (!is_error($status)) { $i++; $data2 = array('uniacid' => $_W['uniacid'], 'sid' => $sid, 'pid' => $li['id'], 'oid' => $id, 'status' => 1, 'aid' => $status, 'addtime' => TIMESTAMP); pdo_insert('daijia_order_print', $data2); } } } // if($i > 0) { // pdo_query('UPDATE ' . tablename('str_order') . " SET print_nums = print_nums + {$i} WHERE uniacid = {$_W['uniacid']} AND id = {$id}"); // } else { // exit('发送打印指令失败。没有有效的机器号'); // } // exit('success'); //打印结束 if ($params['type'] == $credit) { message('支付成功!', $this->createMobileUrl('daijia', array('op' => 'yes')), 'success'); } else { message('支付成功!', '../../app/' . $this->createMobileUrl('daijia', array('op' => 'yes')), 'success'); } } }
public function payResult($params) { global $_W; $fee = intval($params['fee']); $data = array('status' => $params['result'] == 'success' ? 1 : 0); $paytype = array('credit' => '1', 'wechat' => '2', 'alipay' => '2', 'delivery' => '3'); // 卡券代金券备注 if (!empty($params['is_usecard'])) { $cardType = array('1' => '微信卡券', '2' => '系统代金券'); $data['paydetail'] = '使用' . $cardType[$params['card_type']] . '支付了' . ($params['fee'] - $params['card_fee']); $data['paydetail'] .= '元,实际支付了' . $params['card_fee'] . '元。'; } $data['paytype'] = $paytype[$params['type']]; if ($params['type'] == 'wechat') { $data['transid'] = $params['tag']['transaction_id']; } if ($params['type'] == 'delivery') { $data['status'] = 1; } $sql = 'SELECT `goodsid` FROM ' . tablename('shopping_order_goods') . ' WHERE `orderid` = :orderid'; $goodsId = pdo_fetchcolumn($sql, array(':orderid' => $params['tid'])); $sql = 'SELECT `total`, `totalcnf` FROM ' . tablename('shopping_goods') . ' WHERE `id` = :id'; $goodsInfo = pdo_fetch($sql, array(':id' => $goodsId)); // 更改库存 if ($goodsInfo['totalcnf'] == '1' && !empty($goodsInfo['total'])) { pdo_update('shopping_goods', array('total' => $goodsInfo['total'] - 1), array('id' => $goodsId)); } pdo_update('shopping_order', $data, array('id' => $params['tid'])); if ($params['from'] == 'return') { //积分变更 $this->setOrderCredit($params['tid']); $order = pdo_fetch("SELECT `price`, `paytype`, `from_user`, `addressid` FROM " . tablename('shopping_order') . " WHERE id = '{$params['tid']}'"); $ordergoods = pdo_fetchall("SELECT goodsid, total FROM " . tablename('shopping_order_goods') . " WHERE orderid = '{$params['tid']}'", array(), 'goodsid'); $goods = pdo_fetchall("SELECT id, title, thumb, marketprice, unit, total FROM " . tablename('shopping_goods') . " WHERE id IN ('" . implode("','", array_keys($ordergoods)) . "')"); $address = pdo_fetch("SELECT * FROM " . tablename('shopping_address') . " WHERE id = :id", array(':id' => $order['addressid'])); if (!empty($this->module['config']['noticeemail']) || !empty($this->module['config']['mobile'])) { $body = "<h3>购买商品清单</h3> <br />"; if (!empty($goods)) { foreach ($goods as $row) { $body .= "名称:{$row['title']} ,数量:{$ordergoods[$row['id']]['total']} <br />"; } } $paytype = $order['paytype'] == '3' ? '货到付款' : '已付款' . '<br />'; $body .= '总金额:' . $order['price'] . '元' . $paytype . '<br />'; $body .= '<h3>购买用户详情</h3> <br />'; $body .= '真实姓名:' . $address['realname'] . '<br />'; $body .= '地区:' . $address['province'] . ' - ' . $address['city'] . ' - ' . $address['area'] . '<br />'; $body .= '详细地址:' . $address['address'] . '<br />'; $body .= '手机:' . $address['mobile'] . '<br />'; // 邮件提醒 if (!empty($this->module['config']['noticeemail'])) { load()->func('communication'); ihttp_email($this->module['config']['noticeemail'], '微商城订单提醒', $body); } // 短信提醒 if (!empty($this->module['config']['mobile'])) { load()->model('cloud'); $body = str_replace(array('<h3>', '</h3>', '<br />'), array('', '', "\n"), $body); cloud_sms_send($this->module['config']['mobile'], $body); } } //支付成功,打印订单 if (empty($order)) { exit('订单不存在或已经删除'); } //获取所有打印机 $prints = pdo_fetchall('SELECT * FROM ' . tablename('shopping_print') . ' WHERE uniacid = :aid AND status = 1', array(':aid' => $_W['uniacid'])); if (empty($prints)) { // exit('没有有效的打印机'); } $orderinfo = ''; $orderinfo .= '名称 单价 数量 金额<BR>'; $orderinfo .= '--------------------------------<BR>'; foreach ($goods as $row) { $orderInfo .= "{$row['title']}{$row['marketprice']}{$ordergoods[$row['id']]['total']}{$order['price']} <br />"; } $orderInfo .= '--------------------------------<BR>'; $orderinfo .= "合计:{$order['price']}元<BR>"; $orderinfo .= "下单人:{$address['realname']}<BR>"; $orderinfo .= "地址:{$address['province']} - {$address['city']} - {$address['area']} {$address['address']} <BR>"; $orderinfo .= "联系电话:{$address['mobile']}<BR>"; $orderinfo .= "支付方式:{$order['paytype']}<BR>"; include 'wprint.class.php'; //遍历所有打印机 foreach ($prints as $li) { if (!empty($li['qrcode_link'])) { $orderinfo .= "<QR>{$li['qrcode_link']}</QR>"; } if (!empty($li['print_no']) && !empty($li['key'])) { $wprint = new wprint(); $status = $wprint->StrPrint($li['print_no'], $li['key'], $orderinfo, 1); 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('shopping_order_print', $data); } } } // if($i > 0) { // pdo_query('UPDATE ' . tablename('str_order') . " SET print_nums = print_nums + {$i} WHERE uniacid = {$_W['uniacid']} AND id = {$id}"); // } else { // exit('发送打印指令失败。没有有效的机器号'); // } // exit('success'); //打印结束 $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']; } $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 doWebManage() { global $_W, $_GPC; $op = trim($_GPC['op']) ? trim($_GPC['op']) : 'cate_list'; $sid = intval($_GPC['__sid']); $store = pdo_fetch('SELECT id, title FROM ' . tablename('str_store') . ' WHERE uniacid = :aid AND id = :id', array(':aid' => $_W['uniacid'], ':id' => $sid)); if (empty($store)) { message('门店信息不存在或已删除', $this->createWebUrl('store'), 'error'); } $pay_types = array('alipay' => '支付宝支付', 'wechat' => '微信支付', 'credit' => '余额支付', 'delivery' => '餐到付款'); if ($op == 'cate_list') { $condition = ' uniacid = :aid AND sid = :sid'; $params[':aid'] = $_W['uniacid']; $params[':sid'] = $sid; if (!empty($_GPC['keyword'])) { $condition .= " AND title LIKE '%{$_GPC['keyword']}%'"; } $pindex = max(1, intval($_GPC['page'])); $psize = 20; $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('str_dish_category') . ' WHERE ' . $condition, $params); $lists = pdo_fetchall('SELECT * FROM ' . tablename('str_dish_category') . ' WHERE ' . $condition . ' ORDER BY displayorder DESC,id ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params, 'id'); if (!empty($lists)) { $ids = implode(',', array_keys($lists)); $nums = pdo_fetchall('SELECT count(*) AS num,cid FROM ' . tablename('str_dish') . " WHERE uniacid = :aid AND cid IN ({$ids}) GROUP BY cid", array(':aid' => $_W['uniacid']), 'cid'); } $pager = pagination($total, $pindex, $psize); if (checksubmit('submit')) { if (!empty($_GPC['ids'])) { foreach ($_GPC['ids'] as $k => $v) { $data = array('title' => trim($_GPC['title'][$k]), 'displayorder' => intval($_GPC['displayorder'][$k])); pdo_update('str_dish_category', $data, array('uniacid' => $_W['uniacid'], 'id' => intval($v))); } message('编辑成功', $this->createWebUrl('manage', array('op' => 'cate_list')), 'success'); } } include $this->template('category'); } elseif ($op == 'cate_post') { if (checksubmit('submit')) { if (!empty($_GPC['title'])) { foreach ($_GPC['title'] as $k => $v) { $v = trim($v); if (empty($v)) { continue; } $data['sid'] = $sid; $data['uniacid'] = $_W['uniacid']; $data['title'] = $v; $data['displayorder'] = intval($_GPC['displayorder'][$k]); pdo_insert('str_dish_category', $data); } } message('添加菜品分类成功', $this->createWebUrl('manage', array('sid' => $sid, 'op' => 'cate_list')), 'success'); } include $this->template('category'); } elseif ($op == 'cate_del') { $id = intval($_GPC['id']); pdo_delete('str_dish_category', array('uniacid' => $_W['uniacid'], 'sid' => $sid, 'id' => $id)); pdo_delete('str_dish', array('uniacid' => $_W['uniacid'], 'sid' => $sid, 'cid' => $id)); message('删除菜品分类成功', $this->createWebUrl('manage', array('op' => 'cate_list')), 'success'); } elseif ($op == 'dish_list') { $condition = ' uniacid = :aid AND sid = :sid'; $params[':aid'] = $_W['uniacid']; $params[':sid'] = $sid; if (!empty($_GPC['keyword'])) { $condition .= " AND title LIKE '%{$_GPC['keyword']}%'"; } if (!empty($_GPC['cid'])) { $condition .= " AND cid = :cid"; $params[':cid'] = intval($_GPC['cid']); } $pindex = max(1, intval($_GPC['page'])); $psize = 20; $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('str_dish') . ' WHERE ' . $condition, $params); $lists = pdo_fetchall('SELECT * FROM ' . tablename('str_dish') . ' WHERE ' . $condition . ' ORDER BY displayorder DESC,id ASC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params); $pager = pagination($total, $pindex, $psize); $category = pdo_fetchall('SELECT title, id FROM ' . tablename('str_dish_category') . ' WHERE uniacid = :aid AND sid = :sid', array(':aid' => $_W['uniacid'], ':sid' => $sid), 'id'); include $this->template('dish'); } elseif ($op == 'dish_post') { load()->func('tpl'); $category = pdo_fetchall('SELECT title, id FROM ' . tablename('str_dish_category') . ' WHERE uniacid = :aid AND sid = :sid ORDER BY displayorder DESC, id ASC', array(':aid' => $_W['uniacid'], ':sid' => $sid)); $id = intval($_GPC['id']); if ($id) { $item = pdo_fetch('SELECT * FROM ' . tablename('str_dish') . ' WHERE uniacid = :aid AND id = :id', array(':aid' => $_W['uniacid'], ':id' => $id)); if (empty($item)) { message('菜品不存在或已删除', $this->createWebUrl('manage', array('dish_list')), 'success'); } } else { $item['total'] = -1; } if (checksubmit('submit')) { $data = array('sid' => $sid, 'uniacid' => $_W['uniacid'], 'title' => trim($_GPC['title']), 'price' => intval($_GPC['price']), 'total' => intval($_GPC['total']), 'sailed' => intval($_GPC['sailed']), 'is_display' => intval($_GPC['is_display']), 'cid' => intval($_GPC['cid']), 'thumb' => trim($_GPC['thumb']), 'displayorder' => intval($_GPC['displayorder']), 'description' => trim($_GPC['description'])); if ($id) { pdo_update('str_dish', $data, array('uniacid' => $_W['uniacid'], 'id' => $id)); } else { pdo_insert('str_dish', $data); } message('编辑菜品成功', $this->createWebUrl('manage', array('op' => 'dish_list')), 'success'); } include $this->template('dish'); } elseif ($op == 'order') { //获取模块的支付方式 load()->func('tpl'); $condition = ' WHERE uniacid = :aid AND sid = :sid'; $params[':aid'] = $_W['uniacid']; $params[':sid'] = $sid; $status = intval($_GPC['status']); if ($status) { $condition .= ' AND status = :stu'; $params[':stu'] = $status; } $keyword = trim($_GPC['keyword']); if (!empty($keyword)) { $condition .= " AND (username LIKE '%{$keyword}%' OR mobile LIKE '%{$keyword}%')"; } $pay_ty = trim($_GPC['pay_type']); if (!empty($pay_ty)) { $condition .= " AND pay_type = :pay_ty"; $params[':pay_ty'] = $pay_ty; } $pay_sta = trim($_GPC['pay_status']); if (!empty($pay_sta)) { $condition .= " AND pay_status = :pay_sta"; $params[':pay_sta'] = $pay_sta; } if (!empty($_GPC['addtime'])) { $starttime = strtotime($_GPC['addtime']['start']); $endtime = strtotime($_GPC['addtime']['end']) + 86399; } else { $starttime = strtotime('-15 day'); $endtime = TIMESTAMP; } $condition .= " AND addtime > :start AND addtime < :end"; $params[':start'] = $starttime; $params[':end'] = $endtime; $pindex = max(1, intval($_GPC['page'])); $psize = 20; $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('str_order') . $condition, $params); $data = pdo_fetchall('SELECT * FROM ' . tablename('str_order') . $condition . ' ORDER BY addtime DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params); $pager = pagination($total, $pindex, $psize); include $this->template('order'); } elseif ($op == 'orderdetail') { $id = intval($_GPC['id']); $order = pdo_fetch('SELECT * FROM ' . tablename('str_order') . ' WHERE uniacid = :aid AND id = :id', array(':aid' => $_W['uniacid'], ':id' => $id)); if (empty($order)) { message('订单不存在或已经删除', $this->createWebUrl('manage', array('op' => 'order')), 'error'); } else { $order['dish'] = iunserializer($order['dish']); $comment = pdo_fetchall('SELECT * FROM ' . tablename('str_dish_comment') . ' WHERE uniacid = :aid AND oid = :id', array(':aid' => $_W['uniacid'], ':id' => $id), 'did'); } include $this->template('order'); } elseif ($op == 'ajaxorder') { $oid = intval($_GPC['oid']); $status = intval($_GPC['status']); $column = trim($_GPC['column']); $is_exist = pdo_fetch('SELECT id FROM ' . tablename('str_order') . ' WHERE uniacid = :aid AND id = :id', array(':aid' => $_W['uniacid'], ':id' => $oid)); if (empty($is_exist)) { exit('订单不存在'); } pdo_update('str_order', array($column => $status), array('uniacid' => $_W['uniacid'], 'id' => $oid)); exit('success'); } elseif ($op == 'orderdel') { $id = intval($_GPC['id']); pdo_delete('str_order', array('uniacid' => $_W['uniacid'], 'id' => $id)); pdo_delete('str_dish_comment', array('uniacid' => $_W['uniacid'], 'oid' => $id)); message('删除订单成功', $this->createWebUrl('manage', array('op' => 'order')), 'success'); } elseif ($op == 'print_post') { $id = intval($_GPC['id']); if ($id > 0) { $item = pdo_fetch('SELECT * FROM ' . tablename('str_print') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id)); } if (empty($item)) { $item = array('status' => 1, 'print_nums' => 1); } if (checksubmit('submit')) { $data['status'] = intval($_GPC['status']); $data['name'] = !empty($_GPC['name']) ? trim($_GPC['name']) : message('打印机名称不能为空', '', 'error'); $data['print_no'] = !empty($_GPC['print_no']) ? trim($_GPC['print_no']) : message('机器号不能为空', '', 'error'); $data['key'] = !empty($_GPC['key']) ? trim($_GPC['key']) : message('打印机key不能为空', '', 'error'); $data['print_nums'] = intval($_GPC['print_nums']) ? intval($_GPC['print_nums']) : 1; if (!empty($_GPC['qrcode_link']) && (strexists($_GPC['qrcode_link'], 'http://') || strexists($_GPC['qrcode_link'], 'https://'))) { $data['qrcode_link'] = trim($_GPC['qrcode_link']); } $data['uniacid'] = $_W['uniacid']; $data['sid'] = $sid; if (!empty($item) && $id) { pdo_update('str_print', $data, array('uniacid' => $_W['uniacid'], 'id' => $id)); } else { pdo_insert('str_print', $data); } message('更新打印机设置成功', $this->createWebUrl('manage', array('op' => 'print_list')), 'success'); } include $this->template('print'); } elseif ($op == 'print_list') { $data = pdo_fetchall('SELECT * FROM ' . tablename('str_print') . ' WHERE uniacid = :uniacid AND sid = :sid', array(':uniacid' => $_W['uniacid'], ':sid' => $sid)); include $this->template('print'); } elseif ($op == 'print_del') { $id = intval($_GPC['id']); pdo_delete('str_print', array('uniacid' => $_W['uniacid'], 'id' => $id)); message('删除打印机成功', referer(), 'success'); } elseif ($op == 'log_del') { $id = intval($_GPC['id']); pdo_delete('str_order_print', array('uniacid' => $_W['uniacid'], 'id' => $id)); message('删除打印记录成功', referer(), 'success'); } elseif ($op == 'print_log') { $id = intval($_GPC['id']); $item = pdo_fetch('SELECT * FROM ' . tablename('str_print') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id)); if (empty($item)) { message('打印机不存在或已删除', $this->createWebUrl('manage', array('op' => 'print_list')), 'success'); } if (!empty($item['print_no']) && !empty($item['key'])) { include 'wprint.class.php'; $wprint = new wprint(); $status = $wprint->QueryPrinterStatus($item['print_no'], $item['key']); if (is_error($status)) { $status = '查询打印机状态失败。请刷新页面重试'; } } $condition = ' WHERE a.uniacid = :aid AND a.sid = :sid AND a.pid = :pid'; $params[':aid'] = $_W['uniacid']; $params[':sid'] = $sid; $params[':pid'] = $id; if (!empty($_GPC['oid'])) { $oid = trim($_GPC['oid']); $condition .= ' AND a.oid = :oid'; $params[':oid'] = $oid; } $pindex = max(1, intval($_GPC['page'])); $psize = 20; $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('str_order_print') . ' AS a ' . $condition, $params); $data = pdo_fetchall('SELECT a.*,b.username,b.mobile FROM ' . tablename('str_order_print') . ' AS a LEFT JOIN' . tablename('str_order') . ' AS b ON a.oid = b.id' . $condition . ' ORDER BY addtime DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params); $pager = pagination($total, $pindex, $psize); include $this->template('print'); } elseif ($op == 'ajaxprint') { $id = intval($_GPC['id']); $order = pdo_fetch('SELECT * FROM ' . tablename('str_order') . ' WHERE uniacid = :aid AND sid = :sid AND id = :id', array(':aid' => $_W['uniacid'], ':sid' => $sid, ':id' => $id)); if (empty($order)) { exit('订单不存在或已经删除'); } $order['dish'] = iunserializer($order['dish']); $pay_types = array('alipay' => '支付宝支付', 'wechat' => '微信支付', 'credit' => '余额支付', 'delivery' => '餐到付款'); $order['pay_type'] = !empty($pay_types[$order['pay_type']]) ? $pay_types[$order['pay_type']] : '其他支付方式'; //获取该门店的所有打印机 $prints = pdo_fetchall('SELECT * FROM ' . tablename('str_print') . ' WHERE uniacid = :aid AND sid = :sid AND status = 1', array(':aid' => $_W['uniacid'], ':sid' => $sid)); if (empty($prints)) { exit('没有有效的打印机'); } $store = pdo_fetch('SELECT title FROM ' . tablename('str_store') . ' WHERE uniacid = :aid AND id = :sid', array(':aid' => $_W['uniacid'], ':sid' => $sid)); $orderinfo = ''; $orderinfo .= "<CB>{$store['title']}</CB>\n"; $orderinfo .= '名称 单价 数量 金额\\n'; $orderinfo .= '--------------------------------\\n'; if (!empty($order['dish'])) { foreach ($order['dish'] as $di) { $dan = $di['price'] / $di['num']; $orderinfo .= str_pad(cutstr($di['title'], 7), '21', ' ', STR_PAD_RIGHT); $orderinfo .= ' ' . str_pad($dan, '6', ' ', STR_PAD_RIGHT); $orderinfo .= 'X ' . str_pad($di['num'], '3', ' ', STR_PAD_RIGHT); $orderinfo .= ' ' . str_pad($di['price'], '5', ' ', STR_PAD_RIGHT); $orderinfo .= '\\n'; } } if (!empty($order['note'])) { $orderinfo .= '备注:' . $order['note'] . '\\n'; } $orderinfo .= '--------------------------------\\n'; $orderinfo .= "合计:{$order['price']}元\n"; $orderinfo .= "下单人:{$order['username']}\n"; $orderinfo .= "送餐地址:{$order['address']}\n"; $orderinfo .= "联系电话:{$order['mobile']}\n"; $orderinfo .= "支付方式:{$order['pay_type']}\n"; if (!empty($order['delivery_time'])) { $orderinfo .= "送餐时间:{$order['delivery_time']}"; } include 'wprint.class.php'; foreach ($prints as $li) { if (!empty($li['qrcode_link'])) { $orderinfo .= "<QR>{$li['qrcode_link']}</QR>\n"; } if (!empty($li['print_no']) && !empty($li['key'])) { $wprint = new wprint(); $status = $wprint->StrPrint($li['print_no'], $li['key'], $orderinfo, 1); 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('str_order_print', $data); } } } if ($i > 0) { pdo_query('UPDATE ' . tablename('str_order') . " SET print_nums = print_nums + {$i} WHERE uniacid = {$_W['uniacid']} AND id = {$id}"); } else { exit('发送打印指令失败。没有有效的机器号'); } exit('success'); } //账号管理员 if ($op == 'ctrl') { $accounts = uni_accounts(); foreach ($accounts as $k => $li) { if ($li['level'] < 3) { unset($li[$k]); } } $config = pdo_fetch('SELECT notice_acid, groupid FROM ' . tablename('str_store') . ' WHERE uniacid = :uniacid AND id = :sid', array(':uniacid' => $_W['uniacid'], ':sid' => $sid)); if (!empty($config['notice_acid'])) { $groups = pdo_fetch('SELECT * FROM ' . tablename('mc_fans_groups') . ' WHERE uniacid = :uniacid AND acid = :acid', array(':uniacid' => $_W['uniacid'], ':acid' => $config['notice_acid'])); !empty($groups) && ($groups = iunserializer($groups['groups'])); } if (checksubmit('submit')) { $acid = intval($_GPC['acid']); $groupid = intval($_GPC['groupid']); pdo_update('str_store', array('notice_acid' => $acid, 'groupid' => $groupid), array('uniacid' => $_W['uniacid'], 'id' => $sid)); message('设置微信管理员成功', referer(), 'success'); } include $this->template('ctrl'); } if ($op == 'fangroup') { $acid = intval($_GPC['acid']); $data = pdo_fetch('SELECT * FROM ' . tablename('mc_fans_groups') . ' WHERE uniacid = :uniacid AND acid = :acid', array(':uniacid' => $_W['uniacid'], ':acid' => $acid)); $out['errcode'] = 0; $out['errmsg'] = ''; if (empty($data)) { $out['errcode'] = 1; $out['errmsg'] = '请先更新粉丝分组'; exit(json_encode($out)); } $data = iunserializer($data['groups']); $out['errmsg'] = $data; exit(json_encode($out)); } }
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; } } } }