自动问候功能提交

This commit is contained in:
wong
2025-09-26 15:37:15 +08:00
parent 1e1b65684d
commit acabbf30da
11 changed files with 462 additions and 33 deletions

View File

@@ -2,7 +2,7 @@
namespace app\chukebao\controller;
use app\chukebao\model\AiFriendSettings;
use app\chukebao\model\FriendSettings;
use app\chukebao\model\Questions;
use library\ResponseHelper;
use think\Db;
@@ -125,7 +125,7 @@ class AiSettingsController extends BaseController
$wechatAccountId = $this->request->param('wechatAccountId', '');
$userId = $this->getUserInfo('id');
$companyId = $this->getUserInfo('companyId');
$aiType = AiFriendSettings::where(['userId' => $userId, 'companyId' => $companyId,'friendId' => $friendId,'wechatAccountId' => $wechatAccountId])->value('type');
$aiType = FriendSettings::where(['userId' => $userId, 'companyId' => $companyId,'friendId' => $friendId,'wechatAccountId' => $wechatAccountId])->value('type');
if (empty($aiType)) {
$aiType = 0;
}
@@ -154,23 +154,23 @@ class AiSettingsController extends BaseController
return ResponseHelper::error('该好友不存在');
}
$aiFriendSettings = AiFriendSettings::where(['userId' => $userId, 'companyId' => $companyId,'friendId' => $friendId,'wechatAccountId' => $wechatAccountId])->find();
$friendSettings = FriendSettings::where(['userId' => $userId, 'companyId' => $companyId,'friendId' => $friendId,'wechatAccountId' => $wechatAccountId])->find();
Db::startTrans();
try {
if (empty($aiFriendSettings)) {
$aiFriendSettings = new AiFriendSettings();
$aiFriendSettings->companyId = $companyId;
$aiFriendSettings->userId = $userId;
$aiFriendSettings->type = $type;
$aiFriendSettings->wechatAccountId = $wechatAccountId;
$aiFriendSettings->friendId = $friendId;
$aiFriendSettings->createTime = time();
$aiFriendSettings->updateTime = time();
if (empty($friendSettings)) {
$friendSettings = new FriendSettings();
$friendSettings->companyId = $companyId;
$friendSettings->userId = $userId;
$friendSettings->type = $type;
$friendSettings->wechatAccountId = $wechatAccountId;
$friendSettings->friendId = $friendId;
$friendSettings->createTime = time();
$friendSettings->updateTime = time();
}else{
$aiFriendSettings->type = $type;
$aiFriendSettings->updateTime = time();
$friendSettings->type = $type;
$friendSettings->updateTime = time();
}
$aiFriendSettings->save();
$friendSettings->save();
Db::commit();
return ResponseHelper::success(' ', '配置成功');
} catch (\Exception $e) {
@@ -230,11 +230,7 @@ class AiSettingsController extends BaseController
Db::name('ai_friend_settings')->whereIn('friendId',$friendIds)->update(['type' => $type,'updateTime' => time()]);
}
$existing = Db::name('ai_friend_settings')
->where('companyId', $companyId)
->where('friendId', 'in', $friendIds)
->field('friendId')
->select();
$existing = FriendSettings::where('companyId', $companyId)->where('friendId', 'in', $friendIds)->field('friendId')->select();
$existingPhones = array_column($existing, 'friendId');
}