|
@@ -11,8 +11,10 @@ use DI\Attribute\Inject;
|
|
|
use LinFly\Annotation\Attributes\Route\Controller;
|
|
use LinFly\Annotation\Attributes\Route\Controller;
|
|
|
use LinFly\Annotation\Attributes\Route\GetMapping;
|
|
use LinFly\Annotation\Attributes\Route\GetMapping;
|
|
|
use LinFly\Annotation\Attributes\Route\Middleware;
|
|
use LinFly\Annotation\Attributes\Route\Middleware;
|
|
|
|
|
+use LinFly\Annotation\Attributes\Route\PostMapping;
|
|
|
use support\Request;
|
|
use support\Request;
|
|
|
use support\Response;
|
|
use support\Response;
|
|
|
|
|
+use Webman\Push\Api;
|
|
|
|
|
|
|
|
|
|
|
|
|
#[Controller("/api/service/chat"),Middleware(AuthMiddleware::class)]
|
|
#[Controller("/api/service/chat"),Middleware(AuthMiddleware::class)]
|
|
@@ -34,13 +36,13 @@ class Service extends Base
|
|
|
$param['poi_id'] = $request->user['store_id'];
|
|
$param['poi_id'] = $request->user['store_id'];
|
|
|
$param['service_id'] = $request->user['id'];
|
|
$param['service_id'] = $request->user['id'];
|
|
|
$data = $this->service->setModel()->getList($param,['user' => function($query){
|
|
$data = $this->service->setModel()->getList($param,['user' => function($query){
|
|
|
- $query->field("openid,nickname,mobile");
|
|
|
|
|
|
|
+ $query->field("openid,nickname,mobile,create_at");
|
|
|
}],true,['last','avatar'],['last' => function($data,$resp) use($param){
|
|
}],true,['last','avatar'],['last' => function($data,$resp) use($param){
|
|
|
$last = (new SaasChatMsg)->where(["poi_id" => $resp['poi_id'],"service_id" => $param['service_id'],"openid" => $resp['openid']])->order("create_at desc")->field("content,create_at,type")->findOrEmpty();
|
|
$last = (new SaasChatMsg)->where(["poi_id" => $resp['poi_id'],"service_id" => $param['service_id'],"openid" => $resp['openid']])->order("create_at desc")->field("content,create_at,type")->findOrEmpty();
|
|
|
if ($last->isEmpty()) {
|
|
if ($last->isEmpty()) {
|
|
|
- return ['type' => "text","content"=>"无",'num' => 0,"create_at"=> formatTime(date("Y-m-d H:i:s",time()))];
|
|
|
|
|
|
|
+ return ['type' => "text","content"=>"无",'num' => 0,'time' => time(),"create_at"=> formatTime(date("Y-m-d H:i:s",time()))];
|
|
|
}
|
|
}
|
|
|
- return ["content"=> $last['content'],'num' => 0,"create_at"=> formatTime($last['create_at']),'type' => $last['type']];
|
|
|
|
|
|
|
+ return ["content"=> $last['content'],'num' => 0,"create_at"=> formatTime($last['create_at']),"time"=> strtotime($last['create_at']),'type' => $last['type']];
|
|
|
},'avatar' => function(){
|
|
},'avatar' => function(){
|
|
|
return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png";
|
|
return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png";
|
|
|
}]);
|
|
}]);
|
|
@@ -50,4 +52,64 @@ class Service extends Base
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ #[GetMapping('msg')]
|
|
|
|
|
+ public function getMessageData(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $request->all();
|
|
|
|
|
+ $msg = (new SaasChatMsg)->where(['openid' => $param['openid'],'poi_id' => $request->user['store_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" => $param['size'] ?? 10,
|
|
|
|
|
+ "page" => $param['page'] ?? 1,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ return successTrans(100010,pageFormatMsg($msg),200);
|
|
|
|
|
+ } catch (\Throwable $th) {
|
|
|
|
|
+ return error($th->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[PostMapping('send')]
|
|
|
|
|
+ public function sendMessageData(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "content.require" => trans("empty.require"),
|
|
|
|
|
+ "groupId.require" => trans("empty.require"),
|
|
|
|
|
+ "openid.require" => trans("empty.require"),
|
|
|
|
|
+ "type.require" => trans("empty.require"),
|
|
|
|
|
+ ],"post");
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ $str = preg_replace('/\s+/','',$param['content']);
|
|
|
|
|
+ if (empty($str)) return error("请勿发送空消息");
|
|
|
|
|
+ $state = (new SaasChatMsg)->insertGetId([
|
|
|
|
|
+ "source" => 2,
|
|
|
|
|
+ "openid" => $param['openid'],
|
|
|
|
|
+ "content" => is_array($param['content'])?json_encode($param['content']):$param['content'],
|
|
|
|
|
+ "type" => $param['type'],
|
|
|
|
|
+ "msgId" => time(),
|
|
|
|
|
+ "poi_id" => $param['groupId'],
|
|
|
|
|
+ "service_id" => $request->user['id'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $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("user-{$param['openid']}","message",[
|
|
|
|
|
+ "type" => $param['type'],
|
|
|
|
|
+ "time" => time() * 1000,
|
|
|
|
|
+ "msgId" => time(),
|
|
|
|
|
+ "content" => is_array($param['content'])?json_encode($param['content']):$param['content'],
|
|
|
|
|
+ "source" => 2,
|
|
|
|
|
+ "avatar" => "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png",
|
|
|
|
|
+ "poi_id" => $param['groupId'],
|
|
|
|
|
+ "openid" => $param['openid'],
|
|
|
|
|
+ "service_id" => $request->user['id'],
|
|
|
|
|
+ "create_at" => formatTime(time()),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ return successTrans("success.data",['time' => formatTime(time())]);
|
|
|
|
|
+ } catch (\Throwable $th) {
|
|
|
|
|
+ return error($th->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|