diff --git a/server/application/admin/controller/Master.php b/server/application/admin/controller/Master.php
index 2e136ff..3a387be 100644
--- a/server/application/admin/controller/Master.php
+++ b/server/application/admin/controller/Master.php
@@ -841,4 +841,80 @@ class Master extends Backend
}
$this->success($target === 'disabled' ? '已停用该师傅账号并强制下线' : '已恢复启用该师傅账号');
}
+
+ /**
+ * 后台重置师傅登录密码或支付密码
+ */
+ public function resetpwd($ids = null)
+ {
+ $id = (int)($ids ?: $this->request->param('ids'));
+ $row = $this->model->find($id);
+ if (!$row) {
+ $this->error(__('No Results were found'));
+ }
+ $mid = (int)$row['id'];
+ $security = Db::name('master_security')->where('master_id', $mid)->find();
+
+ if ($this->request->isPost()) {
+ $this->token();
+ $params = $this->request->post('row/a', []);
+ $type = trim((string)($params['type'] ?? ''));
+ $newPassword = (string)($params['new_password'] ?? '');
+
+ if (!in_array($type, ['login', 'payment', 'both'], true)) {
+ $this->error('请选择有效的重置类型');
+ }
+ if ($type === 'login' && $newPassword !== '' && !preg_match('/^\S{6,30}$/', $newPassword)) {
+ $this->error('新登录密码须为6至30位非空字符');
+ }
+ if ($type === 'payment' && $newPassword !== '' && !preg_match('/^\d{6}$/', $newPassword)) {
+ $this->error('新支付密码须为6位数字');
+ }
+
+ Db::startTrans();
+ try {
+ \app\common\library\MasterSecurity::ensure($mid);
+
+ if ($type === 'login' || $type === 'both') {
+ if ($type === 'login' && $newPassword !== '') {
+ $salt = \fast\Random::alnum();
+ $encrypted = \app\common\library\MasterAuth::instance()->getEncryptPassword($newPassword, $salt);
+ Db::name('master')->where('id', $mid)->update(['password' => $encrypted, 'salt' => $salt, 'updatetime' => time()]);
+ } else {
+ Db::name('master')->where('id', $mid)->update(['password' => '', 'salt' => '', 'updatetime' => time()]);
+ }
+ Db::name('master_security')->where('master_id', $mid)->update([
+ 'failed_attempts' => 0,
+ 'locked_until' => 0,
+ ]);
+ }
+
+ if ($type === 'payment' || $type === 'both') {
+ $payHash = ($type === 'payment' && $newPassword !== '') ? password_hash($newPassword, PASSWORD_DEFAULT) : '';
+ Db::name('master_security')->where('master_id', $mid)->update([
+ 'payment_password_hash' => $payHash,
+ 'payment_failed_attempts' => 0,
+ 'payment_locked_until' => 0,
+ ]);
+ }
+
+ Db::commit();
+ } catch (\Throwable $e) {
+ Db::rollback();
+ $this->error('重置失败:' . $e->getMessage());
+ }
+
+ if ($type === 'login' || $type === 'both') {
+ \app\common\library\MasterToken::clear($mid);
+ }
+ $this->success('密码重置成功');
+ }
+
+ $this->view->assign([
+ 'row' => $row,
+ 'hasLoginPassword' => !empty($row['password']),
+ 'hasPaymentPassword' => $security && (string)$security['payment_password_hash'] !== '',
+ ]);
+ return $this->view->fetch();
+ }
}
diff --git a/server/application/admin/view/master/index.html b/server/application/admin/view/master/index.html
index 707e3e3..20426d0 100644
--- a/server/application/admin/view/master/index.html
+++ b/server/application/admin/view/master/index.html
@@ -23,6 +23,7 @@
diff --git a/server/application/admin/view/master/resetpwd.html b/server/application/admin/view/master/resetpwd.html
new file mode 100644
index 0000000..18e6b76
--- /dev/null
+++ b/server/application/admin/view/master/resetpwd.html
@@ -0,0 +1,50 @@
+
diff --git a/server/application/api/controller/MasterAuth.php b/server/application/api/controller/MasterAuth.php
index 2fe2b1d..35e6ed5 100644
--- a/server/application/api/controller/MasterAuth.php
+++ b/server/application/api/controller/MasterAuth.php
@@ -12,7 +12,7 @@ use think\Db;
*/
class MasterAuth extends MasterBase
{
- protected $noNeedLogin = ['login', 'wxlogin', 'wxPhoneLogin'];
+ protected $noNeedLogin = ['login', 'wxPhoneLogin'];
/**
* 师傅手机号 + 密码登录(H5调试/账号密码通道)
@@ -71,40 +71,12 @@ class MasterAuth extends MasterBase
}
/**
- * 师傅端微信小程序 OpenID 静默/授权登录
+ * 师傅端微信小程序 OpenID 静默登录(已下线,统一走微信手机号授权登录)
* @ApiMethod (POST)
*/
public function wxlogin()
{
- $code = trim((string)$this->request->post('code'));
- $nickname = trim((string)$this->request->post('nickname'));
- $avatar = trim((string)$this->request->post('avatar'));
- if ($code === '') {
- $this->error('缺少微信登录凭证 code');
- }
-
- $wx = WxLogin::jscode2session($code, 'master');
- if (isset($wx['error'])) {
- $this->error($wx['error'], ['wx_errcode' => isset($wx['errcode']) ? (int)$wx['errcode'] : 0]);
- }
-
- $ret = WxLogin::provisionMaster(
- $wx['openid'],
- isset($wx['unionid']) ? $wx['unionid'] : '',
- isset($wx['session_key']) ? $wx['session_key'] : '',
- $nickname,
- $avatar
- );
- if (!$this->masterAuth->direct($ret['master_id'])) {
- $this->error($this->masterAuth->getError() ?: '登录失败');
- }
-
- $this->success('登录成功', [
- 'token' => $this->masterAuth->getToken(),
- 'expires' => 2592000,
- 'masterinfo' => $this->profileData(),
- 'is_new' => $ret['is_new'],
- ]);
+ $this->error('师傅端已取消静默登录,请使用微信手机号授权登录');
}
/**
@@ -144,6 +116,10 @@ class MasterAuth extends MasterBase
}
$ret = WxLogin::provisionMasterWithMobile($mobile, $openid, $unionid, $sessionKey);
+ $masterRow = Db::name('master')->field('status')->where('id', $ret['master_id'])->find();
+ if ($masterRow && isset($masterRow['status']) && $masterRow['status'] !== 'normal') {
+ $this->error('师傅账号已被禁用');
+ }
if (!$this->masterAuth->direct($ret['master_id'])) {
$this->error($this->masterAuth->getError() ?: '登录失败');
}
@@ -176,21 +152,28 @@ class MasterAuth extends MasterBase
}
/**
- * 安全状态查询(登录密码 / 支付密码)
+ * 安全状态查询(登录密码 / 支付密码 / 绑定手机号 / 实名状态)
*/
public function securityStatus()
{
$mid = $this->masterId();
- $master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
+ $master = Db::name('master')->field('password,mobile,verify_status')->where('id', $mid)->find();
$security = Db::name('master_security')->where('master_id', $mid)->find();
+ $rawMobile = trim((string)($master['mobile'] ?? ''));
+ $maskedMobile = strlen($rawMobile) === 11
+ ? (substr($rawMobile, 0, 3) . '****' . substr($rawMobile, -4))
+ : $rawMobile;
+
$this->success('', [
'has_login_password' => !empty($master['password']),
'has_payment_password' => $security && $security['payment_password_hash'] !== '',
+ 'mobile' => $maskedMobile,
+ 'verify_status' => (string)($master['verify_status'] ?? 'draft'),
]);
}
/**
- * 设置或修改师傅登录密码
+ * 设置或修改师傅登录密码(未设置时直接设置,已设置时需校验原密码)
* @ApiMethod (POST)
*/
public function changeLoginPassword()
@@ -202,7 +185,7 @@ class MasterAuth extends MasterBase
$this->error('登录密码须为6至30位非空字符');
}
- $master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
+ $master = Db::name('master')->field('password')->where('id', $mid)->find();
if (!empty($master['password'])) {
try {
MasterSecurity::verify($mid, 'login', $old);
@@ -211,19 +194,23 @@ class MasterAuth extends MasterBase
}
$ignoreOld = false;
} else {
- $this->verifyBoundPhone($this->request->post('phone_code', ''), (string)$master['mobile']);
$ignoreOld = true;
}
if (!$this->masterAuth->changepwd($new, $old, $ignoreOld)) {
$this->error($this->masterAuth->getError() ?: '设置失败');
}
+ MasterSecurity::ensure($mid);
+ Db::name('master_security')->where('master_id', $mid)->update([
+ 'failed_attempts' => 0,
+ 'locked_until' => 0,
+ ]);
MasterToken::clear($mid);
$this->success('登录密码已更新,请重新登录');
}
/**
- * 首次设置师傅支付密码(支持已设登录密码走登录密码验证,或未设登录密码走绑定微信手机号验证)
+ * 首次设置师傅支付密码
* @ApiMethod (POST)
*/
public function setPaymentPassword()
@@ -234,20 +221,6 @@ class MasterAuth extends MasterBase
$this->error('支付密码须为6位数字');
}
- $master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
- $phoneCode = trim((string)$this->request->post('phone_code', ''));
- if ($phoneCode !== '') {
- $this->verifyBoundPhone($phoneCode, (string)($master['mobile'] ?? ''));
- } elseif (!empty($master['password'])) {
- try {
- MasterSecurity::verify($mid, 'login', (string)$this->request->post('login_password', ''));
- } catch (\Throwable $e) {
- $this->error($e->getMessage());
- }
- } else {
- $this->error('请先验证绑定手机号或设置登录密码');
- }
-
MasterSecurity::ensure($mid);
$updated = Db::name('master_security')
->where('master_id', $mid)
@@ -260,7 +233,7 @@ class MasterAuth extends MasterBase
}
/**
- * 修改师傅支付密码
+ * 修改师傅支付密码(需校验原支付密码)
* @ApiMethod (POST)
*/
public function changePaymentPassword()
@@ -286,18 +259,6 @@ class MasterAuth extends MasterBase
$this->success('支付密码修改成功');
}
- protected function verifyBoundPhone($code, $mobile)
- {
- if (trim((string)$code) === '') {
- $this->error('请先验证绑定的微信手机号');
- }
- $phone = WxLogin::getPhoneNumber((string)$code, 'master');
- $verified = isset($phone['purePhoneNumber']) ? (string)$phone['purePhoneNumber'] : (string)($phone['phoneNumber'] ?? '');
- if (isset($phone['error']) || $verified === '' || !hash_equals((string)$mobile, $verified)) {
- $this->error('手机号验证失败,请使用绑定手机号重新验证');
- }
- }
-
protected function profileData()
{
$mid = $this->masterId();
diff --git a/server/public/assets/js/backend/master.js b/server/public/assets/js/backend/master.js
index c5fc8ac..2cc348f 100644
--- a/server/public/assets/js/backend/master.js
+++ b/server/public/assets/js/backend/master.js
@@ -175,6 +175,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'backend/admin-table-layout',
icon: 'fa fa-certificate',
classname: 'btn btn-xs btn-success btn-dialog btn-skills-mst',
url: 'master/skills'
+ },
+ {
+ name: 'resetpwd',
+ text: '重置密码',
+ title: function (row) {
+ return '重置密码 - ' + (row.realname || row.nickname || row.mobile);
+ },
+ icon: 'fa fa-key',
+ classname: 'btn btn-xs btn-warning btn-dialog btn-resetpwd-mst',
+ url: 'master/resetpwd',
+ visible: function () { return !!table.data('operate-resetpwd'); }
}
]
}
@@ -230,6 +241,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'backend/admin-table-layout',
audit: function () {
Controller.api.bindevent();
},
+ resetpwd: function () {
+ var $form = $("#resetpwd-form");
+ var $pwdGroup = $("#new-password-group");
+ var $pwdInput = $("#c-new-password");
+ $form.on("change", "input[name='row[type]']", function () {
+ var val = $(this).val();
+ if (val === 'both') {
+ $pwdInput.val('');
+ $pwdGroup.hide();
+ } else {
+ $pwdGroup.show();
+ $pwdInput.attr('maxlength', val === 'payment' ? 6 : 30);
+ }
+ });
+ Controller.api.bindevent();
+ },
detail: function () {
$(document).on('click', '.btn-master-unbind-wx', function () {
var id = $(this).data('id');
diff --git a/yjyf-master-app/pages/master/security.vue b/yjyf-master-app/pages/master/security.vue
index 9073150..edf922d 100644
--- a/yjyf-master-app/pages/master/security.vue
+++ b/yjyf-master-app/pages/master/security.vue
@@ -2,50 +2,166 @@
-
-
- 登录密码
- {{ status.has_login_password ? '已设置' : '未设置' }}
+
+
+
+
+
+ {{ isAccountSafe ? '账号安全保护中' : '建议完善安全设置' }}
+ 登录账号:{{ status.mobile || '-' }}
+
-
- 支付密码(用于提现验证)
- {{ status.has_payment_password ? '已设置' : '未设置' }}
+
+
+
+
+ 账号信息
+
+
+ 绑定手机号
+
+ {{ status.mobile || '-' }}
+ 已绑定
+
+
+
+ 实名认证
+
+ {{ verifyStatusText }}
+
+
+
+
+
+
+
+
+ 安全凭证
+
+
+
+ 登录密码
+ 用于 H5 网页端手机号密码登录
+
+
+ {{ status.has_login_password ? '已设置' : '未设置' }}
+
+
+
+
+
+ 支付密码
+ 用于余额提现安全确认
+
+
+ {{ status.has_payment_password ? '已设置' : '未设置' }}
+
+
+
+
+
+
+ 退出登录
- 退出登录
-
-
- {{ sheetTitle }}取消
+
+
+
+
+ {{ sheetTitle }}
+ 取消
+
+
+
-
-
-
- 请使用绑定的微信手机号验证身份。
-
-
-
-
- 请在微信小程序中完成手机号验证后设置。
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 如忘记原密码,请联系平台管理员在后台重置
+
+
-
-
-
-
-
- 当前尚未设置登录密码,请通过绑定微信手机号验证后设置支付密码。
-
-
-
-
- 请在微信小程序内完成手机号验证,或先设置登录密码。
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 如忘记原支付密码,请联系平台管理员在后台重置
@@ -70,8 +186,31 @@
const oldPassword = ref('');
const newPassword = ref('');
const confirmPassword = ref('');
+ const showOldPwd = ref(false);
+ const showNewPwd = ref(false);
+ const showConfirmPwd = ref(false);
- const sheetTitle = computed(() => mode.value === 'login' ? '登录密码' : '支付密码');
+ const isAccountSafe = computed(() => !!(status.value.mobile && status.value.has_payment_password));
+
+ const verifyStatusText = computed(() => {
+ const map = { pass: '已认证', pending: '审核中', reject: '未通过', draft: '未认证' };
+ return map[status.value.verify_status] || '未认证';
+ });
+
+ const verifyTagClass = computed(() => {
+ const st = status.value.verify_status;
+ if (st === 'pass') return 'tag-success';
+ if (st === 'pending') return 'tag-warning';
+ if (st === 'reject') return 'tag-danger';
+ return 'tag-muted';
+ });
+
+ const sheetTitle = computed(() => {
+ if (mode.value === 'login') {
+ return status.value.has_login_password ? '修改登录密码' : '设置登录密码';
+ }
+ return status.value.has_payment_password ? '修改支付密码' : '设置支付密码';
+ });
async function load() {
if (!isLogin()) {
@@ -84,64 +223,86 @@
} catch (e) {}
}
- function close() {
- if (busy.value) return;
- mode.value = '';
+ function resetFormFields() {
oldPassword.value = '';
newPassword.value = '';
confirmPassword.value = '';
+ showOldPwd.value = false;
+ showNewPwd.value = false;
+ showConfirmPwd.value = false;
+ }
+
+ function close() {
+ if (busy.value) return;
+ mode.value = '';
+ resetFormFields();
}
function openPassword(which) {
+ resetFormFields();
mode.value = which;
}
+ function goVerifyStatus() {
+ if (status.value.verify_status === 'pass') return;
+ uni.navigateTo({ url: '/pages/master/apply' });
+ }
+
function validPassword() {
- const valid = mode.value === 'payment' ? /^\d{6}$/.test(newPassword.value) : /^\S{6,30}$/.test(newPassword.value);
- if (!valid || newPassword.value !== confirmPassword.value) {
- uni.showToast({ title: '请检查两次输入的密码', icon: 'none' });
+ const isPayment = mode.value === 'payment';
+ const needOld = isPayment ? status.value.has_payment_password : status.value.has_login_password;
+ if (needOld && !oldPassword.value) {
+ uni.showToast({ title: '请输入原密码', icon: 'none' });
+ return false;
+ }
+
+ if (isPayment) {
+ if (!/^\d{6}$/.test(newPassword.value)) {
+ uni.showToast({ title: '支付密码须为6位数字', icon: 'none' });
+ return false;
+ }
+ } else {
+ if (!/^\S{6,30}$/.test(newPassword.value)) {
+ uni.showToast({ title: '登录密码须为6至30位非空字符', icon: 'none' });
+ return false;
+ }
+ }
+
+ if (newPassword.value !== confirmPassword.value) {
+ uni.showToast({ title: '两次输入的新密码不一致', icon: 'none' });
return false;
}
return true;
}
- async function onPhoneVerifyLogin(event) {
- const code = event.detail && event.detail.code;
- if (!code) { uni.showToast({ title: '未完成手机号验证', icon: 'none' }); return; }
- await savePassword(code);
- }
-
- async function onPhoneVerifyPayment(event) {
- const code = event.detail && event.detail.code;
- if (!code) { uni.showToast({ title: '未完成手机号验证', icon: 'none' }); return; }
- await savePassword(code);
- }
-
- async function savePassword(phoneCode = '') {
- if (typeof phoneCode !== 'string') phoneCode = '';
+ async function savePassword() {
if (busy.value || !validPassword()) return;
busy.value = true;
try {
if (mode.value === 'login') {
- await api.changeLoginPassword({ old_password: oldPassword.value, new_password: newPassword.value, phone_code: phoneCode });
+ await api.changeLoginPassword({
+ old_password: oldPassword.value,
+ new_password: newPassword.value
+ });
clearAuth();
- uni.showToast({ title: '请重新登录', icon: 'none' });
- setTimeout(() => uni.reLaunch({ url: '/pages/login/login' }), 700);
+ uni.showToast({ title: '密码已更新,请重新登录', icon: 'none' });
+ setTimeout(() => uni.reLaunch({ url: '/pages/login/login' }), 800);
return;
}
+
const firstSetup = !status.value.has_payment_password;
- if (!firstSetup) {
- await api.changePaymentPassword({ old_password: oldPassword.value, new_password: newPassword.value });
+ if (firstSetup) {
+ await api.setPaymentPassword({ new_password: newPassword.value });
} else {
- await api.setPaymentPassword({
- login_password: oldPassword.value,
- phone_code: phoneCode,
+ await api.changePaymentPassword({
+ old_password: oldPassword.value,
new_password: newPassword.value
});
}
+
busy.value = false;
close();
- uni.showToast({ title: '保存成功' });
+ uni.showToast({ title: firstSetup ? '设置成功' : '修改成功', icon: 'success' });
if (setupFromPayment.value && firstSetup) {
try { await finishPaymentSetup(uni); } catch (e) { uni.showToast({ title: e.message, icon: 'none' }); }
} else {
@@ -168,8 +329,9 @@
title: '退出登录',
content: '确认退出当前师傅账号?',
confirmColor: '#F0710D',
- success: (result) => {
+ success: async (result) => {
if (result.confirm) {
+ try { await api.logout(); } catch (e) {}
clearAuth();
uni.reLaunch({ url: '/pages/login/login' });
}
@@ -202,20 +364,116 @@
diff --git a/yjyf-master-app/utils/api.js b/yjyf-master-app/utils/api.js
index 7695990..c7e8be5 100644
--- a/yjyf-master-app/utils/api.js
+++ b/yjyf-master-app/utils/api.js
@@ -16,7 +16,6 @@ export default {
/* ---------- 师傅端独立鉴权与安全 ---------- */
login: (data) => post('/master_auth/login', data, { silent: true }),
- wxLogin: (data) => post('/master_auth/wxlogin', data, { silent: true }),
wxPhoneLogin: (data) => post('/master_auth/wxPhoneLogin', data, { silent: true }),
logout: () => post('/master_auth/logout', {}, { silent: true }),
profile: () => get('/master_auth/profile'),
diff --git a/yjyf-master-app/utils/wxlogin.js b/yjyf-master-app/utils/wxlogin.js
index 2f61f7a..6f315d8 100644
--- a/yjyf-master-app/utils/wxlogin.js
+++ b/yjyf-master-app/utils/wxlogin.js
@@ -1,17 +1,8 @@
/**
- * 微信登录统一入口
- * 解决两个线上问题:
- * 1) code 一次性(5 分钟、单次有效)——静默登录与手动登录若同时发起会互相抢 code
- * → 用「单飞(in-flight)」保证同一时刻只有一个换取流程
- * 2) 40029(invalid code)——可能来自 code 已被消费/过期
- * → 自动用全新 code 重试一次
+ * 微信登录辅助工具
+ * 师傅端统一使用「获取微信手机号」登录,不做 OpenID 静默登录。
+ * 此处仅提供 getWxCode() 用于在手机号授权时同步换取 OpenID 完成绑定。
*/
-import api from './api.js';
-import { setToken, setUser } from './request.js';
-
-let inflight = null;
-
-/** 取微信一次性 code */
export function getWxCode() {
return new Promise((resolve, reject) => {
uni.login({
@@ -21,45 +12,3 @@ export function getWxCode() {
});
});
}
-
-function isCodeInvalid(err) {
- const code = err && err.data ? Number(err.data.wx_errcode) : 0;
- if (code === 40029 || code === 40163) return true;
- return /invalid code|code been used|40029/i.test((err && err.message) || '');
-}
-
-/**
- * 用 code 换 token;遇到 code 失效自动换新 code 重试一次
- */
-async function exchange(payload, retry) {
- const code = await getWxCode();
- try {
- const data = await api.wxLogin(Object.assign({}, payload, { code: code }));
- setToken(data.token);
- setUser(data.masterinfo || data.userinfo);
- return data;
- } catch (err) {
- if (retry && isCodeInvalid(err)) {
- return exchange(payload, false);
- }
- throw err;
- }
-}
-
-/**
- * 主动授权登录(点击「微信一键登录」)
- */
-export function wxAuthorizeLogin(payload) {
- if (inflight) {
- // 复用在途结果,避免抢同一个 code
- return inflight.then((data) => {
- if (data) return data;
- return exchange(payload || {}, true);
- });
- }
- inflight = exchange(payload || {}, true).then(
- (data) => { inflight = null; return data; },
- (err) => { inflight = null; throw err; }
- );
- return inflight;
-}