Files
huangjingfen/pro_v3.5.1_副本/crmeb/utils/Canvas.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

324 lines
9.8 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\utils;
/**
* Class Canvas
* @package crmeb\utils
* @method $this setFileName(string $fileName) 设置文件名
* @method $this setPath(string $path) 设置存放路径
* @method $this setImageType(string $imageType) 设置图片类型
* @method $this setBackgroundHeight(int $backgroundHeight) 设置背景高
* @method $this setBackgroundWidth(int $backgroundWidth) 设置背景宽
* @method $this setFontSize(int $fontSize) 设置字体大小
* @method $this setFontColor($fontColor) 设置字体颜色
* @method $this setFontLeft(int $fontLeft) 设置字体距离左侧位置
* @method $this setFontTop(int $fontTop) 设置字体距离顶部位置
* @method $this setFontText(string $fontText) 设置文字
* @method $this setFontPath(string $fontPath) 设置字体文件路径
* @method $this setFontAngle(int $fontAngle) 设置字体角度
* @method $this setImageUrl(string $imageUrl) 设置图片路径
* @method $this setImageLeft(int $imageLeft) 设置图片距离左侧位置
* @method $this setImageTop(int $imageTop) 设置图片距离顶部位置
* @method $this setImageRight(int $imageRight) 设置图片距离左侧位置
* @method $this setImageStream(bool $imageStream) 设置图片是否未流文件
* @method $this setImageBottom(int $imageBottom) 设置图片距离底部位置
* @method $this setImageWidth(int $imageWidth) 设置图片宽
* @method $this setImageHeight(int $imageHeight) 设置图片高
* @method $this setImageOpacity(int $imageOpacity) 设置图片透明度
*/
class Canvas
{
const FONT = 'statics/font/Alibaba-PuHuiTi-Regular.otf';
/**
* 背景宽
* @var int
*/
protected $backgroundWidth = 600;
/**
* 背景高
* @var int
*/
protected $backgroundHeight = 1000;
/**
* 图片类型
* @var string
*/
protected $imageType = 'jpeg';
/**
* 保存地址
* @var string
*/
protected $path = 'uploads/routine/';
/**
* 文件名
* @var string
*/
protected $fileName;
/**
* 规则
* @var array
*/
protected $propsRule = ['fileName', 'path', 'imageType', 'backgroundHeight', 'backgroundWidth'];
/**
* 字体数据集
* @var array
*/
protected $fontValue = [];
/**
* 字体默认可设置vlaue
* @var array
*/
protected $defaultFontValue = [
'fontSize' => 0,
'fontColor' => '231,180,52',
'fontLeft' => 0,
'fontTop' => 0,
'fontText' => '',
'fontPath' => self::FONT,
'fontAngle' => 0,
];
protected $defaultFont;
/**
* 图片数据集
* @var array
*/
protected $imageValue = [];
/**
* 图片可设置属性
* @var array
*/
protected $defaultImageValue = [
'imageUrl' => '',
'imageLeft' => 0,
'imageTop' => 0,
'imageRight' => 0,
'imageBottom' => 0,
'imageWidth' => 0,
'imageHeight' => 0,
'imageOpacity' => 0,
'imageStream' => false,
];
/**
* 实例化本身
* @var self
*/
protected static $instance;
protected $defaultImage;
protected function __construct()
{
$this->defaultImage = $this->defaultImageValue;
$this->defaultFont = $this->defaultFontValue;
}
/**
* 实例化本类
* @return Canvas
*/
public static function instance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* 创建一个新图象
* @param string $file
* @return array
*/
public function createFrom(string $file): array
{
$file = str_replace('https', 'http', $file);
$imagesize = getimagesize($file);
$type = image_type_to_extension($imagesize[2], true);
switch ($type) {
case '.png':
$canvas = imagecreatefrompng($file);
break;
case '.jpg':
case '.jpeg':
$canvas = imagecreatefromjpeg($file);
break;
case '.gif':
$canvas = imagecreatefromgif($file);
break;
}
return [$canvas, $imagesize];
}
/**
* 放入字体
* @return $this
*/
public function pushFontValue()
{
array_push($this->fontValue, $this->defaultFontValue);
$this->defaultFontValue = $this->defaultFont;
return $this;
}
/**
* 放入图片
* @return $this
*/
public function pushImageValue()
{
array_push($this->imageValue, $this->defaultImageValue);
$this->defaultImageValue = $this->defaultImage;
return $this;
}
/**
* 创建背景
* @param int $w
* @param int $h
* @return false|resource
*/
public function createTrueColor(int $w = 0, int $h = 0)
{
return imagecreatetruecolor($w ? $w : $this->backgroundWidth, $h ? $h : $this->backgroundHeight);
}
/**
* 开始画图
* @param bool $force 生成错误时是否抛出异常
* @return string
* @throws \Exception
*/
public function starDrawChart(bool $force = false): string
{
try {
$image = $this->createTrueColor();
foreach ($this->imageValue as $item) {
if ($item['imageUrl']) {
if ($item['imageStream']) {
$res = getimagesizefromstring($item['imageUrl']);
$mer = imagecreatefromstring($item['imageUrl']);
} else {
[$mer, $res] = $this->createFrom($item['imageUrl']);
}
if ($mer && $res) {
$scrW = $res[0] ?? 0;
$scrH = $res[1] ?? 0;
$imageWidth = $item['imageWidth'] ?: $scrW;
$imageHeight = $item['imageHeight'] ?: $scrH;
imagecopyresampled($image, $mer, $item['imageLeft'], $item['imageTop'], $item['imageRight'], $item['imageBottom'], $imageWidth, $imageHeight, $scrW, $scrH);
unset($scrW, $scrH, $imageWidth, $imageHeight, $res, $mer);
}
}
}
foreach ($this->fontValue as $val) {
if (!is_array($val['fontColor']))
$fontColor = explode(',', $val['fontColor']);
else
$fontColor = $val['fontColor'];
if (count($fontColor) < 3)
throw new \RuntimeException('fontColor Separation of thousand bits');
[$r, $g, $b] = $fontColor;
$fontColor = imagecolorallocate($image, $r, $g, $b);
$val['fontLeft'] = $val['fontLeft'] < 0 ? $this->backgroundWidth - abs($val['fontLeft']) : $val['fontLeft'];
$val['fontTop'] = $val['fontTop'] < 0 ? $this->backgroundHeight - abs($val['fontTop']) : $val['fontTop'];
imagettftext($image, $val['fontSize'], $val['fontAngle'], $val['fontLeft'], $val['fontTop'], $fontColor, $val['fontPath'], $val['fontText']);
unset($r, $g, $b, $fontColor);
}
if (is_null($this->fileName)) {
$this->fileName = md5(time());
}
$strlen = stripos($this->path, 'uploads');
$path = $this->path;
if ($strlen !== false) {
$path = substr($this->path, 8);
}
make_path($path, 4, true);
$save_file = $this->path . $this->fileName . '.' . $this->imageType;
switch ($this->imageType) {
case 'jpeg':
case 'jpg':
imagejpeg($image, public_path() . $save_file, 70);
break;
case 'png':
imagepng($image, public_path() . $save_file, 70);
break;
case 'gif':
imagegif($image, public_path() . $save_file, 70);
break;
default:
throw new \RuntimeException('Incorrect type set:' . $this->imageType);
}
imagedestroy($image);
return $save_file;
} catch (\Throwable $e) {
if ($force || $e instanceof \RuntimeException)
throw new \Exception($e->getMessage());
return '';
}
}
/**
* Magic access..
*
* @param $method
* @param $args
* @return $this
*/
public function __call($method, $args): self
{
if (0 === stripos($method, 'set') && strlen($method) > 3) {
$method = lcfirst(substr($method, 3));
}
$imageValueKes = array_keys($this->defaultImageValue);
$fontValueKes = array_keys($this->defaultFontValue);
if (in_array($method, $imageValueKes)) {
$this->defaultImageValue[$method] = array_shift($args);
}
if (in_array($method, $fontValueKes)) {
$this->defaultFontValue[$method] = array_shift($args);
}
if (in_array($method, $this->propsRule)) {
$this->{$method} = array_shift($args);
}
return $this;
}
}