CRMEB/backend/app/services/user/UserSpreadServices.php
吴昊天 d50837b663 refactor(分销): 开源侧下线佣金提现,与私有分支口径对齐
移除佣金/提现控制器与前端页面,订单与用户链路去掉分销佣金逻辑,安装 SQL 与文档同步。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-28 10:40:30 +08:00

106 lines
3.3 KiB
PHP
Raw Permalink 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\user;
use crmeb\basic\BaseService;
use app\dao\user\UserSpreadDao;
/**
* 用户推广关系服务
* Class UserSpreadServices
* @package app\services\user
*/
class UserSpreadServices extends BaseService
{
/**
* @var UserSpreadDao
*/
protected $dao;
/**
* UserSpreadServices constructor.
* @param UserSpreadDao $dao
*/
public function __construct(UserSpreadDao $dao)
{
$this->dao = $dao;
}
/**
* 记录推广关系
* @param int $uid
* @param int $spread_uid
* @return false|mixed
*/
public function setSpread(int $uid, int $spread_uid, int $spread_time = 0)
{
if (!$uid || !$spread_uid) return false;
$handled = event('DistributionServiceProxy', [
'service' => 'DistributionRelationServices',
'action' => 'bind',
'args' => [$uid, $spread_uid, $spread_time ?: time()],
]);
if (is_array($handled) && ($handled[0] ?? null) !== null) {
return (bool)$handled[0];
}
/** @var UserServices $userServices */
$userServices = app()->make(UserServices::class);
if (!$userServices->getUserInfo($uid, 'uid')) {
return false;
}
if (!$userServices->getUserInfo($spread_uid, 'uid')) {
return false;
}
if ($this->dao->save(['uid' => $uid, 'spread_uid' => $spread_uid, 'spread_time' => $spread_time ?: time()])) {
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->getUserInfo($uid, '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));
}
}