LiveRoomDataJob.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Job;
  4. use App\Master\Enum\RedisKeyEnum;
  5. use App\Master\Framework\Extend\BaseJob;
  6. use App\Model\Arts\LiveRoomLogLikeModel;
  7. use App\Model\Arts\LiveRoomLogModel;
  8. use App\Utils\LogUtil;
  9. use App\Utils\RedisUtil;
  10. class LiveRoomDataJob extends BaseJob
  11. {
  12. //日志板块
  13. protected string $LOG_MODULE = 'LiveRoomDataJob';
  14. /**
  15. * 任务执行失败后的重试次数,即最大执行次数为 $maxAttempts+1 次
  16. */
  17. protected int $maxAttempts = 2;
  18. public function __construct($params)
  19. {
  20. parent::__construct($params);
  21. }
  22. /**
  23. * 执行
  24. * @param $params
  25. * @return bool
  26. */
  27. protected function do($params): bool
  28. {
  29. // 增加 点赞
  30. if (!empty($params['like'])) {
  31. LogUtil::info('增加点赞', $this->LOG_MODULE, __FUNCTION__);
  32. if ($params['like'] > 0) {
  33. $res = LiveRoomLogModel::where('session', $params['session'])->increment('like', $params['like']);
  34. LiveRoomLogLikeModel::likes($params['user_id'], $params['room_id'], $params['room_no'], $params['session'], $params['like']);
  35. } else {
  36. $res = LiveRoomLogModel::where('session', $params['session'])->decrement('like', $params['like'] * -1);
  37. }
  38. }
  39. // 增加ccu
  40. if (!empty($params['ccu'])) {
  41. LogUtil::info('增加ccu', $this->LOG_MODULE, __FUNCTION__);
  42. if ($params['ccu'] > 0) {
  43. $res = LiveRoomLogModel::where('session', $params['session'])->increment('ccu', $params['ccu']);
  44. } else {
  45. $res = LiveRoomLogModel::where('session', $params['session'])->decrement('ccu', $params['ccu'] * -1);
  46. }
  47. }
  48. // 增加分享次数
  49. if (!empty($params['share_num'])) {
  50. LogUtil::info('增加分享次数', $this->LOG_MODULE, __FUNCTION__);
  51. if ($params['share_num'] > 0) {
  52. $res = LiveRoomLogModel::where('session', $params['session'])->increment('share_num', $params['share_num']);
  53. } else {
  54. $res = LiveRoomLogModel::where('session', $params['session'])->decrement('share_num', $params['share_num'] * -1);
  55. }
  56. }
  57. // 增加关注量
  58. if (!empty($params['follow_num'])) {
  59. LogUtil::info('增加关注量', $this->LOG_MODULE, __FUNCTION__);
  60. if ($params['follow_num'] > 0) {
  61. $res = LiveRoomLogModel::where('session', $params['session'])->increment('follow_num', $params['follow_num']);
  62. } else {
  63. $res = LiveRoomLogModel::where('session', $params['session'])->decrement('follow_num', $params['follow_num'] * -1);
  64. }
  65. }
  66. // 增加商品销量
  67. if (!empty($params['goods_sales'])) {
  68. LogUtil::info('增加商品销量', $this->LOG_MODULE, __FUNCTION__);
  69. if ($params['goods_sales'] > 0) {
  70. $res = LiveRoomLogModel::where('session', $params['session'])->increment('goods_sales', $params['goods_sales']);
  71. } else {
  72. $res = LiveRoomLogModel::where('session', $params['session'])->decrement('goods_sales', $params['goods_sales'] * -1);
  73. }
  74. }
  75. if (!isset($res) || !$res) {
  76. return $this->error('执行失败');
  77. }
  78. return $this->success('执行成功');
  79. }
  80. }