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

220 lines
8.0 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\services\order;
use app\dao\order\StoreOrderDao;
use app\jobs\order\AutoCommentOrderJob;
use app\services\BaseServices;
use app\services\product\product\StoreProductReplyServices;
use app\services\user\UserServices;
use think\annotation\Inject;
use think\exception\ValidateException;
/**
* 订单评价
* Class StoreOrderCommentServices
* @package app\services\order
* @mixin StoreOrderDao
*/
class StoreOrderCommentServices extends BaseServices
{
/**
* 评论默认数据
* @var string[]
*/
protected array $commentArr = [
'reply_score' => 3,
'product_score' => 5,
'service_score' => 5,
'delivery_score' => 5,
'comment' => '',
'pics' => [],
];
/**
* @var StoreOrderDao
*/
#[Inject]
protected StoreOrderDao $dao;
/**
* 订单评价
* @param int $oid
* @param int $uid
* @param array $group
* @param string $unique
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function comment(int $oid, int $uid = 0, array $group = [], string $unique = '')
{
if (!$oid) throw new ValidateException('参数错误!');
$order = $this->dao->get($oid);
if (!$order) {
throw new ValidateException('订单不存在!');
}
$where = ['oid' => $oid];
if ($unique) {
$where['unique'] = $unique;
}
/** @var StoreOrderCartInfoServices $cartInfoServices */
$cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
$cartInfos = $cartInfoServices->getColumn($where, 'oid,product_id,cart_info,unique');
if (!$cartInfos) {
throw new ValidateException('评价商品不存在');
}
$is_sync = $group['is_sync'] ?? 0;
unset($group['is_sync']);
$group = array_merge($this->commentArr, array_intersect_key($group, $this->commentArr));
$group['comment'] = htmlspecialchars(trim($group['comment']));
if ($group['product_score'] < 1) throw new ValidateException('请为商品评分');
if ($group['service_score'] < 1) throw new ValidateException('请为商家服务评分');
if ($group['delivery_score'] < 1) throw new ValidateException('请为物流服务评分');
if ($group['pics']){
$pics = is_array($group['pics']) ? $group['pics'] : explode(',', $group['pics']);
$group['pics'] = json_encode($pics);
}
$user_info = [];
if ($uid) {
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$user_info = $userServices->getUserInfo($uid);
}
if ($order['store_id']) {
$group['type'] = 1;
$group['relation_id'] = $order['store_id'];
} elseif ($order['supplier_id']) {
$group['type'] = 2;
$group['relation_id'] = $order['supplier_id'];
} else {
$group['type'] = $group['relation_id'] = 0;
}
$group = array_merge($group, [
'uid' => $uid,
'nickname' => $user_info['nickname'] ?? substr(md5($oid . time()), 0, 12),
'avatar' => $user_info['avatar'] ?? sys_config('h5_avatar'),
'oid' => $oid,
'add_time' => time(),
'reply_type' => 'product'
]);
/** @var StoreProductReplyServices $replyServices */
$replyServices = app()->make(StoreProductReplyServices::class);
$data_all = [];
$ids = [];
$sync = [];
foreach ($cartInfos as $cartInfo) {
if ($replyServices->be(['oid' => $cartInfo['oid'], 'unique' => $cartInfo['unique']])) continue;
$_info = is_string($cartInfo['cart_info']) ? json_decode($cartInfo['cart_info'], true) : $cartInfo['cart_info'];
if (isset($_info['activity_id']) && $_info['activity_id']) $productId = $_info['product_id'];
else $productId = $cartInfo['product_id'];
$ids[] = $productId;
$group['unique'] = $cartInfo['unique'];
$group['product_id'] = $productId;
$group['sku_unique'] = $_info['productInfo']['attrInfo']['unique'] ?? '';
$group['sku'] = $_info['productInfo']['attrInfo']['suk'] ?? '';
$data_all[] = $group;
}
if ($is_sync) {
$sync = [
'content_type' => 1,
'content' => $group['comment'] ?? '',
'slider_image' => $pics ?? [],
'relation_id' => $uid,
'product_id' => $ids
];
}
if ($data_all) {
$res = $replyServices->saveAll($data_all);
if (!$res) {
throw new ValidateException('评价失败!');
}
}
try {
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$orderServices->checkOrderOver($replyServices, $cartInfoServices->getCartColunm(['oid' => $oid, 'is_gift' => 0], 'unique', ''), $oid);
} catch (\Exception $e) {
throw new ValidateException($e->getMessage());
}
//清除评价缓存
$replyServices->cacheTag()->clear();
//订单评价成功事件
event('order.comment', [$order]);
if ($ids) {
//商品评价
event('product.reply', [$ids, $is_sync, $sync]);
}
return true;
}
/**
* 执行自动默认好评
* @param array $where
* @param int $page
* @param int $maxLimit
* @return bool
*/
public function runAutoCommentOrder(array $where, int $page = 0, int $maxLimit = 0)
{
/** @var StoreOrderStoreOrderStatusServices $service */
$service = app()->make(StoreOrderStoreOrderStatusServices::class);
$orderList = $service->getOrderIds($where, $page, $maxLimit);
foreach ($orderList as $order) {
if ($order['status'] == 3) {
continue;
}
$group = ['comment' => '此用户未作评价'];
$this->comment((int)$order['id'], (int)$order['uid'], $group);
}
return true;
}
/**
* 自动默认好评
* @return bool
*/
public function autoCommentOrder()
{
//7天前时间戳
$systemCommentTime = (int)sys_config('system_comment_time', 0);
//0为取消自动默认好评功能
if ($systemCommentTime == 0) {
return true;
}
$sevenDay = strtotime(date('Y-m-d H:i:s', strtotime('-' . $systemCommentTime . ' day')));
/** @var StoreOrderStoreOrderStatusServices $service */
$service = app()->make(StoreOrderStoreOrderStatusServices::class);
$where = [
'change_time' => $sevenDay,
'is_del' => 0,
'paid' => 1,
'status' => 2,
'change_type' => ['user_take_delivery', 'take_delivery', 'writeoff']
];
$maxLimit = 20;
$count = $service->getOrderCount($where);
if ($count > $maxLimit) {
$pages = ceil($count / $maxLimit);
for ($i = 1; $i <= $pages; $i++) {
AutoCommentOrderJob::dispatch([$where, $i, $maxLimit]);
}
} else {
$this->runAutoCommentOrder($where);
}
return true;
}
}