travel/service/app/admin/controller/QaController.php

66 lines
1.8 KiB
PHP
Raw Normal View History

2024-06-24 20:58:23 +08:00
<?php
namespace app\admin\controller;
use app\model\Qas;
use support\Request;
class QaController extends base
{
public function getQaList(Request $request)
{
2024-06-26 15:38:38 +08:00
$list = Qas::fieldRaw('city_name,title,content')->select();
2024-06-24 20:58:23 +08:00
return $this->success($list);
}
public function getQaDetail(Request $request)
{
2024-06-26 15:38:38 +08:00
$id = $request->get('id');
if (empty($id)) return $this->error(2001, 'id data cannot be empty!');
2024-06-24 20:58:23 +08:00
2024-06-26 15:38:38 +08:00
$data = Qas::fieldRaw('id,city_name,title,content')->find();
2024-06-24 20:58:23 +08:00
return $this->success($data);
}
public function addQa(Request $request)
{
$post = $request->post();
2024-06-26 15:38:38 +08:00
if (empty($post['city_name'])) return $this->error(2001, 'city_name data cannot be empty!');
2024-06-24 20:58:23 +08:00
if (empty($post['title'])) return $this->error(2001, 'title data cannot be empty!');
if (empty($post['content'])) return $this->error(2001, 'content data cannot be empty!');
try {
$data = Qas::create($post);
} catch (\Exception $e) {
return $this->error(2002, $e->getMessage());
}
return $this->success($data);
}
public function editQa(Request $request)
{
$post = $request->post();
if (empty($post['id'])) return $this->error(2001, 'id data cannot be empty!');
try {
$data = Qas::update($post);
} catch (\Exception $e) {
return $this->error(2002, $e->getMessage());
}
return $this->success($data);
}
public function delQa(Request $request)
{
$id = $request->get('id');
if (empty($id)) return $this->error(2001, 'id data cannot be empty!');
try {
$data = Qas::destroy($id);
} catch (\Exception $e) {
return $this->error(2002, $e->getMessage());
}
return $this->success($data);
}
}