调整商户冻结金额解冻

This commit is contained in:
luofei 2024-03-08 11:05:36 +08:00
parent 54bf58b197
commit 50248f1c2b

View File

@ -18,24 +18,39 @@ use app\common\repositories\user\UserBillRepository;
use crmeb\interfaces\ListenerInterface; use crmeb\interfaces\ListenerInterface;
use crmeb\services\TimerService; use crmeb\services\TimerService;
use think\facade\Db; use think\facade\Db;
use think\facade\Log;
class AutoUnlockMerchantMoneyListen extends TimerService implements ListenerInterface class AutoUnlockMerchantMoneyListen extends TimerService implements ListenerInterface
{ {
public function handle($event): void public function handle($event): void
{ {
$this->tick(1000 * 60 * 20, function () { $this->tick(1000 * 60 * 60, function () {
request()->clearCache(); if (time() >= strtotime('today 18:00:00') && time() >= strtotime('today 20:00:00')) {
$userBill = app()->make(UserBillRepository::class); request()->clearCache();
$timer = ((int)systemConfig('mer_lock_time')); /** @var UserBillRepository $userBill */
$time = date('Y-m-d H:i:s', $timer ? strtotime("- $timer day") : time()); $userBill = app()->make(UserBillRepository::class);
$bills = $userBill->getTimeoutMerchantMoneyBill($time); // $timer = ((int)systemConfig('mer_lock_time'));
$merchant = app()->make(MerchantRepository::class); // $time = date('Y-m-d H:i:s', $timer ? strtotime("- $timer day") : time());
foreach ($bills as $bill) { $time = date('Y-m-d 00:00:00');
Db::transaction(function () use ($bill, $merchant) { $bills = $userBill->getTimeoutMerchantMoneyBill($time);
$merchant->addMoney($bill->mer_id, $bill->number); $merchant = app()->make(MerchantRepository::class);
$bill->status = 1; $count = 0;
$bill->save(); foreach ($bills as $bill) {
}); Db::startTrans();
try {
$merchant->addMoney($bill->mer_id, $bill->number);
$bill->status = 1;
$bill->save();
Db::commit();
$count++;
} catch (\Throwable $e) {
Db::rollback();
Log::error('商户冻结金额解冻出错:' . $e->getMessage());
}
}
if ($count > 0) {
Log::info('商户冻结金额解冻成功:' . $count);
}
} }
}); });
} }