88 lines
2.2 KiB
PHP
88 lines
2.2 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* @Created by PhpStorm.
|
||
|
* @Author:Soar
|
||
|
* @Time:2023/11/21 15:09
|
||
|
*/
|
||
|
|
||
|
namespace app\admin\service;
|
||
|
|
||
|
use app\admin\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'];
|
||
|
$data['weigh'] = $add_data['weigh'];
|
||
|
|
||
|
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'];
|
||
|
$data['weigh'] = $edit_data['weigh'];
|
||
|
$id = $edit_data['id'];
|
||
|
|
||
|
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());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|