<?php
namespace app\admin\controller;
use think\Cache;
use think\Request;

class Xitong extends \think\Controller{
	
    public function clearCache(){
		if(request()->isPost()){
			try{
				Cache::clear();
			} catch (\Exception $e) {
				$this->error('清空缓存失败');
			}
			$this->success('清空缓存成功');
		}
	}
    public function userd()
	{
		$AgentNameD = \think\Session::clear();
		$this->success("账号已安全退出", url("@admin/Login"));
		return $this->fetch();
	}
	public function index()
	{
		return $this->fetch();
	}
	public function duanxin()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("smsconfig")->field(true)->page($request["page"], $request["limit"])->select();
			if ($data_dx) {
				$data["code"] = 0;
				$data["msg"] = "成功";
				$data["count"] = \think\Db::name("smsconfig")->count();
				$TT = [];
				foreach ($data_dx as $value) {
					$TT[] = array_merge($value);
				}
				$data["data"] = $TT;
			} else {
				$data["code"] = 1;
				$data["msg"] = "无数据";
				$data["count"] = "0";
				$data["data"] = [];
			}
			return json($data);
		}
		return $this->fetch();
	}
	public function smsupdate()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("smsconfig")->field("Id")->where("Id", $request["Id"])->find();
			if ($data_dx) {
				if ($request["field"] != "state") {
					if ($request["field"] == "smsname") {
						if (\think\Db::name("smsconfig")->where("Id", $request["Id"])->update(["smsname" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "templateCode") {
						if (\think\Db::name("smsconfig")->where("Id", $request["Id"])->update(["templateCode" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "smskey") {
						if (\think\Db::name("smsconfig")->where("Id", $request["Id"])->update(["smskey" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "smskey1") {
						if (\think\Db::name("smsconfig")->where("Id", $request["Id"])->update(["smskey1" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					}
				}
			}
			$data["code"] = 0;
			return json($data);
		}
	}
	public function libao()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("shopconfig")->field(true)->page($request["page"], $request["limit"])->select();
			if ($data_dx) {
				$data["code"] = 0;
				$data["msg"] = "成功";
				$data["count"] = \think\Db::name("shopconfig")->count();
				$TT = [];
				foreach ($data_dx as $value) {
					$TT[] = array_merge($value);
				}
				$data["data"] = $TT;
			} else {
				$data["code"] = 1;
				$data["msg"] = "无数据";
				$data["count"] = "0";
				$data["data"] = [];
			}
			return json($data);
		}
		return $this->fetch();
	}
	public function jiekou()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("payconfig")->field(true)->page($request["page"], $request["limit"])->select();
			if ($data_dx) {
				$data["code"] = 0;
				$data["msg"] = "成功";
				$data["count"] = \think\Db::name("payconfig")->count();
				$TT = [];
				foreach ($data_dx as $value) {
					$TT[] = array_merge($value);
				}
				$data["data"] = $TT;
			} else {
				$data["code"] = 1;
				$data["msg"] = "无数据";
				$data["count"] = "0";
				$data["data"] = [];
			}
			return json($data);
		}
		return $this->fetch();
	}
	public function libaoform()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$request["state"] = 1;
			$datae = \think\Db::name("shopconfig")->insert($request);
			if ($datae) {
				$this->success("成功");
			} else {
				$this->success("失败");
			}
		}
		return $this->fetch();
	}
	public function libaoupdate()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("shopconfig")->field("Id")->where("Id", $request["Id"])->find();
			if ($data_dx) {
				if ($request["field"] != "state") {
					if ($request["field"] == "name") {
						if (\think\Db::name("shopconfig")->where("Id", $request["Id"])->update(["name" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "item") {
						if (\think\Db::name("shopconfig")->where("Id", $request["Id"])->update(["item" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "paynum") {
						if (\think\Db::name("shopconfig")->where("Id", $request["Id"])->update(["paynum" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "type") {
						if (\think\Db::name("shopconfig")->where("Id", $request["Id"])->update(["type" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					}elseif($request["field"]=="desc"){
                        if(\think\Db::name("shopconfig")->where("Id", $request["Id"])->update(["desc" => $request["modify"]])){
                            $data["msg"]="成功";
                        }
                    }
				}
			}
			$data["code"] = 0;
			return json($data);
		}
	}
	public function libaoxg()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$username = \think\Db::name("shopconfig")->field("state")->where("Id", $request["Id"])->find();
			if ($username["state"] == 1) {
				if (\think\Db::name("shopconfig")->where("Id", $request["Id"])->update(["state" => "0"])) {
					$data["code"] = 0;
					$data["msg"] = "下架成功";
				}
			}
			if ($username["state"] == 0) {
				if (\think\Db::name("shopconfig")->where("Id", $request["Id"])->update(["state" => "1"])) {
					$data["code"] = 0;
					$data["msg"] = "上架成功";
				}
			}
			return json($data);
		}
	}
	public function leichong()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("leichongconfig")->field(true)->page($request["page"], $request["limit"])->select();
			if ($data_dx) {
				$data["code"] = 0;
				$data["msg"] = "成功";
				$data["count"] = \think\Db::name("leichongconfig")->count();
				$TT = [];
				foreach ($data_dx as $value) {
					$TT[] = array_merge($value);
				}
				$data["data"] = $TT;
			} else {
				$data["code"] = 1;
				$data["msg"] = "无数据";
				$data["count"] = "0";
				$data["data"] = [];
			}
			return json($data);
		}
		return $this->fetch();
	}
	public function leichongform()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$request["state"] = 1;
			$datae = \think\Db::name("leichongconfig")->insert($request);
			if ($datae) {
				$this->success("成功");
			} else {
				$this->success("失败");
			}
		}
		return $this->fetch();
	}
	public function leichongupdate()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("leichongconfig")->field("Id")->where("Id", $request["Id"])->find();
			if ($data_dx) {
				if ($request["field"] != "state") {
					if ($request["field"] == "name") {
						if (\think\Db::name("leichongconfig")->where("Id", $request["Id"])->update(["name" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "item") {
						if (\think\Db::name("leichongconfig")->where("Id", $request["Id"])->update(["item" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "paynum") {
						if (\think\Db::name("leichongconfig")->where("Id", $request["Id"])->update(["paynum" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					}elseif ($request["field"] == "desc") {
						if (\think\Db::name("leichongconfig")->where("Id", $request["Id"])->update(["desc" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					}
				}
			}
			$data["code"] = 0;
			return json($data);
		}
	}
	public function leichongxg()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$username = \think\Db::name("leichongconfig")->field("state")->where("Id", $request["Id"])->find();
			if ($username["state"] == 1) {
				if (\think\Db::name("leichongconfig")->where("Id", $request["Id"])->update(["state" => "0"])) {
					$data["code"] = 0;
					$data["msg"] = "下架成功";
				}
			}
			if ($username["state"] == 0) {
				if (\think\Db::name("leichongconfig")->where("Id", $request["Id"])->update(["state" => "1"])) {
					$data["code"] = 0;
					$data["msg"] = "上架成功";
				}
			}
			return json($data);
		}
	}
	public function meirilc()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("meirilcconfig")->field(true)->page($request["page"], $request["limit"])->select();
			if ($data_dx) {
				$data["code"] = 0;
				$data["msg"] = "成功";
				$data["count"] = \think\Db::name("meirilcconfig")->count();
				$TT = [];
				foreach ($data_dx as $value) {
					$TT[] = array_merge($value);
				}
				$data["data"] = $TT;
			} else {
				$data["code"] = 1;
				$data["msg"] = "无数据";
				$data["count"] = "0";
				$data["data"] = [];
			}
			return json($data);
		}
		return $this->fetch();
	}
	public function meirilcform()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$request["state"] = 1;
			$datae = \think\Db::name("meirilcconfig")->insert($request);
			if ($datae) {
				$this->success("成功");
			} else {
				$this->success("失败");
			}
		}
		return $this->fetch();
	}
	public function meirilcupdate()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("meirilcconfig")->field("Id")->where("Id", $request["Id"])->find();
			if ($data_dx) {
				if ($request["field"] != "state") {
					if ($request["field"] == "name") {
						if (\think\Db::name("meirilcconfig")->where("Id", $request["Id"])->update(["name" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "item") {
						if (\think\Db::name("meirilcconfig")->where("Id", $request["Id"])->update(["item" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					} elseif ($request["field"] == "paynum") {
						if (\think\Db::name("meirilcconfig")->where("Id", $request["Id"])->update(["paynum" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					}elseif ($request["field"] == "desc") {
						if (\think\Db::name("meirilcconfig")->where("Id", $request["Id"])->update(["desc" => $request["modify"]])) {
							$data["msg"] = "成功";
						}
					}
				}
			}
			$data["code"] = 0;
			return json($data);
		}
	}
	public function meirilcxg()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$username = \think\Db::name("meirilcconfig")->field("state")->where("Id", $request["Id"])->find();
			if ($username["state"] == 1) {
				if (\think\Db::name("meirilcconfig")->where("Id", $request["Id"])->update(["state" => "0"])) {
					$data["code"] = 0;
					$data["msg"] = "下架成功";
				}
			}
			if ($username["state"] == 0) {
				if (\think\Db::name("meirilcconfig")->where("Id", $request["Id"])->update(["state" => "1"])) {
					$data["code"] = 0;
					$data["msg"] = "上架成功";
				}
			}
			return json($data);
		}
	}
	public function payupdate()
	{
		$request = \think\Request::instance()->post();
		if ($request) {
			$data_dx = \think\Db::name("payconfig")->field("Id")->where("Id", $request["Id"])->find();
			if ($data_dx) {
				if ($request["field"] == "smsname") {
					if (\think\Db::name("payconfig")->where("Id", $request["Id"])->update(["smsname" => $request["modify"]])) {
						$data["msg"] = "成功";
					}
				} elseif ($request["field"] == "templateCode") {
					if (\think\Db::name("payconfig")->where("Id", $request["Id"])->update(["templateCode" => $request["modify"]])) {
						$data["msg"] = "成功";
					}
				}
			}
			$data["code"] = 0;
			return json($data);
		}
	}
}