私域操盘手 - 调整场景获客列表业务逻辑

This commit is contained in:
柳清爽
2025-05-19 16:30:19 +08:00
parent 1d0eb15b84
commit 1a9afdd58e
13 changed files with 474 additions and 508 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
* 获客场景模型类
*/
class PlanScene extends Model
{
use SoftDelete;
const STATUS_ACTIVE = 1; // 活动状态
// 设置表名
protected $name = 'plan_scene';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
protected $deleteTime = 'deleteTime';
protected $defaultSoftDelete = 0;
}

View File

@@ -35,9 +35,16 @@ Route::group('v1/', function () {
});
// 获客场景相关
Route::group('plan/scenes', function () {
Route::get('', 'app\cunkebao\controller\Scene@index'); // 获取场景列表
Route::post('create', 'app\cunkebao\controller\Plan@index'); // 获取场景列表
Route::group('plan', function () {
Route::get('scenes', 'app\cunkebao\controller\plan\GetPlanSceneListV1Controller@index');
// 添加计划任务
Route::post('add', 'app\cunkebao\controller\Plan@index');
// 获取计划任务列表
Route::get('list', 'app\cunkebao\controller\Plan@getList');
});
// 流量池相关
@@ -86,15 +93,6 @@ Route::group('v1/', function () {
Route::get('getMemberList', 'app\cunkebao\controller\chatroom\GetChatroomListV1Controller@getMemberList'); // 获取群详情
});
// 计划任务相关路由
Route::group('plan', function () {
// 添加计划任务
Route::post('add', 'app\cunkebao\controller\Plan@index');
// 获取计划任务列表
Route::get('list', 'app\cunkebao\controller\Plan@getList');
});
})->middleware(['jwt']);
return [];

View File

@@ -1,67 +0,0 @@
<?php
namespace app\cunkebao\controller;
use app\cunkebao\model\PlanScene;
use think\Controller;
use think\facade\Request;
/**
* 获客场景控制器
*/
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, 'sort 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
]);
}
}

View File

@@ -1,64 +0,0 @@
<?php
namespace app\cunkebao\controller;
use app\cunkebao\model\TrafficTag as TrafficTagModel;
use think\Controller;
use think\facade\Request;
/**
* 流量标签控制器
*/
class TrafficTag extends Controller
{
/**
* 获取标签列表
*
* @return \think\response\Json
*/
public function index()
{
try {
// 获取登录用户信息
$userInfo = request()->userInfo;
// 获取查询条件
$where = [];
// 关键词搜索
$keyword = Request::param('keyword', '');
if (!empty($keyword)) {
$where[] = ['tagName', 'like', "%{$keyword}%"];
}
// 添加公司ID过滤条件
$where[] = ['companyId', '=', $userInfo['companyId']];
// 获取分页参数
$page = (int)Request::param('page', 1);
$limit = (int)Request::param('limit', 200); // 默认每页显示200条
// 获取排序参数
$sort = Request::param('sort', 'id');
$order = Request::param('order', 'desc');
// 查询列表
$list = TrafficTagModel::getTagsByCompany($where, "{$sort} {$order}", $page, $limit);
return json([
'code' => 200,
'msg' => '获取成功',
'data' => [
'total' => $list->total(),
'list' => $list->items(),
'page' => $page,
'limit' => $limit
]
]);
} catch (\Exception $e) {
return json([
'code' => 500,
'msg' => '获取失败:' . $e->getMessage()
]);
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace app\cunkebao\controller\plan;
use app\common\model\PlanScene as PlansSceneModel;
use app\cunkebao\controller\BaseController;
use library\ResponseHelper;
/**
* 获客场景控制器
*/
class GetPlanSceneListV1Controller extends BaseController
{
/**
* 获取开启的场景列表
*
* @return array
*/
protected function getSceneList(): array
{
return PlansSceneModel::where(
[
'status' => PlansSceneModel::STATUS_ACTIVE
]
)
->order('sort desc')
->select()->toArray();
}
/**
* 获取场景列表
*
* @return \think\response\Json
*/
public function index()
{
return ResponseHelper::success(
$this->getSceneList()
);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace app\cunkebao\controller\plan;
use library\ResponseHelper;
use think\Controller;
use think\Db;
use think\facade\Request;
/**
* 获客场景控制器
*/
class PostCreateAddFriendPlanV1Controller extends Controller
{
/**
* 添加计划任务
*
* @return \think\response\Json
*/
public function index()
{
try {
// 获取表单数据
$data = [
'name' => Request::post('name', ''),
'sceneId' => Request::post('sceneId', 0),
'status' => Request::post('status', 0),
'reqConf' => Request::post('reqConf', ''),
'msgConf' => Request::post('msgConf', ''),
'tagConf' => Request::post('tagConf', ''),
'createTime' => time(),
'updateTime' => time()
];
// 验证必填字段
if (empty($data['name'])) {
return ResponseHelper::error('计划名称不能为空', 400);
}
if (empty($data['sceneId'])) {
return ResponseHelper::error('场景ID不能为空', 400);
}
// 验证数据格式
if (!$this->validateJson($data['reqConf'])) {
return ResponseHelper::error('好友申请设置格式不正确', 400);
}
if (!$this->validateJson($data['msgConf'])) {
return ResponseHelper::error('消息设置格式不正确', 400);
}
if (!$this->validateJson($data['tagConf'])) {
return ResponseHelper::error('标签设置格式不正确', 400);
}
// 插入数据库
$result = Db::name('friend_plan')->insert($data);
if ($result) {
return ResponseHelper::success([], '添加计划任务成功');
} else {
return ResponseHelper::error('添加计划任务失败', 500);
}
} catch (\Exception $e) {
return ResponseHelper::error('系统错误: ' . $e->getMessage(), 500);
}
}
}

View File

@@ -1,43 +0,0 @@
<?php
namespace app\cunkebao\model;
use think\Model;
/**
* 获客场景模型类
*/
class PlanScene extends Model
{
// 设置表名
protected $name = 'plan_scene';
/**
* 获取场景列表
*
* @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
];
}
}