<?php

namespace app\controller\api;

use app\dao\UserDao;
use app\dao\UserRewardDao;
use support\Request;

use App\Utils\ApiResponseApp;
use app\model\User;

use App\model\Reward;
use hg\apidoc\annotation as Apidoc;
use support\Db;

/**
 * @Apidoc\Title("公共控制器?")
 */

class TurntableController
{
    protected $noNeedLogin = ['lists', 'get_project', 'get_projectdetailed', 'get_mechanism_list'];


    /**
     * @Apidoc\Title("1.0 返回抽奖配置")
     * @Apidoc\Url("api/Tturntable/lists")
     * @Apidoc\Method("POST")
     */
    public function lists(Request $request)
    {

        $res=Reward::all();
        return ApiResponseApp::success($res);
    }


    /**
     * @Apidoc\Title("1.0 抽奖点击后 返回抽奖结构)
     * @Apidoc\Url("api/Tturntable/lottery")
     * @Apidoc\Method("POST")
     */
    public function lottery(Request $request)
    {
        $user_id = $request->data['id'];
        $user = User::find($user_id);
        if($user->money<10){
            return ApiResponseApp::error([],'账户余额不足');
        }
        //TODO 这里好像还需要写是否完成今天的任务
        UserRewardDao::lottery($user_id,-10);
        UserRewardDao::winning($user_id,1);
        return ApiResponseApp::success(1,'恭喜抽中1.00');
    }

}
