|
|
@@ -10,6 +10,7 @@ use app\model\saas\SaasChatStore;
|
|
|
use app\model\saas\SaasService;
|
|
|
use app\model\saas\SaasStore;
|
|
|
use app\model\saas\SaasUserOpen;
|
|
|
+use app\model\system\SystemUser;
|
|
|
use app\service\saas\ChatStoreService;
|
|
|
use DI\Attribute\Inject;
|
|
|
use LinFly\Annotation\Attributes\Route\Controller;
|
|
|
@@ -44,7 +45,7 @@ class Chat extends Base
|
|
|
}
|
|
|
$param['openid'] = $request->user['openid'];
|
|
|
$list = $this->service->setModel()->getList($param,null,true,['last','avatar'],['last' => function($data,$resp) use($param){
|
|
|
- $last = (new SaasChatMsg)->where(['poi_id' => $resp['poi_id'],'openid' => $param['openid'],'is_user' => 0])->order("create_at desc")->field("content,create_at,type")->findOrEmpty();
|
|
|
+ $last = (new SaasChatMsg)->where(['poi_id' => $resp['poi_id'],'openid' => $param['openid']])->order("create_at","desc")->field("content,create_at,type")->findOrEmpty();
|
|
|
if ($last->isEmpty()) {
|
|
|
return ['type' => "text","content"=>"-",'num' => 0,"create_at"=> formatTime(date("Y-m-d H:i:s",time()))];
|
|
|
}
|
|
|
@@ -75,6 +76,8 @@ class Chat extends Base
|
|
|
"poi.require" => "参数错误",
|
|
|
"size.require" => "参数错误",
|
|
|
"page.require" => "参数错误",
|
|
|
+ "goods.default" => "",
|
|
|
+ "order.default" => "",
|
|
|
],$request->method());
|
|
|
if (!is_array($param)) return error($param);
|
|
|
$store = (new SaasStore)->where("poi_id",$param['poi'])->findOrEmpty();
|
|
|
@@ -101,6 +104,43 @@ class Chat extends Base
|
|
|
]);
|
|
|
$serviceAvatar = sConf("service.logo");
|
|
|
$star = (new SaasService)->where("poi_id",$param['poi'])->with(['quick'])->findOrEmpty();
|
|
|
+ // 获取在线客服
|
|
|
+ $service = (new SystemUser)->where(['store_id' => $param['poi'],"type" => 3,"is_line" => 1])->order("last_msg_at","asc")->findOrEmpty();
|
|
|
+ print_r($service->toArray());
|
|
|
+ if ($service->isEmpty()) { // 无客服在线
|
|
|
+ return success("ok",[
|
|
|
+ "avatar" => $userAvatar,
|
|
|
+ "userId" => md5($request->user['openid']),
|
|
|
+ "msg" => $msg,
|
|
|
+ "service" => $serviceAvatar,
|
|
|
+ "store" => [
|
|
|
+ "shopName" => $store['poi_name'],
|
|
|
+ "shopId" => $store['poi_id'],
|
|
|
+ ],
|
|
|
+ "quick" => $star,
|
|
|
+ "chat_id" => 0, // 客服ID
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $chatStore = (new SaasChatStore)->where(['poi_id'=> $store['poi_id'],"openid" => $request->user['openid']])->findOrEmpty();
|
|
|
+ if ($chatStore->isEmpty()) {
|
|
|
+ $chatStore->insertGetId([
|
|
|
+ "poi_id" => $store['poi_id'],
|
|
|
+ "poi_name" => $store['poi_name'],
|
|
|
+ "openid" => $request->user['openid'],
|
|
|
+ "nickname" => $request->user['nickname'],
|
|
|
+ "service_id" => $service['id'],
|
|
|
+ "order" => $param['order']??'',
|
|
|
+ "goods" => $param['goods']??'',
|
|
|
+ "last_at" => getDateFull()
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ $chatStore->service_id = $service['id'];
|
|
|
+ $chatStore->order = $param['order']??'';
|
|
|
+ $chatStore->nickname = $request->user['nickname'];
|
|
|
+ $chatStore->goods = $param['goods']??'';
|
|
|
+ $chatStore->last_at = getDateFull();
|
|
|
+ $chatStore->save();
|
|
|
+ }
|
|
|
return success("ok",[
|
|
|
"avatar" => $userAvatar,
|
|
|
"userId" => md5($request->user['openid']),
|
|
|
@@ -110,7 +150,8 @@ class Chat extends Base
|
|
|
"shopName" => $store['poi_name'],
|
|
|
"shopId" => $store['poi_id'],
|
|
|
],
|
|
|
- "quick" => $star
|
|
|
+ "quick" => $star,
|
|
|
+ "chat_id" => $service['id'], // 客服ID
|
|
|
]);
|
|
|
} catch (\Throwable $throwable) {
|
|
|
return error($throwable->getMessage());
|
|
|
@@ -183,6 +224,7 @@ class Chat extends Base
|
|
|
$param = $this->_valid([
|
|
|
"content.require" => trans("empty.require"),
|
|
|
"groupId.require" => trans("empty.require"),
|
|
|
+ "chatId.require" => trans("empty.require"),
|
|
|
"type.require" => trans("empty.require")
|
|
|
],"post");
|
|
|
if (!is_array($param)) return error($param);
|
|
|
@@ -193,14 +235,14 @@ class Chat extends Base
|
|
|
"type" => $param['type'],
|
|
|
"msgId" => time(),
|
|
|
"poi_id" => $param['groupId'],
|
|
|
- "service_id" => '105', // 客服ID
|
|
|
+ "service_id" => $param['chatId'], // 客服ID
|
|
|
]);
|
|
|
- $chatStore = (new SaasChatStore)->where(['openid' => $request->user['openid'],"service_id" => 105])->with(['user' => function($query){
|
|
|
+ $chatStore = (new SaasChatStore)->where(['openid' => $request->user['openid'],"service_id" => $param['chatId']])->with(['user' => function($query){
|
|
|
$query->field("openid,nickname,avatar,mobile,create_at");
|
|
|
}])->append(['avatar'])->withAttr(['avatar' => function () {
|
|
|
return sConf("service.logo");
|
|
|
}])->findOrEmpty();
|
|
|
- $total = (new SaasChatMsg)->where(["poi_id" => $chatStore['poi_id'],"service_id" => 105,"openid" => $chatStore['openid'],'is_read' => 0])->count();
|
|
|
+ $total = (new SaasChatMsg)->where(["poi_id" => $chatStore['poi_id'],"service_id" => $param['chatId'],"openid" => $chatStore['openid'],'is_read' => 0])->count();
|
|
|
if (!$chatStore->isEmpty()) {
|
|
|
$chatStore->last_at = getDateFull();
|
|
|
$chatStore->save();
|
|
|
@@ -213,7 +255,7 @@ class Chat extends Base
|
|
|
}
|
|
|
// 推送消息
|
|
|
$api = new Api('http://127.0.0.1:3232', config('plugin.webman.push.app.app_key'),config('plugin.webman.push.app.app_secret'));
|
|
|
- $api->trigger("service-105","message",[
|
|
|
+ $api->trigger("service-{$param['chatId']}","message",[
|
|
|
"type" => $param['type'],
|
|
|
"content" => is_array($param['content'])?json_encode($param['content']):$param['content'],
|
|
|
"openid" => $request->user['openid'],
|
|
|
@@ -244,7 +286,7 @@ class Chat extends Base
|
|
|
$param = $this->_valid([
|
|
|
"groupId.require" => trans("empty.require"),
|
|
|
"type.require" => trans("empty.require"),
|
|
|
- "sendId.require" => trans("empty.require"),
|
|
|
+ "chatId.require" => trans("empty.require"),
|
|
|
],"post");
|
|
|
if (!is_array($param)) return error($param);
|
|
|
$resp = UploadExtend::uploadFile();
|
|
|
@@ -257,14 +299,14 @@ class Chat extends Base
|
|
|
"type" => $param['type'],
|
|
|
"msgId" => time(),
|
|
|
"poi_id" => $param['groupId'],
|
|
|
- "service_id" => '105', // 客服ID
|
|
|
+ "service_id" => $param['chatId'], // 客服ID
|
|
|
]);
|
|
|
- $chatStore = (new SaasChatStore)->where(['openid' => $request->user['openid'],"service_id" => 105])->with(['user' => function($query){
|
|
|
+ $chatStore = (new SaasChatStore)->where(['openid' => $request->user['openid'],"service_id" => $param['chatId']])->with(['user' => function($query){
|
|
|
$query->field("openid,nickname,avatar,mobile,create_at");
|
|
|
}])->append(['avatar'])->withAttr(['avatar' => function () {
|
|
|
return sConf("service.logo");
|
|
|
}])->findOrEmpty();
|
|
|
- $total = (new SaasChatMsg)->where(["poi_id" => $chatStore['poi_id'],"service_id" => 105,"openid" => $chatStore['openid'],'is_read' => 0])->count();
|
|
|
+ $total = (new SaasChatMsg)->where(["poi_id" => $chatStore['poi_id'],"service_id" => $param['chatId'],"openid" => $chatStore['openid'],'is_read' => 0])->count();
|
|
|
if (!$chatStore->isEmpty()) {
|
|
|
$chatStore->last_at = getDateFull();
|
|
|
$chatStore->save();
|
|
|
@@ -277,7 +319,7 @@ class Chat extends Base
|
|
|
}
|
|
|
// 推送消息
|
|
|
$api = new Api('http://127.0.0.1:3232', config('plugin.webman.push.app.app_key'),config('plugin.webman.push.app.app_secret'));
|
|
|
- $api->trigger("service-105","message",[
|
|
|
+ $api->trigger("service-{$param['chatId']}","message",[
|
|
|
"type" => $param['type'],
|
|
|
"content" => is_array($param['content'])?json_encode($param['content']):$param['content'],
|
|
|
"openid" => $request->user['openid'],
|