AddPayNotifyJob.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://doc.hyperf.io
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
  10. */
  11. namespace App\Jobs;
  12. use App\Model\Mongo\PayNotifyModel;
  13. use App\Model\Mongo\RegisterModel;
  14. use App\Model\VipOrderModel;
  15. use Hyperf\AsyncQueue\Job;
  16. class AddPayNotifyJob extends Job
  17. {
  18. public $params;
  19. public function __construct($params)
  20. {
  21. // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
  22. $this->params = $params;
  23. }
  24. public function handle()
  25. {
  26. try {
  27. make(PayNotifyModel::class)->db()
  28. ->insertOne($this->params);
  29. $uid = VipOrderModel::query()->where('id', $this->params['order_id'])
  30. ->value('user_id');
  31. make(RegisterModel::class)->db()->updateOne(
  32. ['uid' => (int)$uid],
  33. ['$set' => ['is_vip' => 1]]
  34. );
  35. } catch (\Exception $exception) {
  36. logger('AddPayNotifyJob', [$exception->getMessage()]);
  37. }
  38. }
  39. }