- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明 Made-with: Cursor
95 lines
2.7 KiB
PHP
95 lines
2.7 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | Author: ScottPan Team
|
||
// +----------------------------------------------------------------------
|
||
|
||
declare (strict_types=1);
|
||
|
||
namespace app\services\user;
|
||
|
||
use app\services\agent\AgentLevelServices;
|
||
use app\services\BaseServices;
|
||
use app\dao\user\UserWechatUserDao;
|
||
use think\annotation\Inject;
|
||
|
||
/**
|
||
* Class UserWechatuserServices
|
||
* @package app\services\user
|
||
* @mixin UserWechatUserDao
|
||
*/
|
||
class UserWechatuserServices extends BaseServices
|
||
{
|
||
|
||
/**
|
||
* @var UserWechatUserDao
|
||
*/
|
||
#[Inject]
|
||
protected UserWechatUserDao $dao;
|
||
|
||
/**
|
||
* 自定义简单查询总数
|
||
* @param array $where
|
||
* @return int
|
||
*/
|
||
public function getCount(array $where): int
|
||
{
|
||
return $this->dao->getCount($where);
|
||
}
|
||
|
||
/**
|
||
* 复杂条件搜索列表
|
||
* @param array $where
|
||
* @param string $field
|
||
* @return array
|
||
*/
|
||
public function getWhereUserList(array $where, string $field): array
|
||
{
|
||
$where = $this->normalizeHjfMemberLevelWhere($where);
|
||
[$page, $limit] = $this->getPageValue();
|
||
$order_string = '';
|
||
$order_arr = ['asc', 'desc'];
|
||
if (isset($where['now_money']) && in_array($where['now_money'], $order_arr)) {
|
||
$order_string = 'now_money ' . $where['now_money'];
|
||
}
|
||
$list = $this->dao->getListByModel($where, $field, $order_string, $page, $limit);
|
||
$count = $this->dao->getCountByWhere($where);
|
||
return [$list, $count];
|
||
}
|
||
|
||
/**
|
||
* 将会员列表筛选「HJF 等级(grade)」转为 eb_user.agent_level 条件,供 UserWechatUserDao 使用。
|
||
*/
|
||
protected function normalizeHjfMemberLevelWhere(array $where): array
|
||
{
|
||
if (!array_key_exists('hjf_member_level', $where)) {
|
||
return $where;
|
||
}
|
||
$raw = $where['hjf_member_level'];
|
||
if ($raw === null) {
|
||
unset($where['hjf_member_level']);
|
||
|
||
return $where;
|
||
}
|
||
if (is_string($raw)) {
|
||
$raw = trim($raw);
|
||
}
|
||
// 空串/仅空白:不按分销等级筛选(避免 (int)' '=>0 误加 agent_level=0)
|
||
if ($raw === '') {
|
||
unset($where['hjf_member_level']);
|
||
|
||
return $where;
|
||
}
|
||
$grade = (int)$raw;
|
||
/** @var AgentLevelServices $agentLevel */
|
||
$agentLevel = app()->make(AgentLevelServices::class);
|
||
if ($grade === 0) {
|
||
$where['hjf_agent_level_id'] = 0;
|
||
} else {
|
||
$where['hjf_agent_level_id'] = $agentLevel->getLevelIdByGrade($grade) ?: -1;
|
||
}
|
||
unset($where['hjf_member_level']);
|
||
|
||
return $where;
|
||
}
|
||
}
|