文件
fenleixinxi/application/admin/controller/user/User.php
linda 297e1a7f79 feat(admin): 会员列表去角色组/邮箱/等级列,手机号全量展示;新增微信手机号快捷获取接口
需求:后台「会员列表」取消『角色组 / 电子邮箱 / 等级』三列;手机号要全部能取到并展示。

- user/user 列表:移除 group.name / email / level 三列,手机号列移到昵称之后并加格式化:
  有绑定号→直接显示;未绑定但有发布信息→显示该会员最近一条发布信息的联系电话并标注「来自发布信息」;两者都没有→显示「未绑定」
- user/user 控制器 index():改用 toArray() 后按行补 mobile_source,未绑定手机号时回落到 fc_post.phone(不含软删)
- 新增 A5 POST /api/v1/auth/wx-phone:用小程序 access_token 调 phonenumber.getPhoneNumber 换号写入 fa_user.mobile;
  access_token 带缓存(fc_config wx.accessToken/wx.accessTokenExpire,提前 5 分钟失效);微信侧失败时给出「请改用手动输入」
  的业务文案,前端据此回落 A2 bind-phone —— 修复「微信会员手机号取不到」的根因(此前小程序侧绑定是假实现)
- 路由登记:application/route.php 新增 api/v1/auth/wx-phone
- tools/verify-api.mjs:新增 A5(缺 code 文案)与 A2(手机号格式)检查
2026-10-16 09:33:56 +08:00

130 行
3.7 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\admin\controller\user;
use app\common\controller\Backend;
use app\common\library\Auth;
use think\Db;
/**
* 会员管理
*
* @icon fa fa-user
*/
class User extends Backend
{
protected $relationSearch = true;
protected $searchFields = 'id,username,nickname';
/**
* @var \app\admin\model\User
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\User;
}
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with('group')
->where($where)
->order($sort, $order)
->paginate($limit);
$rows = [];
foreach ($list as $k => $v) {
$v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
$v->hidden(['password', 'salt']);
$item = $v->toArray();
// 手机号全量展示(v1.0.8):
// 微信登录注册的会员默认没有绑定手机号(fa_user.mobile 为空),
// 此时回落到「该会员最近一条发布信息里的联系电话」,并标记来源 mobile_source=post;
// 两者都没有则返回空串,前端显示「未绑定」。
$mobile = trim((string)$item['mobile']);
if ($mobile === '') {
$postPhone = Db::name('fc_post')
->where('user_id', $v->id)
->where('phone', '<>', '')
->whereNull('deletetime')
->order('id desc')
->value('phone');
if ($postPhone) {
$item['mobile'] = (string)$postPhone;
$item['mobile_source'] = 'post';
}
}
$rows[] = $item;
}
$result = ["total" => $list->total(), "rows" => $rows];
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$this->token();
}
return parent::add();
}
/**
* 编辑
*/
public function edit($ids = null)
{
if ($this->request->isPost()) {
$this->token();
}
$row = $this->model->get($ids);
$this->modelValidate = true;
if (!$row) {
$this->error(__('No Results were found'));
}
$this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
return parent::edit($ids);
}
/**
* 删除
*/
public function del($ids = "")
{
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$row = $this->model->get($ids);
$this->modelValidate = true;
if (!$row) {
$this->error(__('No Results were found'));
}
Auth::instance()->delete($row['id']);
$this->success();
}
}