ImitateCommentlikesStepJob.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Posts\WxComment;
  4. use App\Models\Posts\WxPost;
  5. use App\Wen\Utils\CommentUtils;
  6. use App\Wen\Utils\UserUtils;
  7. use App\Wen\Utils\Utils;
  8. use Illuminate\Bus\Queueable;
  9. use Illuminate\Contracts\Queue\ShouldBeUnique;
  10. use Illuminate\Contracts\Queue\ShouldQueue;
  11. use Illuminate\Foundation\Bus\Dispatchable;
  12. use Illuminate\Queue\InteractsWithQueue;
  13. use Illuminate\Queue\SerializesModels;
  14. class ImitateCommentlikesStepJob implements ShouldQueue
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. public $tries = 1;
  18. protected $comment_id = 0;
  19. protected $need_like = 0;
  20. /**
  21. * Create a new job instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct($comment_id, $need_like)
  26. {
  27. //
  28. $this->comment_id = $comment_id;
  29. $this->need_like = $need_like;
  30. }
  31. /**
  32. * Execute the job.
  33. *
  34. * @return void
  35. */
  36. public function handle()
  37. {
  38. if( $this->need_like <= 0 ){
  39. return;
  40. }
  41. global $__MINI_GLOBAL_REQUEST_ENV__;
  42. $__MINI_GLOBAL_REQUEST_ENV__ = 'api';
  43. $comment = WxComment::find($this->comment_id);
  44. if(!$comment){
  45. return;
  46. }
  47. if($comment->comment_state != 1){
  48. return;
  49. }
  50. if(WxPost::where('id', $comment->posts_id)->where('is_examine', 1)->where('posts_state', 0)->exists()){
  51. $uid = UserUtils::get_a_random_robot_uid();
  52. if($uid > 0){
  53. $comment_author_id = WxComment::where('id', $this->comment_id)->value('user_id');
  54. global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
  55. if($comment_author_id > 0 && in_array($comment_author_id, explode(',', env('APP_SUPER_ADMIN_USER_ID', '')))){
  56. $__MINI_GLOBAL_IS_ADMIN_SUPER__ = true;
  57. }
  58. CommentUtils::comment_like($uid, $this->comment_id);
  59. $__MINI_GLOBAL_IS_ADMIN_SUPER__ = false;
  60. if($comment_author_id > 0){
  61. $follow_rate = _between_(Settings::get('robot_action_follow_rate', 100), 0, 100) / 100;
  62. if($follow_rate != 0){
  63. ImitateUserFollowsStepJob::dispatch($comment_author_id, mini_rand(0, 2))->delay(now()->addMinutes(mini_rand(1, 20)));
  64. }
  65. }
  66. ImitateCommentlikesStepJob::dispatch($this->comment_id, ($this->need_like - 1))->delay(now()->addMinutes(mini_rand(6, 30)));
  67. }
  68. }
  69. }
  70. }