<?php
namespace Api\Controller;

use Think\Controller;

header("Content-Type:text/html;CharSet=UTF-8");
class WithdrawController extends Controller
{
    /**
     *  提现申请
     */
    public function apply()
    {
        $openid = $_GET['openid'];
        $money = I('money');
        if (!$openid || $openid == "NULL" || $openid == "undefined") {
            $data = array("status" => -1, "msg" => "openid有误");
        } elseif (!$money || $money == "NULL" || $money == "undefined" || !is_numeric($money)) {
            $data = array("status" => -1, "msg" => "申请金额有误");
        } elseif ($money < 1) {
            $data = array("status" => -1, "msg" => "提现金额至少1元");
        } else {
            $data = D("FundApply")->saveData($openid, $money);
        }
        apiReturn($data);
    }

    /**
     * 提现明细
     */
    public function applyList()
    {
        $openid = $_GET['openid'];
        if (!$openid || $openid == "NULL" || $openid == "undefined") {
            $data = array("status" => -1, "msg" => "openid有误");
        } else {
            $list = M("fundApply")->where("`openid`='{$openid}' AND `status`>0")->select();
            if (!$list) {
                $list = array();
            }
            foreach ($list as $kl => $vl) {
                $list[$kl]['create_time'] = date("Y-m-d H:i", $vl['create_time']);
            }
            unset($kl, $vl);
            $data = array("status" => 1, "result" => $list);
        }
        apiReturn($data);
    }
}