<?php

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

class Message 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 index()
    {
        $message = Model('Userproduct');
        $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['userProduct_buyTime'] = array('between', array($begin, $end));
        }
        $type = input('get.type');
        if ($type) {
            if($type == -1){
                $condition['userProduct_maturityTime'] = array('<',date('Y-m-d',time()));
            }
            if($type == 1){
                $condition['userProduct_maturityTime'] = array('>=',date('Y-m-d',time()));
            }
        }
        $usermessage = $message->getUserProduct($condition);
        $this->assign('show_page', $usermessage->render());
        $this->assign('usermessage', $usermessage);

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

}

?>
