Files
huangjingfen/pro_v3.5.1_副本/app/services/out/OutStoreOrderRefundServices.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

202 lines
7.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~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\out;
use app\dao\order\StoreOrderRefundDao;
use app\services\BaseServices;
use app\services\order\StoreOrderServices;
use app\services\pay\PayServices;
use crmeb\exceptions\AdminException;
use crmeb\exceptions\ApiException;
use app\services\order\StoreOrderRefundServices;
use crmeb\services\HttpService;
use think\annotation\Inject;
/**
* 售后单
* Class OutStoreOrderRefundServices
* @package app\services\order
*/
class OutStoreOrderRefundServices extends BaseServices
{
/**
* 订单services
* @var OutStoreOrderServices
*/
#[Inject]
protected OutStoreOrderServices $storeOrderServices;
/**
* @var StoreOrderRefundDao
*/
#[Inject]
protected StoreOrderRefundDao $dao;
/**
* 售后单列表
* @param array $where
* @return array
*/
public function refundList(array $where)
{
[$page, $limit] = $this->getPageValue();
$field = 'id, store_order_id, uid, order_id, refund_type, refund_num, refund_price, refunded_price, refund_phone, refund_express, refund_express_name,
refund_explain, refund_img, refund_reason, refuse_reason, remark, refunded_time, cart_info, is_cancel, is_del, add_time';
$list = $this->dao->getRefundList($where, $field, [], $page, $limit);
$count = $this->dao->count($where);
foreach ($list as $key => &$item) {
$item['pay_price'] = $item['refund_price'];
unset($item['refund_price']);
$item['items'] = $this->tidyCartList($item['cart_info']);
unset($list[$key]['cart_info']);
}
return compact('list', 'count');
}
/**
* 格式化订单商品
* @param array $carts
* @return array
*/
public function tidyCartList(array $carts): array
{
$list = [];
foreach ($carts as $cart) {
$list[] = [
'store_name' => $cart['productInfo']['store_name'] ?? '',
'suk' => $cart['productInfo']['attrInfo']['suk'] ?? '',
'image' => $cart['productInfo']['attrInfo']['image'] ?: $cart['productInfo']['image'],
'price' => sprintf("%.2f", $cart['truePrice'] ?? '0.00'),
'cart_num' => $cart['cart_num'] ?? 0
];
}
return $list;
}
/**
* 售后单生成
* @param int $id
* @param string $pushUrl
* @return bool
*/
public function refundCreatePush(int $id, string $pushUrl): bool
{
$refundInfo = $this->getInfo('', $id);
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$orderInfo = $orderServices->get($refundInfo['store_order_id'], ['id', 'order_id']);
if (!$orderInfo) {
throw new AdminException('订单不存在');
}
$refundInfo['order'] = $orderInfo->toArray();
return $this->outPush($pushUrl, $refundInfo, '售后单');
}
/**
* 售后单取消
* @param int $id
* @param string $pushUrl
* @return bool
*/
public function cancelApplyPush(int $id, string $pushUrl): bool
{
$refundInfo = $this->getInfo('', $id);
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$orderInfo = $orderServices->get($refundInfo['store_order_id'], ['id', 'order_id']);
if (!$orderInfo) {
throw new AdminException('订单不存在');
}
$refundInfo['order'] = $orderInfo->toArray();
return $this->outPush($pushUrl, $refundInfo, '取消售后单');
}
/**
* 默认数据推送
* @param string $pushUrl
* @param array $data
* @param string $tip
* @return bool
*/
function outPush(string $pushUrl, array $data, string $tip = ''): bool
{
$param = json_encode($data, JSON_UNESCAPED_UNICODE);
$res = HttpService::postRequest($pushUrl, $param, ['Content-Type:application/json', 'Content-Length:' . strlen($param)]);
$res = $res ? json_decode($res, true) : [];
if (!$res || !isset($res['code']) || $res['code'] != 0) {
\think\facade\Log::error(json_encode(['msg' => $tip . '推送失败', 'data' => $res], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
);
return false;
}
return true;
}
/**
* 退款订单详情
* @param string $orderId 售后单号
* @param int $id 售后单ID
* @return mixed
*/
public function getInfo(string $orderId = '', int $id = 0)
{
$field = ['id', 'store_order_id', 'order_id', 'uid', 'refund_type', 'refund_num', 'refund_price',
'refunded_price', 'refund_phone', 'refund_express', 'refund_express_name', 'refund_explain',
'refund_img', 'refund_reason', 'refuse_reason', 'remark', 'refunded_time', 'cart_info', 'is_cancel', 'is_del', 'add_time'];
if ($id > 0) {
$where = $id;
} else {
$where = ['order_id' => $orderId];
}
$refund = $this->dao->get($where, $field, ['orderData']);
if (!$refund) throw new ApiException(410173);
$refund = $refund->toArray();
//核算优惠金额
$totalPrice = 0;
$vipTruePrice = 0;
foreach ($refund['cart_info'] ?? [] as $key => &$cart) {
$cart['sum_true_price'] = sprintf("%.2f", $cart['sum_true_price'] ?? bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2));
$cart['vip_sum_truePrice'] = bcmul($cart['vip_truePrice'], $cart['cart_num'] ?: 1, 2);
$vipTruePrice = bcadd((string)$vipTruePrice, $cart['vip_sum_truePrice'], 2);
if (isset($order['split']) && $order['split']) {
$refund['cart_info'][$key]['cart_num'] = $cart['surplus_num'];
if (!$cart['surplus_num']) unset($refund['cart_info'][$key]);
}
$totalPrice = bcadd($totalPrice, $cart['sum_true_price'], 2);
}
$refund['vip_true_price'] = $vipTruePrice;
/** @var StoreOrderRefundServices $refundServices */
$refundServices = app()->make(StoreOrderRefundServices::class);
$refund['use_integral'] = $refundServices->getOrderSumPrice($refund['cart_info'], 'use_integral', false);
$refund['coupon_price'] = $refundServices->getOrderSumPrice($refund['cart_info'], 'coupon_price', false);
$refund['deduction_price'] = $refundServices->getOrderSumPrice($refund['cart_info'], 'integral_price', false);
$refund['pay_postage'] = $refundServices->getOrderSumPrice($refund['cart_info'], 'postage_price', false);
$refund['total_price'] = bcadd((string)$totalPrice, bcadd((string)$refund['deduction_price'], (string)$refund['coupon_price'], 2), 2);
$refund['items'] = $this->tidyCartList($refund['cart_info']);
if (in_array($refund['refund_type'], [0, 1, 2, 4, 5])) {
$title = '申请退款中';
} elseif ($refund['refund_type'] == 3) {
$title = '拒绝退款';
} else {
$title = '已退款';
}
$refund['refund_type_name'] = $title;
$refund['pay_type_name'] = PayServices::PAY_TYPE[$refund['pay_type']] ?? '其他方式';
unset($refund['cart_info']);
return $refund;
}
}