Files
huangjingfen/pro_v3.5.1_副本/crmeb/services/upload/extend/cos/Client.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

577 lines
15 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~2022 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
namespace crmeb\services\upload\extend\cos;
use crmeb\exceptions\UploadException;
use crmeb\services\wechat\util\XML;
/**
* Class Client
* @author 等风来
* @email 136327134@qq.com
* @date 2022/9/29
* @package crmeb\services\upload\extend\cos
*/
class Client
{
/**
* @var string
*/
protected $accessKey;
/**
* @var string
*/
protected $secretKey;
/**
* @var string
*/
protected $appid;
/**
* @var mixed|string
*/
protected $bucket;
/**
* @var mixed|string
*/
protected $region;
/**
* @var mixed|string
*/
protected $uploadUrl;
/**
* @var string
*/
protected $action = '';
/**
* @var array
*/
protected $response = ['content' => null, 'code' => 200, 'header' => []];
/**
* @var array
*/
protected $request = ['header' => [], 'body' => [], 'host' => ''];
/**
* @var string
*/
protected $cosacl = 'public-read';
/**
* Client constructor.
* @param array $config
*/
public function __construct(array $config)
{
$this->accessKey = $config['accessKey'] ?? '';
$this->secretKey = $config['secretKey'] ?? '';
$this->appid = $config['appid'] ?? '';
$this->bucket = $config['bucket'] ?? '';
$this->region = $config['region'] ?? 'ap-chengdu';
$this->uploadUrl = $config['uploadUrl'] ?? '';
}
/**
* 获取实际请求
* @return array
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
public function getResponse()
{
$response = $this->response;
$this->response = ['content' => null, 'http_code' => 200, 'header' => []];
return $response;
}
/**
* @return array
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
public function getRequest()
{
$request = $this->request;
$this->request = ['header' => [], 'body' => [], 'host' => ''];
return $request;
}
/**
* 拼接请求地址
* @return string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/9/29
*/
protected function makeUpUrl()
{
return $this->bucket . '.cos.' . $this->region . '.myqcloud.com';
}
/**
* @return bool
* @author 等风来
* @email 136327134@qq.com
* @date 2022/9/29
*/
protected function ssl()
{
return strstr($this->uploadUrl, 'https://') !== false;
}
/**
* 检查参数
* @author 等风来
* @email 136327134@qq.com
* @date 2022/9/29
*/
protected function checkOptions()
{
if (!$this->bucket) {
throw new UploadException('请传入桶名');
}
if (!$this->region) {
throw new UploadException('请传入所属地域');
}
if (!$this->accessKey) {
throw new UploadException('请传入SecretId');
}
if (!$this->secretKey) {
throw new UploadException('请传入SecretKey');
}
}
/**
* 上传文件
* @param string $key
* @param $body
* @return string[]
* @author 等风来
* @email 136327134@qq.com
* @date 2022/9/29
*/
public function putObject(string $key, $body)
{
$this->checkOptions();
$url = $this->makeUpUrl();
$header = [
'Content-Type' => 'image/jpeg',
'x-cos-acl' => $this->cosacl,
'Content-MD5' => base64_encode(md5($body, true)),
'Host' => $url
];
$imageUrl = ($this->ssl() ? 'https://' : 'http://') . $url . '/' . $key;
$res = $this->request($imageUrl, 'PUT', ['body' => $body], $header);
if ($res && !empty($res['Message'])) {
throw new UploadException($res['Message']);
}
return [
'name' => $key,
'path' => $imageUrl
];
}
/**
* 删除文件
* @param string $bucket
* @param string $key
* @return array|false
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/19
*/
public function deleteObject(string $bucket, string $key)
{
$url = $this->getRequestHost($bucket);
$header = [
'Host' => $url
];
$res = $this->request('https://' . $url . '/' . $key, 'delete', [], $header);
if ($res && !empty($res['Message'])) {
throw new UploadException($res['Message']);
}
return $res;
}
/**
* 获取桶列表
* @return array|false|\SimpleXMLElement|string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/19
*/
public function listBuckets()
{
$url = 'service.cos.myqcloud.com';
$header = [
'Host' => $url
];
$res = $this->request('https://' . $url . '/', 'get', [], $header);
if ($res && !empty($res['Message'])) {
throw new UploadException($res['Message']);
}
return $res;
}
/**
* 检测桶不存在返回true
* @param string $bucket
* @param string $region
* @return bool
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
public function headBucket(string $bucket, string $region = '')
{
$url = $this->getRequestHost($bucket, $region);
$header = [
'Host' => $url
];
$this->request('https://' . $url, 'head', [], $header);
$response = $this->getResponse();
return $response['code'] == 404;
}
/**
* 创建桶
* @param string $bucket
* @param string $region
* @param string $acl
* @return array|false|\SimpleXMLElement|string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
public function createBucket(string $bucket, string $region = '', string $acl = 'public-read')
{
return $this->noBodyRequest('put', $bucket, $region, $acl);
}
/**
* 组合成xml
* @param array $data
* @param string $root
* @param string $itemKey
* @return string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
protected function xmlBuild(array $xmlAttr, string $root = 'xml', string $itemKey = 'item')
{
$xml = '<' . $root . '>';
$xml .= '<' . $itemKey . '>';
foreach ($xmlAttr as $kk => $vv) {
if (is_array($vv)) {
foreach ($vv as $v) {
$xml .= '<' . $kk . '>' . $v . '</' . $kk . '>';
}
} else {
$xml .= '<' . $kk . '>' . $vv . '</' . $kk . '>';
}
}
$xml .= '</' . $itemKey . '>';
$xml .= '</' . $root . '>';
return $xml;
}
/**
* 设置跨域
* @param string $bucket
* @param string $region
* @param array $data
* @return string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
public function putBucketCors(string $bucket, array $data, string $region = '')
{
$url = $this->getRequestHost($bucket, $region);
$xml = $this->xmlBuild($data, 'CORSConfiguration', 'CORSRule');
$header = [
'Host' => $url,
'Content-Type' => 'application/xml',
'Content-Length' => strlen($xml),
'Content-MD5' => base64_encode(md5($xml, true))
];
$res = $this->request('https://' . $url . '/?cors', 'put', ['xml' => $xml], $header);
if ($res && !empty($res['Message'])) {
throw new UploadException($res['Message']);
}
return $res;
}
/**
* 删除
* @param string $name
* @param string $region
* @return array|false|\SimpleXMLElement|string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
public function deleteBucket(string $name, string $region = '')
{
return $this->noBodyRequest('delete', $name, $region);
}
/**
* 获取桶下的
* @param string $name
* @param string $region
* @return array|false|\SimpleXMLElement|string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
public function getBucketDomain(string $name, string $region = '')
{
$this->action = 'domain';
return $this->noBodyRequest('get', $name, $region);
}
/**
* 绑定域名
* @param string $bucket
* @param string $region
* @param array $data
* @return array|false|\SimpleXMLElement|string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/19
*/
public function putBucketDomain(string $bucket, string $region, array $data)
{
$url = $this->getRequestHost($bucket, $region);
$xml = $this->xmlBuild($data, 'DomainConfiguration', 'DomainRule');
$header = [
'Host' => $url,
'Content-Type' => 'application/xml',
'Content-Length' => strlen($xml),
'Content-MD5' => base64_encode(md5($xml, true))
];
$res = $this->request('https://' . $url . '/?domain', 'put', ['xml' => $xml], $header);
if ($res && !empty($res['Message'])) {
throw new UploadException($res['Message']);
}
return $res;
}
/**
* @param string $bucket
* @param string $region
* @return string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
protected function getRequestHost(string $bucket, string $region = '')
{
if (!$this->accessKey) {
throw new UploadException('请传入SecretId');
}
if (!$this->secretKey) {
throw new UploadException('请传入SecretKey');
}
if (strstr($bucket, '-') === false) {
$bucket = $bucket . '-' . $this->appid;
}
return $bucket . '.cos.' . ($region ?: $this->region) . '.myqcloud.com';
}
/**
* @param string $method
* @param string $bucket
* @param string $region
* @param string|null $acl
* @return array|false|\SimpleXMLElement|string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/10/17
*/
public function noBodyRequest(string $method, string $bucket, string $region = '', string $acl = null, bool $isExc = true)
{
$url = $this->getRequestHost($bucket, $region);
$header = [
'Host' => $url
];
if ($acl) {
$header['x-cos-acl'] = $acl;
}
if (in_array($method, ['put', 'post'])) {
$header['Content-Length'] = 0;
}
$res = $this->request('https://' . $url . '/' . ($this->action ? '?' . $this->action : ''), $method, [], $header);
$this->action = '';
if ($isExc) {
if ($res && !empty($res['Message'])) {
throw new UploadException($res['Message']);
}
}
return $res;
}
/**
* 发起请求
* @param string $url
* @param string $method
* @param array $data
* @param array $header
* @param int $timeout
* @return array|false|\SimpleXMLElement|string
* @author 等风来
* @email 136327134@qq.com
* @date 2022/9/29
*/
public function request(string $url, string $method, array $data, array $header = [], int $timeout = 5)
{
$this->request['body'] = $data;
$this->request['host'] = $url;
$urlAttr = parse_url($url);
$curl = curl_init($url);
$method = strtoupper($method);
//请求方式
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
//超时时间
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
//设置header头
$header = array_merge($header, $this->getSign($url, $method, $urlAttr['path'] ?? '', [], $header));
$this->request['header'] = $header;
$clientHeader = [];
foreach ($header as $key => $item) {
$clientHeader[] = $key . ':' . $item;
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $clientHeader);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
//返回抓取数据
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//输出header头信息
curl_setopt($curl, CURLOPT_HEADER, true);
//TRUE 时追踪句柄的请求字符串,从 PHP 5.1.3 开始可用。这个很关键就是允许你查看请求header
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
//https请求
if (1 == strpos("$" . $url, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
//post请求
if ($method == 'PUT' && !empty($data['body'])) {
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// 注意这里的'file'是上传地址指定的key名
curl_setopt($curl, CURLOPT_POSTFIELDS, $data['body']);
}
if (!empty($data['xml'])) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data['xml']);
}
[$content, $status] = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)];
$content = trim(substr($content, $status['header_size']));
$this->response['content'] = $content;
$this->response['code'] = $status['http_code'];
$this->response['header'] = $status;
$res = XML::parse($content);
if ($res) {
return $res;
}
return (intval($status["http_code"]) === 200) ? $content : false;
}
/**
* 获取签名
* @param string $method
* @param string $urlPath
* @param array $query
* @param array $headers
* @return array
* @author 等风来
* @email 136327134@qq.com
* @date 2022/9/27
*/
public function getSign(string $url, string $method, string $urlPath, array $query = [], array $headers = [])
{
return (new Signature($this->accessKey, $this->secretKey, ['signHost' => $url]))->signRequest($method, $urlPath, $query, $headers);
}
}