Files
huangjingfen/pro_v3.5.1_副本/crmeb/services/upload/storage/Qiniu.php
apple 434aa8c69d feat(fsgx): 完成全部24项开发任务 Phase1-7
Phase1 后端核心:
- 新增 fsgx_v1.sql 迁移脚本(is_queue_goods/frozen_points/available_points/no_assess)
- SystemConfigServices 返佣设置扩展(周期人数/分档比例/范围/时机)
- StoreOrderCreateServices 周期循环佣金计算
- StoreOrderTakeServices 佣金发放后同步冻结积分
- StoreProductServices/StoreProduct 保存 is_queue_goods

Phase2 后端接口:
- GET /api/hjf/brokerage/progress 佣金周期进度
- GET /api/hjf/assets/overview 资产总览
- HjfPointsServices 每日 frozen_points 0.4‰ 释放定时任务
- PUT /adminapi/hjf/member/{uid}/no_assess 不考核接口
- GET /adminapi/hjf/points/release_log 积分日志接口

Phase3 前端清理:
- hjfCustom.js 路由精简(仅保留 points/log)
- hjfQueue.js/hjfMember.js API 清理/重定向至 CRMEB 原生接口
- pages.json 公排→推荐佣金/佣金记录/佣金规则

Phase4-5 前端改造:
- queue/status.vue 推荐佣金进度页整体重写
- 商品详情/订单确认/支付结果页文案与逻辑改造
- 个人中心/资产页/引导页/规则页文案改造
- HjfQueueProgress/HjfRefundNotice/HjfAssetCard 组件改造
- 推广中心嵌入佣金进度摘要
- hjfMockData.js 全量更新(公排字段→佣金字段)

Phase6 Admin 增强:
- 用户列表新增 frozen_points/available_points 列及不考核操作按钮
- hjfPoints.js USE_MOCK=false 对接真实积分日志接口

Phase7 配置文档:
- docs/fsgx-phase7-config-checklist.md 后台配置与全链路验收清单

Made-with: Cursor
2026-03-23 22:32:19 +08:00

494 lines
16 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
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\services\upload\storage;
use crmeb\basic\BaseUpload;
use crmeb\exceptions\UploadException;
use crmeb\services\HttpService;
use Qiniu\Auth;
use Qiniu\Http\Client;
use Qiniu\Http\Error;
use Qiniu\Storage\BucketManager;
use Qiniu\Storage\UploadManager;
use Qiniu\Config;
use think\exception\ValidateException;
/**
* 七牛云上传
* Class Qiniu
*/
class Qiniu extends BaseUpload
{
/**
* accessKey
* @var mixed
*/
protected $accessKey;
/**
* secretKey
* @var mixed
*/
protected $secretKey;
/**
* 句柄
* @var object
*/
protected $handle;
/**
* 空间域名 Domain
* @var mixed
*/
protected $uploadUrl;
/**
* 存储空间名称 公开空间
* @var mixed
*/
protected $storageName;
/**
* COS使用 所属地域
* @var mixed|null
*/
protected $storageRegion;
/**
* 水印位置
* @var string[]
*/
protected $position = [
'1' => 'NorthWest',//:左上
'2' => 'North',//:中上
'3' => 'NorthEast',//:右上
'4' => 'West',//:左中
'5' => 'Center',//:中部
'6' => 'East',//:右中
'7' => 'SouthWest',//:左下
'8' => 'South',//:中下
'9' => 'SouthEast',//:右下
];
/**
* 初始化
* @param array $config
* @return mixed|void
*/
public function initialize(array $config)
{
parent::initialize($config);
$this->accessKey = $config['accessKey'] ?? null;
$this->secretKey = $config['secretKey'] ?? null;
$this->uploadUrl = $this->checkUploadUrl($config['uploadUrl'] ?? '');
$this->storageName = $config['storageName'] ?? null;
$this->storageRegion = $config['storageRegion'] ?? null;
}
/**
* 实例化七牛云
* @return object|Auth
*/
protected function app()
{
if (!$this->accessKey || !$this->secretKey) {
throw new UploadException('Please configure accessKey and secretKey');
}
$this->handle = new Auth($this->accessKey, $this->secretKey);
return $this->handle;
}
/**
* 上传文件
* @param string $file
* @return array|bool|mixed|\StdClass|string
*/
public function move(string $file = 'file')
{
$fileHandle = app()->request->file($file);
if (!$fileHandle) {
return $this->setError('Upload file does not exist');
}
if ($this->validate) {
try {
$error = [
$file . '.filesize' => 'Upload filesize error',
$file . '.fileExt' => 'Upload fileExt error',
$file . '.fileMime' => 'Upload fileMine error'
];
validate([$file => $this->validate], $error)->check([$file => $fileHandle]);
} catch (ValidateException $e) {
return $this->setError($e->getMessage());
}
}
$key = $this->saveFileName($fileHandle->getRealPath(), $fileHandle->getOriginalExtension());
$key = $this->getUploadPath($key);
$token = $this->app()->uploadToken($this->storageName);
try {
$uploadMgr = new UploadManager();
[$result, $error] = $uploadMgr->putFile($token, $key, $fileHandle->getRealPath());
if ($error !== null) {
return $this->setError($error->message());
}
$this->fileInfo->uploadInfo = $result;
$this->fileInfo->realName = $fileHandle->getOriginalName();
$this->fileInfo->filePath = $this->uploadUrl . '/' . $key;
$this->fileInfo->fileName = $key;
$this->fileInfo->filePathWater = $this->water($this->fileInfo->filePath);
$this->authThumb && $this->thumb($this->fileInfo->filePath);
return $this->fileInfo;
} catch (UploadException $e) {
return $this->setError($e->getMessage());
}
}
/**
* 文件流上传
* @param string $fileContent
* @param string|null $key
* @return array|bool|mixed|\StdClass
*/
public function stream(string $fileContent, string $key = null)
{
if (!$key) {
$key = $this->saveFileName();
}
$key = $this->getUploadPath($key);
$this->verifyExtension($key);
$token = $this->app()->uploadToken($this->storageName, $key);
try {
$uploadMgr = new UploadManager();
[$result, $error] = $uploadMgr->put($token, $key, $fileContent);
if ($error !== null) {
return $this->setError($error->message());
}
$this->fileInfo->uploadInfo = $result;
$this->fileInfo->realName = $key;
$this->fileInfo->filePath = $this->uploadUrl . '/' . $key;
$this->fileInfo->fileName = $key;
$this->fileInfo->filePathWater = $this->water($this->fileInfo->filePath);
$this->authThumb && $this->thumb($this->fileInfo->filePath);
return $this->fileInfo;
} catch (UploadException $e) {
return $this->setError($e->getMessage());
}
}
/**
* 缩略图
* @param string $filePath
* @param string $type
* @return mixed|string[]
*/
public function thumb(string $filePath = '', string $type = 'all')
{
$filePath = $this->getFilePath($filePath);
$data = ['big' => $filePath, 'mid' => $filePath, 'small' => $filePath];
$this->fileInfo->filePathBig = $this->fileInfo->filePathMid = $this->fileInfo->filePathSmall = $this->fileInfo->filePathWater = $filePath;
if ($filePath) {
$config = $this->thumbConfig;
foreach ($this->thumb as $v) {
if ($type == 'all' || $type == $v) {
$height = 'thumb_' . $v . '_height';
$width = 'thumb_' . $v . '_width';
if (isset($config[$height]) && isset($config[$width]) && $config[$height] && $config[$width]) {
$key = 'filePath' . ucfirst($v);
$this->fileInfo->$key = $filePath . '?imageView2/2/w/' . $config[$width] . '/h/' . $config[$height];
$this->fileInfo->$key = $this->water($this->fileInfo->$key);
$data[$v] = $this->fileInfo->$key;
}
}
}
}
return $data;
}
/**
* 水印
* @param string $filePath
* @return mixed|string
*/
public function water(string $filePath = '')
{
$filePath = $this->getFilePath($filePath);
$waterConfig = $this->waterConfig;
$waterPath = $filePath;
if ($waterConfig['image_watermark_status'] && $filePath) {
if (strpos($filePath, '?') === false) {
$filePath .= '?watermark';
} else {
$filePath .= '&watermark';
}
switch ($waterConfig['watermark_type']) {
case 1://图片
if (!$waterConfig['watermark_image']) {
throw new ValidateException('请先配置水印图片');
}
$waterPath = $filePath .= '/1/image/' . base64_encode($waterConfig['watermark_image']) . '/gravity/' . ($this->position[$waterConfig['watermark_position']] ?? 'SouthEest') . '/dissolve/' . $waterConfig['watermark_opacity'] . '/dx/' . $waterConfig['watermark_x'] . '/dy/' . $waterConfig['watermark_y'];
break;
case 2://文字
if (!$waterConfig['watermark_text']) {
throw new ValidateException('请先配置水印文字');
}
$waterPath = $filePath .= '/2/text/' . base64_encode($waterConfig['watermark_text']) . '/fill/' . base64_encode($waterConfig['watermark_text_color']) . '/fontsize/' . $waterConfig['watermark_text_size'] . '/gravity/' . ($this->position[$waterConfig['watermark_position']] ?? 'SouthEest') . '/dx/' . $waterConfig['watermark_x'] . '/dy/' . $waterConfig['watermark_y'];
break;
}
}
return $waterPath;
}
/**
* 获取视频封面图
* @param string $filePath
* @param string $type
* @param int $time
* @return array
*/
public function videoCoverImage(string $filePath = '', string $type = 'all', int $time = 1)
{
$data = ['big' => $filePath, 'mid' => $filePath, 'small' => $filePath];
$this->fileInfo->filePathBig = $this->fileInfo->filePathMid = $this->fileInfo->filePathSmall = $this->fileInfo->filePathWater = $filePath;
if ($filePath) {
//?fops=vframe/jpg/offset/7/w/480/h/360
foreach ($this->thumb as $v) {
if ($type == 'all' || $type == $v) {
$height = 600;
$width = 400;
$key = 'filePath' . ucfirst($v);
$this->fileInfo->$key = $filePath . '?fops=vframe/jpg/offset/' . $time . '/w/' . $width . '/h/' . $height;
$data[$v] = $this->fileInfo->$key;
}
}
}
return $data;
}
/**
* 获取上传配置信息
* @return array
*/
public function getSystem()
{
$token = $this->app()->uploadToken($this->storageName);
$domain = $this->uploadUrl;
$key = $this->saveFileName();
return compact('token', 'domain', 'key');
}
/**
* 删除资源
* @param $key
* @param $bucket
* @return mixed
*/
public function delete(string $key)
{
$bucketManager = new BucketManager($this->app(), new Config());
return $bucketManager->delete($this->storageName, $key);
}
/**
* 获取七牛云上传密钥
* @return mixed|string
*/
public function getTempKeys()
{
$token = $this->app()->uploadToken($this->storageName);
$domain = $this->uploadUrl;
$key = $this->saveFileName(NULL, 'mp4');
$type = 'QINIU';
return compact('token', 'domain', 'key', 'type');
}
/**
* 获取当前所有桶列表
* @param string|null $region
* @param bool $line
* @param bool $shared
* @return bool|mixed
*/
public function listbuckets(string $region = null, bool $line = false, bool $shared = false)
{
$bucket = new BucketManager($this->app());
[$response, $error] = $bucket->listbuckets($region, $line ? 'true' : 'false', $shared ? 'true' : 'false');
if ($error !== null) {
return $this->setError($error->message());
}
return $response;
}
/**
* @param string $name
* @param string $region
* @return bool|mixed
*/
public function createBucket(string $name, string $region = 'z0')
{
$regionData = $this->getRegion();
if (!in_array($region, array_column($regionData, 'value'))) {
return $this->setError('七牛云:无效的区域');
}
$url = 'https://' . Config::UC_HOST . '/mkbucketv3/' . $name . '/region/' . $region;
$body = null;
$headers = $this->app()->authorizationV2($url, 'POST', $body, 'application/json');
$headers["Content-Type"] = 'application/json';
$ret = Client::post($url, $body, $headers);
if (!$ret->ok()) {
$error = new Error($url, $ret);
if ('bucket exists' === $error->message()) {
return $this->setError('七牛云:云空间已存在');
}
return $this->setError('七牛云:' . $error->message());
}
return ($ret->body === null) ? array() : $ret->json();
}
/**
* 获取区域
* @return mixed|\string[][]
*/
public function getRegion()
{
return [
[
'value' => 'z0',
'label' => '华东'
],
[
'value' => 'z1',
'label' => '华北'
],
[
'value' => 'z2',
'label' => '华南'
],
[
'value' => 'na0',
'label' => '北美'
],
[
'value' => 'as0',
'label' => '东南亚'
],
[
'value' => 'cn-east-2',
'label' => '华东-浙江2'
],
];
}
/**
* 删除空间
* @param string $name
* @return bool|mixed
*/
public function deleteBucket(string $name)
{
$bucket = new BucketManager($this->app());
[$response, $error] = $bucket->deleteBucket($name);
if ($error !== null) {
return $this->setError($error->message());
}
return $response;
}
/**
* 获取七牛域名
* @param string $name
* @return array|bool|mixed|null
*/
public function getDomian(string $name)
{
$url = 'https://' . Config::UC_HOST . '/v2/domains?tbl=' . $name;
$body = null;
$headers = $this->app()->authorizationV2($url, 'POST', $body, 'application/x-www-form-urlencoded');
$headers["Content-Type"] = 'application/x-www-form-urlencoded';
$ret = Client::post($url, $body, $headers);
if (!$ret->ok()) {
$error = new Error($url, $ret);
return $this->setError('七牛云:' . $error->message());
}
return ($ret->body === null) ? array() : $ret->json();
}
public function getDomianInfo(string $host)
{
$url = 'https://' . Config::API_HOST . '/domain/' . $host;
$headers = $this->app()->authorization($url, null, 'application/x-www-form-urlencoded');
$headers["Content-Type"] = 'application/x-www-form-urlencoded';
$ret = Client::get($url, $headers);
if (!$ret->ok()) {
$error = new Error($url, $ret);
return $this->setError('七牛云:' . $error->message());
}
return ($ret->body === null) ? array() : $ret->json();
}
/**
*
* @param string $name
* @param string $domain
* @param string|null $region
* @return array|bool|mixed|null
*/
public function bindDomian(string $name, string $domain, string $region = null)
{
$parseDomin = parse_url($domain);
$url = 'https://' . Config::API_HOST . '/domain/' . $parseDomin['host'];
$body = [
'type' => 'normal',
'platform' => 'web',
'geocover' => 'china',
'source' => [
'sourceType' => 'qiniuBucket',
'sourceQiniuBucket' => $name,
'TestURLPath' => 'qiniu_do_not_delete.gif',
],
'protocol' => $parseDomin['scheme'],
'cache' => [
'cacheControls' => [
[
'time' => 1,
'timeunit' => 4,
'type' => 'all',
'rule' => '*'
]
],
'ignoreParam' => false
]
];
$bodyJson = json_encode($body);
$headers = $this->app()->authorization($url, $bodyJson, 'application/json');
$headers["Content-Type"] = 'application/json';
$ret = Client::post($url, $bodyJson, $headers);
if (!$ret->ok()) {
$error = new Error($url, $ret);
return $this->setError('七牛云:' . $error->message());
}
return ($ret->body === null) ? array() : $ret->json();
}
/**
* 跨域
* @param string $name
* @param string $region
* @return bool
*/
public function setBucketCors(string $name, string $region)
{
return true;
}
}