<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;

class Controller extends BaseController {
	use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
	function __construct() {
		$this->_init();
	}
	function _init() {
        //初始化设置开奖token
       
	}
	/**
	 * 列编辑
	 *
	 * @param Request $req
	 * @return void
	 */
	function EditCols(Request $req) {
		$id = intval($req->id);
		if ($id < 1) {
			return responseToJson(-20004);
		}
		$field = $req->field;
		$value = $req->value;
		if (empty($field) || empty($value)) {
			return responseToJson(-20005);
		}
		if (($result = $this->EditColsValidate($field, $value)) < 1) {
			return responseToJson($result);
		}
		$model = $this->getEditColsModel();
		if (!$model) {
			return responseToJson(-20006);
		}
		$model = resolve('\\App\\Model\\' . $model)->find($id);
		$model->$field = $value;
		$re = $model->save();
		return responseToJson(1);
	}
	/**
	 * 设定自动编辑的模型,返回编辑的模型
	 *
	 * @return void
	 */
	function getEditColsModel() {
		return;
	}

	/**
	 * 检测自动保存数据
	 *
	 * @param [type] $field
	 * @param [type] $value
	 * @return void
	 */
	function EditColsValidate($field, $value) {
		return 1;
	}

}
