ClearUserIntegralJob.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\jobs;
  12. use app\common\repositories\store\product\ProductRepository;
  13. use app\common\repositories\user\UserBillRepository;
  14. use app\common\repositories\user\UserRepository;
  15. use crmeb\interfaces\JobInterface;
  16. use think\facade\Db;
  17. use think\facade\Log;
  18. class ClearUserIntegralJob implements JobInterface
  19. {
  20. public function fire($job, $data)
  21. {
  22. try {
  23. $user = app()->make(UserRepository::class)->get($data['uid']);
  24. if ($user && $user->integral > 0) {
  25. $validIntegral = app()->make(UserBillRepository::class)->validIntegral($data['uid'], $data['startTime'], $data['endTime']);
  26. if ($user->integral > $validIntegral) {
  27. $clear = bcsub($user->integral, $validIntegral, 0);
  28. $user->integral = $validIntegral;
  29. app()->make(UserBillRepository::class)->decBill($user->uid, 'integral', 'timeout', [
  30. 'link_id' => 0,
  31. 'status' => 1,
  32. 'title' => '积分过期',
  33. 'number' => $clear,
  34. 'mark' => $clear . '积分已过期',
  35. 'balance' => $user->integral
  36. ]);
  37. $user->save();
  38. }
  39. }
  40. } catch (\Exception $e) {
  41. Log::info('用户ID:' . $data['uid'] . '积分清理失败');
  42. }
  43. $job->delete();
  44. }
  45. public function failed($data)
  46. {
  47. // TODO: Implement failed() method.
  48. }
  49. }