<?php
declare(strict_types=1);
namespace App\Controller;

use App\JsonRpc\PublicRpcServiceInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use App\Tools\Result;
use App\Tools\CommonService;
/**
 * Class PublicController
 * @package App\Controller
 */
#[AutoController]
class PublicController extends AbstractController
{

    /**
     * @var PublicRpcServiceInterface
     */
    #[Inject]
    private $publicServiceClient;

    /**
     * 地区
     * @return array
     */
    public function getDistrictList()
    {
        $pid = $this->request->input("pid",0);
        $data = [
            'pid'=>$pid
        ];
        $result = $this->publicServiceClient->getDistrictList($data);
        return $result ? Result::success($result['data']) : Result::error($result['message']);
    }

    /**
     * 获取用户等级
     * @return array
     */
    public function getUserLevelList()
    {
        $result = $this->publicServiceClient->getUserLevelList([]);
        return $result ? Result::success($result['data']) : Result::error($result['message']);
    }
    public function uploadFile()
    {
        $urlN = new CommonService();
        $file = $this->request->file('file');
        try {
            if ($file == null) {
               return  Result::error("未找到上传文件");
            }
            $data = CommonService::uploadFile($file, ['png','jpg','png','jpeg','gif','xls', 'xlsx', 'pdf', 'xls', 'xlsx', 'doc', 'docx', 'ppt', 'zip', 'pptx', 'mp4', 'flv'], 'image');
            $data['imgUrl'] = $urlN->imgUrl($data['src']);
            return  Result::success($data, '上传成功');
        } catch (\Exception $e) {
            return Result::error($e->getMessage());

        }
    }




}