|
@@ -3,6 +3,7 @@
|
|
|
namespace app\controller\api;
|
|
namespace app\controller\api;
|
|
|
|
|
|
|
|
use app\extra\basic\Base;
|
|
use app\extra\basic\Base;
|
|
|
|
|
+use app\extra\tools\UploadExtend;
|
|
|
use app\middleware\AuthMiddleware;
|
|
use app\middleware\AuthMiddleware;
|
|
|
use app\model\saas\SaasChatMsg;
|
|
use app\model\saas\SaasChatMsg;
|
|
|
use app\model\saas\SaasChatStore;
|
|
use app\model\saas\SaasChatStore;
|
|
@@ -68,9 +69,18 @@ class Service extends Base
|
|
|
$store = (new SaasStore)->where("poi_id",$param['poi'])->findOrEmpty();
|
|
$store = (new SaasStore)->where("poi_id",$param['poi'])->findOrEmpty();
|
|
|
if ($store->isEmpty()) return error("店铺不存在");
|
|
if ($store->isEmpty()) return error("店铺不存在");
|
|
|
$chatStore = (new SaasChatStore)->where(['poi_id'=> $store['poi_id'],"openid" => $request->user['openid']])->findOrEmpty();
|
|
$chatStore = (new SaasChatStore)->where(['poi_id'=> $store['poi_id'],"openid" => $request->user['openid']])->findOrEmpty();
|
|
|
|
|
+ // 获取最新的10条聊天记录
|
|
|
|
|
+ $msg = (new SaasChatMsg)->where(['openid' => $request->user['openid'],'poi_id' => $store['poi_id']])->append(['avatar','time'])->withAttr(['avatar' => function(){
|
|
|
|
|
+ return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png";
|
|
|
|
|
+ },'time' => function($resp,$data){
|
|
|
|
|
+ return strtotime($data['create_at']) * 1000;
|
|
|
|
|
+ }])->order("id","desc")->paginate([
|
|
|
|
|
+ "list_rows" => 10,
|
|
|
|
|
+ "page" => 1
|
|
|
|
|
+ ]);
|
|
|
// 获取在线客服
|
|
// 获取在线客服
|
|
|
$service = (new SystemUser)->where("store_id",$param['poi'])->where("type",3)->where("is_line",1)->findOrEmpty();
|
|
$service = (new SystemUser)->where("store_id",$param['poi'])->where("type",3)->where("is_line",1)->findOrEmpty();
|
|
|
- if ($service->isEmpty()) return $this->encode("ok",['store' => $store,'code' => 3]); // 无客服在线
|
|
|
|
|
|
|
+ if ($service->isEmpty()) return $this->encode("ok",['store' => $store,'code' => 3,'sendId' => $request->user['openid'],'msg' => pageFormatMsg($msg),"serviceId" => 0]); // 无客服在线
|
|
|
if ($chatStore->isEmpty()) {
|
|
if ($chatStore->isEmpty()) {
|
|
|
$chatStore->insertGetId([
|
|
$chatStore->insertGetId([
|
|
|
"poi_id" => $store['poi_id'],
|
|
"poi_id" => $store['poi_id'],
|
|
@@ -79,15 +89,6 @@ class Service extends Base
|
|
|
"service_id" => $service['id']
|
|
"service_id" => $service['id']
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
- // 获取最新的10条聊天记录
|
|
|
|
|
- $msg = (new SaasChatMsg)->where(['openid' => $request->user['openid'],'poi_id' => $store['poi_id']])->append(['avatar','time'])->withAttr(['avatar' => function(){
|
|
|
|
|
- return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png";
|
|
|
|
|
- },'time' => function($resp,$data){
|
|
|
|
|
- return strtotime($data['create_at']) * 1000;
|
|
|
|
|
- }])->order("id","desc")->paginate([
|
|
|
|
|
- "list_rows" => 10,
|
|
|
|
|
- "page" => 1
|
|
|
|
|
- ]);
|
|
|
|
|
return $this->encode("ok",['store' => $store,'code' => 1,'sendId' => $request->user['openid'],'msg' => pageFormatMsg($msg),"serviceId" => $service['id']]); // 客服在线
|
|
return $this->encode("ok",['store' => $store,'code' => 1,'sendId' => $request->user['openid'],'msg' => pageFormatMsg($msg),"serviceId" => $service['id']]); // 客服在线
|
|
|
} catch (\Throwable $throwable) {
|
|
} catch (\Throwable $throwable) {
|
|
|
return error($throwable->getMessage());
|
|
return error($throwable->getMessage());
|
|
@@ -155,6 +156,9 @@ class Service extends Base
|
|
|
"openid" => $request->user['openid'],
|
|
"openid" => $request->user['openid'],
|
|
|
"service_id" => $param['sendId'],
|
|
"service_id" => $param['sendId'],
|
|
|
"create_at" => formatTime(time()),
|
|
"create_at" => formatTime(time()),
|
|
|
|
|
+ "user" => [
|
|
|
|
|
+ "nickname" => $request->user['nickname']
|
|
|
|
|
+ ]
|
|
|
]);
|
|
]);
|
|
|
return successTrans("success.data");
|
|
return successTrans("success.data");
|
|
|
} catch (\Throwable $throwable) {
|
|
} catch (\Throwable $throwable) {
|
|
@@ -162,4 +166,68 @@ class Service extends Base
|
|
|
return error($throwable->getMessage());
|
|
return error($throwable->getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送图片消息
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return Response
|
|
|
|
|
+ */
|
|
|
|
|
+ #[PostMapping("send/img")]
|
|
|
|
|
+ public function sendImgMsg(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $resp = UploadExtend::uploadFile();
|
|
|
|
|
+ if (!isset($resp[0]['url'])) return error("发送失败");
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "groupId.require" => trans("empty.require"),
|
|
|
|
|
+ "type.require" => trans("empty.require"),
|
|
|
|
|
+ "sendId.require" => trans("empty.require"),
|
|
|
|
|
+ ],"post");
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ $param['content'] = $resp[0]['url'];
|
|
|
|
|
+ $state = (new SaasChatMsg)->insertGetId([
|
|
|
|
|
+ "source" => 1,
|
|
|
|
|
+ "openid" => $request->user['openid'],
|
|
|
|
|
+ "content" => is_array($param['content'])?json_encode($param['content']):$param['content'],
|
|
|
|
|
+ "type" => $param['type'],
|
|
|
|
|
+ "msgId" => time(),
|
|
|
|
|
+ "poi_id" => $param['groupId'],
|
|
|
|
|
+ "service_id" => $param['sendId'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $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-{$param['sendId']}","message",[
|
|
|
|
|
+ "type" => $param['type'],
|
|
|
|
|
+ "time" => time() * 1000,
|
|
|
|
|
+ "msgId" => time(),
|
|
|
|
|
+ "content" => is_array($param['content'])?json_encode($param['content']):$param['content'],
|
|
|
|
|
+ "source" => 1,
|
|
|
|
|
+ "avatar" => "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png",
|
|
|
|
|
+ "poi_id" => $param['groupId'],
|
|
|
|
|
+ "openid" => $request->user['openid'],
|
|
|
|
|
+ "service_id" => $param['sendId'],
|
|
|
|
|
+ "create_at" => formatTime(time()),
|
|
|
|
|
+ "user" => [
|
|
|
|
|
+ "nickname" => $request->user['nickname']
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]);
|
|
|
|
|
+ return successTrans("success.data",['path' => $param['content']],200);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ echo $throwable->getMessage()."\n";
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[PostMapping("send/address")]
|
|
|
|
|
+ public function setOrderAddress(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $request->all();
|
|
|
|
|
+ print_r($param);
|
|
|
|
|
+
|
|
|
|
|
+ return success("提交成功");
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ echo $throwable->getMessage()."\n";
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|