SendSignInRewardsJob.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Jobs;
  3. use App\Events\Task\LastSignInEvent;
  4. use App\Model\TaskAwarkLogModel;
  5. use App\Repositories\ConfigRepoistory;
  6. use App\Repositories\Service\UserSingInService;
  7. use App\Repositories\TaskAwarkLogRepository;
  8. use Hyperf\AsyncQueue\Job;
  9. class SendSignInRewardsJob extends Job
  10. {
  11. public $params;
  12. public function __construct($params)
  13. {
  14. // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
  15. $this->params = $params;
  16. }
  17. public function handle()
  18. {
  19. try {
  20. //获取连续签到次数
  21. $counFrequency = make(UserSingInService::class)->getContinuousSignCount($this->params['user_id']);
  22. //获取签到奖励配置
  23. $signInRewardStr = make(ConfigRepoistory::class)->get('sign_in_reward', 'rule');
  24. $signInReward = json_decode($signInRewardStr, true);
  25. //今日签到奖励
  26. $signReward = $signInReward[$counFrequency];
  27. //连续签到奖励
  28. if ($counFrequency == 6) {
  29. dispatch_event(new LastSignInEvent(['user_id' => $this->params['user_id']]));
  30. }
  31. $setData = [
  32. 'uid' => $this->params['user_id'],
  33. 'reward' => $signReward,
  34. 'date' => date('Y-m-d'),
  35. 'reward_way' => TaskAwarkLogModel::REWARD_WAY_SIGN_IN,
  36. 'reward_type' => TaskAwarkLogModel::REWARD_TYPE_MOVIE_CONUT,
  37. 'is_add_up' => TaskAwarkLogModel::IS_ADD_UP_OFF,
  38. ];
  39. make(TaskAwarkLogRepository::class)->create($setData);
  40. } catch (\Exception $exception) {
  41. logger('SendSignInRewardsJob', [$exception->getMessage()]);
  42. }
  43. }
  44. }