AccountAction::do_scorecharge PHP Method

do_scorecharge() public method

public do_scorecharge ( )
    public function do_scorecharge()
    {
        $price = intval($_POST['charge_value']);
        if ($price < 1) {
            exit(json_encode(array('status' => 0, 'info' => '充值金额不正确')));
        }
        $type = intval($_POST['charge_type']);
        $types = array('alipay', 'weixin');
        if (!isset($types[$type])) {
            exit(json_encode(array('status' => 0, 'info' => '充值方式不支持')));
        }
        $chargeConfigs = model('Xdata')->get('admin_Config:charge');
        if (!in_array($types[$type], $chargeConfigs['charge_platform'])) {
            exit(json_encode(array('status' => 0, 'info' => '充值方式不支持')));
        }
        $data['serial_number'] = 'CZ' . date('YmdHis') . rand(0, 9) . rand(0, 9);
        $data['charge_type'] = $type;
        $data['charge_value'] = $price;
        $data['uid'] = $this->mid;
        $data['ctime'] = time();
        $data['status'] = 0;
        $data['charge_sroce'] = intval($price * abs(intval($chargeConfigs['charge_ratio'])));
        $data['charge_order'] = '';
        $result = D('credit_charge')->add($data);
        $res = array();
        if ($result) {
            $data['charge_id'] = $result;
            $res['status'] = 1;
            $res['info'] = 'OK';
            switch ($type) {
                case 0:
                    $res['request_url'] = $this->alipay($data);
                    break;
                case 1:
                    $res['request_url'] = $this->weixin($data);
                    break;
                default:
                    $res['request_url'] = '';
            }
        } else {
            $res['status'] = 0;
            $res['info'] = '充值创建失败';
        }
        exit(json_encode($res));
    }