CancelUserServices.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\user;
  12. use app\model\order\StoreOrder;
  13. use app\model\user\AwardIntegral;
  14. use app\model\user\UserIntegral;
  15. use app\services\BaseServices;
  16. use app\services\wechat\WechatUserServices;
  17. use think\facade\Log;
  18. class CancelUserServices extends BaseServices
  19. {
  20. public function cancelUser(int $uid)
  21. {
  22. try {
  23. /** @var UserServices $userService */
  24. $userService = app()->make(UserServices::class);
  25. /** @var WechatUserServices $wechatUserServices */
  26. $wechatUserServices = app()->make(WechatUserServices::class);
  27. $userService->update(['spread_uid' => $uid], ['spread_uid' => 0]);// 清除用户与下级的关系
  28. $userService->update($uid, ['spread_uid' => 0, 'integral' => 0, 'now_money' => 0]);//清除
  29. $userService->update(['work_uid' => $uid], ['work_uid' => 0, 'work_userid' => '']);//清除企业微信上下级关系
  30. $userService->destroy($uid);// 软删除用户
  31. $wechatUserServices->update(['uid' => $uid], ['is_del' => 1, 'unionid' => '', 'openid' => time() . rand(1000, 9999)]);// 删除微信用户
  32. // CancelUserJob::dispatch([$uid]);// 相关记录删除队列
  33. AwardIntegral::where('uid', $uid)->delete();
  34. UserIntegral::where('uid', $uid)->delete();
  35. StoreOrder::where('uid', $uid)->update(['is_system_del' => 1, 'remark' => '用户注销删除']);
  36. } catch (\Throwable $e) {
  37. Log::error('注销用户失败,失败原因:' . $e->getMessage());
  38. }
  39. }
  40. }