UserJob.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\user\UserServices;
  13. use app\services\wechat\WechatUserServices;
  14. use crmeb\basic\BaseJobs;
  15. use crmeb\traits\QueueTrait;
  16. use think\facade\Log;
  17. class UserJob extends BaseJobs
  18. {
  19. use QueueTrait;
  20. /**
  21. * 执行同步数据后
  22. * @param $openids
  23. * @return bool
  24. */
  25. public function doJob($openids)
  26. {
  27. if (!$openids || !is_array($openids)) {
  28. return true;
  29. }
  30. $noBeOpenids = [];
  31. try {
  32. /** @var WechatUserServices $wechatUser */
  33. $wechatUser = app()->make(WechatUserServices::class);
  34. $noBeOpenids = $wechatUser->syncWechatUser($openids);
  35. } catch (\Throwable $e) {
  36. Log::error('更新wechatUser用户信息失败,失败原因:' . $e->getMessage());
  37. }
  38. if (!$noBeOpenids) {
  39. return true;
  40. }
  41. try {
  42. /** @var UserServices $user */
  43. $user = app()->make(UserServices::class);
  44. $user->importUser($noBeOpenids);
  45. } catch (\Throwable $e) {
  46. Log::error('新增用户失败,失败原因:' . $e->getMessage());
  47. }
  48. return true;
  49. }
  50. }