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

namespace app\admin\controller\bbfxshop\double_track;

use app\admin\controller\bbfxshop\Base;
use think\Db;


class Level extends Base
{
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\DoubleTrack;
    }
    
    public function delete(){
        $this->commonDelete("bbfx_double_track_level");
    }
    
    public function detail(){
        $params = $this->param();
        
        $levels = $this->model->getLevels();
        
        $info = Db::name("bbfx_double_track_level")->where(['id'=>$params['id']])->find();
        if(empty($info)){
            __error("操作失败");
        }
        
        __success('操作成功',['info'=>$info]); 
    }
    
    public function getlist(){
        $params = $this->param();
        
        
    	$list = $this->model->getLevels();
    	
      	
      	__success("操作成功",['list'=>$list]);
    }
    
    
    public function post(){
        $params = $this->param();
        
        
      	if(empty($params['name'])){
        	__error("请填写等级名称");
        }
        
        $id = $params['id'];
      
    	$data = array(
          	"name"=>$params['name'],
          	"management_reward"=>floatval($params['management_reward']),
          	"big_market_achievement"=>floatval($params['big_market_achievement']),
          	"small_market_achievement"=>floatval($params['small_market_achievement']),
          	"level"=>intval($params['level']),
        );
        
        $data['uniacid'] = UNIACID;
        
        if(intval($id) > 0){
            $res = Db::name("bbfx_double_track_level")->where(["id"=>$id])->update($data);
        }
        else{
            $res = Db::name("bbfx_double_track_level")->insertGetId($data);
            $data['id'] = $res;
        }
      	
      	if($res){
      	    $data['id'] = $id;
      	    \app\admin\model\AdminLog::record("","",$data,"bbfx_double_track_level");
        	__success("编辑成功");
        }
      	else{
        	__success("操作成功");
        }
    }
}