change struct
This commit is contained in:
37
app/Bean/Queue/Api/QueueAddPostBean.php
Normal file
37
app/Bean/Queue/Api/QueueAddPostBean.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Queue\Api;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueAddPostBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_add_post';
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $type;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
41
app/Bean/Queue/Api/QueueUserActiveStatusBean.php
Normal file
41
app/Bean/Queue/Api/QueueUserActiveStatusBean.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Queue\Api;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueUserActiveStatusBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_user_active_status';
|
||||||
|
|
||||||
|
protected $uid;
|
||||||
|
protected $queue_created_at;
|
||||||
|
|
||||||
|
public function getUid()
|
||||||
|
{
|
||||||
|
return $this->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUid($uid): void
|
||||||
|
{
|
||||||
|
$this->uid = $uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQueueCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->queue_created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setQueueCreatedAt($queue_created_at): void
|
||||||
|
{
|
||||||
|
$this->queue_created_at = $queue_created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Api;
|
namespace App\Jobs\Api;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueAddPostBean;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
use App\Models\Api\Post\PostPushBoxModel;
|
use App\Models\Api\Post\PostPushBoxModel;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
@ -28,7 +29,17 @@ class AddPostQueue implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(array $params): void
|
public function handle(array $params): void
|
||||||
{
|
{
|
||||||
|
$bean = new QueueAddPostBean($params);
|
||||||
$oPostPushBoxModel = new PostPushBoxModel();
|
$oPostPushBoxModel = new PostPushBoxModel();
|
||||||
$oPostPushBoxModel->addPostQueueConsumer($params);
|
$oPostPushBoxModel->addPostQueueConsumer($bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueAddPostBean $bean,$delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueAddPostBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Api;
|
namespace App\Jobs\Api;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueUserActiveStatusBean;
|
||||||
use App\Models\Api\Customer\CustomerUserExtendModel;
|
use App\Models\Api\Customer\CustomerUserExtendModel;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -26,7 +27,17 @@ class UserActiveStatusQueue implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(array $params): void
|
public function handle(array $params): void
|
||||||
{
|
{
|
||||||
|
$bean = new QueueUserActiveStatusBean($params);
|
||||||
$oCustomerUserExtendModel = new CustomerUserExtendModel();
|
$oCustomerUserExtendModel = new CustomerUserExtendModel();
|
||||||
$oCustomerUserExtendModel->activeUserStatusQueueConsumer($params);
|
$oCustomerUserExtendModel->activeUserStatusQueueConsumer($bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueUserActiveStatusBean $bean,$delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueUserActiveStatusBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Models\Api\Customer;
|
namespace App\Models\Api\Customer;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueUserActiveStatusBean;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
use App\Jobs\Api\UserActiveStatusQueue;
|
use App\Jobs\Api\UserActiveStatusQueue;
|
||||||
use App\Models\Api\Base\ApiBaseModel;
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
use App\Models\Api\Post\PostPushBoxModel;
|
use App\Models\Api\Post\PostPushBoxModel;
|
||||||
use App\Models\Api\WebSocket\CustomerWsHistoryModel;
|
use App\Models\Api\WebSocket\CustomerWsHistoryModel;
|
||||||
use App\Structs\QueueUserActiveStatusStruct;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@ -114,7 +114,11 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
if ($res) {
|
if ($res) {
|
||||||
//记录日志
|
//记录日志
|
||||||
$oCustomerChangeInfoLogModel->addUserActiveStatusLog($oUserExtend->uid, $oUserExtend->is_active, self::IS_ACTIVE_YES, CustomerChangeInfoLogModel::REMARK_DAILY_CHECK_USER_ACTIVE_STATUS_YES);
|
$oCustomerChangeInfoLogModel->addUserActiveStatusLog($oUserExtend->uid, $oUserExtend->is_active, self::IS_ACTIVE_YES, CustomerChangeInfoLogModel::REMARK_DAILY_CHECK_USER_ACTIVE_STATUS_YES);
|
||||||
$this->activeUserStatusToQueueProducer($oUserExtend->uid); //投递到消息队列
|
//投递到消息队列
|
||||||
|
$oQueueUserActiveStatusBean = new QueueUserActiveStatusBean();
|
||||||
|
$oQueueUserActiveStatusBean->setUid($oUserExtend->uid);
|
||||||
|
$oQueueUserActiveStatusBean->setQueueCreatedAt(date('Y-m-d H:i:s'));
|
||||||
|
UserActiveStatusQueue::putToQueue($oQueueUserActiveStatusBean);
|
||||||
}
|
}
|
||||||
} else { //三日内不活跃
|
} else { //三日内不活跃
|
||||||
if ($oUserExtend->is_active == self::IS_ACTIVE_NO) continue; //已经是不活跃用户
|
if ($oUserExtend->is_active == self::IS_ACTIVE_NO) continue; //已经是不活跃用户
|
||||||
@ -150,7 +154,11 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
if ($res) {
|
if ($res) {
|
||||||
//记录日志
|
//记录日志
|
||||||
$oCustomerChangeInfoLogModel->addUserActiveStatusLog($uid, $oCustomerUserExtendModel->is_active, self::IS_ACTIVE_YES, CustomerChangeInfoLogModel::REMARK_DAILY_CHECK_USER_ACTIVE_STATUS_YES);
|
$oCustomerChangeInfoLogModel->addUserActiveStatusLog($uid, $oCustomerUserExtendModel->is_active, self::IS_ACTIVE_YES, CustomerChangeInfoLogModel::REMARK_DAILY_CHECK_USER_ACTIVE_STATUS_YES);
|
||||||
$this->activeUserStatusToQueueProducer($uid); //投递到消息队列
|
//投递到消息队列
|
||||||
|
$oQueueUserActiveStatusBean = new QueueUserActiveStatusBean();
|
||||||
|
$oQueueUserActiveStatusBean->setUid($uid);
|
||||||
|
$oQueueUserActiveStatusBean->setQueueCreatedAt(date('Y-m-d H:i:s'));
|
||||||
|
UserActiveStatusQueue::putToQueue($oQueueUserActiveStatusBean);
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
@ -160,18 +168,10 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//投递到消息队列,处理活跃推送信箱更新问题
|
|
||||||
function activeUserStatusToQueueProducer($uid): void
|
|
||||||
{
|
|
||||||
$params = QueueUserActiveStatusStruct::PARAMS;
|
|
||||||
$params['uid'] = $uid;
|
|
||||||
$params['queueCreatedAt'] = date('Y-m-d H:i:s');
|
|
||||||
UserActiveStatusQueue::dispatch($params)->onQueue(QueueUserActiveStatusStruct::QUEUE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
function activeUserStatusQueueConsumer($params): void
|
function activeUserStatusQueueConsumer(QueueUserActiveStatusBean $bean): void
|
||||||
{
|
{
|
||||||
$uid = $params['uid'];
|
$uid = $bean->getUid();
|
||||||
$oPostPushBoxModel = new PostPushBoxModel();
|
$oPostPushBoxModel = new PostPushBoxModel();
|
||||||
$oPostPushBoxModel->pullBigFanMasterPostConsumer($uid);
|
$oPostPushBoxModel->pullBigFanMasterPostConsumer($uid);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Models\Api\Post;
|
namespace App\Models\Api\Post;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueAddPostBean;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Jobs\Api\AddPostQueue;
|
||||||
use App\Models\Api\Base\ApiBaseModel;
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
use App\Models\Api\Post\Structs\PostParamsStruct;
|
use App\Models\Api\Post\Structs\PostParamsStruct;
|
||||||
use App\Tools\Tools;
|
use App\Tools\Tools;
|
||||||
@ -82,7 +84,11 @@ class PostModel extends ApiBaseModel
|
|||||||
$aItem['created_at'] = $sDateTime;
|
$aItem['created_at'] = $sDateTime;
|
||||||
$res = $this->addItem($aItem);
|
$res = $this->addItem($aItem);
|
||||||
if ($res) {
|
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;
|
return $res;
|
||||||
}
|
}
|
||||||
@ -99,12 +105,6 @@ class PostModel extends ApiBaseModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送到消息队列处理新增post
|
|
||||||
function pushToQueue($type, $id): void
|
|
||||||
{
|
|
||||||
PostPushBoxModel::addPostQueueProducer(['type' => $type, 'id' => $id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ModelException
|
* @throws ModelException
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models\Api\Post;
|
namespace App\Models\Api\Post;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueAddPostBean;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
use App\Jobs\Api\AddPostQueue;
|
use App\Jobs\Api\AddPostQueue;
|
||||||
use App\Models\Api\Base\ApiBaseModel;
|
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\Customer\CustomerUserExtendModel;
|
||||||
use App\Models\Api\Follow\FollowModel;
|
use App\Models\Api\Follow\FollowModel;
|
||||||
use App\Models\Api\Post\Structs\PostParamsStruct;
|
use App\Models\Api\Post\Structs\PostParamsStruct;
|
||||||
use App\Structs\QueueAddPostStruct;
|
|
||||||
use App\Tools\CollectOffsetLimit;
|
use App\Tools\CollectOffsetLimit;
|
||||||
use App\Tools\Tools;
|
use App\Tools\Tools;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
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
|
* @throws ModelException
|
||||||
*/
|
*/
|
||||||
function addPostQueueConsumer(array $params)
|
function addPostQueueConsumer(QueueAddPostBean $bean)
|
||||||
{
|
{
|
||||||
if (empty($params)) return false;
|
$id = $bean->getId();
|
||||||
if (isset($params['id'])) return false;
|
$type = $bean->getType();
|
||||||
if (isset($params['type'])) return false;
|
if (empty($id)) return false;
|
||||||
$id = $params['id'];
|
if (empty($type)) return false;
|
||||||
$type = $params['type'];
|
|
||||||
|
|
||||||
if (!in_array($type, [self::TYPE_POST, self::TYPE_REPOST, self::TYPE_COMMENT])) return false;
|
if (!in_array($type, [self::TYPE_POST, self::TYPE_REPOST, self::TYPE_COMMENT])) return false;
|
||||||
if (empty($id)) return false;
|
if (empty($id)) return false;
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Structs;
|
|
||||||
|
|
||||||
class QueueAddPostStruct
|
|
||||||
{
|
|
||||||
const QUEUE_NAME = 'queue_add_post';
|
|
||||||
const PARAMS = [
|
|
||||||
'type'=>'',
|
|
||||||
'id'=>'',
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Structs;
|
|
||||||
|
|
||||||
class QueueUserActiveStatusStruct
|
|
||||||
{
|
|
||||||
const QUEUE_NAME = 'queue_user_active_status';
|
|
||||||
const PARAMS = [
|
|
||||||
'uid'=>'',
|
|
||||||
'queueCreatedAt'=>'',
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Structs;
|
|
||||||
|
|
||||||
class QueueWalletAddrTransactionChangeStruct
|
|
||||||
{
|
|
||||||
const QUEUE_NAME = 'queue_wallet_addr_transaction_change';
|
|
||||||
const PARAMS = [
|
|
||||||
'wallet_addr_transaction_id'=>'',
|
|
||||||
'wallet_addr_transaction_type'=>'',
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Structs;
|
|
||||||
|
|
||||||
class QueueWalletPlatformUserWithdrawStruct
|
|
||||||
{
|
|
||||||
const QUEUE_NAME = 'wallet_platform_user_transaction_id';
|
|
||||||
const PARAMS = [
|
|
||||||
'id'=>'',
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user