| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Jobs;
- use App\Events\Task\LastSignInEvent;
- use App\Model\TaskAwarkLogModel;
- use App\Repositories\ConfigRepoistory;
- use App\Repositories\Service\UserSingInService;
- use App\Repositories\TaskAwarkLogRepository;
- use Hyperf\AsyncQueue\Job;
- class SendSignInRewardsJob extends Job
- {
- public $params;
- public function __construct($params)
- {
- // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
- $this->params = $params;
- }
- public function handle()
- {
- try {
- //获取连续签到次数
- $counFrequency = make(UserSingInService::class)->getContinuousSignCount($this->params['user_id']);
- //获取签到奖励配置
- $signInRewardStr = make(ConfigRepoistory::class)->get('sign_in_reward', 'rule');
- $signInReward = json_decode($signInRewardStr, true);
- //今日签到奖励
- $signReward = $signInReward[$counFrequency];
- //连续签到奖励
- if ($counFrequency == 6) {
- dispatch_event(new LastSignInEvent(['user_id' => $this->params['user_id']]));
- }
- $setData = [
- 'uid' => $this->params['user_id'],
- 'reward' => $signReward,
- 'date' => date('Y-m-d'),
- 'reward_way' => TaskAwarkLogModel::REWARD_WAY_SIGN_IN,
- 'reward_type' => TaskAwarkLogModel::REWARD_TYPE_MOVIE_CONUT,
- 'is_add_up' => TaskAwarkLogModel::IS_ADD_UP_OFF,
- ];
- make(TaskAwarkLogRepository::class)->create($setData);
- } catch (\Exception $exception) {
- logger('SendSignInRewardsJob', [$exception->getMessage()]);
- }
- }
- }
|