| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- /**
- * Created by PhpStorm.
- * Name: 芸众商城系统
- * Author: 广州市芸众信息科技有限公司
- * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
- * Date: 2022/8/3
- * Time: 16:40
- */
- namespace business\common\notice;
- use business\common\models\MessageNotice;
- abstract class BusinessMessageNoticeBase
- {
- /**
- * @var MessageNotice
- */
- protected $messageNotice;
- protected $noticeIds;
- /**
- * @return mixed
- */
- final public function getNoticeIds()
- {
- return $this->noticeIds;
- }
- /**
- * @param mixed $noticeIds
- */
- final public function setNoticeIds($noticeIds): void
- {
- $this->noticeIds = $noticeIds;
- }
- final public function getMessageNotice()
- {
- return $this->messageNotice;
- }
- final public function setMessageNotice(MessageNotice $messageNotice)
- {
- $this->messageNotice = $messageNotice;
- }
- /**
- * @param array $userIdArray
- * @param array $param
- * @param string|mixed $html
- */
- protected function saveNotice(array $userIdArray, array $param, $html = '')
- {
- $createData = [
- 'param' => $param,
- 'html' => $html ?: '',
- ];
- $createData = array_merge($createData,$this->getMessageNotice()->getAttributes());
- $noticeIds = [];
- foreach ($userIdArray as $user_id) {
- $createData['recipient_id'] = $user_id;
- $notice = MessageNotice::create($createData);
- if ($notice) {
- $noticeIds[] = $notice->id;
- }
- }
- $this->setNoticeIds($noticeIds);
- //这里可以设置最后一个保存的消息记录
- // if($notice){
- // $this->setMessageNotice($notice);
- // }
- $this->sendSocket($noticeIds);
- //return $noticeIds;
- }
- final protected function sendSocket($noticeIds)
- {
- //这里可以直接让方法返回,
- $notices = MessageNotice::whereIn('id', $noticeIds)->get();
- // \Log::debug('-----webSocketNotice-----',$notices->pluck('id')->all());
- $signUserIds = $notices->map(function (MessageNotice $notice) {
- return $notice->hasOneRecipient->uid ?: null;
- })->filter()->unique()->values()->toArray();
- if (empty($signUserIds)) {
- return;
- }
- $firstNotice = $notices->first();
- $msg = $this->webSocketMessage($firstNotice);
- if (empty($msg)) {
- return;
- }
- if (!isset($msg['logo'])) {
- $shopSet = \Setting::get('shop.shop');
- $msg['logo'] = yz_tomedia($shopSet['logo']);
- }
- if (!isset($msg['notice_time'])) {
- $msg['notice_time'] = date('Y-m-d H:i:s', time());
- }
- // \Log::debug('-----webSocketNotice-----',$signUserIds);
- // \Log::debug('-----webSocketNotice-----',$msg);
- $this->webSocketNotice($signUserIds, $msg);
- }
- /**
- * 发送webSocket消息通知
- * @param $user_ids array 会员ID数组
- * @param $content mixed 文本内容
- * @param string $type
- */
- final protected function webSocketNotice($user_ids, $content, $type = 'businessMessageNotice')
- {
- \app\process\InnerSocket::send($user_ids, $content, $type);
- }
- public function sendStaff()
- {
- return $this->messageNotice->hasOneCreator;
- }
- //考虑到需要删除
- public function delete(){}
- /**
- * @param MessageNotice $notice
- * @return array [code,logo,jump_url,creator_name,notice_time,content,type]
- */
- abstract public function webSocketMessage(MessageNotice $notice);
- /**
- * @return mixed
- */
- abstract public function showBody();
- /**
- * @param array $data
- */
- abstract public function create($data);
- /**
- * 保持与服务容器绑定的标识一致
- * @return string
- */
- abstract public function getPlugin();
- /**
- * @return string
- */
- abstract public function getPluginName();
- /**
- * 消息类型集合
- * @return array
- */
- abstract public function getAllType();
- }
|