<?php

namespace app\badminapi\controller;


use app\lib\wx_encode\WXBizMsgCrypt;
use app\badminapi\controller\merchant\Open;
use app\models\merchant\MerchantCodeAudit;
use app\models\system\MerchantDailyReport;
use app\models\system\SystemDailyReport;
use app\Request;
use crmeb\basic\BaseModel;
use crmeb\services\CacheService;
use crmeb\services\UtilService;
use think\db\exception\DbException;
use think\Exception;
use think\facade\App;

class Test
{

    public function index(Request $request)
    {
        BaseModel::beginTrans();
        try {
            $res = ['auditid' => 425384030, 'errcode' => 0];
            if (isset($res['errcode']) && $res['errcode'] == 0) {
                $ret = MerchantCodeAudit::create(['mer_id' => 1, 'auditid' => $res['auditid'], 'commit_time' => time()]);
                if ($ret) {
                    BaseModel::commitTrans();
                    return app('json')->success('提交审核完成');
                } else {
                    BaseModel::rollbackTrans();
                    return app('json')->success(MerchantCodeAudit::getErrorInfo('审核记录失败，请手动记录'), ['auditid' => $res['auditid']]);
                }
            } else {
                BaseModel::rollbackTrans();
                return app('json')->fail($res['errmsg'] ?? $res['msg'] ?? '请求错误');
            }
        } catch (Exception $e) {
            BaseModel::rollbackTrans();
            return app('json')->fail($e->getMessage(), ['file' => $e->getFile(), 'line' => $e->getLine()]);
        } catch (DbException $e) {
            BaseModel::rollbackTrans();
            return app('json')->fail($e->getMessage(), ['file' => $e->getFile(), 'line' => $e->getLine()]);
        }
    }

    public function wxCallback()
    {
        $appid = '';
        $res = new Open(new App(),true)->wxCallback($appid);
        dump($res);
    }
}