<?php

namespace app\adminapi\controller\master_worker;

use app\adminapi\controller\BaseAdminController;
use app\adminapi\validate\master_worker\MasterWorkerRetentionMoneyLogValidate;
use app\common\logic\RetentionMoneyLogic;
use app\workerapi\lists\MasterWorkerRetentionMoneyLogLists;

class RetentionMoneyLogController extends BaseAdminController
{
    public array $notNeedLogin = ['totalAmount'];
    public function lists()
    {
        return $this->dataLists(new MasterWorkerRetentionMoneyLogLists());
    }

    public function totalAmount()
    {
        $params = (new MasterWorkerRetentionMoneyLogValidate())->get()->goCheck('totalAmount');
        $result = RetentionMoneyLogic::totalAmount($params);
        if (false === $result) {
            return $this->fail(RetentionMoneyLogic::getError());
        }
        return $this->success('操作成功',$result, 1, 0);
    }

    public function add()
    {
        $params = (new MasterWorkerRetentionMoneyLogValidate())->post()->goCheck('add');
        $result = RetentionMoneyLogic::addDeduct($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(RetentionMoneyLogic::getError());
    }
}