...
|
...
|
@@ -33,6 +33,7 @@ use Illuminate\Support\Arr; |
|
|
use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
/**
|
|
|
* Class ChatRecordService
|
...
|
...
|
@@ -71,7 +72,7 @@ class ChatRecordService extends BaseService |
|
|
// 聊天方式
|
|
|
$type = $request->type;
|
|
|
// 根据标签获取标签内容
|
|
|
$category_id = $request->category_id;
|
|
|
$category_id = $request->category_id ? : 0;
|
|
|
// 默认带上下文
|
|
|
$context = 1;
|
|
|
$labels = [];
|
...
|
...
|
@@ -256,19 +257,21 @@ class ChatRecordService extends BaseService |
|
|
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
$result = $model->items()->create($item);
|
|
|
if (!$result) {
|
|
|
$result1 = $model->items()->create($item);
|
|
|
if (!$result1) {
|
|
|
$this->message = '聊天失败。';
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
ChatRecordItemJob::dispatch($result);
|
|
|
|
|
|
// 发送消息
|
|
|
$result = $this->send($user, $model, $body, $model->context, $stream);
|
|
|
$result2 = $this->send($user, $model, $body, $model->context, $stream);
|
|
|
DB::commit();
|
|
|
|
|
|
return $result;
|
|
|
ChatRecordItemJob::dispatch($result1);
|
|
|
|
|
|
ChatRecordItemJob::dispatch($result2);
|
|
|
|
|
|
return $result2;
|
|
|
} catch (\Exception $e) {
|
|
|
$this->message = $e->getMessage();
|
|
|
|
...
|
...
|
@@ -352,11 +355,12 @@ class ChatRecordService extends BaseService |
|
|
$type = request('type', 1);
|
|
|
$query = $user->chatRecords()->with(['items'])->where('type', $type);
|
|
|
$category_id = request('category_id');
|
|
|
if ($type === 2) {
|
|
|
if ($type == 2) {
|
|
|
$query = $query->where('category_id', $category_id);
|
|
|
}
|
|
|
|
|
|
$model = $query->latest()->first();
|
|
|
Log::info($model);
|
|
|
if (\request('test') == 1) {
|
|
|
dump($model);
|
|
|
}
|
...
|
...
|
@@ -413,7 +417,7 @@ class ChatRecordService extends BaseService |
|
|
$type = request('type', 1);
|
|
|
$query = $user->chatRecords()->with(['items'])->where('type', $type);
|
|
|
$category_id = request('category_id');
|
|
|
if ($type === 2) {
|
|
|
if ($type == 2) {
|
|
|
$query = $query->where('category_id', $category_id);
|
|
|
}
|
|
|
|
...
|
...
|
|