www_fpvone_cn/application/index/service/ScheduleService.php

85 lines
2.1 KiB
PHP

<?php
/**
* @Created by PhpStorm.
* @Author:Soar
* @Time:2023/11/21 16:23
*/
namespace app\index\service;
use app\common\model\MatchSchedule;
use think\Db;
use Yansongda\Pay\Exception\Exception;
class ScheduleService extends Service
{
public function __construct()
{
$this->matchScheduleModel = new MatchSchedule();
}
public function getOne($scheduleId)
{
return $this->matchScheduleModel->get($scheduleId);
}
public function getByWhere($param)
{
return $this->matchScheduleModel->all($param);
}
public function addSchedule($add_data)
{
$data['match_id'] = $add_data['match_id'];
$data['title'] = $add_data['title'];
$data['content'] = $add_data['content'];
$data['schedule_date'] = $add_data['date'];
Db::startTrans();
try {
if ($this->matchScheduleModel->insertGetId($data)) {
Db::commit();
}
return true;
} catch (Exception $exception) {
Db::rollback();
$this->error($exception->getMessage());
}
}
public function editSchedule($edit_data)
{
$data['match_id'] = $edit_data['match_id'];
$data['title'] = $edit_data['title'];
$data['content'] = $edit_data['content'];
$data['schedule_date'] = $edit_data['date'];
$id = $edit_data['date'];
Db::startTrans();
try {
if ($this->matchScheduleModel->update($data, ['id' => $id])) {
Db::commit();
}
return true;
} catch (Exception $exception) {
Db::rollback();
$this->error($exception->getMessage());
}
}
public function delSchedule($scheduleId)
{
Db::startTrans();
try {
if ($this->matchScheduleModel->where('id', $scheduleId)->delete()) {
Db::commit();
}
return true;
} catch (Exception $exception) {
Db::rollback();
$this->error($exception->getMessage());
}
}
}