Files
huangjingfen/pro_v3.5.1_副本/app/controller/admin/v1/user/UserLabel.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

311 lines
10 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 app\controller\admin\v1\user;
use app\controller\admin\AuthController;
use app\services\user\label\UserLabelCateServices;
use app\services\user\label\UserLabelRelationServices;
use app\services\user\label\UserLabelServices;
use crmeb\services\wechat\config\WorkConfig;
use crmeb\services\wechat\Work;
use think\annotation\Inject;
/**
* 用户标签控制器
* Class UserLabel
* @package app\controller\admin\v1\user
*/
class UserLabel extends AuthController
{
/**
* @var UserLabelServices
*/
#[Inject]
protected UserLabelServices $services;
/**
* 标签列表
* @return mixed
*/
public function index()
{
$where = $this->request->getMore([
['label_cate', ''],
['label_name', ''],
['label_type', ''],
['status', ''],
]);
$where['type'] = 0;
return $this->success($this->services->getList($where));
}
/**
* 获取带分类的用户标签列表
* @param UserLabelCateServices $userLabelCateServices
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function tree_list(UserLabelCateServices $userLabelCateServices)
{
[$label_type] = $this->request->getMore([
['label_type', ''],
], true);
$cate = $userLabelCateServices->getLabelCateAll();
$data = [];
$label = [];
if ($cate) {
foreach ($cate as $value) {
$data[] = [
'id' => $value['id'] ?? 0,
'value' => $value['id'] ?? 0,
'label_cate' => 0,
'label_name' => $value['name'] ?? '',
'label' => $value['name'] ?? '',
'store_id' => $value['store_id'] ?? 0,
'type' => $value['type'] ?? 1,
];
}
$label = $this->services->getList(['type' => 0, 'label_type' => $label_type]);
$label = $label['list'] ?? [];
if ($label) {
foreach ($label as &$item) {
$item['label'] = $item['label_name'];
$item['value'] = $item['id'];
}
}
}
return $this->success($this->services->get_tree_children($data, $label));
}
/**
* 添加修改标签表单
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function add()
{
[$id, $label_cate] = $this->request->getMore([
['id', 0],
['label_cate', 0]
], true);
return $this->success($this->services->add((int)$id, 0, 0, $label_cate));
}
/**
* 保存标签表单数据
* @param int $id
* @return mixed
*/
public function save()
{
$data = $this->request->postMore([
['id', 0],
['label_cate', 0],
['label_name', ''],//标签名称数组
['label_type', 1],//标签类型,1:手动;2 自动
['is_product', 0],//商品条件,1 开启 0 关闭
['is_property', 0],//资产条件,1 开启 0 关闭
['is_trade', 0],//交易条件,1 开启0 关闭
['is_customer', 0],//客户条件,1 开启 0 关闭
['is_condition', 1],//条件类型,1 条件满足任一,2全部条件满足
['product', []],//商品条件
['property', []],//资产条件
['trade', []],//交易条件
['customer', []],//客户条件
['status', 1],//状态
]);
// if (!$data['label_name'] = trim($data['label_name'])) return $this->fail('会员标签不能为空!');
$label_name = is_array($data['label_name']) ? $data['label_name'] : [$data['label_name']];
foreach ($label_name as $value) {
if ($this->services->fieldExists('label_name', $value, (int)$data['id'])) {
return $this->fail("会员标签{$value}已存在!");
}
}
$this->services->saveData((int)$data['id'], $data);
return $this->success('保存成功');
}
/**
* 删除
* @param $id
* @throws \Exception
*/
public function delete()
{
[$id] = $this->request->getMore([
['id', 0],
], true);
if (!$id) return $this->fail('数据不存在');
$this->services->delLabel((int)$id);
return $this->success('刪除成功!');
}
/**
* 标签分类
* @param UserLabelCateServices $services
* @return mixed
*/
public function getUserLabel(UserLabelCateServices $services, $uid)
{
[$uids, $all, $where] = $this->request->postMore([
['uids', []],
['all', 0],
['where', ""],
], true);
if (count($uids) == 1) {
$uid = $uids[0] ?? 0;
}
return $this->success($services->getUserLabel((int)$uid));
}
/**
* 设置用户标签
* @param UserLabelRelationServices $services
* @param $uid
* @return mixed
*/
public function setUserLabel(UserLabelRelationServices $services, $uid)
{
[$labels, $unLabelIds] = $this->request->postMore([
['label_ids', []],
['un_label_ids', []]
], true);
if (!count($labels) && !count($unLabelIds)) {
return $this->fail('请先添加用户标签');
}
if ($services->setUserLable($uid, $labels) && $services->unUserLabel($uid, $unLabelIds)) {
return $this->success('设置成功');
} else {
return $this->fail('设置失败');
}
}
/**
* 同步客户标签
* @param WorkConfig $config
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function synchroWorkLabel(WorkConfig $config, Work $work)
{
if (!$config->corpId) {
return $this->fail('请先配置企业微信ID');
}
$config = $work->getAppConfig(WorkConfig::TYPE_USER);
// if (empty($config['secret'])) {
// return $this->fail('请先配置企业微信客户secret');
// }
if ($this->services->authWorkClientLabel()) {
return $this->success('已加入消息队列,进行同步。请稍等片刻');
} else {
return $this->fail('加入消息队列失败');
}
}
/**
* 获取标签详情信息
* @param int $id 标签ID
* @return mixed
*/
public function info($id)
{
if (!$id) {
return $this->fail('数据不存在');
}
$info = $this->services->getInfo($id);
return $this->success($info);
}
/**
* 批量处理用户标签检查
* @return mixed
*/
public function batchProcess()
{
[$labelIds, $action] = $this->request->postMore([
['label_ids', []],
['action', 'update']
], true);
if (empty($labelIds)) {
return $this->fail('请选择要处理的标签');
}
try {
/** @var \app\services\user\label\UserLabelBatchProcessServices $batchProcessServices */
$batchProcessServices = app()->make(\app\services\user\label\UserLabelBatchProcessServices::class);
$result = $batchProcessServices->processLabelChange($labelIds, $action);
if ($result) {
return $this->success('批量处理任务已启动,正在后台处理中,请稍后查看处理结果');
} else {
return $this->fail('批量处理任务启动失败');
}
} catch (\Throwable $e) {
return $this->fail('批量处理失败:' . $e->getMessage());
}
}
/**
* 获取批量处理状态
* @return mixed
*/
public function batchStatus()
{
try {
/** @var \app\services\user\label\UserLabelBatchProcessServices $batchProcessServices */
$batchProcessServices = app()->make(\app\services\user\label\UserLabelBatchProcessServices::class);
$status = $batchProcessServices->getBatchProcessStatus();
return $this->success($status);
} catch (\Throwable $e) {
return $this->fail('获取处理状态失败:' . $e->getMessage());
}
}
/**
* 触发所有自动标签的用户检查
* @return mixed
*/
public function processAllAutoLabels()
{
try {
// 获取所有自动标签
$autoLabels = $this->services->getLabelList([
'label_type' => 2, // 自动标签
'status' => 1 // 启用状态
]);
if (empty($autoLabels)) {
return $this->fail('没有找到启用的自动标签');
}
$labelIds = array_column($autoLabels, 'id');
/** @var \app\services\user\label\UserLabelBatchProcessServices $batchProcessServices */
$batchProcessServices = app()->make(\app\services\user\label\UserLabelBatchProcessServices::class);
$result = $batchProcessServices->processLabelChange($labelIds, 'check_all');
if ($result) {
return $this->success('所有自动标签检查任务已启动,共处理 ' . count($labelIds) . ' 个标签,正在后台处理中');
} else {
return $this->fail('批量处理任务启动失败');
}
} catch (\Throwable $e) {
return $this->fail('处理失败:' . $e->getMessage());
}
}
}