<?php

namespace app\user\controller;
use think\Lang;

class Cost extends UserControl
{

    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
        Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/db.lang.php');

    }
    public function orderManagement()
    {
        $condition['a.user_id'] = session('user_id');
        $status = input('get.status');
        if ($status) {
            $condition['order_status'] = input('get.status');
        }
        $time = input('get.timeRang');//print_r(input('get.page'));print_r(input('get.aa'));die;
        if(!empty($time)){
            $gap = explode(' - ', $time);
            $begin = $gap[0];
            $end = $gap[1];
            $condition['order_buyTime'] = array('between', array($begin, $end));
        }
        $allOrder = model('order')->getOrder($condition);
        $this->assign('allOrder', $allOrder);
        $this->assign('show_page', $allOrder->render());
        $this->assign('status', $status);

        return $this->fetch('orderManagement');
    }
    public function recharge()
    {
        $userId = session('user_id');
        $userInfo = model('user')->getUserInfo($userId);
        $this->assign('userInfo', $userInfo);
        $status = input('get.status');
        $this->assign('status', $status);
        $systemPayment = model('systempayment')->getSystempayment($userId);
        $zhifubao = '';
        $weixin = '';
        $bank = '';
        foreach ($systemPayment as $value) {
            if ($value->systemPayment_type == 1 && $value->systemPayment_status == 1) {
                $zhifubao = $value;
            } elseif ($value->systemPayment_type == 2 && $value->systemPayment_status == 1) {
                $weixin = $value;
            } elseif ($value->systemPayment_type == 3 && $value->systemPayment_status == 1) {
                $bank = $value;
            }
        }
        $this->assign('zhifubao', $zhifubao);
        $this->assign('weixin', $weixin);
        $this->assign('bank', $bank);


        return $this->fetch('recharge');
    }
    public function rechargeSubmit()
    {
        $data['recharge_type'] = input('post.type');
        $data['recharge_identity'] = input('post.orderNumber');
        $getRecharge = model('recharge')->getRecharge($data);
        if ($getRecharge) {
            return ["msg"=>"错误：已提交过该订单号"];
        }
        $userId = session('user_id');
        $getInfo = model('userinfo')->getInfo($userId);
        $data['user_id'] = session('user_id');
        $data['user_money'] = $getInfo->userInfo_money;
        $data['recharge_time'] = date('Y-m-d H:i:s');
        $data['recharge_status'] = 2;
        $addBack = model('recharge')->addRecharge($data);
        if ($addBack) {
            return ["msg"=>"成功：人工操作流程较长，金额预计在操作完成后2-3天到账，请耐心等待"];
        } else {
            return ["msg"=>"错误：系统错误，请重新提交"];
        }
    }
    public function transaction()
    {
        $condition['user_id'] = session('user_id');
        $time = input('get.timeRang');
        if (!empty($time)) {
            $gap = explode(' - ', $time);
            $begin = $gap[0];
            $end = date('Y-m-d', strtotime ("+1 day", strtotime($gap[1])));
            $condition['recharge_time'] = array('between', array($begin, $end));
        }
        $type = input('get.type');
        if ($type) {
            $condition['recharge_type'] = $type;
        }
        $allRecharge = model('recharge')->selectRecharge($condition);
        $this->assign('allRecharge', $allRecharge);
        $this->assign('show_page', $allRecharge->render());

        return $this->fetch('transaction');
    }

}

?>
