Files
huangjingfen/pro_v3.5.1_副本/app/services/user/UserSpreadServices.php

210 lines
8.0 KiB
PHP
Raw Normal View History

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
<?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\user;
use app\services\BaseServices;
use app\dao\user\UserSpreadDao;
use app\services\order\store\BranchOrderServices;
use app\services\user\level\SystemUserLevelServices;
use think\annotation\Inject;
/**
* Class UserSpreadServices
* @package app\services\user
* @mixin UserSpreadDao
*/
class UserSpreadServices extends BaseServices
{
/**
* @var UserSpreadDao
*/
#[Inject]
protected UserSpreadDao $dao;
/**
* 记录推广关系
* @param int $uid
* @param int $spread_uid
* @param int $spread_time
* @param int $admin_id
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function setSpread(int $uid, int $spread_uid, int $spread_time = 0, int $admin_id = 0)
{
if (!$uid || !$spread_uid) return false;
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
if (!$userServices->userExist($uid)) {
return false;
}
if (!$userServices->userExist($spread_uid)) {
return false;
}
$data = ['uid' => $uid, 'spread_uid' => $spread_uid, 'spread_time' => $spread_time ?: time(), 'admin_id' => $admin_id];
if ($this->dao->save($data)) {
return true;
} else {
return false;
}
}
/**
* 查询推广用户uids
* @param int $uid
* @param int $type 1:一级2二级 0:所有
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSpreadUids(int $uid, int $type = 0, array $where = [])
{
if (!$uid) return [];
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
if (!$userServices->userExist($uid)) {
return [];
}
if ($where && isset($where['time'])) {
$where['timeKey'] = 'spread_time';
}
$where['spread_uid'] = $uid;
$spread_one = $this->dao->getSpreadUids($where);
if ($type == 1) {
return $spread_one;
}
$where['spread_uid'] = $spread_one;
$spread_two = $this->dao->getSpreadUids($where);
if ($type == 2) {
return $spread_two;
}
return array_unique(array_merge($spread_one, $spread_two));
}
/**
* 门店推广统计详情列表
* @param int $store_id
* @param int $staff_id
* @param array $time
* @return array|array[]
*/
public function time(int $store_id, int $staff_id, array $time = [])
{
if (!$time) {
return [[], []];
}
[$start, $stop, $front, $front_stop] = $time;
$where = ['store_id' => $store_id];
if ($staff_id) {
$where['staff_id'] = $staff_id;
}
$frontPrice = $this->dao->count($where + ['time' => [$front, $front_stop], 'timeKey' => 'spread_time']);
$nowPrice = $this->dao->count($where + ['time' => [$start, $stop], 'timeKey' => 'spread_time']);
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getList($where + ['time' => [$start, $stop], 'timeKey' => 'spread_time'], '*', ['user'], $page, $limit);
/** @var BranchOrderServices $order */
$order = app()->make(BranchOrderServices::class);
$order_where = ['time' => $time, 'is_del' => 0, 'is_system_del' => 0, 'paid' => 1, 'pid' => 0, 'refund_status' => [0, 3]];
foreach ($list as &$item) {
$item['spread_time'] = $item['spread_time'] ? date('Y-m-d H:i:s', $item['spread_time']) : '';
$orderCount = $order->column($order_where + ['uid' => $item['uid']], 'count(`id`) as count,sum(`pay_price`) as price');
$item['order_count'] = $orderCount[0]['count'] ?? 0;
$item['order_price'] = $orderCount[0]['price'] ?? 0.00;
}
return [[$nowPrice, $frontPrice], $list];
}
/**
* 获取推广列表
* @param int $uid
* @param UserServices $userServices
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSpreadList(array $where, string $field = '*', array $with = ['user'], bool $type = true)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getList($where, $field, $with, $page, $limit);
$count = $this->dao->count($where);
/** @var BranchOrderServices $order */
$order = app()->make(BranchOrderServices::class);
foreach ($list as &$item) {
$item['spread_time'] = $item['spread_time'] ? date('Y-m-d H:i:s', $item['spread_time']) : '';
$item['type'] = $item['admin_id'] ? ('手动变更(' . ($item['real_name'] ?? '') . ')') : '自动变更';
if ($type) {
$orderCount = $order->column(['uid' => $item['uid'], 'is_del' => 0, 'is_system_del' => 0, 'paid' => 1, 'pid' => 0, 'refund_status' => [0, 3]], 'count(`id`) as count,sum(`pay_price`) as price');
$item['order_count'] = $orderCount[0]['count'] ?? 0;
$item['order_price'] = $orderCount[0]['price'] ?? 0.00;
}
}
return compact('list', 'count');
}
/**
* 获取好友uids 我推广的 推广我的
* @param int $uid
* @return array
*/
public function getFriendUids(int $uid)
{
$result = [];
if ($uid) {
$spread = $this->dao->getColumn(['spread_uid' => $uid], 'uid');
$sup_spread = $this->dao->getColumn(['uid' => $uid], 'spread_uid');
$result = array_unique(array_merge($spread, $sup_spread));
}
return $result;
}
/**
* 获取好友
* @param int $id
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFriendList(int $uid, string $field = 'uid,nickname,level,add_time')
{
$uids = $this->getFriendUids($uid);
$list = [];
$count = 0;
if ($uids) {
[$page, $limit] = $this->getPageValue();
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
$list = $userServices->getList(['uid' => $uids], $field, $page, $limit);
/** @var SystemUserLevelServices $systemLevelServices */
$systemLevelServices = app()->make(SystemUserLevelServices::class);
$systemLevelList = $systemLevelServices->getWhereLevelList([], 'id,name');
if ($systemLevelList) $systemLevelServices = array_combine(array_column($systemLevelList, 'id'), $systemLevelList);
foreach ($list as &$item) {
$item['type'] = $systemLevelServices[$item['level']]['name'] ?? '暂无';
$item['add_time'] = $item['add_time'] && is_numeric($item['add_time']) ? date('Y-m-d H:i:s', $item['add_time']) : '';
}
$count = $this->dao->count(['spread_uid' => $uid]);
}
return compact('list', 'count');
}
}