<?php

namespace app\queue\single;

use Webman\RedisQueue\Consumer;
use app\model\WorkRecord;
use think\facade\Db;

class Studio implements Consumer
{
    // 要消费的队列名
    public $queue = 'Studio';
    public $connection = 'default';

    // 消费Notify
    public function consume($data)
    {
        return false;
        $this->log('开始结算:');
        $list = (new \app\model\BalanceLog)->setSuffix('_currency3')
            ->where('status',1)
            ->order('created_at','asc')
            ->select();
        if(!$list){
            return ;
        }
        foreach($list as $log){
            Db::startTrans();
            try {
                $log->status = 2;
                $log->save();
                \app\model\User::transform(
                    'currency3',
                    'money',
                    $log->user_id,
                    $log->amount,
                    \app\enum\BalanceType::STUDIO_REALESE,
                    $log->id
                );
                \app\model\User::currency4($log->user_id,$log->amount,\app\enum\BalanceType::STUDIO_REALESE,$log->id);
                Db::commit();
            } catch (\Exception $e) {
                Db::rollback();
                $this->log($e->getMessage());
                throw $e;
            }
        }
    }
    function log($msg = ''){
        \support\Log::channel('studio')->alert($msg);
    }
    // 消费失败回调
    public function onConsumeFailure(\Throwable $e, $package)
    {
        $this->log('consume failure:'.$e->getMessage());
    }
}