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
207 lines
7.2 KiB
PHP
207 lines
7.2 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 app\services\work;
|
||
|
||
|
||
use app\dao\work\WorkMediaDao;
|
||
use app\services\BaseServices;
|
||
use crmeb\basic\BaseModel;
|
||
use crmeb\services\FileService;
|
||
use crmeb\services\wechat\Work;
|
||
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
|
||
use GuzzleHttp\Exception\GuzzleException;
|
||
use think\annotation\Inject;
|
||
use think\db\exception\DataNotFoundException;
|
||
use think\db\exception\DbException;
|
||
use think\db\exception\ModelNotFoundException;
|
||
use think\exception\ValidateException;
|
||
use think\Model;
|
||
|
||
/**
|
||
* 企业微信素材
|
||
* Class WorkMediaServices
|
||
* @package app\services\work
|
||
* @mixin WorkMediaDao
|
||
*/
|
||
class WorkMediaServices extends BaseServices
|
||
{
|
||
|
||
/**
|
||
* @var WorkMediaDao
|
||
*/
|
||
#[Inject]
|
||
protected WorkMediaDao $dao;
|
||
|
||
/**
|
||
* 获取附件资源
|
||
* @param string $url
|
||
* @param string $type
|
||
* @param int $uploadType
|
||
* @return array|bool
|
||
* @throws DataNotFoundException
|
||
* @throws DbException
|
||
* @throws GuzzleException
|
||
* @throws InvalidConfigException
|
||
* @throws ModelNotFoundException
|
||
*/
|
||
public function getPathMediaInfo(string $url, string $type, int $uploadType = 0)
|
||
{
|
||
$pathInfo = parse_url($url);
|
||
$path = $pathInfo['path'];
|
||
$mediaInfo = [];
|
||
$md5Path = md5($path);
|
||
$info = $this->dao->get(['md5_path' => $md5Path, 'type' => $type, 'upload_type' => $uploadType], ['media_id', 'url', 'temporary']);
|
||
if ($info) {
|
||
if ($info->temporary && $info->media_id) {
|
||
$mediaInfo = $info->toArray();
|
||
}
|
||
if (((int)$info->temporary) === 0) {
|
||
$mediaInfo = $info->toArray();
|
||
}
|
||
}
|
||
|
||
if (!$mediaInfo) {
|
||
if (str_starts_with($path, '/')) {
|
||
$path = substr($path, 1);
|
||
}
|
||
$pathUrl = public_path() . $path;
|
||
if (is_file($pathUrl)) {
|
||
$uploadInfo = $this->mediaUpload($uploadType, $pathUrl, $type, $md5Path, $info);
|
||
$mediaInfo['media_id'] = $uploadInfo['media_id'];
|
||
} else {
|
||
//获取文件内容
|
||
$stream = file_get_contents($url);
|
||
|
||
//创建文件路径
|
||
$dir = public_path() . 'uploads' . DS . 'temp';
|
||
try {
|
||
FileService::mkDir($dir);
|
||
} catch (\Throwable $e) {
|
||
throw new ValidateException($e->getMessage());
|
||
}
|
||
|
||
//把文件流保存到本地
|
||
$pathUrl = $dir . DS . basename($url);
|
||
file_put_contents($pathUrl, $stream);
|
||
|
||
//上传到素材附件
|
||
$uploadInfo = $this->mediaUpload($uploadType, $pathUrl, $type, $md5Path, $info);
|
||
unlink($pathUrl);
|
||
|
||
$mediaInfo['media_id'] = $uploadInfo['media_id'];
|
||
|
||
}
|
||
}
|
||
return $mediaInfo;
|
||
}
|
||
|
||
/**
|
||
* 上传临时素材
|
||
* @param int $uploadType
|
||
* @param string $pathUrl
|
||
* @param string $type
|
||
* @param string $md5Path
|
||
* @param $info
|
||
* @return BaseModel|Model
|
||
* @throws GuzzleException
|
||
* @throws InvalidConfigException
|
||
*/
|
||
public function mediaUpload(int $uploadType, string $pathUrl, string $type, string $md5Path, $info)
|
||
{
|
||
if ($uploadType) {
|
||
$resMedia = Work::mediaUploadAttachment($pathUrl, $type);
|
||
} else {
|
||
$resMedia = Work::mediaUpload($pathUrl, $type);
|
||
}
|
||
if ($info) {
|
||
$info->media_id = $resMedia['media_id'];
|
||
$info->valid_time = (int)$resMedia['created_at'] + 60 * 60 * 24 * 3 - 60;//3天有效期
|
||
$info->save();
|
||
return $info;
|
||
} else {
|
||
return $this->dao->save([
|
||
'path' => $pathUrl,
|
||
'md5_path' => $md5Path,
|
||
'type' => $type,
|
||
'upload_type' => $uploadType,
|
||
'media_id' => $resMedia['media_id'],
|
||
'valid_time' => (int)$resMedia['created_at'] + 60 * 60 * 24 * 3 - 60,//3天有效期
|
||
'create_time' => time(),
|
||
'temporary' => 1
|
||
]);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取欢迎语
|
||
* @param array $welcome
|
||
* @return array
|
||
* @throws DataNotFoundException
|
||
* @throws DbException
|
||
* @throws GuzzleException
|
||
* @throws InvalidConfigException
|
||
* @throws ModelNotFoundException
|
||
*/
|
||
public function resolvingWelcome(array $welcome, int $uploadType = 0)
|
||
{
|
||
//清除过期的附件
|
||
$this->dao->deleteValidFile();
|
||
$attachments = [];
|
||
foreach ($welcome['attachments'] as $item) {
|
||
switch ($item['msgtype']) {
|
||
case 'image':
|
||
$mediaInfo = $this->getPathMediaInfo($item['image']['pic_url'], 'image', $uploadType);
|
||
if (!empty($mediaInfo['media_id'])) {
|
||
$item['image']['media_id'] = $mediaInfo['media_id'];
|
||
unset($item['image']['pic_url']);
|
||
$attachments[] = $item;
|
||
}
|
||
break;
|
||
case 'link':
|
||
|
||
break;
|
||
case 'miniprogram':
|
||
$mediaInfo = $this->getPathMediaInfo($item['miniprogram']['pic_url'], 'image', $uploadType);
|
||
if (!empty($mediaInfo['media_id'])) {
|
||
$item['miniprogram']['pic_media_id'] = $mediaInfo['media_id'];
|
||
unset($item['miniprogram']['pic_url']);
|
||
$attachments[] = $item;
|
||
}
|
||
break;
|
||
case 'video':
|
||
$mediaInfo = $this->getPathMediaInfo($item['video']['url'], 'video', $uploadType);
|
||
if (!empty($mediaInfo['media_id'])) {
|
||
$item['video']['media_id'] = $mediaInfo['media_id'];
|
||
unset($item['video']['url']);
|
||
$attachments[] = $item;
|
||
}
|
||
break;
|
||
case 'file':
|
||
$mediaInfo = $this->getPathMediaInfo($item['file']['url'], 'file', $uploadType);
|
||
if (!empty($mediaInfo['media_id'])) {
|
||
$item['file']['media_id'] = $mediaInfo['media_id'];
|
||
unset($item['file']['url']);
|
||
$attachments[] = $item;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
return [
|
||
'text' => [
|
||
'content' => $welcome['text']['content'],
|
||
],
|
||
'attachments' => $attachments
|
||
];
|
||
}
|
||
}
|