public function refund_back(){
$return_id = I('id');
$return_goods = M('return_goods')->where("id= $return_id")->find();
$rec_goods = M('order_goods')->where(array('order_id'=>$return_goods['order_id'],'goods_id'=>$return_goods['goods_id']))->find();
$order = M('order')->where(array('order_id'=>$rec_goods['order_id']))->find();
if($order['pay_code'] == 'weixin' || $order['pay_code'] == 'alipay' || $order['pay_code'] == 'alipayMobile'){
$return_money = $return_goods['refund_money'];
if($order['pay_code'] == 'weixin'){
include_once PLUGIN_PATH."payment/weixin/weixin.class.php";
$payment_obj = new \weixin();
$data = array('transaction_id'=>$order['transaction_id'],'total_fee'=>$order['order_amount'],'refund_fee'=>$return_money);
$result = $payment_obj->payment_refund($data);
if($result['return_code'] == 'SUCCESS'){
M('order_goods')->where(array('rec_id'=>$rec_goods['rec_id']))->save(array('is_send'=>3));
$updata = array('refund_type'=>2,'refundtime'=>time(),'status'=>3);
M('return_goods')->where("id= $return_id")->save($updata);
//使用积分或者余额抵扣部分一一退还
if($return_goods['refund_deposit']>0 || $return_goods['refund_integral']>0){
accountLog($return_goods['user_id'],$return_goods['refund_deposit'],$return_goods['refund_integral'],'用户申请商品退款',0,$return_goods['order_id'],$return_goods['order_sn']);
}
//若该商品有赠送积分则追回
$order_goods = M('order_goods')->where(array('rec_id'=>$return_goods['rec_id']))->find();
if($order_goods['give_integral']>0){
accountLog($return_goods['user_id'],0,-$return_goods['refund_integral'],'退货积分追回',0,$return_goods['order_id'],$return_goods['order_sn']);
}
$this->success('退款成功');
}else{
$this->error($result['return_msg']);
}