Files
huangjingfen/pro_v3.5.1_副本/app/services/message/service/StoreServiceServices.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

234 lines
9.6 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\message\service;
use app\dao\message\service\StoreServiceDao;
use app\services\BaseServices;
use app\services\user\UserServices;
use crmeb\exceptions\AdminException;
use crmeb\services\FormBuilder;
use think\annotation\Inject;
use think\exception\ValidateException;
/**
* 客服
* Class StoreServiceServices
* @package app\services\message\service
* @mixin StoreServiceDao
*/
class StoreServiceServices extends BaseServices
{
/**
* 创建form表单
* @var FormBuilder
*/
#[Inject]
protected FormBuilder $builder;
/**
* @var StoreServiceDao
*/
#[Inject]
protected StoreServiceDao $dao;
/**
* 获取客服列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getServiceList(array $where)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getServiceList($where, $page, $limit);
foreach ($list as &$item) {
if (!isset($item['workMember'])) {
$item['workMember'] = [];
}
if (isset($item['wx_name']) && !isset($item['nickname'])) {
$item['nickname'] = $item['wx_name'];
}
}
$this->updateNonExistentService(array_column($list, 'uid'));
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* @param array $uids
* @return bool
*/
public function updateNonExistentService(array $uids = [])
{
if (!$uids) {
return true;
}
/** @var UserServices $services */
$services = app()->make(UserServices::class);
$userUids = $services->getColumn([['uid', 'in', $uids]], 'uid');
$unUids = array_diff($uids, $userUids);
return $this->dao->deleteNonExistentService($unUids);
}
/**
* 创建客服表单
* @param array $formData
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function createServiceForm(array $formData = [])
{
if ($formData) {
$field[] = $this->builder->frameImage('avatar', '客服头像:', $this->url('admin/widget.images/index', ['fodder' => 'avatar'], true), $formData['avatar'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
} else {
$field[] = $this->builder->frameImage('image', '商城用户:', $this->url('admin/system.user/list', ['fodder' => 'image'], true))->icon('ios-add')->width('960px')->height('550px')->modal(['footer-hide' => true])->Props(['srcKey' => 'image']);
$field[] = $this->builder->hidden('uid', 0);
$field[] = $this->builder->hidden('avatar', '');
}
$field[] = $this->builder->input('nickname', '客服名称:', $formData['nickname'] ?? '')->col(24)->required();
$field[] = $this->builder->input('phone', '手机号码:', $formData['phone'] ?? '')->col(24)->required();
if ($formData) {
$field[] = $this->builder->input('account', '客服账号:', $formData['account'] ?? '')->col(24)->required();
$field[] = $this->builder->input('password', '客服密码:')->type('password')->col(24);
$field[] = $this->builder->input('true_password', '确认密码:')->type('password')->col(24);
} else {
$field[] = $this->builder->input('account', '客服账号:')->col(24)->required();
$field[] = $this->builder->input('password', '客服密码:')->type('password')->col(24)->required();
$field[] = $this->builder->input('true_password', '确认密码:')->type('password')->col(24)->required();
}
$field[] = $this->builder->switches('account_status', '账号状态:', (int)($formData['account_status'] ?? 0))->appendControl(1, [
$this->builder->switches('status', '客服状态:', (int)($formData['status'] ?? 0))->falseValue(0)->trueValue(1)->openStr('打开')->closeStr('关闭')->size('large'),
$this->builder->switches('customer', '手机订单管理:', $formData['customer'] ?? 0)->falseValue(0)->trueValue(1)->openStr('打开')->closeStr('关闭')->size('large'),
$this->builder->switches('notify', '订单通知:', $formData['notify'] ?? 0)->falseValue(0)->trueValue(1)->openStr('打开')->closeStr('关闭')->size('large'),
])->falseValue(0)->trueValue(1)->openStr('开启')->closeStr('关闭')->size('large');
return $field;
}
/**
* 创建客服获取表单
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function create()
{
return create_form('添加客服', $this->createServiceForm(), $this->url('/app/wechat/kefu'), 'POST');
}
/**
* 编辑获取表单
* @param int $id
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function edit(int $id)
{
$serviceInfo = $this->dao->get($id);
if (!$serviceInfo) {
throw new AdminException('数据不存在!');
}
return create_form('编辑客服', $this->createServiceForm($serviceInfo->toArray()), $this->url('/app/wechat/kefu/' . $id), 'PUT');
}
/**
* 获取某人的聊天记录用户列表
* @param int $uid
* @return array|array[]
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getChatUser(int $uid)
{
/** @var StoreServiceLogServices $serviceLog */
$serviceLog = app()->make(StoreServiceLogServices::class);
/** @var UserServices $serviceUser */
$serviceUser = app()->make(UserServices::class);
$uids = $serviceLog->getChatUserIds($uid);
if (!$uids) {
return [];
}
return $serviceUser->getUserList(['uid' => $uids], 'nickname,uid,avatar as headimgurl');
}
/**
* 检查用户是否是客服
* @param array $where
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function checkoutIsService(array $where)
{
return (bool)$this->dao->count($where);
}
/**
* 查询聊天记录和获取客服uid
* @param int $uid 当前用户uid
* @param int $uidTo 上翻页id
* @param int $limit 展示条数
* @param int $toUid 客服uid
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getRecord(int $uid, int $uidTo, int $limit = 10, int $toUid = 0)
{
if (!$toUid) {
$serviceInfoList = $this->getServiceList(['noId' => [$uid], 'status' => 1, 'account_status' => 1, 'online' => 1]);
if (!count($serviceInfoList)) {
throw new ValidateException('暂无客服人员在线,请稍后联系');
}
$uids = array_column($serviceInfoList['list'], 'uid');
if (!$uids) {
throw new ValidateException('暂无客服人员在线,请稍后联系');
}
/** @var StoreServiceRecordServices $recordServices */
$recordServices = app()->make(StoreServiceRecordServices::class);
//上次聊天客服优先对话
$toUid = $recordServices->getLatelyMsgUid(['to_uid' => $uid], 'user_id');
//如果上次聊天的客不在当前客服中从新
if (!in_array($toUid, $uids)) {
$toUid = 0;
}
if (!$toUid) {
mt_srand();
$toUid = $uids[array_rand($uids)] ?? 0;
}
if (!$toUid) {
throw new ValidateException('暂无客服人员在线,请稍后联系');
}
}
$userInfo = $this->dao->get(['uid' => $toUid], ['nickname', 'avatar']);
if (!$userInfo) {
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$userInfo = $userServices->get(['uid' => $toUid], ['nickname', 'avatar']);
if (!$userInfo) {
$userInfo['nickname'] = '';
$userInfo['avatar'] = '';
}
}
/** @var StoreServiceLogServices $logServices */
$logServices = app()->make(StoreServiceLogServices::class);
$result = ['serviceList' => [], 'uid' => $toUid, 'nickname' => $userInfo['nickname'], 'avatar' => $userInfo['avatar']];
$serviceLogList = $logServices->getServiceChatList(['chat' => [$uid, $toUid], 'is_tourist' => 0], $limit, $uidTo);
$result['serviceList'] = array_reverse($logServices->tidyChat($serviceLogList));
return $result;
}
}