111 lines
3.1 KiB
PHP
111 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\model\QaCitys;
|
|
use app\model\Qas;
|
|
use support\Log;
|
|
use support\Request;
|
|
|
|
class QaController extends base
|
|
{
|
|
public function getQaList(Request $request)
|
|
{
|
|
$city_id = $request->get('city_id');
|
|
$keyword = $request->get('keyword');
|
|
|
|
$list = Qas::order('id decs');
|
|
|
|
if (!empty($city_id)){
|
|
$list = $list->where(['status' => 1, 'city_id' => $city_id]);
|
|
}
|
|
if (!empty($keyword)){
|
|
$list = $list->whereRaw("title LIKE ? OR content LIKE ?", ['%'.$keyword.'%', '%'.$keyword.'%']);
|
|
}
|
|
$list = $list->paginate($request->get('limit',10));
|
|
|
|
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::with('qaCitys')->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));
|
|
|
|
return $this->success($list);
|
|
}
|
|
|
|
public function getQaDetail(Request $request)
|
|
{
|
|
$id = $request->get('id');
|
|
if (empty($id)) return $this->error(2001, 'id data cannot be empty!');
|
|
|
|
$data = Qas::where('status',1)->find();
|
|
|
|
return $this->success($data);
|
|
}
|
|
|
|
public function addQa(Request $request)
|
|
{
|
|
$post = $request->post();
|
|
if (empty($post['city_id'])) return $this->error(2001, 'city_id data cannot be empty!');
|
|
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!');
|
|
unset($post['create_time']);
|
|
unset($post['update_time']);
|
|
|
|
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->post('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);
|
|
}
|
|
|
|
public function getQaCityList()
|
|
{
|
|
$list = QaCitys::order('city_id desc')->select();
|
|
return $this->success($list);
|
|
}
|
|
} |