ImitateCircleJoinStepJob.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Jobs;
  3. use App\Http\Controllers\Api\Repositories\WxCircleRepositores;
  4. use App\Models\Circle\WxCircle;
  5. use App\Wen\Utils\CircleUtils;
  6. use App\Wen\Utils\UserUtils;
  7. use Illuminate\Bus\Queueable;
  8. use Illuminate\Contracts\Queue\ShouldBeUnique;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Queue\SerializesModels;
  13. class ImitateCircleJoinStepJob implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. public $tries = 1;
  17. protected $circle_id = 0;
  18. protected $need_join = 0;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct($circle_id, $need_join)
  25. {
  26. //
  27. $this->circle_id = $circle_id;
  28. $this->need_join = $need_join;
  29. }
  30. /**
  31. * Execute the job.
  32. *
  33. * @return void
  34. */
  35. public function handle()
  36. {
  37. if( $this->need_join <= 0 ){
  38. return;
  39. }
  40. global $__MINI_GLOBAL_REQUEST_ENV__;
  41. $__MINI_GLOBAL_REQUEST_ENV__ = 'api';
  42. $circle = WxCircle::find($this->circle_id);
  43. if(_empty_($circle)){
  44. return;
  45. }
  46. if($circle->circle_state != 1){
  47. return;
  48. }
  49. $uid = UserUtils::get_a_random_robot_uid();
  50. if($uid > 0){
  51. $p = CircleUtils::can_i_visit($circle, $uid);
  52. if($p == 2 || $p == 1){
  53. return;
  54. }
  55. WxCircleRepositores::userFollowCircle($uid, $this->circle_id);
  56. $circle_user_id = $circle->user_id;
  57. if($circle_user_id > 0){
  58. $follow_rate = _between_(Settings::get('robot_action_follow_rate', 100), 0, 100) / 100;
  59. if($follow_rate != 0){
  60. ImitateUserFollowsStepJob::dispatch($circle_user_id, mini_rand(0, 2))->delay(now()->addMinutes(mini_rand(1, 30)));
  61. }
  62. }
  63. ImitateCircleJoinStepJob::dispatch($this->circle_id, ($this->need_join - 1))->delay(now()->addMinutes(mini_rand(6, 30)));
  64. }
  65. }
  66. }