计划任务 - 获客场景
This commit is contained in:
15
Server/application/plan/config/route.php
Normal file
15
Server/application/plan/config/route.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 计划模块路由配置
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\facade\Route;
|
||||
|
||||
// 定义RESTful风格的API路由
|
||||
Route::group('v1/', function () {
|
||||
// 获客场景相关
|
||||
Route::group('plan/scenes', function () {
|
||||
Route::get('', 'app\\plan\\controller\\Scene@index'); // 获取场景列表
|
||||
Route::get(':id', 'app\\plan\\controller\\Scene@read'); // 获取场景详情
|
||||
});
|
||||
})->middleware(['jwt']);
|
||||
67
Server/application/plan/controller/Scene.php
Normal file
67
Server/application/plan/controller/Scene.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace app\plan\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Request;
|
||||
use app\plan\model\PlanScene;
|
||||
|
||||
/**
|
||||
* 获客场景控制器
|
||||
*/
|
||||
class Scene extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取场景列表
|
||||
*
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$page = Request::param('page', 1, 'intval');
|
||||
$limit = Request::param('limit', 10, 'intval');
|
||||
$keyword = Request::param('keyword', '');
|
||||
|
||||
// 构建查询条件
|
||||
$where = [];
|
||||
if (!empty($keyword)) {
|
||||
$where[] = ['name', 'like', "%{$keyword}%"];
|
||||
}
|
||||
|
||||
// 默认只显示有效场景
|
||||
$where[] = ['status', '=', 1];
|
||||
|
||||
// 查询列表
|
||||
$result = PlanScene::getSceneList($where, 'id desc', $page, $limit);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $result
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个场景详情
|
||||
*
|
||||
* @param int $id 场景ID
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
// 查询场景信息
|
||||
$scene = PlanScene::getSceneInfo($id);
|
||||
|
||||
if (!$scene) {
|
||||
return json([
|
||||
'code' => 404,
|
||||
'msg' => '场景不存在'
|
||||
]);
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $scene
|
||||
]);
|
||||
}
|
||||
}
|
||||
75
Server/application/plan/model/PlanScene.php
Normal file
75
Server/application/plan/model/PlanScene.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace app\plan\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 获客场景模型类
|
||||
*/
|
||||
class PlanScene extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $name = 'plan_scene';
|
||||
protected $prefix = 'tk_';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
protected $deleteTime = 'deleteTime';
|
||||
|
||||
// 定义字段类型
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'status' => 'integer',
|
||||
'createTime' => 'integer',
|
||||
'updateTime' => 'integer',
|
||||
'deleteTime' => 'integer'
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取场景列表
|
||||
*
|
||||
* @param array $where 查询条件
|
||||
* @param string $order 排序
|
||||
* @param int $page 页码
|
||||
* @param int $limit 每页数量
|
||||
* @return array 场景列表和总数
|
||||
*/
|
||||
public static function getSceneList($where = [], $order = 'id desc', $page = 1, $limit = 10)
|
||||
{
|
||||
// 构建查询
|
||||
$query = self::where($where);
|
||||
|
||||
// 计算总数
|
||||
$total = $query->count();
|
||||
|
||||
// 分页查询数据
|
||||
$list = $query->page($page, $limit)
|
||||
->order($order)
|
||||
->select();
|
||||
|
||||
return [
|
||||
'list' => $list,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个场景信息
|
||||
*
|
||||
* @param int $id 场景ID
|
||||
* @return array|null 场景信息
|
||||
*/
|
||||
public static function getSceneInfo($id)
|
||||
{
|
||||
return self::where('id', $id)->find();
|
||||
}
|
||||
}
|
||||
@@ -27,4 +27,7 @@ include __DIR__ . '/../application/store/config/route.php';
|
||||
// 加载CozeAI模块路由配置
|
||||
include __DIR__ . '/../application/cozeai/config/route.php';
|
||||
|
||||
// 加载Plan模块路由配置
|
||||
include __DIR__ . '/../application/plan/config/route.php';
|
||||
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user