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

205 lines
7.5 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\LiveAnchorDao;
use app\jobs\activity\AutoUpdateLiveJob;
use app\services\BaseServices;
use crmeb\exceptions\AdminException;
use crmeb\services\CacheService;
use crmeb\services\FormBuilder as Form;
use crmeb\services\wechat\MiniProgram;
use FormBuilder\Factory\Iview;
use think\annotation\Inject;
use think\facade\Route as Url;
/**
* 主播
* Class LiveAnchorServices
* @package app\services\activity\live
* @mixin LiveAnchorDao
*/
class LiveAnchorServices extends BaseServices
{
/**
* @var LiveAnchorDao
*/
#[Inject]
protected LiveAnchorDao $dao;
/**
* 获取某个主播
* @param int $id
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLiveAnchor(int $id)
{
return $this->dao->get($id);
}
/**
* 获取主播列表
* @param array $where 查询条件
* @return array
*/
public function getList(array $where)
{
[$page, $limit] = $this->getPageValue();
$where['is_del'] = 0;
$list = $this->dao->getList($where, '*', $page, $limit);
$count = $this->dao->count($where);
return compact('count', 'list');
}
/**
* 添加修改标签表单
* @param int $id
* @return mixed
*/
public function add(int $id)
{
$anchor = $this->getLiveAnchor($id);
$field = array();
if (!$anchor) {
$title = '添加主播';
$field[] = Form::input('name', '主播名称:', '')->maxlength(20)->required('请填写名称');
$field[] = Form::input('wechat', '主播微信号:', '')->maxlength(32)->required('请填写微信号');
$field[] = Form::input('phone', '主播手机号:', '')->maxlength(20)->required('请填写手机号');
$field[] = Form::frameImage('cover_img', '主播图像:', Url::buildUrl('admin/widget.images/index', array('fodder' => 'cover_img')), '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true])->appendValidate(Iview::validateStr()->required()->message('请选择图像'));
} else {
$title = '修改主播';
$field[] = Form::hidden('id', $anchor->getData('id'));
$field[] = Form::input('name', '主播名称:', $anchor->getData('name'))->maxlength(20)->required('请填写名称');
$field[] = Form::input('wechat', '主播微信号:', $anchor->getData('wechat'))->maxlength(32)->required('请填写微信号');
$field[] = Form::input('phone', '主播手机号:', $anchor->getData('phone'))->maxlength(20)->required('请填写手机号');
$field[] = Form::frameImage('cover_img', '主播图像:', Url::buildUrl('admin/widget.images/index', array('fodder' => 'cover_img')), $anchor->getData('cover_img'))->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true])->appendValidate(Iview::validateStr()->required()->message('请选择图像'));
}
return create_form($title, $field, $this->url('/live/anchor/save'), 'POST');
}
/**
* 保存标签表单数据
* @param int $id
* @param array $data
* @return mixed
*/
public function save(int $id, array $data)
{
$liveAnchor = $this->dao->get(['wechat' => $data['wechat']]);
if (!MiniProgram::getRoleList(2, 0, 30, $data['wechat'])) {
return ['auth' => true];
}
if ($id) {
if ($liveAnchor && $id != $liveAnchor['id']) {
throw new AdminException('该主播已经存在');
}
if ($this->dao->update($id, $data)) {
return true;
} else {
throw new AdminException('修改失败或者您没有修改什么!');
}
} else {
unset($data['id']);
if ($liveAnchor) {
throw new AdminException('该主播已经存在');
}
if ($this->dao->save($data)) {
return true;
} else {
throw new AdminException('添加失败!');
}
}
}
/**
* 删除
* @param $id
* @throws \Exception
*/
public function delAnchor(int $id)
{
if ($anchor = $this->getLiveAnchor($id)) {
if (!$this->dao->update($id, ['is_del' => 1])) {
throw new AdminException('删除失败,请稍候再试!');
}
/** @var LiveRoomServices $liveRoom */
$liveRoom = app()->make(LiveRoomServices::class);
$room = $liveRoom->get(['anchor_wechat' => $anchor['wechat'], 'is_del' => 0], ['id']);
if ($room) {
$liveRoom->delete((int)$room->id);
}
}
return true;
}
/**
* 设置是否显示
* @param int $id
* @param $is_show
* @return mixed
*/
public function setShow(int $id, $is_show)
{
if (!$this->getLiveAnchor($id))
throw new AdminException('数据不存在');
if ($this->dao->update($id, ['is_show' => $is_show])) {
return $is_show == 1 ? '显示成功' : '隐藏成功';
} else {
throw new AdminException($is_show == 1 ? '显示失败' : '隐藏失败');
}
}
/**
* 同步微信主播列表
* @param bool $is_job 是否为定时任务调用
* @return bool
*/
public function syncAnchor($is_job = false)
{
$key = md5('Live_sync_status');
$res = CacheService::redisHandler()->get($key);
if (!$res || $is_job) {
$start = 0;
$limit = 30;
$data = $dataAll = [];
$anchors = $this->dao->getColumn([], 'id,wechat', 'wechat');
do {
$wxAnchor = MiniProgram::getRoleList(2, $start, $limit);
foreach ($wxAnchor as $anchor) {
if (isset($anchors[$anchor['username']])) {
$this->dao->update($anchors[$anchor['username']]['id'], ['cover_img' => $anchor['headingimg'], 'name' => $anchor['nickname']]);
} else {
$data['name'] = $anchor['nickname'];
$data['wechat'] = $anchor['username'];
$data['cover_img'] = $anchor['headingimg'];
$data['add_time'] = $anchor['updateTimestamp'] ?? time();
$dataAll[] = $data;
}
}
$start++;
} while (count($wxAnchor) >= $limit);
if ($dataAll) {
$this->dao->saveAll($dataAll);
}
if (!$is_job) AutoUpdateLiveJob::dispatchSece(120);
CacheService::redisHandler()->set($key, 1, 0);
}
return true;
}
}