UserSpreadJob.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\user;
  12. use app\services\user\UserServices;
  13. use app\services\user\UserSpreadServices;
  14. use crmeb\basic\BaseJobs;
  15. use crmeb\traits\QueueTrait;
  16. use think\facade\Log;
  17. /**
  18. * 用户推广关系
  19. * Class UserSpreadJob
  20. * @package app\jobs\user
  21. */
  22. class UserSpreadJob extends BaseJobs
  23. {
  24. use QueueTrait;
  25. /**
  26. * 记录用户推广关系
  27. * @param int $uid
  28. * @param int $spreadUid
  29. * @return bool
  30. */
  31. public function doJob(int $uid, int $spreadUid, int $spread_time = 0, int $admin_id = 0)
  32. {
  33. if (!$uid || !$spreadUid || $uid == $spreadUid) {
  34. return true;
  35. }
  36. try {
  37. /** @var UserSpreadServices $userSpreadServices */
  38. $userSpreadServices = app()->make(UserSpreadServices::class);
  39. //记录
  40. $userSpreadServices->setSpread($uid, $spreadUid, $spread_time, $admin_id);
  41. /** @var UserServices $userServices */
  42. $userServices = app()->make(UserServices::class);
  43. //增加推广人数
  44. $userServices->incField($spreadUid, 'spread_count', 1);
  45. } catch (\Throwable $e) {
  46. Log::error('记录用户推广失败,失败原因:' . $e->getMessage());
  47. }
  48. return true;
  49. }
  50. }