AddExchangeCodeJob.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\PaymentResultModel;
  13. use App\Model\Mongo\VipCodeExchangeHistoryModel;
  14. use Carbon\Carbon;
  15. use Hyperf\AsyncQueue\Job;
  16. class AddExchangeCodeJob 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(VipCodeExchangeHistoryModel::class)->db()
  28. ->insertOne(
  29. [
  30. 'nick' => $this->params['nick'],
  31. 'user_id' => $this->params['user_id'],
  32. 'user_code' => $this->params['user_code'],
  33. 'code' => $this->params['code'],
  34. 'title' => $this->params['title'],
  35. 'day' => $this->params['day'],
  36. 'created_at' => Carbon::now()->toDateTimeString(),
  37. ]
  38. );
  39. } catch (\Exception $exception) {
  40. logger('AddExchangeCodeJob', [$exception->getMessage()]);
  41. }
  42. }
  43. }