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
218 lines
8.5 KiB
PHP
218 lines
8.5 KiB
PHP
<?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;
|
||
|
||
|
||
use crmeb\exceptions\AdminException;
|
||
use think\exception\ValidateException;
|
||
use think\Image;
|
||
|
||
class DownloadImageService
|
||
{
|
||
//是否生成缩略图
|
||
protected $thumb = false;
|
||
//缩略图宽度
|
||
protected $thumbWidth = 300;
|
||
//缩略图高度
|
||
protected $thumHeight = 300;
|
||
//存储位置
|
||
protected $path = 'attach';
|
||
|
||
protected $rules = ['thumb', 'thumbWidth', 'thumHeight', 'path'];
|
||
|
||
/**
|
||
* 获取即将要下载的图片扩展名
|
||
* @param string $url
|
||
* @param string $ex
|
||
* @return array|string[]
|
||
*/
|
||
public function getImageExtname($url = '', $ex = 'jpg')
|
||
{
|
||
$_empty = ['file_name' => '', 'ext_name' => $ex];
|
||
if (!$url) return $_empty;
|
||
if (strpos($url, '?')) {
|
||
$_tarr = explode('?', $url);
|
||
$url = trim($_tarr[0]);
|
||
}
|
||
$arr = explode('.', $url);
|
||
if (!is_array($arr) || count($arr) <= 1) return $_empty;
|
||
$ext_name = trim($arr[count($arr) - 1]);
|
||
$ext_name = !$ext_name ? $ex : $ext_name;
|
||
return ['file_name' => md5($url) . '.' . $ext_name, 'ext_name' => $ext_name];
|
||
}
|
||
|
||
/**
|
||
* 下载图片
|
||
* @param string $url
|
||
* @param string $name
|
||
* @param int $upload_type
|
||
* @return mixed
|
||
*/
|
||
public function downloadImage(string $url, $name = '')
|
||
{
|
||
if (!$name) {
|
||
// 获取要下载的文件名称
|
||
$downloadImageInfo = $this->getImageExtname($url);
|
||
$ext = $downloadImageInfo['ext_name'];
|
||
$name = $downloadImageInfo['file_name'];
|
||
if (!$name) throw new ValidateException('上传图片不存在');
|
||
} else {
|
||
$ext = $this->getImageExtname($name)['ext_name'];
|
||
}
|
||
if (!in_array($ext, ['png', 'jpg', 'jpeg', 'gif'])) {
|
||
throw new ValidateException('格式错误,文件后缀不允许');
|
||
}
|
||
if (strstr($url, 'http://') === false && strstr($url, 'https://') === false) {
|
||
$url = 'http:' . $url;
|
||
}
|
||
$url = str_replace('https://', 'http://', $url);
|
||
if ($this->path == 'attach') {
|
||
$date_dir = date('Y') . DIRECTORY_SEPARATOR . date('m') . DIRECTORY_SEPARATOR . date('d');
|
||
$to_path = $this->path . '/' . $date_dir;
|
||
} else {
|
||
$to_path = $this->path;
|
||
}
|
||
$upload = UploadService::init(1);
|
||
if (!file_exists($upload->uploadDir($to_path) . '/' . $name)) {
|
||
ob_start();
|
||
readfile($url);
|
||
$content = ob_get_contents();
|
||
ob_end_clean();
|
||
$size = strlen(trim($content));
|
||
if (!$content || $size <= 2) throw new ValidateException('图片流获取失败');
|
||
if ($upload->to($to_path)->down($content, $name) === false) {
|
||
throw new ValidateException('图片下载失败');
|
||
}
|
||
$imageInfo = $upload->getDownloadInfo();
|
||
$path = $imageInfo['dir'];
|
||
if ($this->thumb) {
|
||
Image::open(root_path() . 'public' . $path)->thumb($this->thumbWidth, $this->thumHeight)->save(root_path() . 'public' . $path);
|
||
$this->thumb = false;
|
||
}
|
||
} else {
|
||
$path = '/uploads/' . $to_path . '/' . $name;
|
||
$imageInfo['name'] = $name;
|
||
}
|
||
$date['path'] = $path;
|
||
$date['name'] = $imageInfo['name'];
|
||
$date['size'] = $imageInfo['size'] ?? '';
|
||
$date['mime'] = $imageInfo['type'] ?? '';
|
||
$date['image_type'] = 1;
|
||
$date['is_exists'] = false;
|
||
return $date;
|
||
}
|
||
|
||
/**
|
||
* 网络图片下载
|
||
* @param $url
|
||
* @param $name
|
||
* @param $type
|
||
* @param $timeout
|
||
* @param $w
|
||
* @param $h
|
||
* @return array|string
|
||
*/
|
||
public function downloadOnlineImage($url = '', $name = '', $type = 0, $timeout = 30, $w = 0, $h = 0)
|
||
{
|
||
if (!strlen(trim($url))) return '';
|
||
if (!strlen(trim($name))) {
|
||
//TODO 获取要下载的文件名称
|
||
$downloadImageInfo = $this->getImageExtname($url);
|
||
$ext = $downloadImageInfo['ext_name'];
|
||
$name = $downloadImageInfo['file_name'];
|
||
if (!strlen(trim($name))) throw new ValidateException('上传图片不存在');
|
||
} else {
|
||
$ext = $this->getImageExtname($name)['ext_name'];
|
||
}
|
||
if (!in_array($ext, ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bpm', 'tif', 'pcx', 'tga', 'exif', 'fpx', 'svg', 'apng'])) {
|
||
$headerArray = get_headers(str_replace('\\', '/', $url), true);
|
||
if (is_array($headerArray['Content-Type']) && count($headerArray['Content-Type']) == 2) {
|
||
$contentType = $headerArray['Content-Type'][1];
|
||
} else {
|
||
$contentType = $headerArray['Content-Type'];
|
||
}
|
||
if(!$contentType) throw new ValidateException('格式错误,文件后缀不允许');
|
||
$img = explode('/',$contentType);
|
||
if($img[0]!= 'image') throw new ValidateException('格式错误,文件后缀不允许');
|
||
}
|
||
if (strstr($url, 'http://') === false && strstr($url, 'https://') === false) {
|
||
$url = 'http:' . $url;
|
||
}
|
||
$url = str_replace('https://', 'http://', $url);
|
||
if ($this->path == 'attach') {
|
||
$date_dir = date('Y') . DIRECTORY_SEPARATOR . date('m') . DIRECTORY_SEPARATOR . date('d');
|
||
$to_path = $this->path . '/' . $date_dir;
|
||
} else {
|
||
$to_path = $this->path;
|
||
}
|
||
//TODO 获取远程文件所采用的方法
|
||
if ($type) {
|
||
$ch = curl_init();
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
|
||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //TODO 跳过证书检查
|
||
if (stripos($url, "https://") !== FALSE) curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //TODO 从证书中检查SSL加密算法是否存在
|
||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('user-agent:' . $_SERVER['HTTP_USER_AGENT']));
|
||
if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);//TODO 是否采集301、302之后的页面
|
||
$content = curl_exec($ch);
|
||
curl_close($ch);
|
||
} else {
|
||
try {
|
||
ob_start();
|
||
if (substr($url, 0, 2) == '//') {
|
||
$url = "https:" . $url;
|
||
}
|
||
readfile($url);
|
||
$content = ob_get_contents();
|
||
ob_end_clean();
|
||
} catch (\Exception $e) {
|
||
throw new ValidateException($e->getMessage());
|
||
}
|
||
}
|
||
$size = strlen(trim($content));
|
||
if (!$content || $size <= 2) throw new ValidateException('图片流获取失败');
|
||
$upload_type = sys_config('upload_type', 1);
|
||
$upload = UploadService::init($upload_type);
|
||
if ($upload->to($to_path)->validate()->setAuthThumb(false)->stream($content, $name) === false) {
|
||
throw new ValidateException($upload->getError());
|
||
}
|
||
$imageInfo = $upload->getUploadInfo();
|
||
$date['path'] = $imageInfo['dir'];
|
||
$date['name'] = $imageInfo['name'];
|
||
$date['size'] = $imageInfo['size'];
|
||
$date['mime'] = $imageInfo['type'];
|
||
$date['image_type'] = $upload_type;
|
||
$date['is_exists'] = false;
|
||
return $date;
|
||
}
|
||
|
||
/**
|
||
* @param $name
|
||
* @param $arguments
|
||
* @return $this
|
||
*/
|
||
public function __call($name, $arguments)
|
||
{
|
||
if (in_array($name, $this->rules)) {
|
||
if ($name === 'path') {
|
||
$this->{$name} = $arguments[0] ?? 'attach';
|
||
} else {
|
||
$this->{$name} = $arguments[0] ?? null;
|
||
}
|
||
return $this;
|
||
} else {
|
||
throw new \RuntimeException('Method does not exist' . __CLASS__ . '->' . $name . '()');
|
||
}
|
||
}
|
||
}
|