niucloud-admin/niucloud/app/service/admin/weapp/WeappPackageService.php
2023-09-06 18:49:12 +08:00

71 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\service\admin\weapp;
use app\dict\sys\FileDict;
use core\base\BaseAdminService;
use app\dict\sys\StorageDict;
use app\service\core\upload\CoreUploadService;
use core\exception\UploadFileException;
use app\model\weapp\WeappVersion;
/**
* 小程序包版本发布
*/
class WeappPackageService extends BaseAdminService
{
public function __construct()
{
parent::__construct();
$this->model = new WeappVersion();
}
/**
* 添加小程序版本
* @param array $data
* @return mixed
*/
public function add(array $data)
{
$data[ 'create_time' ] = time();
$res = $this->model->create($data);
return $res->id;
}
/**
* 获取小程序版本列表
* @param array $where
* @return array
*/
public function getPage(array $where = [])
{
$field = 'id, code, content, create_time, path';
$order = 'create_time desc';
$search_model = $this->model->field($field)->order($order);
return $this->pageQuery($search_model);
}
/**
* 文件上传
* @param $file
* @param string $type
* @return array
* @throws Exception
*/
public function document($file, string $type){
if(!in_array($type, FileDict::getSceneType()))
throw new UploadFileException('UPLOAD_TYPE_ERROR');
$dir = 'attachment/document/'.$type.'/'.'/'.date('Ym').'/'.date('d');
$core_upload_service = new CoreUploadService();
return $core_upload_service->document($file, $type, $dir, StorageDict::LOCAL);
}
}