change struct
This commit is contained in:
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Models\Api\Post;
|
||||
|
||||
use App\Bean\Queue\Api\QueueAddPostBean;
|
||||
use App\Exceptions\ModelException;
|
||||
use App\Jobs\Api\AddPostQueue;
|
||||
use App\Models\Api\Base\ApiBaseModel;
|
||||
use App\Models\Api\Post\Structs\PostParamsStruct;
|
||||
use App\Tools\Tools;
|
||||
@ -82,7 +84,11 @@ class PostModel extends ApiBaseModel
|
||||
$aItem['created_at'] = $sDateTime;
|
||||
$res = $this->addItem($aItem);
|
||||
if ($res) {
|
||||
$this->pushToQueue(self::TYPE_POST, $res->id);
|
||||
//发送到消息队列处理新增post
|
||||
$oQueueAddPostBean = new QueueAddPostBean();
|
||||
$oQueueAddPostBean->setId($res->id);
|
||||
$oQueueAddPostBean->setType(self::TYPE_POST);
|
||||
AddPostQueue::putToQueue(new QueueAddPostBean(['id' => $res->id, 'type' => $type]));
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
@ -99,12 +105,6 @@ class PostModel extends ApiBaseModel
|
||||
}
|
||||
}
|
||||
|
||||
//发送到消息队列处理新增post
|
||||
function pushToQueue($type, $id): void
|
||||
{
|
||||
PostPushBoxModel::addPostQueueProducer(['type' => $type, 'id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ModelException
|
||||
*/
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Api\Post;
|
||||
|
||||
use App\Bean\Queue\Api\QueueAddPostBean;
|
||||
use App\Exceptions\ModelException;
|
||||
use App\Jobs\Api\AddPostQueue;
|
||||
use App\Models\Api\Base\ApiBaseModel;
|
||||
@ -9,7 +10,6 @@ use App\Models\Api\Comment\PostCommentModel;
|
||||
use App\Models\Api\Customer\CustomerUserExtendModel;
|
||||
use App\Models\Api\Follow\FollowModel;
|
||||
use App\Models\Api\Post\Structs\PostParamsStruct;
|
||||
use App\Structs\QueueAddPostStruct;
|
||||
use App\Tools\CollectOffsetLimit;
|
||||
use App\Tools\Tools;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
@ -82,22 +82,16 @@ class PostPushBoxModel extends ApiBaseModel
|
||||
);
|
||||
}
|
||||
|
||||
public static function addPostQueueProducer(array $params): void
|
||||
{
|
||||
AddPostQueue::dispatch($params)->onQueue(QueueAddPostStruct::QUEUE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交后调用事件,在消费队列跑推送
|
||||
* @throws ModelException
|
||||
*/
|
||||
function addPostQueueConsumer(array $params)
|
||||
function addPostQueueConsumer(QueueAddPostBean $bean)
|
||||
{
|
||||
if (empty($params)) return false;
|
||||
if (isset($params['id'])) return false;
|
||||
if (isset($params['type'])) return false;
|
||||
$id = $params['id'];
|
||||
$type = $params['type'];
|
||||
$id = $bean->getId();
|
||||
$type = $bean->getType();
|
||||
if (empty($id)) return false;
|
||||
if (empty($type)) return false;
|
||||
|
||||
if (!in_array($type, [self::TYPE_POST, self::TYPE_REPOST, self::TYPE_COMMENT])) return false;
|
||||
if (empty($id)) return false;
|
||||
|
||||
Reference in New Issue
Block a user