<?php

namespace Active\Lib;

use Dever;
Class Manage {
	#全额退款
	public function refund_api($id){
		$data = Dever::db('active/order')->find($id);
		$param = array
        (
            'project_id' => 6,
            'channel_id' => 1,
            'system_source' => 1,
            'account_id' => 8,
            'order_id' => $data['order_num'],
            'refund_cash' => $data['price'],
            //'refund_order_id' => '',
        );
        if($data['status'] != 2){
        	Dever::alert('此状态下不可退款');
        }

        if ($data['price'] > 0) {
            $result = Dever::load('pay/api.refund', $param);

            if (!$result) {
                # 退款失败,抛出错误
                //throw new \Exception('退款失败');
                Dever::alert('退款失败,请联系管理员');
            }else{
            	Dever::db('active/order')->update(array('where_id'=>$id,'set_status'=>6));
            }
        }
  		return 'reload';
	}
}