<?php

namespace app\command;

use app\extra\jhfPay\Pay;
use app\extra\tools\CodeExtend;
use app\extra\tools\DataExtend;
use app\model\system\SystemUserBankcard;
use app\model\system\SystemUserMoney;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class DayPay extends Command
{

    protected static string $defaultName = 'day:pay';
    protected static string $defaultDescription = '每日结算金额发放';


    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $card = (new SystemUserBankcard)->select();
        $day = date("Y-m-d",strtotime("-1 day"));
        $cardData = unique_arr($card->toArray(),"member_id");
        $respJhf = (new Pay)->config([
            "appid"  => sConf("wechat.jhf_appid"),
            "mch_id" => sConf("wechat.jhf_mch_id"),
            "aeskey" => sConf("wechat.jhf_aeskey"),
            "pubkey" => sConf("wechat.jhf_pubkey"),
            "prikey" => sConf("wechat.jhf_prikey"),
        ]);
        if (!empty($cardData)) {
            foreach ($cardData as $val)
            {
                $jsResp = $respJhf->createBalanceWithdraw([
                    "app_id" => sConf("wechat.jhf_appid"),
                    "order_no"  => $val['member_id'].CodeExtend::uniqidDate(14),
                    "member_id" => $val['member_id'],
                    "remark"    => "{$day}-结算",
                    "notify_url"    => "https://panel.huiyinduo.cn/notify/withdraw",
                ]);
                echo getDateFull()."=={$val['user_name']}==开始结算\n";
                echo json_encode($jsResp)."\n";
            }
        }
        return self::SUCCESS;
    }


}