<?php
namespace App\Sports\Controller;

use BaseController\Controller;
use Biz\Match\GetmatchData;
use Biz\Match\GetOddsData;

/**
 * 前台赛事规则数据接口
 * User: tank
 * Date: 2019/10/11
 */
class RuleMatch extends Controller{
    public function init() {
        $this->commonFunction =  C()->get('commonFunction');
        $this->getTypeData = new GetmatchData();
        $this->getOddsData = new GetOddsData();

    }

    /**
     * 获取各球类玩法规则数据
     */
    public function getMatchRule(){
        
        //请求模块名称
        $modular = $_REQUEST['modular']?:'体育';
        //请求规则组名称
        $group = $_REQUEST['group']?:'一般体育说明';
        try {
            if(empty($modular) || empty($group)){
                throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
            }

            //拼装查询条件
            $where = [
                ['modular_name','=',$modular],
                ['group_name','=',$group],
            ];

            //获取各球类规则
            $match_rule = lm('st_match_rule',"Sports")
            ->select('modular_name','group_name','author','atime','utime','status','content')
            ->where($where)
            ->first()
            ->toArray();

            //获取所有模块/分组
            $rule_menu = lm('st_match_rule_group',"Sports")
            ->select('modular_id','modular_name','id as group_id','group_name')
            ->get()
            ->toArray();

            //获取模块
            $modular_data =  $this->commonFunction->array_unset_tt($rule_menu,'modular_name');

            $rule_menu_data = [];
            foreach($modular_data as $k=>$v){
                $dd['modular_id'] = $v['modular_id'];
                $dd['modular_name'] = $v['modular_name'];

                foreach($rule_menu as $kk=>$vv){
                    $ddd['group_id'] = $vv['group_id'];
                    $ddd['group_name'] = $vv['group_name'];
                    if($vv['modular_name'] == $k){
                        $dd['group'][] = $ddd;
                    }
                }
                $rule_menu_data[] = $dd;
            }

            $data = [
                'rule_menu' =>$rule_menu_data,
                'match_rule'=>$match_rule
            ];


            Render($data, '1', lang('Tips','Sports')->get('success'));
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }


}