AgentJob.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs;
  12. use app\services\agent\AgentLevelServices;
  13. use app\services\user\UserServices;
  14. use crmeb\basic\BaseJobs;
  15. use crmeb\traits\QueueTrait;
  16. use think\facade\Log;
  17. /**
  18. * 检测分销员等级升级
  19. * Class OrderJob
  20. * @package crmeb\jobs
  21. */
  22. class AgentJob extends BaseJobs
  23. {
  24. use QueueTrait;
  25. /**
  26. * 执行检测升级
  27. * @param $order
  28. * @return bool
  29. */
  30. public function doJob(int $uid)
  31. {
  32. //检测分销员等级升级
  33. try {
  34. //商城分销是否开启
  35. if (!sys_config('brokerage_func_status')) {
  36. return true;
  37. }
  38. /** @var UserServices $userServices */
  39. $userServices = app()->make(UserServices::class);
  40. $userInfo = $userServices->getUserInfo($uid);
  41. if (!$userInfo) {
  42. return true;
  43. }
  44. //获取上级uid || 开启自购返回自己uid
  45. $spread_uid = $userServices->getSpreadUid($uid, $userInfo);
  46. $two_spread_uid = 0;
  47. if ($spread_uid > 0 && $one_user_info = $userServices->getUserInfo($spread_uid)) {
  48. $two_spread_uid = $userServices->getSpreadUid($spread_uid, $one_user_info, false);
  49. }
  50. $uids = array_unique([$uid, $spread_uid, $two_spread_uid]);
  51. /** @var AgentLevelServices $agentLevelServices */
  52. $agentLevelServices = app()->make(AgentLevelServices::class);
  53. //检测升级
  54. $agentLevelServices->checkUserLevelFinish($uid, $uids);
  55. return true;
  56. } catch (\Throwable $e) {
  57. Log::error('检测分销等级升级失败,失败原因:' . $e->getMessage());
  58. }
  59. }
  60. }