admin-api/crmeb/jobs/ClearUserIntegralJob.php

49 lines
1.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace crmeb\jobs;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserRepository;
use crmeb\interfaces\JobInterface;
use think\facade\Db;
use think\facade\Log;
class ClearUserIntegralJob implements JobInterface
{
public function fire($job, $data)
{
try {
$user = app()->make(UserRepository::class)->get($data['uid']);
if ($user && $user->integral > 0) {
$validIntegral = app()->make(UserBillRepository::class)->validIntegral($data['uid'], $data['startTime'], $data['endTime']);
if ($user->integral > $validIntegral) {
$clear = bcsub($user->integral, $validIntegral, 0);
$user->integral = $validIntegral;
app()->make(UserBillRepository::class)->decBill($user->uid, 'integral', 'timeout', [
'link_id' => 0,
'status' => 1,
'title' => '积分过期',
'number' => $clear,
'mark' => $clear . '积分已过期',
'balance' => $user->integral
]);
$user->save();
}
}
} catch (\Exception $e) {
Log::info('用户ID' . $data['uid'] . '积分清理失败');
}
$job->delete();
}
public function failed($data)
{
// TODO: Implement failed() method.
}
}