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
195 lines
7.7 KiB
PHP
195 lines
7.7 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\order;
|
||
|
||
use app\dao\order\StoreOrderPromotionsDao;
|
||
use app\services\BaseServices;
|
||
use think\annotation\Inject;
|
||
use think\exception\ValidateException;
|
||
|
||
/**
|
||
* Class StoreOrderPromotionsServices
|
||
* @package app\services\order
|
||
* @mixin StoreOrderPromotionsDao
|
||
*/
|
||
class StoreOrderPromotionsServices extends BaseServices
|
||
{
|
||
/**
|
||
* @var StoreOrderPromotionsDao
|
||
*/
|
||
#[Inject]
|
||
protected StoreOrderPromotionsDao $dao;
|
||
|
||
/**
|
||
* 保存订单优惠详情
|
||
* @param int $uid
|
||
* @param int $oid
|
||
* @param array $cartList
|
||
* @param array $promotionsList
|
||
* @return int
|
||
*/
|
||
public function setPromotionsDetail(int $uid, int $oid, array $cartList, array $promotionsList)
|
||
{
|
||
$group = [];
|
||
if ($promotionsList) {
|
||
$time = time();
|
||
foreach ($cartList as $key => $cart) {
|
||
foreach ($promotionsList as $promotions) {
|
||
$details = $promotions['details'] ?? [];
|
||
$unique = $cart['product_attr_unique'] ?? '';
|
||
if ($details && isset($details[$unique]['sum_promotions_price'])) {
|
||
$group[] = [
|
||
'oid' => $oid,
|
||
'uid' => $uid,
|
||
'product_id' => $cart['productInfo']['id'],
|
||
'promotions_id' => $promotions['id'],
|
||
'promotions_price' => (float)$details[$unique]['sum_promotions_price'] ?? 0,
|
||
'add_time' => $time
|
||
];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if ($group) {
|
||
return $this->dao->saveAll($group);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 获取订单商品实际参与优惠活动 以及优惠金额
|
||
* @param int $oid
|
||
* @return array
|
||
*/
|
||
public function getOrderPromotionsDetail(int $oid)
|
||
{
|
||
$result = $this->dao->getPromotionsDetailList(['oid' => $oid], '*,sum(`promotions_price`) as promotions_price', ['promotions'], 'promotions_id');
|
||
if ($result) {
|
||
$typeArr = array_column($result, 'promotions_type');
|
||
array_multisort($typeArr, SORT_ASC, $result);
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 拆分订单同步拆分优惠活动记录
|
||
* @param int $oid
|
||
* @return bool
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
*/
|
||
public function splitOrderPromotions(int $oid)
|
||
{
|
||
/** @var StoreOrderServices $storeOrderServices */
|
||
$storeOrderServices = app()->make(StoreOrderServices::class);
|
||
$orderInfo = $storeOrderServices->getOne(['id' => $oid, 'is_del' => 0]);
|
||
if (!$orderInfo) {
|
||
throw new ValidateException('订单不存在');
|
||
}
|
||
$promotions_give = [];
|
||
$promotions = [];
|
||
if (isset($orderInfo['promotions_give']) && $orderInfo['promotions_give']) {
|
||
$promotions_give = is_string($orderInfo['promotions_give']) ? json_decode($promotions_give, true) : $orderInfo['promotions_give'];
|
||
}
|
||
$promotions = $promotions_give['promotions'] ?? [];
|
||
$pid = $orderInfo['pid'] > 0 ? $orderInfo['pid'] : $orderInfo['id'];
|
||
//查询优惠记录
|
||
$orderPromotions = $this->dao->getPromotionsDetailList(['order_id' => $oid]);
|
||
//查询子订单
|
||
$spliteOrder = $storeOrderServices->getColumn(['pid' => $pid, 'is_system_del' => 0], 'id,order_id');
|
||
if ($spliteOrder && $orderPromotions && $promotions) {
|
||
/** @var StoreOrderCartInfoServices $storeOrderCartInfoServices */
|
||
$storeOrderCartInfoServices = app()->make(StoreOrderCartInfoServices::class);
|
||
$data_all = $data = [];
|
||
$data['uid'] = $orderInfo['uid'];
|
||
$data['add_time'] = time();
|
||
foreach ($spliteOrder as $order) {
|
||
$cartInfo = $storeOrderCartInfoServices->getColumn(['oid' => $order['id']], 'id,product_id,cart_num,cart_info');
|
||
if (!$cartInfo) {
|
||
continue;
|
||
}
|
||
$data['oid'] = $order['id'];
|
||
foreach ($cartInfo as $key => $cart) {
|
||
$data['product_id'] = $cart['product_id'];
|
||
$_info = is_string($cart['cart_info']) ? json_decode($cart['cart_info'], true) : $cart['cart_info'];
|
||
$unique = $_info['product_attr_unique'] ?? '';
|
||
foreach ($promotions as $key => $info) {
|
||
if (isset($info['details'][$unique])) {
|
||
$data['promotions_id'] = $info['id'];
|
||
$data['promotions_price'] = floatval($info['details'][$unique]['sum_promotions_price'] ?? 0);
|
||
$data_all[] = $data;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if ($data_all) {
|
||
$this->transaction(function () use ($data_all, $spliteOrder) {
|
||
$this->dao->delete(['oid' => array_column($spliteOrder, 'id')]);
|
||
$this->dao->saveAll($data_all);
|
||
|
||
});
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* 申请退款订单优惠详情处理
|
||
* @param int $oid
|
||
* @param array $cartInfo
|
||
* @return bool
|
||
*/
|
||
public function applyRefundOrderPromotions(int $oid, array $cartInfo = [])
|
||
{
|
||
/** @var StoreOrderServices $storeOrderServices */
|
||
$storeOrderServices = app()->make(StoreOrderServices::class);
|
||
$orderInfo = $storeOrderServices->getOne(['id' => $oid, 'is_del' => 0]);
|
||
if (!$orderInfo) {
|
||
return [];
|
||
}
|
||
$promotions_give = [];
|
||
$promotions = [];
|
||
if (isset($orderInfo['promotions_give']) && $orderInfo['promotions_give']) {
|
||
$promotions_give = is_string($orderInfo['promotions_give']) ? json_decode($promotions_give, true) : $orderInfo['promotions_give'];
|
||
}
|
||
$promotions = $promotions_give['promotions'] ?? [];
|
||
if (!$cartInfo || !$promotions) {
|
||
return [];
|
||
}
|
||
$data_all = [];
|
||
foreach ($promotions as $key => $info) {
|
||
$data = [];
|
||
foreach ($cartInfo as $key => $cart) {
|
||
if (isset($info['details'][$cart['product_id']])) {
|
||
$data['promotions_id'] = $info['id'];
|
||
$data['promotions_type'] = $info['promotions_type'];
|
||
$data['name'] = $info['name'];
|
||
$data['title'] = $info['title'];
|
||
$data['desc'] = $info['desc'];
|
||
$data['promotions_price'] = bcadd((string)($data['promotions_price'] ?? 0), (string)($info['details'][$cart['product_id']]['sum_promotions_price'] ?? 0), 2);
|
||
}
|
||
}
|
||
if ($data) {
|
||
$data_all[] = $data;
|
||
}
|
||
}
|
||
if ($data_all) {
|
||
$typeArr = array_column($data_all, 'promotions_type');
|
||
array_multisort($typeArr, SORT_ASC, $data_all);
|
||
}
|
||
return $data_all;
|
||
}
|
||
|
||
}
|