Files
huangjingfen/pro_v3.5.1_副本/app/services/activity/activityFrame/ActivityFrameServices.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

285 lines
12 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>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\services\activity\activityFrame;
use app\dao\activity\promotions\StorePromotionsDao;
use app\services\activity\promotions\StorePromotionsAuxiliaryServices;
use app\services\BaseServices;
use app\services\product\brand\StoreBrandServices;
use app\services\product\category\StoreProductCategoryServices;
use app\services\product\label\StoreProductLabelServices;
use app\services\product\product\StoreProductRelationServices;
use app\services\product\product\StoreProductServices;
use crmeb\exceptions\AdminException;
use think\annotation\Inject;
use think\exception\ValidateException;
use \crmeb\traits\OptionTrait;
/**
* 活动边框
* Class ActivityFrameServices
* @package app\services\activity\activityFrame
* @mixin StorePromotionsDao
*/
class ActivityFrameServices extends BaseServices
{
use OptionTrait;
/**
* 活动类型
* @var string[]
*/
protected array $promotionsType = [
1 => '限时折扣',
2 => '第N件N折',
3 => '满减满折',
4 => '满送',
5 => '活动边框',
6 => '活动背景',
];
/**
* 参与活动商品类型
* @var string[]
*/
protected array $productPartakeType = [
1 => '全部商品',
2 => '指定商品参与',
3 => '指定商品不参与',
4 => '指定品牌参与',
5 => '指定商品标签参与',
];
/**
* @var StorePromotionsDao
*/
#[Inject]
protected StorePromotionsDao $dao;
/**
* 后台获取活动边框列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function systemPage(array $where)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getList($where, '*', $page, $limit);
$count = 0;
if ($list) {
/** @var StoreProductServices $storeProductServices */
$storeProductServices = app()->make(StoreProductServices::class);
/** @var StoreProductRelationServices $storeProductRelationServices */
$storeProductRelationServices = app()->make(StoreProductRelationServices::class);
/** @var StorePromotionsAuxiliaryServices $promotionsAuxiliaryServices */
$promotionsAuxiliaryServices = app()->make(StorePromotionsAuxiliaryServices::class);
foreach ($list as &$item) {
if ($item['status']) {
if ($item['start_time'] > time()) {
$item['start_status'] = 0;
$item['start_name'] = '未开始';
} else if ($item['stop_time'] < time()) {
$item['start_name'] = '已结束';
$item['start_status'] = -1;
} else if ($item['stop_time'] > time() && $item['start_time'] < time()) {
$item['start_name'] = '进行中';
$item['start_status'] = 1;
}
} else {
$item['start_status'] = -1;
$item['start_name'] = '已结束';
}
$item['start_time'] = $item['start_time'] ? date('Y-m-d H:i:s', $item['start_time']) : '';
$item['stop_time'] = $item['stop_time'] ? date('Y-m-d H:i:s', $item['stop_time']) : '';
$promotionsAuxiliaryData = $promotionsAuxiliaryServices->getPromotionsAuxiliaryCache($item['id']);
switch ($item['product_partake_type']) {
case 1://所有商品
$item['product_count'] = $storeProductServices->count(['is_show' => 1, 'is_del' => 0, 'is_verify' => 1]);
break;
case 2://选中商品参与
$product_ids = $promotionsAuxiliaryData;
$item['product_count'] = $product_ids ? $storeProductServices->count(['is_show' => 1, 'is_del' => 0, 'id' => $product_ids, 'is_verify' => 1]) : 0;
break;
case 3:
$item['product_count'] = 0;
break;
case 4://品牌
$product_ids = $promotionsAuxiliaryData ? $storeProductRelationServices->getIdsByWhere(['type' => 2, 'relation_id' => $promotionsAuxiliaryData]) : [];
$item['product_count'] = $product_ids ? $storeProductServices->count(['is_show' => 1, 'is_del' => 0, 'id' => $product_ids, 'is_verify' => 1]) : 0;
break;
case 5://商品标签
$product_ids = $promotionsAuxiliaryData ? $storeProductRelationServices->getIdsByWhere(['type' => 3, 'relation_id' => $promotionsAuxiliaryData]) : [];
$item['product_count'] = $product_ids ? $storeProductServices->count(['is_show' => 1, 'is_del' => 0, 'id' => $product_ids, 'is_verify' => 1]) : 0;
break;
}
}
$count = $this->dao->count($where);
}
return compact('list', 'count');
}
/**
* 获取活动边框想你去那个
* @param int $id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(int $id)
{
$info = $this->dao->get($id, ['*'], ['products' => function ($query) {
$query->field('promotions_id,product_id,unique')->with(['productInfo']);
}, 'brands' => function ($query) {
$query->field('promotions_id,brand_id')->with(['brandInfo' => function ($q) {
$q->field('id,brand_name');
}]);
}, 'productLabels' => function ($query) {
$query->field('promotions_id,store_label_id')->with(['productLabelInfo' => function ($q) {
$q->field('id,label_name');
}]);
}]);
if (!$info) {
throw new AdminException('数据不存在');
}
$info = $info->toArray();
$info['start_time'] = $info['start_time'] ? date('Y-m-d H:i:s', $info['start_time']) : '';
$info['stop_time'] = $info['stop_time'] ? date('Y-m-d H:i:s', $info['stop_time']) : '';
$products = [];
if (isset($info['products']) && $info['products']) {
foreach ($info['products'] as $item) {
$product = is_object($item) ? $item->toArray() : $item;
$product = array_merge($product, $product['productInfo'] ?? []);
unset($product['productInfo']);
$products[] = $product;
}
if ($products) {
$cateIds = implode(',', array_column($products, 'cate_id'));
/** @var StoreProductCategoryServices $categoryService */
$categoryService = app()->make(StoreProductCategoryServices::class);
$cateList = $categoryService->getCateParentAndChildName($cateIds);
foreach ($products as $key => &$item) {
$item['cate_name'] = '';
if (isset($item['cate_id']) && $item['cate_id']) {
$cate_ids = explode(',', $item['cate_id']);
$cate_name = $categoryService->getCateName($cate_ids, $cateList);
if ($cate_name) {
$item['cate_name'] = is_array($cate_name) ? implode(',', $cate_name) : '';
}
}
}
}
}
$info['products'] = $products;
$info['brand_id'] = isset($info['brands']) && $info['brands'] ? array_column($info['brands'], 'brand_id') : [];
$info['store_label_id'] = [];
if (isset($info['productLabels']) && $info['productLabels']) {
foreach ($info['productLabels'] as $label) {
if (isset($label['productLabelInfo']) && $label['productLabelInfo']) {
$info['store_label_id'][] = $label['productLabelInfo'];
}
}
}
unset($info['brands'], $info['productLabels']);
return $info;
}
/**
* 保存活动边框
* @param int $id
* @param array $data
* @return bool
*/
public function saveData(int $id, array $data)
{
if (!$data['section_time'] || count($data['section_time']) != 2) {
throw new AdminException('请选择活动时间');
}
[$start_time, $end_time] = $data['section_time'];
if (strtotime($end_time) < time()) {
throw new AdminException('活动结束时间不能小于当前时间');
}
if ($id) {
$info = $this->dao->get((int)$id);
if (!$info) {
throw new AdminException('数据不存在');
}
}
$data['start_time'] = strtotime($start_time);
$data['stop_time'] = strtotime($end_time);
$promotionsAuxiliaryData = [];
switch ($data['product_partake_type']) {
case 1://全部
$data['product_id'] = [];
break;
case 2://指定ID参与
case 3://指定ID不参与
/** @var StoreProductServices $storeProductServices */
$storeProductServices = app()->make(StoreProductServices::class);
$count = $storeProductServices->count(['is_show' => 1, 'is_del' => 0, 'id' => $data['product_id']]);
$productCount = count(array_unique($data['product_id']));
if ($count != $productCount) {
throw new AdminException('选择商品中有已下架或移入回收站');
}
$promotionsAuxiliaryData['product_id'] = $data['product_id'];
break;
case 4://指定品牌
$data['brand_id'] = array_unique($data['brand_id']);
/** @var StoreBrandServices $storeBrandServices */
$storeBrandServices = app()->make(StoreBrandServices::class);
$brandCount = $storeBrandServices->count(['is_show' => 1, 'is_del' => 0, 'id' => $data['brand_id']]);
if (count(array_unique($data['brand_id'])) != $brandCount) {
throw new AdminException('选择商品品牌中有已下架或删除的');
}
$promotionsAuxiliaryData['brand_id'] = $data['brand_id'];
break;
case 5://指定商品标签
$data['store_label_id'] = array_unique($data['store_label_id']);
/** @var StoreProductLabelServices $storeProductLabelServices */
$storeProductLabelServices = app()->make(StoreProductLabelServices::class);
$labelCount = $storeProductLabelServices->count(['id' => $data['store_label_id']]);
if (count(array_unique($data['store_label_id'])) != $labelCount) {
throw new ValidateException('选择商品标签中有已下架或删除的');
}
$promotionsAuxiliaryData['store_label_id'] = $data['store_label_id'];
break;
default:
throw new ValidateException('暂不支持该类型商品');
break;
}
unset($data['section_time'], $data['promotions']);
$this->transaction(function () use ($id, $data, $promotionsAuxiliaryData) {
$time = time();
$data['update_time'] = $time;
if ($id) {
$this->dao->update($id, $data);
} else {
$data['add_time'] = $time;
$res = $this->dao->save($data);
$id = $res->id;
}
/** @var StorePromotionsAuxiliaryServices $storePromotionsAuxiliaryServices */
$storePromotionsAuxiliaryServices = app()->make(StorePromotionsAuxiliaryServices::class);
//保存关联数据
$storePromotionsAuxiliaryServices->savePromotionsRelation((int)$id, (int)$data['product_partake_type'], $promotionsAuxiliaryData, [], [], false);
});
return true;
}
}