<?php
    /**
     * Created by PhpStorm.
     * User: Lenovo
     * Date: 2018/10/15
     * Time: 16:25
     */

 namespace App\Api\Controller;
use Biz\Account\AccountManager;
use Illuminate\Contracts\Session\Session;

//ini_set('display_errors',1);
//error_reporting(E_ALL);
    class Signin extends BaseController
    {

        //获取用户信息
        private function userInfo(){

            $userinfo = isset($_SESSION["uinfo"])?$_SESSION["uinfo"]:[];
            if(empty($userinfo))Render('',-4001);
            return   $userinfo;
        }

        //当前彩金信息
        private function lotteryInfo($type='sign'){
            $info   =       $lottery = lm ('lottery_money', 'Api')->where ('type',$type)->first ();
            if(empty($info))Render('',-5007);
            return $info->toarray();
        }


        //查看用户连续签到天数
        private function countSignDays($id,$account_identity,$grade){

          $days   =   lm('Lottery_money_log','Api')->Signin(['lottery_money_id'=>$id,'account_identity'=>$account_identity,'grade' =>$grade]);
            if(empty($days))Render('',-600017);
           return $days;
        }

        //今天是否签到
        private function signStatus($userid){
            $has   =   lm('Lottery_money_log','Api')->todaySignin(['account_identity'=>$userid]);
            if($has<0)Render('',$has);
            return $has;

        }

        public function signInfo(){
            $grade = ($this->userInfo())["grade"];
            $id     =  ($this->lotteryInfo())["id"];
            $userid = ($this->userInfo())["account_identity"];
            $days   =   $this->countSignDays($id,$userid,$grade);
            $status =   $this->signStatus($userid);
            if(empty($days))Render('',$days);
            if($status<0)Render('',$status);

           Render(['days'=>$days,'signed'=>$status["active"],'money'=>$status["money"],'time'=>$status["create_time"]],1) ;
        }

        //签到
        public function goSign(){
            $re=C()->get('SignActive')->main($this->userInfo()['account_identity']);
            is_array($re)? Render($re,1): Render('',$re);
        }


    }