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

102 lines
2.9 KiB
PHP
Raw Normal View History

2024-06-24 20:58:23 +08:00
<?php
namespace app\admin\controller;
2024-06-27 17:34:53 +08:00
use app\model\QaCitys;
2024-06-24 20:58:23 +08:00
use app\model\Qas;
use support\Request;
class QaController extends base
{
public function getQaList(Request $request)
{
2024-06-27 17:34:53 +08:00
$city_id = $request->get('city_id');
if (empty($city_id)) return $this->error(2001, 'city_id data cannot be empty!');
$list = Qas::where(['status'=>1,'city_id'=>$city_id])->fieldRaw('title,content')->select();
return $this->success($list);
}
/**
* cms list
* @param Request $request
* @return \support\Response
* @throws \think\db\exception\DbException
*/
public function getQa(Request $request)
{
$title = $request->get('title');
$status = $request->get('status');
$list = Qas::order('create_time desc');
if (!empty($title)){
$list = $list->where('title','like','%'.$title.'%');
}
if (!empty($status)){
$list = $list->where('status',$status);
}
$list = $list->paginate($request->get('limit',10));
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-27 17:34:53 +08:00
$data = Qas::where('status',1)->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!');
2024-06-27 17:34:53 +08:00
unset($post['create_time']);
unset($post['update_time']);
2024-06-24 20:58:23 +08:00
try {
$data = Qas::update($post);
} catch (\Exception $e) {
return $this->error(2002, $e->getMessage());
}
return $this->success($data);
}
public function delQa(Request $request)
{
2024-06-27 17:34:53 +08:00
$id = $request->post('id');
2024-06-24 20:58:23 +08:00
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);
}
2024-06-27 17:34:53 +08:00
public function getQaCityList()
{
$list = QaCitys::order('city_id desc')->select();
return $this->success($list);
}
2024-06-24 20:58:23 +08:00
}