/** * 退单 * $transaction_id 微信订单号 * $out_trade_no 系统订单号 * $total_fee 订单金额 * $refund_fee 退款金额 * */ function refund($data = array()) { $input = new WxPayRefund(); if ($data['transaction_id']) { $input->SetTransaction_id($data['transaction_id']); } if ($data['out_trade_no']) { $input->SetOut_trade_no($data['out_trade_no']); } $input->SetTotal_fee($data['total_fee']); $input->SetRefund_fee($data['refund_fee']); $input->SetOut_refund_no(get_order_sn('zr')); $input->SetOp_user_id(WxPayConfig::MCHID); return WxPayApi::refund($input); }
public function myrefund($transid) { global $_W, $_GPC; include_once 'WxPay.Api.php'; $WxPayApi = new WxPayApi(); $input = new WxPayRefund(); load()->func('communication'); load()->model('account'); $accounts = uni_accounts(); $acid = $_W['uniacid']; $path_cert = '../addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_cert.pem'; //证书路径 $path_key = '../addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_key.pem'; //证书路径 $key = $this->module['config']['apikey']; //商户支付秘钥(API秘钥) $appid = $accounts[$acid]['key']; //身份标识(appid) // $appsecret = $accounts[$acid]['secret'];//身份密钥(appsecret) $mchid = $this->module['config']['mchid']; //微信支付商户号(mchid) $order_out = pdo_fetch("select * from" . tablename('tg_order') . "where transid = '{$transid}'"); $fee = $order_out['price'] * 100; //退款金额 $refundid = $transid; //微信订单号 message("key=" . $key . "appid=" . $appid . "mchid=" . $mchid . "fee=" . $fee . "refundid=" . $refundid); exit; /*$input:退款必须要的参数*/ $input->SetAppid($appid); $input->SetMch_id($mchid); $input->SetOp_user_id($mchid); $input->SetOut_refund_no($mchid . date("YmdHis")); $input->SetRefund_fee($fee); $input->SetTotal_fee($fee); $input->SetTransaction_id($refundid); $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key); if ($result['return_code'] == 'SUCCESS') { return 'success'; } else { return 'fail'; } }
/** * @param $out_trade_no * @return bool * @throws \WxPayException */ public function refund($out_trade_no, $fee) { $WxPayRefund = new \WxPayRefund(); $WxPayRefund->setWxPayApi($this->wxPayApi); $WxPayRefund->SetOut_trade_no($out_trade_no); $WxPayRefund->SetOut_refund_no($out_trade_no); $WxPayRefund->SetTotal_fee($fee); $WxPayRefund->SetRefund_fee($fee); $WxPayRefund->SetOp_user_id($this->wxPayApi->getWxPayConfig()['MCHID']); $result = $this->wxPayApi->refund($WxPayRefund, $this->wxPayConfig['CURL_TIMEOUT']); if ($result['return_code'] == 'FAIL') { //系统出错 throw new \WxPayException("接口调用失败!" . $result['return_msg']); } if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { //退款申请 接收成功 ,结果通过退款查询接口查询 return true; } if ($result['result_code'] == 'FAIL') { //业务提交失败 throw new \WxPayException("业务提交失败!"); } return false; }
printf_info(WxPayApi::refund($input)); exit; } //$_REQUEST["out_trade_no"]= "122531270220150304194108"; ///$_REQUEST["total_fee"]= "1"; //$_REQUEST["refund_fee"] = "1"; if (isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != "") { $out_trade_no = $_REQUEST["out_trade_no"]; $total_fee = $_REQUEST["total_fee"]; $refund_fee = $_REQUEST["refund_fee"]; $input = new WxPayRefund(); $input->SetOut_trade_no($out_trade_no); $input->SetTotal_fee($total_fee); $input->SetRefund_fee($refund_fee); $input->SetOut_refund_no(WxPayConfig::MCHID . date("YmdHis")); $input->SetOp_user_id(WxPayConfig::MCHID); printf_info(WxPayApi::refund($input)); exit; } ?> <body> <form action="#" method="post"> <div style="margin-left:2%;color:#f00">微信订单号和商户订单号选少填一个,微信订单号优先:</div><br/> <div style="margin-left:2%;">微信订单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br /> <div style="margin-left:2%;">商户订单号:</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br /> <div style="margin-left:2%;">订单总金额(分):</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="total_fee" /><br /><br /> <div style="margin-left:2%;">退款金额(分):</div><br/> <input type="text" style="width:96%;height:35px;margin-left:2%;" name="refund_fee" /><br /><br />
/** * 微信退款 v3-b12 * */ public function wxpayOp() { $result = array('state' => 'false', 'msg' => '参数错误,微信退款失败'); $refund_id = intval($_GET['refund_id']); $model_refund = Model('vr_refund'); $condition = array(); $condition['refund_id'] = $refund_id; $condition['refund_state'] = '1'; $detail_array = $model_refund->getDetailInfo($condition); //退款详细 if (!empty($detail_array) && in_array($detail_array['refund_code'], array('wxpay', 'wx_jsapi', 'wx_saoma'))) { $order = $model_refund->getPayDetailInfo($detail_array); //退款订单详细 $refund_amount = $order['pay_refund_amount']; //本次在线退款总金额 if ($refund_amount > 0) { $wxpay = $order['payment_config']; define('WXPAY_APPID', $wxpay['appid']); define('WXPAY_MCHID', $wxpay['mchid']); define('WXPAY_KEY', $wxpay['key']); $total_fee = $order['pay_amount'] * 100; //微信订单实际支付总金额(在线支付金额,单位为分) $refund_fee = $refund_amount * 100; //本次微信退款总金额(单位为分) $api_file = BASE_PATH . DS . 'api' . DS . 'refund' . DS . 'wxpay' . DS . 'WxPay.Api.php'; include $api_file; $input = new WxPayRefund(); $input->SetTransaction_id($order['trade_no']); //微信订单号 $input->SetTotal_fee($total_fee); $input->SetRefund_fee($refund_fee); $input->SetOut_refund_no($detail_array['batch_no']); //退款批次号 $input->SetOp_user_id(WxPayConfig::MCHID); $data = WxPayApi::refund($input); if (!empty($data) && $data['return_code'] == 'SUCCESS') { //请求结果 if ($data['result_code'] == 'SUCCESS') { //业务结果 $detail_array = array(); $detail_array['pay_amount'] = ncPriceFormat($data['refund_fee'] / 100); $detail_array['pay_time'] = time(); $model_refund->editDetail(array('refund_id' => $refund_id), $detail_array); $result['state'] = 'true'; $result['msg'] = '微信成功退款:' . $detail_array['pay_amount']; $refund = $model_refund->getRefundInfo(array('refund_id' => $refund_id)); $consume_array = array(); $consume_array['member_id'] = $refund['buyer_id']; $consume_array['member_name'] = $refund['buyer_name']; $consume_array['consume_amount'] = $detail_array['pay_amount']; $consume_array['consume_time'] = time(); $consume_array['consume_remark'] = '微信在线退款成功(到账有延迟),虚拟退款单号:' . $refund['refund_sn']; QueueClient::push('addConsume', $consume_array); } else { $result['msg'] = '微信退款错误,' . $data['err_code_des']; //错误描述 } } else { $result['msg'] = '微信接口错误,' . $data['return_msg']; //返回信息 } } } exit(json_encode($result)); }
public function doWebOrder() { global $_W, $_GPC; load()->func('tpl'); checklogin(); $this->checkmode(); $weid = $_W['uniacid']; $operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display'; if ($operation == 'display') { $pindex = max(1, intval($_GPC['page'])); $psize = 20; $status = $_GPC['status']; $is_tuan = $_GPC['is_tuan']; $condition = " o.uniacid = :weid"; $paras = array(':weid' => $_W['uniacid']); if (empty($starttime) || empty($endtime)) { $starttime = strtotime('-1 month'); $endtime = time(); } if (!empty($_GPC['time'])) { $starttime = strtotime($_GPC['time']['start']); $endtime = strtotime($_GPC['time']['end']) + 86399; $condition .= " AND o.createtime >= :starttime AND o.createtime <= :endtime "; $paras[':starttime'] = $starttime; $paras[':endtime'] = $endtime; } if (!empty($_GPC['pay_type'])) { $condition .= " AND o.pay_type = '{$_GPC['pay_type']}'"; } elseif ($_GPC['pay_type'] === '0') { $condition .= " AND o.pay_type = '{$_GPC['pay_type']}'"; } if (!empty($_GPC['keyword'])) { $condition .= " AND o.orderno LIKE '%{$_GPC['keyword']}%'"; } if (!empty($_GPC['member'])) { $condition .= " AND (a.cname LIKE '%{$_GPC['member']}%' or a.tel LIKE '%{$_GPC['member']}%')"; } if ($status != '') { if ($status == 1) { $condition .= " AND o.status = '" . intval($status) . "' AND success = 0 "; } else { $condition .= " AND o.status = '" . intval($status) . "'"; } } if ($is_tuan != '') { $pp = 1; $condition .= " AND o.is_tuan = 1"; } $sql = "select o.* , a.cname,a.tel from " . tablename('tg_order') . " o" . " left join " . tablename('tg_address') . " a on o.addressid = a.id " . " where {$condition} ORDER BY o.createtime DESC " . "LIMIT " . ($pindex - 1) * $psize . ',' . $psize; $list = pdo_fetchall($sql, $paras); $paytype = array('0' => array('css' => 'default', 'name' => '未支付'), '1' => array('css' => 'info', 'name' => '余额支付'), '2' => array('css' => 'success', 'name' => '在线支付'), '3' => array('css' => 'warning', 'name' => '货到付款')); $orderstatus = array('9' => array('css' => 'default', 'name' => '已取消'), '-1' => array('css' => 'default', 'name' => '已关闭'), '4' => array('css' => 'default', 'name' => '已退款'), '0' => array('css' => 'danger', 'name' => '待付款'), '1' => array('css' => 'info', 'name' => '待发货'), '2' => array('css' => 'warning', 'name' => '待收货'), '3' => array('css' => 'success', 'name' => '已完成')); foreach ($list as &$value) { $s = $value['status']; $value['statuscss'] = $orderstatus[$value['status']]['css']; $value['status'] = $orderstatus[$value['status']]['name']; $value['css'] = $paytype[$value['pay_type']]['css']; if ($value['pay_type'] == 2) { if (empty($value['transid'])) { $value['paytype'] = '微信支付'; } else { $value['paytype'] = '微信支付'; } } else { $value['paytype'] = $paytype[$value['pay_type']]['name']; } $goodsss = pdo_fetch("select * from" . tablename('tg_goods') . "where id = '{$value['g_id']}'"); $value['freight'] = $goodsss['freight']; } $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('tg_order') . " o " . " left join " . tablename('tg_address') . " a on o.addressid = a.id " . " WHERE {$condition}", $paras); $pager = pagination($total, $pindex, $psize); } elseif ($operation == 'detail') { $id = intval($_GPC['id']); $is_tuan = intval($_GPC['is_tuan']); $item = pdo_fetch("SELECT * FROM " . tablename('tg_order') . " WHERE id = :id", array(':id' => $id)); if (empty($item)) { message("抱歉,订单不存在!", referer(), "error"); } if (checksubmit('confirmsend')) { if (!empty($_GPC['isexpress']) && empty($_GPC['expresssn'])) { message('请输入快递单号!'); } pdo_update('tg_order', array('status' => 2, 'express' => $_GPC['express'], 'expresssn' => $_GPC['expresssn']), array('id' => $id)); //发货提醒 $m_send = $this->module['config']['m_send']; $send = $this->module['config']['send']; $send_remark = $this->module['config']['send_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()); $openid = trim($item['openid']); $msg_json = '{ "touser":"******", "template_id":"' . $m_send . '", "url":"' . $url2 . '", "topcolor":"#FF0000", "data":{ "first":{ "value":"\\n' . $send . '\\n", "color":"#000000" }, "keyword1":{ "value":"' . $item['orderno'] . '\\n", "color":"#000000" }, "keyword2":{ "value":"' . $_GPC['express'] . '\\n", "color":"#000000" }, "keyword3":{ "value":"' . $_GPC['expresssn'] . '\\n", "color":"#000000" }, "remark":{ "value":"\\n\\n' . $send_remark . '", "color":"#0099FF" } } }'; include_once 'message.php'; $sendmessage = new WX_message(); $res = $sendmessage->WX_request($url, $msg_json); message('发货操作成功!', referer(), 'success'); } if (checksubmit('cancelsend')) { // $item = pdo_fetch("SELECT transid FROM " . tablename('tg_order') . " WHERE id = :id", array(':id' => $id)); // if (!empty($item['transid'])) { // $this->changeWechatSend($id, 0, $_GPC['cancelreson']); // } pdo_update('tg_order', array('status' => 1), array('id' => $id)); message('取消发货操作成功!', referer(), 'success'); } if (checksubmit('finish')) { pdo_update('tg_order', array('status' => 3), array('id' => $id)); message('订单操作成功!', referer(), 'success'); } if (checksubmit('refund')) { include_once '../addons/feng_fightgroups/WxPay.Api.php'; $WxPayApi = new WxPayApi(); $input = new WxPayRefund(); load()->model('account'); load()->func('communication'); $accounts = uni_accounts(); $acid = $_W['uniacid']; $path_cert = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_cert.pem'; //证书路径 $path_key = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_key.pem'; //证书路径 $key = $this->module['config']['apikey']; //商户支付秘钥(API秘钥) $appid = $accounts[$acid]['key']; //身份标识(appid) // $appsecret = $accounts[$acid]['secret'];//身份密钥(appsecret) $mchid = $this->module['config']['mchid']; //微信支付商户号(mchid) $refund_id = $_GPC['refund_id']; //页面获取的退款订单号 $refund_ids = pdo_fetch("select * from" . tablename('tg_order') . "where id={$refund_id}"); $fee = $refund_ids['price'] * 100; //退款金额 $refundid = $refund_ids['transid']; //微信订单号 /*$input:退款必须要的参数*/ $input->SetAppid($appid); $input->SetMch_id($mchid); $input->SetOp_user_id($mchid); $input->SetOut_refund_no($mchid . date("YmdHis")); $input->SetRefund_fee($fee); $input->SetTotal_fee($fee); $input->SetTransaction_id($refundid); $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key); if ($result['return_code'] == 'SUCCESS') { pdo_update('tg_order', array('status' => 4), array('id' => $refund_id)); $m_ref = $this->module['config']['m_ref']; $ref = $this->module['config']['ref']; $ref_remark = $this->module['config']['ref_remark']; $content = "您已成退款成功"; $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()); $data['touser'] = trim($_W['openid']); $openid = trim($refund_ids['openid']); $msg_json = '{ "touser":"******", "template_id":"' . $m_ref . '", "url":"' . $url2 . '", "topcolor":"#FF0000", "data":{ "first":{ "value":"' . $ref . '", "color":"#000000" }, "reason":{ "value":"购买失败", "color":"#000000" }, "refund":{ "value":"' . $refund_ids['price'] . '", "color":"#000000" }, "remark":{ "value":"\\n' . $ref_remark . '", "color":"#0099FF" } } }'; include_once 'message.php'; $sendmessage = new WX_message(); $res = $sendmessage->WX_request($url, $msg_json); pdo_query("update" . tablename('tg_goods') . " set gnum=gnum+1 where id = '{$refund_ids['g_id']}'"); message('退款成功了!', referer(), 'success'); } else { message('退款失败,服务器正忙,请稍等等!', referer(), 'fail'); } } if (checksubmit('cancel')) { pdo_update('tg_order', array('status' => 1), array('id' => $id)); message('取消完成订单操作成功!', referer(), 'success'); } if (checksubmit('cancelpay')) { pdo_update('tg_order', array('status' => 0), array('id' => $id)); // //设置库存 // $this->setOrderStock($id, false); message('取消订单付款操作成功!', referer(), 'success'); } if (checksubmit('confrimpay')) { pdo_update('tg_order', array('status' => 1, 'pay_type' => 2, 'remark' => $_GPC['remark']), array('id' => $id)); // //设置库存 // $this->setOrderStock($id); message('确认订单付款操作成功!', referer(), 'success'); } if (checksubmit('close')) { pdo_update('tg_order', array('status' => -1, 'remark' => $_GPC['remark']), array('id' => $id)); message('订单关闭操作成功!', referer(), 'success'); } if (checksubmit('open')) { pdo_update('tg_order', array('status' => 0, 'remark' => $_GPC['remark']), array('id' => $id)); message('开启订单操作成功!', referer(), 'success'); } // $dispatch = pdo_fetch("SELECT * FROM " . tablename('shopping_dispatch') . " WHERE id = :id", array(':id' => $item['dispatch'])); // if (!empty($dispatch) && !empty($dispatch['express'])) { // $express = pdo_fetch("select * from " . tablename('shopping_express') . " WHERE id=:id limit 1", array(":id" => $dispatch['express'])); // } $item['user'] = pdo_fetch("SELECT * FROM " . tablename('tg_address') . " WHERE id = {$item['addressid']}"); $goods = pdo_fetchall("select * from" . tablename('tg_goods') . "WHERE id={$item['g_id']}"); $item['goods'] = $goods; } elseif ($operation == 'delete') { /*订单删除*/ $orderid = intval($_GPC['id']); $tuan_id = intval($_GPC['tuan_id']); if (!empty($tuan_id)) { if (pdo_delete('tg_order', array('tuan_id' => $tuan_id))) { message('团订单删除成功', $this->createWebUrl('order', array('op' => 'tuan')), 'success'); } } if (pdo_delete('tg_order', array('id' => $orderid))) { message('订单删除成功', $this->createWebUrl('order', array('op' => 'display')), 'success'); } else { message('订单不存在或已被删除', $this->createWebUrl('order', array('op' => 'display')), 'error'); } } elseif ($operation == 'tuan') { $pindex = max(1, intval($_GPC['page'])); $psize = 10; $is_tuan = $_GPC['is_tuan']; $condition = "uniacid = :weid"; $paras = array(':weid' => $_W['uniacid']); if (!empty($_GPC['keyword'])) { $condition .= " AND tuan_id LIKE '%{$_GPC['keyword']}%'"; } if ($is_tuan != '') { $condition .= " AND is_tuan = 1"; } $sql = "select DISTINCT tuan_id from" . tablename('tg_order') . "where {$condition} order by createtime desc " . "LIMIT " . ($pindex - 1) * $psize . ',' . $psize; $tuan_id = pdo_fetchall($sql, $paras); foreach ($tuan_id as $key => $tuan) { $alltuan = pdo_fetchall("select * from" . tablename('tg_order') . "where tuan_id={$tuan['tuan_id']}"); $ite1 = array(); $ite2 = array(); $ite3 = array(); $ite4 = array(); $ite0 = array(); foreach ($alltuan as $num => $all) { if ($all['status'] == 0) { $ite0[$num] = $all['id']; } if ($all['status'] == 1) { $ite1[$num] = $all['id']; } if ($all['status'] == 2) { $ite2[$num] = $all['id']; } if ($all['status'] == 3) { $ite3[$num] = $all['id']; } if ($all['status'] == 4) { $ite4[$num] = $all['id']; } $goods = pdo_fetch("select * from" . tablename('tg_goods') . "where id = {$all['g_id']}"); } $tuan_id[$key]['itemnum0'] = count($ite0); $tuan_id[$key]['itemnum1'] = count($ite1); $tuan_id[$key]['itemnum2'] = count($ite2); $tuan_id[$key]['itemnum3'] = count($ite3); $tuan_id[$key]['itemnum4'] = count($ite4); $tuan_id[$key]['tsucc'] = count($ite1) + count($ite2) + count($ite3); $tuan_id[$key]['groupnum'] = $goods['groupnum']; $tuan_first_order = pdo_fetch("SELECT * FROM" . tablename('tg_order') . "where tuan_id={$tuan['tuan_id']} and tuan_first = 1"); $hours = $tuan_first_order['endtime']; $time = time(); $date = date('Y-m-d H:i:s', $tuan_first_order['createtime']); //团长开团时间 $endtime = date('Y-m-d H:i:s', strtotime(" {$date} + {$hours} hour")); $date1 = date('Y-m-d H:i:s', $time); /*当前时间*/ $lasttime = strtotime($endtime) - strtotime($date1); //剩余时间(秒数) $tuan_id[$key]['lasttime'] = $lasttime; } $total2 = pdo_fetchall("select DISTINCT tuan_id from" . tablename('tg_order') . "where {$condition}", $paras); $total = count($total2); $pager = pagination($total, $pindex, $psize); } elseif ($operation == 'tuan_detail') { $tuan_id = intval($_GPC['tuan_id']); //指定团的id $is_tuan = intval($_GPC['is_tuan']); $orders = pdo_fetchall("SELECT * FROM " . tablename('tg_order') . " WHERE tuan_id = {$tuan_id}"); $ite1 = array(); $ite2 = array(); $ite3 = array(); $ite4 = array(); $ite0 = array(); foreach ($orders as $key => $order) { if ($order['status'] == 0) { $ite0[$key] = $order['id']; } if ($order['status'] == 1) { $ite1[$key] = $order['id']; } if ($order['status'] == 2) { $ite2[$key] = $order['id']; } if ($order['status'] == 3) { $ite3[$key] = $order['id']; } if ($order['status'] == 4) { $ite4[$key] = $order['id']; } $address = pdo_fetch("SELECT * FROM" . tablename('tg_address') . "where id={$order['addressid']}"); $orders[$key]['cname'] = $address['cname']; $orders[$key]['tel'] = $address['tel']; $orders[$key]['province'] = $address['province']; $orders[$key]['city'] = $address['city']; $orders[$key]['county'] = $address['county']; $orders[$key]['detailed_address'] = $address['detailed_address']; $goods = pdo_fetch("select * from" . tablename('tg_goods') . "where id={$order['g_id']}"); $orders[$key]['freight'] = $goods['freight']; } $num = count($orders); $goodsid = array(); foreach ($orders as $key => $value) { $goodsid['id'] = $value['g_id']; } $goods2 = pdo_fetch("SELECT * FROM " . tablename('tg_goods') . " WHERE id = {$goodsid['id']}"); if (empty($orders)) { message("抱歉,该团购不存在!", referer(), "error"); } $goods2['itemnum0'] = count($ite0); $goods2['itemnum1'] = count($ite1); $goods2['itemnum2'] = count($ite2); $goods2['itemnum3'] = count($ite3); $goods2['itemnum4'] = count($ite4); $goods2['tsucc'] = count($ite1) + count($ite2) + count($ite3); foreach ($orders as $key => $value) { $it['status'] = $value['status']; } //是否过期 $sql2 = "SELECT * FROM" . tablename('tg_order') . "where tuan_id=:tuan_id and tuan_first = :tuan_first"; $params2 = array(':tuan_id' => $tuan_id, ':tuan_first' => 1); $tuan_first_order = pdo_fetch($sql2, $params2); $hours = $tuan_first_order['endtime']; $time = time(); $date = date('Y-m-d H:i:s', $tuan_first_order['createtime']); //团长开团时间 $endtime = date('Y-m-d H:i:s', strtotime(" {$date} + {$hours} hour")); $date1 = date('Y-m-d H:i:s', $time); /*当前时间*/ $lasttime2 = strtotime($endtime) - strtotime($date1); //剩余时间(秒数) //确认发货 if (checksubmit('confirmsend')) { pdo_update('tg_order', array('status' => 2), array('tuan_id' => $tuan_id)); message('发货操作成功!', referer(), 'success'); } //取消发货 if (checksubmit('cancelsend')) { pdo_update('tg_order', array('status' => 1), array('tuan_id' => $tuan_id)); message('取消发货操作成功!', referer(), 'success'); } //确认完成订单 if (checksubmit('finish')) { pdo_update('tg_order', array('status' => 3), array('tuan_id' => $tuan_id)); message('订单操作成功!', referer(), 'success'); } //取消完成订单(状态为已支付) if (checksubmit('cancel')) { pdo_update('tg_order', array('status' => 1), array('tuan_id' => $tuan_id)); message('取消完成订单操作成功!', referer(), 'success'); } //取消支付 if (checksubmit('cancelpay')) { pdo_update('tg_order', array('status' => 0), array('tuan_id' => $tuan_id)); message('取消团订单付款操作成功!', referer(), 'success'); } //确认支付 if (checksubmit('confrimpay')) { pdo_update('tg_order', array('status' => 1, 'pay_type' => 2), array('tuan_id' => $tuan_id)); message('团订单付款操作成功!', referer(), 'success'); } } elseif ($operation == 'output') { $status = $_GPC['status']; $istuan = $_GPC['istuan']; $condition = " uniacid={$weid}"; if ($status != '') { $condition .= " AND status = '" . intval($status) . "'"; } if ($istuan != '') { $condition .= " AND is_tuan = '" . intval($istuan) . "'"; } $orders = pdo_fetchall("select * from" . tablename('tg_order') . "where {$condition}"); error_reporting(E_ALL); date_default_timezone_set('Asia/Shanghai'); include_once 'PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator('http://www.phpernote.com')->setLastModifiedBy('http://www.phpernote.com')->setTitle('Office 2007 XLSX Document')->setSubject('Office 2007 XLSX Document')->setDescription('Document for Office 2007 XLSX, generated using PHP classes.')->setKeywords('office 2007 openxml php')->setCategory('Result file'); if ($istuan != '') { $sql = "select DISTINCT tuan_id from" . tablename('tg_order') . "where {$condition} order by createtime desc"; $tuan_id = pdo_fetchall($sql); foreach ($tuan_id as $key => $tuan) { $alltuan = pdo_fetchall("select * from" . tablename('tg_order') . "where tuan_id={$tuan['tuan_id']}"); $ite1 = array(); $ite2 = array(); $ite3 = array(); $ite4 = array(); $ite0 = array(); foreach ($alltuan as $num => $all) { if ($all['status'] == 0) { $ite0[$num] = $all['id']; } if ($all['status'] == 1) { $ite1[$num] = $all['id']; } if ($all['status'] == 2) { $ite2[$num] = $all['id']; } if ($all['status'] == 3) { $ite3[$num] = $all['id']; } if ($all['status'] == 4) { $ite4[$num] = $all['id']; } $goods = pdo_fetch("select * from" . tablename('tg_goods') . "where id = {$all['g_id']}"); } $tuan_id[$key]['itemnum0'] = count($ite0); $tuan_id[$key]['itemnum1'] = count($ite1); $tuan_id[$key]['itemnum2'] = count($ite2); $tuan_id[$key]['itemnum3'] = count($ite3); $tuan_id[$key]['itemnum4'] = count($ite4); $tuan_id[$key]['tsucc'] = count($ite1) + count($ite2) + count($ite3); $tuan_id[$key]['groupnum'] = $goods['groupnum']; $tuan_first_order = pdo_fetch("SELECT * FROM" . tablename('tg_order') . "where tuan_id={$tuan['tuan_id']} and tuan_first = 1"); $hours = $tuan_first_order['endtime']; $time = time(); $date = date('Y-m-d H:i:s', $tuan_first_order['createtime']); //团长开团时间 $endtime = date('Y-m-d H:i:s', strtotime(" {$date} + {$hours} hour")); $date1 = date('Y-m-d H:i:s', $time); /*当前时间*/ $lasttime = strtotime($endtime) - strtotime($date1); //剩余时间(秒数) $tuan_id[$key]['lasttime'] = $lasttime; } $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '团编号')->setCellValue('B1', '团状态')->setCellValue('C1', '团购商品')->setCellValue('D1', '团购价格'); $i = 2; foreach ($tuan_id as $k => $item) { if ($item['lasttime'] > 0) { if ($item['tsucc'] == $item['groupnum']) { $content = "组团成功(共需" . $item['groupnum'] . "人)【待发货" . $item['itemnum1'] . "人,已发货" . $item['itemnum2'] . "人】"; } if ($item['tsucc'] < $item['groupnum']) { $content = "组团中(共需" . $item['groupnum'] . "人)【已付款" . $item['itemnum1'] . "人,还差" . $item['groupnum'] - $item['tsucc'] . "人】"; } } else { if ($item['tsucc'] == $item['groupnum']) { $content = "组团成功(共需" . $item['groupnum'] . "人)【待发货" . $item['itemnum1'] . "人,已发货" . $item['itemnum2'] . "人】"; } else { $content = "团购失败,团购已过期(共需" . $item['groupnum'] . "人)【待退款" . $item['itemnum1'] . "人,已退款" . $item['itemnum4'] . "人】"; } } $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $i, $item['tuan_id'])->setCellValue('B' . $i, $content)->setCellValue('C' . $i, $goods['gname'])->setCellValue('D' . $i, $goods['gprice']); $i++; } $filename = urlencode('团订单信息统计表') . '_' . date('Y-m-dHis'); } else { $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '订单编号')->setCellValue('B1', '姓名')->setCellValue('C1', '电话')->setCellValue('D1', '总价(元)')->setCellValue('E1', '状态')->setCellValue('F1', '下单时间')->setCellValue('G1', '商品名称')->setCellValue('H1', '收货地址'); $i = 2; foreach ($orders as $k => $v) { $user = pdo_fetch("select * from" . tablename('tg_address') . "where id={$v['addressid']}"); $address = $user['province'] . $user['city'] . $user['county'] . $user['detailed_address']; $goods = pdo_fetch("select * from" . tablename('tg_goods') . "where id = {$v['g_id']}"); if ($user) { $name = $user['cname']; $tel = $user['tel']; } else { $name = ''; $tel = ''; } if ($v['status'] == 0) { $status = '待付款'; $filename = urlencode('待付款订单信息统计表') . '_' . date('Y-m-dHis'); } if ($v['status'] == 1) { $status = '待发货'; $filename = urlencode('待发货订单信息统计表') . '_' . date('Y-m-dHis'); } if ($v['status'] == 2) { $status = '已发货'; $filename = urlencode('已发货订单信息统计表') . '_' . date('Y-m-dHis'); } if ($v['status'] == 3) { $status = '已完成'; $filename = urlencode('已完成订单信息统计表') . '_' . date('Y-m-dHis'); } if ($v['status'] == 9) { $status = '已取消'; $filename = urlencode('已取消订单信息统计表') . '_' . date('Y-m-dHis'); } $time = date('Y-m-d h:i:s', $v['createtime']); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $i, $v['orderno'])->setCellValue('B' . $i, $name)->setCellValue('C' . $i, $tel)->setCellValue('D' . $i, $v['price'])->setCellValue('E' . $i, $status)->setCellValue('F' . $i, $time)->setCellValue('G' . $i, $goods['gname'])->setCellValue('H' . $i, $address); $i++; } } $objPHPExcel->getActiveSheet()->setTitle('拼团订单'); $objPHPExcel->setActiveSheetIndex(0); //$filename=urlencode('订单信息统计表').'_'.date('Y-m-dHis'); //生成xls文件 header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $filename . '.xls"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } elseif ($operation == 'refundall') { include_once '../addons/feng_fightgroups/WxPay.Api.php'; $WxPayApi = new WxPayApi(); $input = new WxPayRefund(); load()->func('communication'); load()->model('account'); $accounts = uni_accounts(); $allorders = pdo_fetchall("select * from" . tablename('tg_order') . "where uniacid={$_W['uniacid']} and status = 1"); $now = time(); $num = 0; foreach ($allorders as $ke => $value) { $endtime = $value['endtime']; if ($now - $value['starttime'] > $endtime * 3600 && $value['transid'] != '') { $num++; $fee = $value['price'] * 100; $refundid = $value['transid']; $acid = $_W['uniacid']; $path_cert = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_cert.pem'; //证书路径 $path_key = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_key.pem'; //证书路径 $key = $this->module['config']['apikey']; //商户支付秘钥(API秘钥) $appid = $accounts[$acid]['key']; //身份标识(appid) $mchid = $this->module['config']['mchid']; //微信支付商户号(mchid) /*$input:退款必须要的参数*/ $input->SetAppid($appid); $input->SetMch_id($mchid); $input->SetOp_user_id($mchid); $input->SetOut_refund_no($mchid . date("YmdHis")); $input->SetRefund_fee($fee); $input->SetTotal_fee($fee); $input->SetTransaction_id($refundid); $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key); if ($result['return_code'] == 'SUCCESS') { pdo_update('tg_order', array('status' => 4), array('id' => $value['id'])); pdo_query("update" . tablename('tg_goods') . " set gnum=gnum+1 where id = '{$value['g_id']}'"); } } } if ($num == 0) { message('未找到已付款且团购过期的微信订单。', referer(), 'fail'); } else { message('一键退款成功!', referer(), 'success'); } } include $this->template('order'); }
/** * @note 申请退款 * @access public * @author zhangchong <*****@*****.**> * @date 2015/7/9 17:31 * @param $params['out_trade_no'] 原订单号 * @param $params['transaction_id'] 微信交易号 交易号和原订单号2选1,如果同时存在 交易号优先级大于原订单号 * @param $params['total_fee'] 订单总金额 单位:元 * @param $params['refund_fee'] 退款金额 单位:元 * @param $params['refund_code'] 退款订单号 * @return array|boolean 返回false表示参数设置错误 **/ public function refund($params = array()) { if (!isset($params['transaction_id']) && !isset($params['out_trade_no'])) { return false; } //简单的验证,订单号和微信交易号都不存在 $input = new WxPayRefund($this->config); if (isset($params['transaction_id'])) { $input->SetTransaction_id($params['transaction_id']); } else { $input->SetOut_trade_no($params['out_trade_no']); } $input->SetTotal_fee($params['total_fee'] * 100); //微信金额单位是分,咱们是元,所以要乘以100 $input->SetRefund_fee($params['refund_fee'] * 100); //微信金额单位是分,咱们是元,所以要乘以100 $input->SetOut_refund_no($params['refund_code']); $input->SetOp_user_id($this->config->mchid); return Pay\WxPayApi::refund($input); }
$acid = $_W['uniacid']; $path_cert = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_cert.pem'; //证书路径 $path_key = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_key.pem'; //证书路径 $key = $this->module['config']['apikey']; //商户支付秘钥(API秘钥) $appid = $accounts[$acid]['key']; //身份标识(appid) $mchid = $this->module['config']['mchid']; //微信支付商户号(mchid) /*$input:退款必须要的参数*/ $input = new WxPayRefund(); $input->SetAppid($appid); $input->SetMch_id($mchid); $input->SetOp_user_id($mchid); $input->SetOut_refund_no($mchid . date("YmdHis")); $input->SetRefund_fee($fee); $input->SetTotal_fee($fee); $input->SetTransaction_id($refundid); $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key); if ($result['return_code'] == 'SUCCESS') { pdo_update('tg_order', array('status' => 4), array('id' => $value['id'])); pdo_query("update" . tablename('tg_goods') . " set gnum=gnum+1 where id = '{$value['g_id']}'"); } } } if ($num == 0) { message('未找到已付款且团购过期的微信订单。', referer(), 'fail'); } else { message('一键退款成功!共处理了' . $num . '个订单。', referer(), 'success');
public function refund($orderno, $price, $type) { global $_GPC, $_W; include_once '../addons/feng_fightgroups/source/WxPay.Api.php'; $WxPayApi = new WxPayApi(); $input = new WxPayRefund(); load()->model('account'); load()->func('communication'); $accounts = uni_accounts(); $acid = $_W['uniacid']; $path_cert = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_cert.pem'; //证书路径 $path_key = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_key.pem'; //证书路径 $key = $this->module['config']['apikey']; //商户支付秘钥(API秘钥) $account_info = pdo_fetch("select * from" . tablename('account_wechats') . "where uniacid={$_W['uniacid']}"); //身份标识(appid) $appid = $account_info['key']; //身份标识(appid) $mchid = $this->module['config']['mchid']; //微信支付商户号(mchid) $refund_ids = pdo_fetch("select * from" . tablename('tg_order') . "where orderno ='{$orderno}'"); $goods = pdo_fetch("select * from" . tablename('tg_goods') . "where id='{$refund_ids['g_id']}'"); if (!empty($price)) { $fee = $price; } else { $fee = $refund_ids['price'] * 100; } //退款金额 $refundid = $refund_ids['transid']; //微信订单号 /*$input:退款必须要的参数*/ $input->SetAppid($appid); $input->SetMch_id($mchid); $input->SetOp_user_id($mchid); $input->SetOut_refund_no($refund_ids['orderno']); $input->SetRefund_fee($fee); $input->SetTotal_fee($refund_ids['price'] * 100); $input->SetTransaction_id($refundid); $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key); //写入退款记录 $data = array('transid' => $refund_ids['transid'], 'refund_id' => $result['refund_id'], 'createtime' => TIMESTAMP, 'status' => 0, 'type' => $type, 'goodsid' => $refund_ids['g_id'], 'orderid' => $refund_ids['id'], 'payfee' => $refund_ids['price'], 'refundfee' => $refund_ids['price'], 'refundername' => $refund_ids['addname'], 'refundermobile' => $refund_ids['mobile'], 'goodsname' => $goods['gname'], 'uniacid' => $_W['uniacid']); pdo_insert('tg_refund_record', $data); if ($result['return_code'] == 'SUCCESS') { if ($type == 3) { pdo_update('tg_order', array('status' => 7, 'is_tuan' => 2), array('id' => $refund_ids['id'])); } else { pdo_update('tg_order', array('status' => 7), array('id' => $refund_ids['id'])); } pdo_update('tg_refund_record', array('status' => 1), array('transid' => $refund_ids['transid'])); /*退款通知*/ require_once IA_ROOT . '/addons/feng_fightgroups/source/Message.class.php'; $access_token = WeAccount::token(); $url1 = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token . ""; $url2 = ''; $sendmessage = new Message(); if ($type == 4) { $res = $sendmessage->part_refund($refund_ids['openid'], $price * 0.01, $this, $url1, $url2); } else { $res = $sendmessage->refund($refund_ids['openid'], $refund_ids['price'], $this, $url1, $url2); } /*退款通知*/ pdo_query("update" . tablename('tg_goods') . " set gnum=gnum+1 where id = '{$refund_ids['g_id']}'"); return 'success'; } else { if ($type == 3) { pdo_update('tg_order', array('status' => 6, 'is_tuan' => 2), array('id' => $refund_ids['id'])); } else { pdo_update('tg_order', array('status' => 6), array('id' => $refund_ids['id'])); } return 'fail'; } }