<?php
namespace app\admin\controller;

use app\admin\BaseController;
use app\common\model\Param as ParamModel;

class Param extends BaseController
{
	
	public function index()
	{
		$param = ParamModel::where(1)->findOrEmpty();
		if ($param->isEmpty()) {
		    $param = new ParamModel;
			$param->save([
				'indextopbg'		=> request()->domain()."/static/images/indextopbg.png",
				'telephone'			=> "",
				'mycodeban'			=> request()->domain()."/static/images/mycodeban.png",
				'mycodecolor'		=> "#f33714",
				'mycodetil'			=> "直说吧，我们要人你要钱，那就来看看！！！",
				'mycodepic'			=> request()->domain()."/static/images/mycodepic.png",
				'brokerformpic'		=> request()->domain()."/static/images/brokerformpic.png",
				'agentformpic'		=> request()->domain()."/static/images/agentformpic.png",
				'workerformpic'		=> request()->domain()."/static/images/workerformpic.png",
				'addcomjobs'		=> 0,
				'addcomjobswyp'		=> 0,
				'topcomjobs'		=> 0,
				'adddemand'			=> 0,
				'adddemandwyd'		=> 0,
				'topdemand'			=> 0,
				'addsupply'			=> 0,
				'topsupply'			=> 0,
				'teldemand'			=> 0,
				'telsupply'			=> 0,
				'mpaccount'			=> request()->domain()."/static/images/mpaccount.png",
				'defviewtol'		=> 0
			]);
		}
		return view('set/param',[
			'param' => $param 
		]);
	}
	
	public function editParam()
	{
		$param = ParamModel::where(1)->find();
		$data = array(
			'indextopbg'		=> input('indextopbg/s', ""),
			'telephone'			=> input('telephone/s', ""),
			'mpaccount'			=> input('mpaccount/s', ""),
			'mycodeban'			=> input('mycodeban/s', ""),
			'mycodecolor'		=> input('mycodecolor/s', ""),
			'mycodetil'			=> input('mycodetil/s', ""),
			'mycodepic'			=> input('mycodepic/s', ""),
			'brokerformpic'		=> input('brokerformpic/s', ""),
			'agentformpic'		=> input('agentformpic/s', ""),
			'workerformpic'		=> input('workerformpic/s', ""),
			'addcomjobs'		=> input('addcomjobs/d', 0),
			'addcomjobswyp'		=> input('addcomjobswyp/d', 0),
			'topcomjobs'		=> input('topcomjobs/d', 0),
			'adddemand'			=> input('adddemand/d', 0),
			'adddemandwyd'		=> input('adddemandwyd/d', 0),
			'topdemand'			=> input('topdemand/d', 0),
			'addsupply'			=> input('addsupply/d', 0),
			'topsupply'			=> input('topsupply/d', 0),
			'teldemand'			=> input('teldemand/d', 0),
			'telsupply'			=> input('telsupply/d', 0),
			'defviewtol'		=> input('defviewtol/d', 0) 
		);
		if ($param==null){
			ParamModel::create($data);
		}else{
			$data['id'] = $param->id;
			ParamModel::update($data);
		}
		exit(json_encode(array(
			'code' 	=> 0,
			'msg'   => ""
		)));
	}
	
}