ClearUserIntegralJob.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace ln\jobs;
  3. use app\common\repositories\store\product\ProductRepository;
  4. use app\common\repositories\user\UserBillRepository;
  5. use app\common\repositories\user\UserRepository;
  6. use ln\interfaces\JobInterface;
  7. use think\facade\Db;
  8. use think\facade\Log;
  9. class ClearUserIntegralJob implements JobInterface
  10. {
  11. public function fire($job, $data)
  12. {
  13. try {
  14. $user = app()->make(UserRepository::class)->get($data['uid']);
  15. if ($user && $user->integral > 0) {
  16. $validIntegral = app()->make(UserBillRepository::class)->validIntegral($data['uid'], $data['startTime'], $data['endTime']);
  17. if ($user->integral > $validIntegral) {
  18. $clear = bcsub($user->integral, $validIntegral, 0);
  19. $user->integral = $validIntegral;
  20. app()->make(UserBillRepository::class)->decBill($user->uid, 'integral', 'timeout', [
  21. 'link_id' => 0,
  22. 'status' => 1,
  23. 'title' => '积分过期',
  24. 'number' => $clear,
  25. 'mark' => $clear . '积分已过期',
  26. 'balance' => $user->integral
  27. ]);
  28. $user->save();
  29. }
  30. }
  31. } catch (\Exception $e) {
  32. Log::info('用户ID:' . $data['uid'] . '积分清理失败');
  33. }
  34. $job->delete();
  35. }
  36. public function failed($data)
  37. {
  38. // TODO: Implement failed() method.
  39. }
  40. }