Commission.php 995 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace addons\shopro\job;
  3. use think\queue\Job;
  4. use think\Db;
  5. use think\exception\HttpResponseException;
  6. use addons\shopro\service\commission\Agent as AgentService;
  7. /**
  8. * 分销任务
  9. */
  10. class Commission extends BaseJob
  11. {
  12. /**
  13. * 分销商升级
  14. */
  15. public function agentUpgrade(Job $job, $payload)
  16. {
  17. try {
  18. $userId = $payload['user_id'];
  19. $agent = new AgentService($userId);
  20. if ($agent->user) {
  21. Db::transaction(function () use ($agent) {
  22. $agent->runAgentUpgradePlan();
  23. });
  24. }
  25. $job->delete();
  26. } catch (HttpResponseException $e) {
  27. $data = $e->getResponse()->getData();
  28. $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
  29. format_log_error($e, 'AgentUpgrade.HttpResponseException', $message);
  30. } catch (\Exception $e) {
  31. format_log_error($e, 'AgentUpgrade');
  32. }
  33. }
  34. }