www_fpvone_cn/application/admin/controller/Schedule.php

215 lines
5.7 KiB
PHP
Raw Normal View History

2024-12-20 12:29:51 +08:00
<?php
/**
* @Created by PhpStorm.
* @Author:Soar
* @Time:2023/11/21 15:11
*/
namespace app\admin\controller;
use app\admin\service\ScheduleService;
use app\common\controller\Backend;
use think\Validate;
class Schedule extends Backend
{
protected $noNeedLogin = ["*"];
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->scheduleService = new ScheduleService();
}
public function getSchedule()
{
$param['match_id'] = $this->request->param("match_id");
$rule = [
'match_id' => 'require',
];
$msg = [
'match_id.require' => '赛事ID不可为空',
];
$validate = new Validate($rule, $msg);
$result = $validate->check($param);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
}
$res = $this->scheduleService->getByWhere($param);
if ($res) {
$resule['data'] = $res;
$resule['code'] = 1;
$resule['msg'] = "获取成功";
} else {
$resule['data'] = [];
$resule['code'] = 1;
$resule['msg'] = "获取失败";
}
return json($resule);
}
public function getOneSchedule()
{
$param['id'] = $this->request->param("id");
$rule = [
'id' => 'require',
];
$msg = [
'id.require' => 'id不可为空',
];
$validate = new Validate($rule, $msg);
$result = $validate->check($param);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
}
$res = $this->scheduleService->getOne($param['id']);
if ($res) {
$resule['data'] = $res;
$resule['code'] = 1;
$resule['msg'] = "获取成功";
} else {
$resule['data'] = [];
$resule['code'] = 1;
$resule['msg'] = "获取失败";
}
return json($resule);
}
public function delete()
{
$param['id'] = $this->request->param("id");
$rule = [
'id' => 'require',
];
$msg = [
'id.require' => 'id不可为空',
];
$validate = new Validate($rule, $msg);
$result = $validate->check($param);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
}
$res = $this->scheduleService->delSchedule($param['id']);
if ($res) {
$resule['data'] = [];
$resule['code'] = 1;
$resule['msg'] = "删除成功";
} else {
$resule['data'] = [];
$resule['code'] = 1;
$resule['msg'] = "删除失败";
}
return json($resule);
}
public function add()
{
$param['match_id'] = $this->request->param("match_id");
$param['title'] = $this->request->param("title");
$param['content'] = $this->request->param("content");
$param['date'] = $this->request->param("date");
$param['weigh'] = $this->request->param("weigh");
$rule = [
'title' => 'require',
'match_id' => 'require',
'content' => 'require',
'date' => 'require',
];
$msg = [
'title.require' => '标题不可为空',
'match_id.require' => '赛程数据不可为空',
'date.require' => '日期不可为空',
'content.require' => '日程内容不可为空',
];
$validate = new Validate($rule, $msg);
$result = $validate->check($param);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
}
$res = $this->scheduleService->addSchedule($param);
if ($res) {
$resule['data'] = [];
$resule['code'] = 1;
$resule['msg'] = "添加成功";
} else {
$resule['data'] = [];
$resule['code'] = 1;
$resule['msg'] = "添加失败";
}
return json($resule);
}
public function editSchedule()
{
$param['match_id'] = $this->request->param("match_id");
$param['title'] = $this->request->param("title");
$param['content'] = $this->request->param("content");
$param['date'] = $this->request->param("date");
$param['weigh'] = $this->request->param("weigh");
$param['id'] = $this->request->param("id");
$rule = [
'title' => 'require',
'match_id' => 'require',
'content' => 'require',
'date' => 'require',
'id' => 'require',
];
$msg = [
'title.require' => '标题不可为空',
'match_id.require' => '赛程数据不可为空',
'date.require' => '日期不可为空',
'content.require' => '日程内容不可为空',
'id.require' => '修改日程ID不可为空',
];
$validate = new Validate($rule, $msg);
$result = $validate->check($param);
if (!$result) {
$this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
}
$res = $this->scheduleService->editSchedule($param);
if ($res) {
$resule['data'] = [];
$resule['code'] = 1;
$resule['msg'] = "修改成功";
} else {
$resule['data'] = [];
$resule['code'] = 1;
$resule['msg'] = "修改失败";
}
return json($resule);
}
}