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

328 lines
11 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\live;
use app\dao\activity\live\LiveRoomDao;
use app\services\BaseServices;
use crmeb\exceptions\AdminException;
use crmeb\services\DownloadImageService;
use crmeb\services\wechat\MiniProgram;
use think\annotation\Inject;
use think\facade\Log;
/**
* 直播间
* Class LiveRoomServices
* @package app\services\activity\live
* @mixin LiveRoomDao
*/
class LiveRoomServices extends BaseServices
{
/**
* @var LiveRoomDao
*/
#[Inject]
protected LiveRoomDao $dao;
/**
* 获取直播间列表(后台)
* @param array $where 查询条件
* @return array
*/
public function getList(array $where)
{
$where['is_del'] = 0;
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getList($where, '*', [], $page, $limit);
$count = $this->dao->count($where);
return compact('count', 'list');
}
/**
* 获取直播间列表
* @param array $where
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function userList(array $where, int $limit = 0)
{
if ($limit) {
$page = 0;
} else {
[$page, $limit] = $this->getPageValue();
}
$where['is_show'] = 1;
$where['is_del'] = 0;
$list = $this->dao->getList($where, '*', ['roomGoods.goods', 'anchor'], $page, $limit);
foreach ($list as &$item) {
$item['roomid'] = $item['room_id'];
$item['goods'] = [];
$item['show_time'] = date('m/d H:i', strtotime($item['start_time']));
if (isset($item['roomGoods']) && $item['roomGoods']) {
$item['goods'] = array_column($item['roomGoods'], 'goods');
}
if (in_array($item['live_status'], [105, 106])) {
$item['live_status'] = 101;
}
if (in_array($item['live_status'], [104, 107])) {
$item['live_status'] = 103;
}
unset($item['roomGoods']);
}
return $list;
}
/**
* 获取直播间回放列表
* @param int $id 直播间ID
* @return array
*/
public function getPlaybacks(int $id)
{
$room = $this->dao->get(['id' => $id, 'is_del' => 0]);
if (!$room) {
throw new AdminException('数据不存在');
}
[$page, $limit] = $this->getPageValue();
return MiniProgram::getLivePlayback($room['room_id'], $page, $limit);
}
/**
* 添加直播间
* @param array $data 直播间数据
* @return bool
*/
public function add(array $data)
{
/** @var LiveAnchorServices $anchorServices */
$anchorServices = app()->make(LiveAnchorServices::class);
$anchor = $anchorServices->get(['wechat' => $data['anchor_wechat']]);
if (!$anchor) {
throw new AdminException('该主播不存在');
}
$data['start_time'] = strtotime($data['start_time']);
$data['end_time'] = strtotime($data['end_time']);
$time = time() + 600;
$time6 = time() + 180 * 24 * 3600;
if ($data['start_time'] < $time || $data['start_time'] > $time6) {
throw new AdminException('开播时间需要在当前时间的10分钟后 并且 开始时间不能在 6 个月后');
}
$t = $data['end_time'] - $data['start_time'];
if ($t < 1800 || $t > 24 * 3600) {
throw new AdminException('开播时间和结束时间间隔不得短于30分钟不得超过24小时');
}
$data['anchor_name'] = $data['anchor_name'] ?? $anchor['name'];
$data['add_time'] = time();
$wxRoom = $this->wxCreate($data);
$data['room_id'] = $wxRoom['roomId'];
$data['status'] = 2;
if (!$this->dao->save($data)) {
throw new AdminException('添加直播间数据失败');
}
return true;
}
/**
* 审核直播间
* @param int $id 直播间ID
* @param int $status 审核状态
* @param string $msg 拒绝原因
* @return void
*/
public function apply($id, $status, $msg = '')
{
$room = $this->dao->get($id);
if (!$room) {
throw new AdminException('数据不存在');
}
$room->status = $status;
if ($status == -1)
$room->error_msg = $msg;
else {
$room->room_id = $this->wxCreate($room)['roomId'];
$room->status = 2;
}
$room->save();
}
/**
* 创建微信直播间
* @param mixed $room 直播间数据
* @return array
*/
public function wxCreate($room)
{
try {
$coverImg = root_path() . 'public' . app()->make(DownloadImageService::class)->downloadImage($room['cover_img'])['path'];
$shareImg = root_path() . 'public' . app()->make(DownloadImageService::class)->downloadImage($room['share_img'])['path'];
} catch (\Throwable $e) {
Log::error('添加直播间封面图出错误,原因:' . $e->getMessage());
$coverImg = root_path() . 'public' . $room['cover_img'];
$shareImg = root_path() . 'public' . $room['share_img'];
}
$data = [
'startTime' => is_string($room['start_time']) ? strtotime($room['start_time']) : $room['start_time'],
'endTime' => is_string($room['end_time']) ? strtotime($room['end_time']) : $room['end_time'],
'name' => $room['name'],
'anchorName' => $room['anchor_name'],
'anchorWechat' => $room['anchor_wechat'],
'screenType' => $room['screen_type'],
'closeGoods' => $room['close_goods'] == 1 ? 0 : 1,
'closeLike' => $room['close_like'] == 1 ? 0 : 1,
'closeComment' => $room['close_comment'] == 1 ? 0 : 1,
'closeReplay' => $room['replay_status'] == 1 ? 0 : 1,
'type' => $room['type'],
'coverImg' => MiniProgram::temporaryUpload($coverImg)['media_id'],
'shareImg' => MiniProgram::temporaryUpload($shareImg)['media_id'],
'closeKf' => 1
];
$data['feedsImg'] = $data['coverImg'];
@unlink($coverImg);
@unlink($shareImg);
return MiniProgram::createLiveRoom($data);
}
/**
* 设置直播间显示状态
* @param int $id 直播间ID
* @param int $is_show 显示状态
* @return string
*/
public function isShow(int $id, $is_show)
{
$this->dao->update($id, ['is_show' => $is_show]);
return $is_show == 1 ? '显示成功' : '隐藏成功';
}
/**
* 删除直播间
* @param int $id 直播间ID
* @return bool
*/
public function delete(int $id)
{
$room = $this->dao->get(['id' => $id, 'is_del' => 0]);
if ($room) {
if (!$this->dao->update($id, ['is_del' => 1])) {
throw new AdminException('删除失败');
}
/** @var LiveRoomGoodsServices $liveRoomGoods */
$liveRoomGoods = app()->make(LiveRoomGoodsServices::class);
$liveRoomGoods->delete(['live_room_id' => $id]);
}
return true;
}
/**
* 设置直播间备注
* @param int $id 直播间ID
* @param string $mark 备注内容
* @return bool
*/
public function mark($id, $mark)
{
return $this->dao->update($id, compact('mark'));
}
/**
* 直播间添加商品
* @param $room_id
* @param array $ids
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function exportGoods(int $room_id, array $ids)
{
$liveGoodsServices = app()->make(LiveGoodsServices::class);
if (count($ids) != count($goods = $liveGoodsServices->goodsList($ids)))
throw new AdminException('请选择正确的直播商品');
if (!$room = $this->dao->validRoom($room_id))
throw new AdminException('直播间状态有误');
$data = [];
/** @var LiveRoomGoodsServices $liveRoomGoodsServices */
$liveRoomGoodsServices = app()->make(LiveRoomGoodsServices::class);
//查询已经关联的
$roomGoods = $liveRoomGoodsServices->getColumn(['live_room_id' => $room_id], 'live_goods_id', 'Live_goods_id');
$goods_ids = [];
foreach ($goods as $key => $item) {
if (isset($roomGoods[$item['id']])) {
unset($goods[$key]);
} else {
$goods_ids[] = $item['goods_id'];
$data[] = [
'live_room_id' => $room_id,
'live_goods_id' => $item['id']
];
}
}
if ($goods_ids) {
$liveRoomGoodsServices->saveAll($data);
return MiniProgram::roomAddGoods($room['room_id'], $goods_ids);
}
return true;
}
/**
* 同步直播间状态
* @return bool
*/
public function syncRoomStatus()
{
$start = 0;
$limit = 50;
$data = $dataAll = [];
$rooms = $this->dao->getColumn([], 'id,room_id,live_status', 'room_id');
$roomIds = [];
do {
$wxRooms = MiniProgram::getLiveInfo($start, $limit);
foreach ($wxRooms as $room) {
if (in_array($room['roomid'], $roomIds)) {
continue;
}
$roomIds[] = $room['roomid'];
if ($rooms && isset($rooms[$room['roomid']])) {
if ($room['live_status'] != $rooms[$room['roomid']]['live_status']) {
$this->dao->update($rooms[$room['roomid']]['id'], ['live_status' => $room['live_status']]);
}
} else {
$data['name'] = $room['name'];
$data['room_id'] = $room['roomid'];
$data['cover_img'] = $room['cover_img'];
$data['share_img'] = $room['share_img'];
$data['live_status'] = $room['live_status'];
$data['start_time'] = $room['start_time'];
$data['end_time'] = $room['end_time'];
$data['anchor_name'] = $room['anchor_name'];
$dataAll[] = $data;
}
}
$start += $limit;
} while (count($wxRooms) >= $limit);
if ($dataAll) {
$this->dao->saveAll($dataAll);
}
return true;
}
}