触客宝 内容管理提交
This commit is contained in:
@@ -31,6 +31,12 @@ Route::group('v1/', function () {
|
||||
Route::get('details', 'app\chukebao\controller\MessageController@details'); // 消息详情
|
||||
});
|
||||
|
||||
//微信分组
|
||||
Route::get('wechatGroup/list', 'app\chukebao\controller\WechatGroupController@getList'); // 微信分组
|
||||
|
||||
|
||||
|
||||
|
||||
//AI相关
|
||||
Route::group('ai/', function () {
|
||||
//问答
|
||||
@@ -84,6 +90,44 @@ Route::group('v1/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\TokensRecordController@getList');
|
||||
});
|
||||
|
||||
|
||||
|
||||
//内容管理
|
||||
Route::group('content/', function () {
|
||||
//素材管理
|
||||
Route::group('material/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\ContentController@getMaterial');
|
||||
Route::post('add', 'app\chukebao\controller\ContentController@createMaterial');
|
||||
Route::get('details', 'app\chukebao\controller\ContentController@detailsMaterial');
|
||||
Route::get('del', 'app\chukebao\controller\ContentController@delMaterial');
|
||||
Route::post('update', 'app\chukebao\controller\ContentController@updateMaterial');
|
||||
});
|
||||
|
||||
//违禁词管理
|
||||
Route::group('sensitiveWord/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\ContentController@getSensitiveWord');
|
||||
Route::post('add', 'app\chukebao\controller\ContentController@createSensitiveWord');
|
||||
Route::get('details', 'app\chukebao\controller\ContentController@detailsSensitiveWord');
|
||||
Route::get('del', 'app\chukebao\controller\ContentController@delSensitiveWord');
|
||||
Route::post('update', 'app\chukebao\controller\ContentController@updateSensitiveWord');
|
||||
Route::get('setStatus', 'app\chukebao\controller\ContentController@setSensitiveWordStatus');
|
||||
});
|
||||
|
||||
|
||||
//关键词管理
|
||||
Route::group('keywords/', function () {
|
||||
Route::get('list', 'app\chukebao\controller\ContentController@getKeywords');
|
||||
Route::post('add', 'app\chukebao\controller\ContentController@createKeywords');
|
||||
Route::get('details', 'app\chukebao\controller\ContentController@detailsKeywords');
|
||||
Route::get('del', 'app\chukebao\controller\ContentController@delKeywords');
|
||||
Route::post('update', 'app\chukebao\controller\ContentController@updateKeywords');
|
||||
Route::get('setStatus', 'app\chukebao\controller\ContentController@setKeywordStatus');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
631
Server/application/chukebao/controller/ContentController.php
Normal file
631
Server/application/chukebao/controller/ContentController.php
Normal file
@@ -0,0 +1,631 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\controller;
|
||||
|
||||
use app\chukebao\model\Keywords;
|
||||
use app\chukebao\model\Material;
|
||||
use app\chukebao\model\SensitiveWord;
|
||||
use think\Db;
|
||||
use library\ResponseHelper;
|
||||
|
||||
class ContentController extends BaseController
|
||||
{
|
||||
//===================================================== 素材管理 =====================================================
|
||||
/**
|
||||
* 素材列表
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getMaterial(){
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$keyword = $this->request->param('keyword', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
$query = Material::where(['userId' => $userId,'companyId' => $companyId,'isDel' => 0])
|
||||
->order('id desc');
|
||||
if (!empty($keyword)){
|
||||
$query->where('title', 'like', '%'.$keyword.'%');
|
||||
}
|
||||
$list = $query->page($page, $limit)->select()->toArray();
|
||||
$total = $query->count();
|
||||
|
||||
foreach ($list as $k => &$v){
|
||||
$user = Db::name('users')->where(['id' => $v['userId']])->field('username,account')->find();
|
||||
if (!empty($user)){
|
||||
$v['userName'] = !empty($user['username']) ? $user['username'] : $user['account'];
|
||||
}else{
|
||||
$v['userName'] = '';
|
||||
}
|
||||
}
|
||||
unset($v);
|
||||
return ResponseHelper::success(['list'=>$list,'total'=>$total]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 素材添加
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createMaterial(){
|
||||
$title = $this->request->param('title', '');
|
||||
$content = $this->request->param('content', []);
|
||||
$cover = $this->request->param('cover', '');
|
||||
$status = $this->request->param('status', 0);
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($title) || empty($content) || empty($cover)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
$newContent = [];
|
||||
foreach ($content as $k => $v){
|
||||
if (in_array($v,['text','image','video','audio','file','link'])){
|
||||
$newContent[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$query = new Material();
|
||||
$query->title = $title;
|
||||
$query->content = !empty($newContent) ? json_encode($newContent,256) : json_encode([],256);
|
||||
$query->cover = $cover;
|
||||
$query->status = $status;
|
||||
$query->userId = $userId;
|
||||
$query->companyId = $companyId;
|
||||
$query->createTime = time();
|
||||
$query->updateTime = time();
|
||||
$query->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ','创建成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('创建失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 素材详情
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function detailsMaterial()
|
||||
{
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($id)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
$data = Material::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($data)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
$data['content'] = json_decode($data['content'],true);
|
||||
unset($data['createTime'],$data['updateTime'],$data['isDel'],$data['delTime']);
|
||||
return ResponseHelper::success($data,'获取成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除素材
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delMaterial()
|
||||
{
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($id)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
$data = Material::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($data)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data->isDel = 1;
|
||||
$data->delTime = time();
|
||||
$data->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success('','删除成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('删除失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改素材
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateMaterial(){
|
||||
$id = $this->request->param('id', '');
|
||||
$title = $this->request->param('title', '');
|
||||
$content = $this->request->param('content', []);
|
||||
$cover = $this->request->param('cover', '');
|
||||
$status = $this->request->param('status', 0);
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($id) || empty($title) || empty($content) || empty($cover)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
$newContent = [];
|
||||
foreach ($content as $k => $v){
|
||||
if (in_array($v,['text','image','video','audio','file','link'])){
|
||||
$newContent[] = $v;
|
||||
}
|
||||
}
|
||||
$query = Material::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($query)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$query->title = $title;
|
||||
$query->content = !empty($newContent) ? json_encode($newContent,256) : json_encode([],256);
|
||||
$query->cover = $cover;
|
||||
$query->status = $status;
|
||||
$query->updateTime = time();
|
||||
$query->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ','修改成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('修改失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
//===================================================== 素材管理 =====================================================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================== 违禁词管理 ====================================================
|
||||
|
||||
/**
|
||||
* 违禁词列表
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getSensitiveWord(){
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$keyword = $this->request->param('keyword', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
$query = SensitiveWord::where(['userId' => $userId,'companyId' => $companyId,'isDel' => 0])
|
||||
->order('id desc');
|
||||
if (!empty($keyword)){
|
||||
$query->where('title', 'like', '%'.$keyword.'%');
|
||||
}
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->select()->toArray();
|
||||
|
||||
|
||||
foreach ($list as $k => &$v){
|
||||
$user = Db::name('users')->where(['id' => $v['userId']])->field('username,account')->find();
|
||||
if (!empty($user)){
|
||||
$v['userName'] = !empty($user['username']) ? $user['username'] : $user['account'];
|
||||
}else{
|
||||
$v['userName'] = '';
|
||||
}
|
||||
}
|
||||
unset($v);
|
||||
return ResponseHelper::success(['list'=>$list,'total'=>$total]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 违禁词添加
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createSensitiveWord(){
|
||||
$title = $this->request->param('title', '');
|
||||
$keywords = $this->request->param('keywords', '');
|
||||
$content = $this->request->param('content', '');
|
||||
$status = $this->request->param('status', 0);
|
||||
$operation = $this->request->param('operation', 0);
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($title) || empty($keywords)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
|
||||
$keywords = explode(',',$keywords);
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$query = new SensitiveWord();
|
||||
$query->title = $title;
|
||||
$query->keywords = $keywords;
|
||||
$query->content = $content;
|
||||
$query->status = $status;
|
||||
$query->operation = $operation;
|
||||
$query->userId = $userId;
|
||||
$query->companyId = $companyId;
|
||||
$query->createTime = time();
|
||||
$query->updateTime = time();
|
||||
$query->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ','创建成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('创建失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 违禁词详情
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function detailsSensitiveWord()
|
||||
{
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($id)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
$data = SensitiveWord::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($data)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
$data['keywords'] = json_decode($data['keywords'],true);
|
||||
$data['keywords'] = implode(',',$data['keywords']);
|
||||
unset($data['createTime'],$data['updateTime'],$data['isDel'],$data['delTime']);
|
||||
return ResponseHelper::success($data,'获取成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 违禁词删除
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delSensitiveWord()
|
||||
{
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($id)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
$data = SensitiveWord::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($data)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data->isDel = 1;
|
||||
$data->delTime = time();
|
||||
$data->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success('','删除成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('删除失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新违禁词
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateSensitiveWord(){
|
||||
$id = $this->request->param('id', '');
|
||||
$title = $this->request->param('title', '');
|
||||
$keywords = $this->request->param('keywords', '');
|
||||
$content = $this->request->param('content', '');
|
||||
$status = $this->request->param('status', 0);
|
||||
$operation = $this->request->param('operation', 0);
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($id) || empty($title) || empty($keywords)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
|
||||
$keywords = explode(',',$keywords);
|
||||
|
||||
$query = SensitiveWord::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($query)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$query->title = $title;
|
||||
$query->keywords = $keywords;
|
||||
$query->content = $content;
|
||||
$query->status = $status;
|
||||
$query->operation = $operation;
|
||||
$query->updateTime = time();
|
||||
$query->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ','修改成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('修改失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改违禁词状态
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setSensitiveWordStatus(){
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($id)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
|
||||
$query = SensitiveWord::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($query)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$query->status = !empty($query['status']) ? 0 : 1;;
|
||||
$query->updateTime = time();
|
||||
$query->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ','修改成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('修改失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==================================================== 违禁词管理 ====================================================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//=================================================== 关键词词管理 ====================================================
|
||||
|
||||
/**
|
||||
* 关键词列表
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getKeywords(){
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$keyword = $this->request->param('keyword', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
$query = Keywords::where(['userId' => $userId,'companyId' => $companyId,'isDel' => 0])
|
||||
->order('id desc');
|
||||
if (!empty($keyword)){
|
||||
$query->where('title', 'like', '%'.$keyword.'%');
|
||||
}
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->select()->toArray();
|
||||
|
||||
|
||||
foreach ($list as $k => &$v){
|
||||
$user = Db::name('users')->where(['id' => $v['userId']])->field('username,account')->find();
|
||||
if (!empty($user)){
|
||||
$v['userName'] = !empty($user['username']) ? $user['username'] : $user['account'];
|
||||
}else{
|
||||
$v['userName'] = '';
|
||||
}
|
||||
}
|
||||
unset($v);
|
||||
return ResponseHelper::success(['list'=>$list,'total'=>$total]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关键词添加
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createKeywords(){
|
||||
$title = $this->request->param('title', '');
|
||||
$type = $this->request->param('type', 0);
|
||||
$keywords = $this->request->param('keywords', '');
|
||||
$replyType = $this->request->param('replyType', 0);
|
||||
$content = $this->request->param('content','');
|
||||
$materialId = $this->request->param('materialId','');
|
||||
$status = $this->request->param('status', 0);
|
||||
$sort = $this->request->param('sort', 50);
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($title) || empty($keywords) || (empty($materialId) && empty($content))){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
|
||||
$keywords = explode(',',$keywords);
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$query = new Keywords();
|
||||
$query->title = $title;
|
||||
$query->type = $type;
|
||||
$query->keywords = !empty($keywords) ? json_encode($keywords,256) : json_encode([]);
|
||||
$query->replyType = $replyType;
|
||||
$query->content = !empty($content) ? json_encode($content,256) : json_encode([]);;
|
||||
$query->materialId = $materialId;
|
||||
$query->status = $status;
|
||||
$query->sort = $sort;
|
||||
$query->userId = $userId;
|
||||
$query->companyId = $companyId;
|
||||
$query->createTime = time();
|
||||
$query->updateTime = time();
|
||||
$query->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ','创建成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('创建失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 关键词详情
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function detailsKeywords()
|
||||
{
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($id)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
$data = Keywords::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($data)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
$data['content'] = json_decode($data['content'],true);
|
||||
$data['keywords'] = json_decode($data['keywords'],true);
|
||||
$data['keywords'] = implode(',',$data['keywords']);
|
||||
unset($data['createTime'],$data['updateTime'],$data['isDel'],$data['delTime']);
|
||||
return ResponseHelper::success($data,'获取成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键词删除
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delKeywords()
|
||||
{
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
if (empty($id)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
$data = Keywords::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($data)){
|
||||
return ResponseHelper::error('该关键词已被删除或者不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data->isDel = 1;
|
||||
$data->delTime = time();
|
||||
$data->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success('','删除成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('删除失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新关键词
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateKeywords(){
|
||||
$id = $this->request->param('id', '');
|
||||
$title = $this->request->param('title', '');
|
||||
$type = $this->request->param('type', 0);
|
||||
$keywords = $this->request->param('keywords', '');
|
||||
$replyType = $this->request->param('replyType', 0);
|
||||
$content = $this->request->param('content','');
|
||||
$materialId = $this->request->param('materialId','');
|
||||
$status = $this->request->param('status', 0);
|
||||
$sort = $this->request->param('sort', 50);
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($title) || empty($keywords) || (empty($materialId) && empty($content))){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
|
||||
$keywords = explode(',',$keywords);
|
||||
|
||||
$query = Keywords::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($query)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$query->title = $title;
|
||||
$query->type = $type;
|
||||
$query->keywords = !empty($keywords) ? json_encode($keywords,256) : json_encode([]);
|
||||
$query->replyType = $replyType;
|
||||
$query->content = !empty($content) ? json_encode($content,256) : json_encode([]);;
|
||||
$query->materialId = $materialId;
|
||||
$query->status = $status;
|
||||
$query->sort = $sort;
|
||||
$query->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ','修改成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('修改失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改关键词状态
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setKeywordStatus(){
|
||||
$id = $this->request->param('id', '');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
if (empty($id)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
|
||||
$query = Keywords::where(['id'=>$id,'isDel' => 0,'userId' => $userId,'companyId' => $companyId])->find();
|
||||
if (empty($query)){
|
||||
return ResponseHelper::error('该素材已被删除或者不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$query->status = !empty($query['status']) ? 0 : 1;
|
||||
$query->updateTime = time();
|
||||
$query->save();
|
||||
Db::commit();
|
||||
return ResponseHelper::success(' ','修改成功');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ResponseHelper::error('修改失败:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=================================================== 关键词词管理 ====================================================
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -41,8 +41,9 @@ class FollowUpController extends BaseController
|
||||
|
||||
$query = FollowUp::where($where);
|
||||
|
||||
$list = $query->where($where)->page($page,$limit)->order('id desc')->select();
|
||||
$total = $query->count();
|
||||
$list = $query->where($where)->page($page,$limit)->order('id desc')->select();
|
||||
|
||||
|
||||
foreach ($list as &$item) {
|
||||
$nickname = Db::table('s2_wechat_friend')->where(['id' => $item['friendId']])->value('nickname');
|
||||
|
||||
@@ -133,9 +133,9 @@ class MessageController extends BaseController
|
||||
$where[] = ['wechatTime','between',[$from,$to]];
|
||||
}
|
||||
|
||||
|
||||
$list = Db::table('s2_wechat_message')->where($where)->page($page,$limit)->order('id DESC')->select();
|
||||
$total = Db::table('s2_wechat_message')->where($where)->count();
|
||||
$list = Db::table('s2_wechat_message')->where($where)->page($page,$limit)->order('id DESC')->select();
|
||||
|
||||
|
||||
|
||||
foreach ($list as $k=>&$v){
|
||||
|
||||
@@ -30,8 +30,9 @@ class QuestionsController extends BaseController
|
||||
if (!empty($keyword)){
|
||||
$query->where('questions|answers', 'like', '%'.$keyword.'%');
|
||||
}
|
||||
$list = $query->page($page, $limit)->select()->toArray();
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->select()->toArray();
|
||||
|
||||
|
||||
foreach ($list as $k => &$v){
|
||||
$user = Db::name('users')->where(['id' => $v['userId']])->field('username,account')->find();
|
||||
|
||||
@@ -40,9 +40,9 @@ class ToDoController extends BaseController
|
||||
}
|
||||
|
||||
$query = ToDo::where($where);
|
||||
|
||||
$list = $query->where($where)->page($page,$limit)->order('id desc')->select();
|
||||
$total = $query->count();
|
||||
$list = $query->where($where)->page($page,$limit)->order('id desc')->select();
|
||||
|
||||
|
||||
foreach ($list as &$item) {
|
||||
$nickname = Db::table('s2_wechat_friend')->where(['id' => $item['friendId']])->value('nickname');
|
||||
|
||||
@@ -33,9 +33,9 @@ class TokensRecordController extends BaseController
|
||||
|
||||
|
||||
$query = TokensRecord::where($where);
|
||||
|
||||
$list = $query->where($where)->page($page,$limit)->order('id desc')->select();
|
||||
$total = $query->count();
|
||||
$list = $query->where($where)->page($page,$limit)->order('id desc')->select();
|
||||
|
||||
|
||||
foreach ($list as &$item) {
|
||||
if (in_array($item['type'],[1])){
|
||||
|
||||
@@ -20,8 +20,9 @@ class WechatChatroomController extends BaseController
|
||||
$query = Db::table('s2_wechat_chatroom')
|
||||
->where(['accountId' => $accountId,'isDeleted' => 0])
|
||||
->order('id desc');
|
||||
$list = $query->page($page, $limit)->select();
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
|
||||
|
||||
|
||||
// 提取所有聊天室ID,用于批量查询
|
||||
|
||||
@@ -18,8 +18,9 @@ class WechatFriendController extends BaseController
|
||||
$query = Db::table('s2_wechat_friend')
|
||||
->where(['accountId' => $accountId,'isDeleted' => 0])
|
||||
->order('id desc');
|
||||
$list = $query->page($page, $limit)->select();
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
|
||||
|
||||
|
||||
// 提取所有好友ID
|
||||
@@ -73,6 +74,8 @@ class WechatFriendController extends BaseController
|
||||
|
||||
// 处理每个好友的数据
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['labels'] = json_decode($v['labels'], true);
|
||||
$v['siteLabels'] = json_decode($v['siteLabels'], true);
|
||||
$v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s', $v['createTime']) : '';
|
||||
$v['updateTime'] = !empty($v['updateTime']) ? date('Y-m-d H:i:s', $v['updateTime']) : '';
|
||||
$v['passTime'] = !empty($v['passTime']) ? date('Y-m-d H:i:s', $v['passTime']) : '';
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\controller;
|
||||
|
||||
use library\ResponseHelper;
|
||||
use think\Db;
|
||||
|
||||
class WechatGroupController extends BaseController
|
||||
{
|
||||
|
||||
public function getList(){
|
||||
|
||||
$accountId = $this->getUserInfo('s2_accountId');
|
||||
$userId = $this->getUserInfo('id');
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
$query = Db::table('s2_wechat_group')->where(['accountId' => $accountId])->whereIn('groupType',[1,2])->order('sortIndex desc,id desc');
|
||||
$list = $query->select();
|
||||
$total = $query->count();
|
||||
|
||||
|
||||
// 处理每个好友的数据
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s', $v['createTime']) : '';
|
||||
}
|
||||
unset($v);
|
||||
|
||||
return ResponseHelper::success(['list'=>$list,'total'=>$total]);
|
||||
}
|
||||
}
|
||||
17
Server/application/chukebao/model/Keywords.php
Normal file
17
Server/application/chukebao/model/Keywords.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\model;
|
||||
|
||||
use think\Model;
|
||||
class Keywords extends Model
|
||||
{
|
||||
protected $pk = 'id';
|
||||
protected $name = 'kf_keywords';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
|
||||
}
|
||||
17
Server/application/chukebao/model/Material.php
Normal file
17
Server/application/chukebao/model/Material.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\model;
|
||||
|
||||
use think\Model;
|
||||
class Material extends Model
|
||||
{
|
||||
protected $pk = 'id';
|
||||
protected $name = 'kf_material';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
|
||||
}
|
||||
17
Server/application/chukebao/model/SensitiveWord.php
Normal file
17
Server/application/chukebao/model/SensitiveWord.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\chukebao\model;
|
||||
|
||||
use think\Model;
|
||||
class SensitiveWord extends Model
|
||||
{
|
||||
protected $pk = 'id';
|
||||
protected $name = 'kf_sensitive_word';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user