微信退款

来源:互联网 发布:geoserver sql view 编辑:程序博客网 时间:2024/04/28 10:43
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'];
$account_info = pdo_fetch("select * from" . tablename('account_wechats') . "where uniacid={$_W['uniacid']}");
$appid = $account_info['key'];
$mchid = $this->module['config']['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->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' => $fee/100,
 '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';
}
}
0 0
原创粉丝点击