<?php
/*
 本代码由 焕岱科技 创建
 技术支持 WX：15285007200
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace app\api\controller\turntable_lottery;

use app\api\controller\Base;
use think\Db;
use app\common\model\bbfxshop\User;


class Index extends Base
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\TurntableLottery;
    }
    
    public function luckdraw(){
        $result = $this->model->luckdraw($this->user['id']);
        if($result['code'] != 1){
            __error($result['message']);
        }
        
        __success("抽奖成功",['rewardIndex'=>$result['data']]);
    }
    
    public function getPrizeList(){
        $config = $this->model->getSet();
        $prize_type = $config['prize_type'];
        $prize = $config['prize'];
        $prize_set = $config;
        unset($config['prize']);
        
        if($prize_type == 1 || empty($prize_type)){
            $sales_amount = $prize['sales_amount'];
            if(empty($sales_amount) || empty($sales_amount['list'])){
                return __json(0,"未配置奖品");
            }
            
            $list = $sales_amount['list'];
            
            $prize_set['list'] = $list;
            
            __success("操作成功",$prize_set);
        }
        else{
            __error("未配置奖品");
        }
    }
}