<?php

namespace app\controller\api;

use support\Request;

use App\Utils\ApiResponseApp;


use App\model\Dictionary;
use App\model\Message;
use App\model\ExchangeRate;
use hg\apidoc\annotation as Apidoc;
use support\Db;

/**
 * @Apidoc\Title("公共控制器?")
 */

class CommonController
{
    protected $noNeedLogin = ['config', 'get_project', 'get_projectdetailed', 'get_mechanism_list'];


    /**
     * @Apidoc\Title("1.0 获取全局配置")
     * @Apidoc\Url("api/common/config")
     * @Apidoc\Method("POST")
     */
    public function config(Request $request)
    {

        $Dictionary=Dictionary::all();
        $res=[];
        $ExchangeRate = ExchangeRate::all();
        $res = [
            "account_notice" => "Log in to link account and get 300 to 3,000 random points a day",
            // "vi_rate" => "2.49",
            // "trx_rate" => "0.00",
            // "nrly_rate" => "30",
            // "trx_rate1" => "",
            // "inr_rate" => "1.62",
            // "php_rate" => null,
            // "brl_rate" => "0.10",
            "brl_fee" => "300",
            "pkr_fee" => "300",
            // "pkr_rate" => "5",
            "pkr_min" => "2000",
            "brl_min" => "5000"
        ];
        foreach ($ExchangeRate as $item) {
            $res[strtolower($item['type']) . '_rate'] = $item['points'];
        }
        $col=['service_1','service_2','service_3','service_url','service_user_url','points'];
        foreach($Dictionary as $key=>$value){
            $res[$value->key]=$value->value;
        }
        return ApiResponseApp::success($res);
    }
        /**
     * @Apidoc\Title("1.0 消息根据type 判断类型")
     * @Apidoc\Url("api/common/messageList")
     * 3是首页弹窗   1是消息中心
     * @Apidoc\Method("POST")
     */
    public function messageList(Request $request){
        $type = $request->get('type');
        $query = Message::query();

        if ($type == 5) {
            // 大于 type(注意:这里假设你想比较的是 'id' 字段)
            $query->where('id', '>', $type);
        }

        if ($type == 3) {
            // 小于 type(同样假设是 'id' 字段)
            $query->where('id', '<', $type);
        }

        if ($type == 1) {
            // 等于特定值(这里是6)
            $query->where('id', '=', 6);
        }

        // 执行查询并获取结果
        $list = $query->get();
        var_dump(1111);

        // 准备返回的数据
        $map = [
            'data' => $list->toArray(),
        ];

        return ApiResponseApp::success($map);
    }

}