123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- declare(strict_types=1);
- namespace App\Job;
- use App\Master\Enum\RedisKeyEnum;
- use App\Master\Framework\Extend\BaseJob;
- use App\Model\Arts\LiveRoomLogLikeModel;
- use App\Model\Arts\LiveRoomLogModel;
- use App\Utils\LogUtil;
- use App\Utils\RedisUtil;
- class LiveRoomDataJob extends BaseJob
- {
- //日志板块
- protected string $LOG_MODULE = 'LiveRoomDataJob';
- /**
- * 任务执行失败后的重试次数,即最大执行次数为 $maxAttempts+1 次
- */
- protected int $maxAttempts = 2;
- public function __construct($params)
- {
- parent::__construct($params);
- }
- /**
- * 执行
- * @param $params
- * @return bool
- */
- protected function do($params): bool
- {
- // 增加 点赞
- if (!empty($params['like'])) {
- LogUtil::info('增加点赞', $this->LOG_MODULE, __FUNCTION__);
- if ($params['like'] > 0) {
- $res = LiveRoomLogModel::where('session', $params['session'])->increment('like', $params['like']);
- LiveRoomLogLikeModel::likes($params['user_id'], $params['room_id'], $params['room_no'], $params['session'], $params['like']);
- } else {
- $res = LiveRoomLogModel::where('session', $params['session'])->decrement('like', $params['like'] * -1);
- }
- }
- // 增加ccu
- if (!empty($params['ccu'])) {
- LogUtil::info('增加ccu', $this->LOG_MODULE, __FUNCTION__);
- if ($params['ccu'] > 0) {
- $res = LiveRoomLogModel::where('session', $params['session'])->increment('ccu', $params['ccu']);
- } else {
- $res = LiveRoomLogModel::where('session', $params['session'])->decrement('ccu', $params['ccu'] * -1);
- }
- }
- // 增加分享次数
- if (!empty($params['share_num'])) {
- LogUtil::info('增加分享次数', $this->LOG_MODULE, __FUNCTION__);
- if ($params['share_num'] > 0) {
- $res = LiveRoomLogModel::where('session', $params['session'])->increment('share_num', $params['share_num']);
- } else {
- $res = LiveRoomLogModel::where('session', $params['session'])->decrement('share_num', $params['share_num'] * -1);
- }
- }
- // 增加关注量
- if (!empty($params['follow_num'])) {
- LogUtil::info('增加关注量', $this->LOG_MODULE, __FUNCTION__);
- if ($params['follow_num'] > 0) {
- $res = LiveRoomLogModel::where('session', $params['session'])->increment('follow_num', $params['follow_num']);
- } else {
- $res = LiveRoomLogModel::where('session', $params['session'])->decrement('follow_num', $params['follow_num'] * -1);
- }
- }
- // 增加商品销量
- if (!empty($params['goods_sales'])) {
- LogUtil::info('增加商品销量', $this->LOG_MODULE, __FUNCTION__);
- if ($params['goods_sales'] > 0) {
- $res = LiveRoomLogModel::where('session', $params['session'])->increment('goods_sales', $params['goods_sales']);
- } else {
- $res = LiveRoomLogModel::where('session', $params['session'])->decrement('goods_sales', $params['goods_sales'] * -1);
- }
- }
- if (!isset($res) || !$res) {
- return $this->error('执行失败');
- }
- return $this->success('执行成功');
- }
- }
|