$userId])->field($field) ->findOrEmpty(); $user['channel'] = UserTerminalEnum::getTermInalDesc($user['channel']); $user->sex = $user->getData('sex'); return $user->toArray(); } public function datas($params): array { $userWhere['id'] = 0; // 超级管理员数据 if (request()->adminInfo['root'] && !request()->adminInfo['user_id']) { unset($userWhere['id']); } // 普通用户数据 if (!request()->adminInfo['root'] && request()->adminInfo['user_id']) { $userWhere['id'] = request()->adminInfo['user_id']; } $where = []; if (!empty($params['keyword'])) { $where[] = ['sn|nickname|account|mobile', 'like', '%' . $params['keyword'] . '%']; } $field = "id,sn,nickname,sex,avatar,account,mobile,channel,is_disable,create_time"; $lists = User::where($userWhere)->where($where) ->limit(0, 100) ->field($field) ->order('id desc') ->select()->toArray(); foreach ($lists as &$item) { $item['userinfo'] = $item['id'] . ' / ' . $item['account']; } return $lists; } /** * @notes 更新用户信息 * @param array $params * @return User * @author 段誉 * @date 2022/9/22 16:38 */ public static function setUserInfo(array $params) { return User::update([ 'id' => $params['id'], $params['field'] => $params['value'] ]); } /** * @notes 调整用户余额 * @param array $params * @return bool|string * @author 段誉 * @date 2023/2/23 14:25 */ public static function adjustUserMoney(array $params) { Db::startTrans(); try { $user = User::find($params['user_id']); if (AccountLogEnum::INC == $params['action']) { //调整可用余额 $user->user_money += $params['num']; $user->save(); //记录日志 AccountLogLogic::add( $user->id, AccountLogEnum::UM_INC_ADMIN, AccountLogEnum::INC, $params['num'], '', $params['remark'] ?? '' ); } else { $user->user_money -= $params['num']; $user->save(); //记录日志 AccountLogLogic::add( $user->id, AccountLogEnum::UM_DEC_ADMIN, AccountLogEnum::DEC, $params['num'], '', $params['remark'] ?? '' ); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); return $e->getMessage(); } } }