feat: 新增账号安全模块及资质校验功能
- 新增账号安全页面及支付密码验证组件 - 新增用户类型选择流程及商家资质管理 - 新增订单资质校验逻辑,师傅需满足订单证书要求 - 新增企业资质认证相关数据库表及接口 - 优化用户列表展示,区分个人与商家用户类型
这个提交包含在:
@@ -43,6 +43,9 @@ class Auth extends Base
|
||||
|
||||
if (!$user) {
|
||||
// 若数据库中无此手机号:直连数据库插入注册新会员
|
||||
if (!preg_match('/^\S{6,30}$/', $password)) {
|
||||
$this->error('登录密码须为6至30位非空字符');
|
||||
}
|
||||
$ret = $this->auth->register($mobile, $password, '', $mobile, []);
|
||||
if (!$ret) {
|
||||
$this->error($this->auth->getError() ?: '注册登录失败');
|
||||
@@ -54,9 +57,10 @@ class Auth extends Base
|
||||
if (empty($user['password'])) {
|
||||
$this->error('该账号尚未设置登录密码,请使用微信一键登录后设置密码');
|
||||
}
|
||||
$encryptPassword = $this->auth->getEncryptPassword($password, $user['salt']);
|
||||
if ($user['password'] !== $encryptPassword) {
|
||||
$this->error('手机号或密码不正确');
|
||||
try {
|
||||
\app\common\library\AccountSecurity::verify((int)$user['id'], 'login', $password);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage() === '密码不正确' ? '手机号或密码不正确' : $e->getMessage());
|
||||
}
|
||||
$this->auth->direct($user['id']);
|
||||
}
|
||||
@@ -83,7 +87,7 @@ class Auth extends Base
|
||||
protected function profileData()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$user = Db::name('user')->field('id,nickname,mobile,email,avatar,money,score,user_type,contact_address,createtime')->where('id', $uid)->find();
|
||||
$user = Db::name('user')->field('id,nickname,mobile,email,avatar,money,score,user_type,identity_selected,company_name,company_legal_person,company_legal_mobile,company_tech_mobile,contact_address,createtime')->where('id', $uid)->find();
|
||||
$master = Db::name('master')->where('user_id', $uid)->find();
|
||||
|
||||
$couponCount = Db::name('user_coupon')->where('user_id', $uid)->where('status', 'unused')->count();
|
||||
@@ -152,13 +156,7 @@ class Auth extends Base
|
||||
'pending_verify' => $getCnt(7),
|
||||
];
|
||||
|
||||
if ($merchantRole === 'member' && $merchant && $merchant['verify_status'] === 'pass') {
|
||||
$userType = 'merchant';
|
||||
} elseif (!empty($user['user_type']) && in_array($user['user_type'], ['personal', 'merchant'], true)) {
|
||||
$userType = $user['user_type'];
|
||||
} else {
|
||||
$userType = ($merchant && $merchant['verify_status'] === 'pass') ? 'merchant' : 'personal';
|
||||
}
|
||||
$userType = in_array($user['user_type'], ['personal', 'merchant'], true) ? $user['user_type'] : 'personal';
|
||||
|
||||
return [
|
||||
'id' => (int)$user['id'],
|
||||
@@ -167,10 +165,11 @@ class Auth extends Base
|
||||
'email' => !empty($user['email']) ? (string)$user['email'] : ($merchant && !empty($merchant['email']) ? (string)$merchant['email'] : ''),
|
||||
'contact_address' => !empty($user['contact_address']) ? (string)$user['contact_address'] : ($merchant ? (string)($merchant['province'] . $merchant['city'] . $merchant['district'] . $merchant['address']) : ''),
|
||||
'user_type' => $userType,
|
||||
'company_name' => $merchant ? (string)$merchant['name'] : '',
|
||||
'legal_person' => $merchant && isset($merchant['legal_person']) ? (string)$merchant['legal_person'] : '',
|
||||
'legal_mobile' => $merchant && isset($merchant['legal_mobile']) ? (string)$merchant['legal_mobile'] : '',
|
||||
'tech_mobile' => $merchant && isset($merchant['tech_mobile']) ? (string)$merchant['tech_mobile'] : '',
|
||||
'identity_selected' => (bool)$user['identity_selected'],
|
||||
'company_name' => $user['company_name'] !== '' ? $user['company_name'] : ($merchant ? (string)$merchant['name'] : ''),
|
||||
'legal_person' => $user['company_legal_person'] !== '' ? $user['company_legal_person'] : ($merchant ? (string)($merchant['legal_person'] ?? '') : ''),
|
||||
'legal_mobile' => $user['company_legal_mobile'] !== '' ? $user['company_legal_mobile'] : ($merchant ? (string)($merchant['legal_mobile'] ?? '') : ''),
|
||||
'tech_mobile' => $user['company_tech_mobile'] !== '' ? $user['company_tech_mobile'] : ($merchant ? (string)($merchant['tech_mobile'] ?? '') : ''),
|
||||
'avatar' => !empty($user['avatar']) ? (strpos((string)$user['avatar'], 'http') === 0 ? $user['avatar'] : cdnurl($user['avatar'], true)) : '',
|
||||
'balance' => (float)$user['money'],
|
||||
'coupon_count' => (int)$couponCount,
|
||||
@@ -190,10 +189,14 @@ class Auth extends Base
|
||||
public function saveAccount()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$currentUserType = Db::name('user')->where('id', $uid)->value('user_type');
|
||||
$userType = trim((string)$this->request->post('user_type', $currentUserType ?: 'personal'));
|
||||
if (!in_array($userType, ['personal', 'merchant'], true)) {
|
||||
$userType = 'personal';
|
||||
$currentUser = Db::name('user')->where('id', $uid)->find();
|
||||
$userType = (string)$currentUser['user_type'];
|
||||
$requestedType = $this->request->post('user_type', null);
|
||||
if ($requestedType !== null && $requestedType !== $userType) {
|
||||
$this->error('用户类型确定后不可自行修改');
|
||||
}
|
||||
if (empty($currentUser['identity_selected'])) {
|
||||
$this->error('请先选择用户类型');
|
||||
}
|
||||
$nickname = trim((string)$this->request->post('nickname', ''));
|
||||
$mobile = trim((string)$this->request->post('mobile', ''));
|
||||
@@ -221,19 +224,18 @@ class Auth extends Base
|
||||
}
|
||||
|
||||
$merchantRel = $this->merchantOf($uid);
|
||||
if ($userType === 'merchant') {
|
||||
if (!$merchantRel || ($merchantRel['merchant']['verify_status'] ?? '') !== 'pass') {
|
||||
$this->error('请先提交企业入驻申请并通过审核后再启用商家账号');
|
||||
}
|
||||
}
|
||||
|
||||
$userUpdate = [
|
||||
'nickname' => $nickname,
|
||||
'user_type' => $userType,
|
||||
'contact_address' => $contactAddress,
|
||||
'email' => $email,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
if ($userType === 'merchant') {
|
||||
foreach (['company_name' => $companyName, 'company_legal_person' => $legalPerson, 'company_legal_mobile' => $legalMobile, 'company_tech_mobile' => $techMobile] as $field => $value) {
|
||||
$requestField = ['company_name' => 'company_name', 'company_legal_person' => 'legal_person', 'company_legal_mobile' => 'legal_mobile', 'company_tech_mobile' => 'tech_mobile'][$field];
|
||||
if ($this->request->has($requestField, 'post')) $userUpdate[$field] = $value;
|
||||
}
|
||||
}
|
||||
if ($mobile !== '' && preg_match('/^1\d{10}$/', $mobile)) {
|
||||
$conflict = Db::name('user')->where('mobile', $mobile)->where('id', '<>', $uid)->find();
|
||||
if ($conflict) {
|
||||
@@ -268,6 +270,22 @@ class Auth extends Base
|
||||
$this->success('保存成功', ['userinfo' => $this->profileData()]);
|
||||
}
|
||||
|
||||
/** 首次登录选择用户类型,原子更新防止重复选择。 */
|
||||
public function selectIdentity()
|
||||
{
|
||||
$type = trim((string)$this->request->post('user_type', ''));
|
||||
if (!in_array($type, ['personal', 'merchant'], true)) {
|
||||
$this->error('请选择个人用户或商家用户');
|
||||
}
|
||||
$updated = Db::name('user')->where('id', $this->uid())->where('identity_selected', 0)->update([
|
||||
'user_type' => $type, 'identity_selected' => 1, 'updatetime' => time(),
|
||||
]);
|
||||
if (!$updated) {
|
||||
$this->error('用户类型确定后不可自行修改');
|
||||
}
|
||||
$this->success('选择成功', ['userinfo' => $this->profileData()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信授权登录(小程序 uni.login 拿到的 code)
|
||||
* @ApiMethod (POST)
|
||||
|
||||
@@ -35,6 +35,16 @@ class Base extends Api
|
||||
return (int)$this->auth->id;
|
||||
}
|
||||
|
||||
/** Verify the account payment password before any balance debit. */
|
||||
protected function requirePaymentPassword()
|
||||
{
|
||||
try {
|
||||
\app\common\library\AccountSecurity::verify($this->uid(), 'payment', (string)$this->request->post('payment_password', ''));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** 验证新头像属于当前账号,且是符合限制的图片附件。 */
|
||||
protected function validateAvatar($url)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ use app\common\library\CommissionService;
|
||||
use app\common\library\FinanceConfigService;
|
||||
use app\common\library\FinishImageUrls;
|
||||
use app\common\library\OrderStatus;
|
||||
use app\common\library\OrderQualification;
|
||||
use app\common\library\PaymentService;
|
||||
use app\common\library\TiandituService;
|
||||
use app\common\library\TencentVerifyService;
|
||||
@@ -750,7 +751,10 @@ class Master extends Base
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$qualificationCerts = OrderQualification::certificates((int)$master['id']);
|
||||
$qualificationToday = date('Y-m-d');
|
||||
foreach ($list as &$row) {
|
||||
$row['qualification_allowed'] = OrderQualification::allows($row['qual_req'], $qualificationCerts, $qualificationToday);
|
||||
unset($row['verify_code'], $row['_has_coord'], $row['_dist_km'], $row['_same_city']);
|
||||
$row['appoint_text'] = $row['appoint_time'] ? date('Y-m-d H:i', (int)$row['appoint_time']) : '接单后与业主预约';
|
||||
$row['pay_amount'] = (float)$row['pay_amount'];
|
||||
@@ -897,6 +901,9 @@ class Master extends Base
|
||||
if ((int)$order['status'] !== OrderStatus::PENDING_ACCEPT || (int)$order['master_id'] !== 0) {
|
||||
$this->error('手慢了,该订单已被接走');
|
||||
}
|
||||
if (!OrderQualification::forMaster($order['qual_req'] ?? '', (int)$master['id'])) {
|
||||
$this->error('该订单要求持有已审核通过且有效的「' . $order['qual_req'] . '」,请先上传认证证书');
|
||||
}
|
||||
|
||||
$affected = Db::name('order')
|
||||
->where('id', $orderId)
|
||||
@@ -1320,6 +1327,9 @@ class Master extends Base
|
||||
if ((int)$order['master_id'] > 0) {
|
||||
$this->error('该订单已选定师傅');
|
||||
}
|
||||
if (!OrderQualification::forMaster($order['qual_req'] ?? '', (int)$master['id'])) {
|
||||
$this->error('该订单要求持有已审核通过且有效的「' . $order['qual_req'] . '」,请先上传认证证书');
|
||||
}
|
||||
if ($amount <= 0) {
|
||||
$this->error('请填写报价金额');
|
||||
}
|
||||
@@ -1354,6 +1364,7 @@ class Master extends Base
|
||||
public function withdraw()
|
||||
{
|
||||
$master = $this->requireMaster();
|
||||
$this->requirePaymentPassword();
|
||||
$amount = round((float)$this->request->post('amount'), 2);
|
||||
$wxCode = trim((string)$this->request->post('wx_code', ''));
|
||||
$channel = trim((string)$this->request->post('channel', 'wechat'));
|
||||
@@ -2331,6 +2342,7 @@ class Master extends Base
|
||||
$estCommission = $estCalc['commission'];
|
||||
$estMasterFee = $estCalc['settle_amount'];
|
||||
|
||||
$qualificationAllowed = OrderQualification::forMaster($order['qual_req'] ?? '', $masterId);
|
||||
$data = [
|
||||
'id' => (int)$order['id'],
|
||||
'order_no' => $order['order_no'],
|
||||
@@ -2368,6 +2380,7 @@ class Master extends Base
|
||||
'express_company' => (string)($order['express_company'] ?? ''),
|
||||
'goods_arrived' => (int)($order['goods_arrived'] ?? 1),
|
||||
'qual_req' => (string)($order['qual_req'] ?? ''),
|
||||
'qualification_allowed' => $qualificationAllowed,
|
||||
'master_req' => (string)($order['master_req'] ?? ''),
|
||||
'contact' => $contactDisplay,
|
||||
'mobile' => $mobile,
|
||||
@@ -2392,8 +2405,8 @@ class Master extends Base
|
||||
'description' => $myQuote['description'],
|
||||
'status' => $myQuote['status'],
|
||||
] : null,
|
||||
'can_grab' => ($order['price_type'] !== 'quote' && (int)$order['status'] === OrderStatus::PENDING_ACCEPT && (int)$order['master_id'] === 0 && (int)$order['user_id'] !== $this->uid()),
|
||||
'can_quote' => ($order['price_type'] === 'quote' && in_array((int)$order['status'], [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING], true) && (int)$order['master_id'] === 0 && !$myQuote && (int)$order['user_id'] !== $this->uid()),
|
||||
'can_grab' => ($qualificationAllowed && $order['price_type'] !== 'quote' && (int)$order['status'] === OrderStatus::PENDING_ACCEPT && (int)$order['master_id'] === 0 && (int)$order['user_id'] !== $this->uid()),
|
||||
'can_quote' => ($qualificationAllowed && $order['price_type'] === 'quote' && in_array((int)$order['status'], [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING], true) && (int)$order['master_id'] === 0 && !$myQuote && (int)$order['user_id'] !== $this->uid()),
|
||||
];
|
||||
|
||||
// 本人已接工单:附带完整履约节点、增项补差、完工取证、结算入账与操作轨迹
|
||||
@@ -2943,7 +2956,7 @@ class Master extends Base
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'notice' => '请上传本人真实的技能证书信息。技能证书审核通过后,才能接商家指定资质要求的订单。',
|
||||
'notice' => '请上传本人真实的技能证书信息。审核通过且在有效期内的证书名称会展示给相关订单用户。',
|
||||
'is_master_applied' => $master ? 1 : 0,
|
||||
'verify_status' => $master ? (string)$master['verify_status'] : '',
|
||||
'items' => $items,
|
||||
|
||||
@@ -591,53 +591,12 @@ class Merchant extends Base
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 要求已通过审核的商家
|
||||
* 若当前用户为 merchant 类型但无 merchant 档案,则自动创建一条空档案兜底
|
||||
* 同一 user_id 只能创建一条(user_id 唯一约束已由后台 add() 保证)
|
||||
*/
|
||||
/** 要求商家档案已通过审核;账号类型不代表企业资质。 */
|
||||
protected function requireMerchant()
|
||||
{
|
||||
$m = $this->merchantInfo();
|
||||
if (!$m) {
|
||||
$curUser = Db::name('user')->where('id', $this->uid())->find();
|
||||
if ($curUser && !empty($curUser['user_type']) && $curUser['user_type'] === 'merchant') {
|
||||
// 再次确认:user_id 必须唯一,防止并发创建重复记录
|
||||
$existCheck = Db::name('merchant')->where('user_id', $this->uid())->find();
|
||||
if ($existCheck) {
|
||||
if ($existCheck['verify_status'] !== 'pass') {
|
||||
Db::name('merchant')->where('id', (int)$existCheck['id'])->update([
|
||||
'verify_status' => 'pass',
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
$existCheck['verify_status'] = 'pass';
|
||||
}
|
||||
return $existCheck;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$newId = Db::name('merchant')->insertGetId([
|
||||
'user_id' => $this->uid(),
|
||||
'name' => !empty($curUser['nickname']) ? (string)$curUser['nickname'] : '商家用户',
|
||||
'license_no' => null,
|
||||
'contact' => (string)$curUser['nickname'],
|
||||
'mobile' => (string)$curUser['mobile'],
|
||||
'address' => isset($curUser['contact_address']) ? (string)$curUser['contact_address'] : '',
|
||||
'email' => isset($curUser['email']) ? (string)$curUser['email'] : '',
|
||||
'verify_status' => 'pass',
|
||||
'createtime' => $now,
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
return Db::name('merchant')->where('id', $newId)->find();
|
||||
}
|
||||
$this->error('请先在「账号信息」切换为商家类型', null, 2001);
|
||||
}
|
||||
if ($m['verify_status'] !== 'pass') {
|
||||
Db::name('merchant')->where('id', (int)$m['id'])->update([
|
||||
'verify_status' => 'pass',
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
$m['verify_status'] = 'pass';
|
||||
if (!$m || $m['verify_status'] !== 'pass') {
|
||||
$this->error('请先完成商家资质审核', null, 2001);
|
||||
}
|
||||
return $m;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use app\common\library\FinanceConfigService;
|
||||
use app\common\library\OrderStatus;
|
||||
use app\common\library\OrderServiceSnapshot;
|
||||
use app\common\library\OrderPaymentResultService;
|
||||
use app\common\library\MasterOrderCredentials;
|
||||
use app\common\library\PaymentService;
|
||||
use app\common\library\TiandituService;
|
||||
use think\Db;
|
||||
@@ -640,6 +641,7 @@ class Order extends Base
|
||||
|
||||
try {
|
||||
if ($payType === 'balance') {
|
||||
$this->requirePaymentPassword();
|
||||
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'order');
|
||||
} else {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'order', 0, $wxCode);
|
||||
@@ -725,6 +727,7 @@ class Order extends Base
|
||||
|
||||
try {
|
||||
if ($payType === 'balance') {
|
||||
$this->requirePaymentPassword();
|
||||
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'diff');
|
||||
} else {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'diff', 0, $wxCode);
|
||||
@@ -1035,6 +1038,23 @@ class Order extends Base
|
||||
}
|
||||
}
|
||||
|
||||
// 一次性读取订单关联师傅的公开技能与有效证书,避免报价列表逐人查询。
|
||||
$credentialMasterIds = array_column($quotes, 'master_id');
|
||||
if ($master) $credentialMasterIds[] = $master['id'];
|
||||
$credentialMasterIds = array_values(array_unique(array_filter(array_map('intval', $credentialMasterIds))));
|
||||
if ($credentialMasterIds) {
|
||||
$skillRows = Db::name('master_skill')->field('master_id,skill_name,status')
|
||||
->where('master_id', 'in', $credentialMasterIds)->where('status', 'normal')->select();
|
||||
$certRows = Db::name('master_cert')->field('master_id,cert_name,status,is_long_term,expire_date')
|
||||
->where('master_id', 'in', $credentialMasterIds)->where('status', 'pass')->select();
|
||||
$credentials = MasterOrderCredentials::project($credentialMasterIds, $skillRows, $certRows, date('Y-m-d'));
|
||||
if ($master) $master = array_merge($master, $credentials[$master['id']]);
|
||||
foreach ($quotes as &$quote) {
|
||||
if (isset($credentials[$quote['master_id']])) $quote = array_merge($quote, $credentials[$quote['master_id']]);
|
||||
}
|
||||
unset($quote);
|
||||
}
|
||||
|
||||
$creatorUser = Db::name('user')->where('id', (int)$order['user_id'])->find();
|
||||
$rawCreatorMobile = (string)(($creatorUser && !empty($creatorUser['mobile'])) ? $creatorUser['mobile'] : $order['mobile']);
|
||||
$maskedCreatorMobile = strlen($rawCreatorMobile) >= 7 ? substr_replace($rawCreatorMobile, '****', 3, 4) : $rawCreatorMobile;
|
||||
@@ -1224,8 +1244,14 @@ class Order extends Base
|
||||
$payType = trim((string)$this->request->post('pay_type', 'wechat'));
|
||||
$order = $this->ownOrder($orderId, 'user');
|
||||
|
||||
$quoteMasterId = (int)Db::name('order_quote')->where('id', $quoteId)->where('order_id', $orderId)->value('master_id');
|
||||
if ($quoteMasterId > 0 && !\app\common\library\OrderQualification::forMaster($order['qual_req'] ?? '', $quoteMasterId)) {
|
||||
$this->error('该师傅目前没有符合订单要求的有效认证证书,请选择其他师傅');
|
||||
}
|
||||
|
||||
try {
|
||||
if ($payType === 'balance') {
|
||||
$this->requirePaymentPassword();
|
||||
$res = PaymentService::payOrderByBalance($order, $this->uid(), 'quote', $quoteId);
|
||||
} else {
|
||||
$res = PaymentService::createOrderJsapiPay($order, $this->uid(), 'quote', $quoteId, $wxCode);
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\library\AccountSecurity;
|
||||
use app\common\library\WxLogin;
|
||||
use app\common\library\TencentVerifyService;
|
||||
use app\common\library\EnterpriseLicenseImage;
|
||||
use think\Db;
|
||||
|
||||
class Security extends Base
|
||||
{
|
||||
private function verifyBoundPhone($code, $mobile)
|
||||
{
|
||||
if (trim((string)$code) === '') $this->error('请先验证绑定的微信手机号');
|
||||
$phone = WxLogin::getPhoneNumber((string)$code);
|
||||
$verified = isset($phone['purePhoneNumber']) ? (string)$phone['purePhoneNumber'] : (string)($phone['phoneNumber'] ?? '');
|
||||
if (isset($phone['error']) || $verified === '' || !hash_equals((string)$mobile, $verified)) {
|
||||
$this->error('手机号验证失败,请使用绑定手机号重新验证');
|
||||
}
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
$user = Db::name('user')->field('password,mobile')->where('id', $this->uid())->find();
|
||||
$security = Db::name('user_security')->where('user_id', $this->uid())->find();
|
||||
$cert = Db::name('user_enterprise_cert')->where('user_id', $this->uid())->find();
|
||||
$this->success('', [
|
||||
'has_login_password' => !empty($user['password']),
|
||||
'has_payment_password' => $security && $security['payment_password_hash'] !== '',
|
||||
'enterprise_cert' => $cert ?: null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeLoginPassword()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$new = (string)$this->request->post('new_password', '');
|
||||
$old = (string)$this->request->post('old_password', '');
|
||||
if (!preg_match('/^\S{6,30}$/', $new)) $this->error('登录密码须为6至30位非空字符');
|
||||
$user = Db::name('user')->field('password,mobile')->where('id', $uid)->find();
|
||||
if (!empty($user['password'])) {
|
||||
try { AccountSecurity::verify($uid, 'login', $old); } catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
$ignoreOld = false;
|
||||
} else {
|
||||
$this->verifyBoundPhone($this->request->post('phone_code', ''), $user['mobile']);
|
||||
$ignoreOld = true;
|
||||
}
|
||||
if (!$this->auth->changepwd($new, $old, $ignoreOld)) $this->error($this->auth->getError() ?: '设置失败');
|
||||
\app\common\library\Token::clear($uid);
|
||||
$this->success('登录密码已更新,请重新登录');
|
||||
}
|
||||
|
||||
public function setPaymentPassword()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$new = (string)$this->request->post('new_password', '');
|
||||
if (!preg_match('/^\d{6}$/', $new)) $this->error('支付密码须为6位数字');
|
||||
try { AccountSecurity::verify($uid, 'login', (string)$this->request->post('login_password', '')); }
|
||||
catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
$updated = Db::name('user_security')->where('user_id', $uid)->where('payment_password_hash', '')->update(['payment_password_hash' => password_hash($new, PASSWORD_DEFAULT)]);
|
||||
if (!$updated) $this->error('支付密码已设置,请使用修改功能');
|
||||
$this->success('支付密码设置成功');
|
||||
}
|
||||
|
||||
public function changePaymentPassword()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$new = (string)$this->request->post('new_password', '');
|
||||
if (!preg_match('/^\d{6}$/', $new)) $this->error('支付密码须为6位数字');
|
||||
$oldHash = (string)Db::name('user_security')->where('user_id', $uid)->value('payment_password_hash');
|
||||
try { AccountSecurity::verify($uid, 'payment', (string)$this->request->post('old_password', '')); }
|
||||
catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
$updated = Db::name('user_security')->where('user_id', $uid)->where('payment_password_hash', $oldHash)->update(['payment_password_hash' => password_hash($new, PASSWORD_DEFAULT)]);
|
||||
if (!$updated) $this->error('支付密码已变更,请重新操作');
|
||||
$this->success('支付密码修改成功');
|
||||
}
|
||||
|
||||
public function submitEnterpriseCert()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$name = trim((string)$this->request->post('company_name', ''));
|
||||
$license = strtoupper(trim((string)$this->request->post('license_no', '')));
|
||||
$image = trim((string)$this->request->post('license_image', ''));
|
||||
$person = trim((string)$this->request->post('legal_person', ''));
|
||||
if ($name === '' || mb_strlen($name) > 255) $this->error('请填写企业名称');
|
||||
if (!preg_match('/^[A-Z0-9]{15,18}$/', $license)) $this->error('请填写正确的营业执照号码');
|
||||
if (mb_strlen($person) > 100) $this->error('法人姓名过长');
|
||||
$attachment = Db::name('attachment')->where('user_id', $uid)->where('url', $image)->where('category', 'cert')->find();
|
||||
if (!$attachment || (int)$attachment['filesize'] > 10 * 1024 * 1024 || !in_array(strtolower((string)$attachment['mimetype']), ['image/jpeg', 'image/png', 'image/webp'], true)) {
|
||||
$this->error('请上传本人营业执照图片');
|
||||
}
|
||||
$existing = Db::name('user_enterprise_cert')->where('user_id', $uid)->find();
|
||||
$data = ['company_name' => $name, 'license_no' => $license, 'license_image' => $image,
|
||||
'legal_person' => $person, 'verify_status' => 'pending', 'audit_msg' => '', 'updatetime' => time()];
|
||||
if ($existing) {
|
||||
if ($existing['verify_status'] !== 'reject') $this->error('已有企业资质申请,审核中或已通过');
|
||||
$updated = Db::name('user_enterprise_cert')->where('id', (int)$existing['id'])->where('verify_status', 'reject')->update($data);
|
||||
if (!$updated) $this->error('申请状态已变更,请刷新后重试');
|
||||
} else {
|
||||
$data['user_id'] = $uid;
|
||||
$data['createtime'] = time();
|
||||
try { Db::name('user_enterprise_cert')->insert($data); }
|
||||
catch (\Throwable $e) { $this->error('提交失败,请刷新后重试'); }
|
||||
}
|
||||
$this->success('企业资质已提交,请等待审核');
|
||||
}
|
||||
|
||||
public function recognizeEnterpriseLicense()
|
||||
{
|
||||
$image = trim((string)$this->request->post('license_image', ''));
|
||||
$attachment = Db::name('attachment')->where('user_id', $this->uid())->where('url', $image)->where('category', 'cert')->find();
|
||||
if (!$attachment || (int)$attachment['filesize'] > 10 * 1024 * 1024 || !in_array(strtolower((string)$attachment['mimetype']), ['image/jpeg', 'image/png', 'image/webp'], true)) {
|
||||
$this->error('请上传本人营业执照图片');
|
||||
}
|
||||
try {
|
||||
$imageBytes = EnterpriseLicenseImage::read($attachment);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('图片读取失败,请重新上传或手动填写');
|
||||
}
|
||||
try {
|
||||
$reply = TencentVerifyService::request('ocr', '2018-11-19', 'BizLicenseOCR', ['ImageBase64' => base64_encode($imageBytes)]);
|
||||
$data = $reply['Response'] ?? [];
|
||||
if (!empty($data['Error']) || empty($data['Name']) || empty($data['RegNum'])) {
|
||||
$this->error('未能识别营业执照,请重新上传或手动填写');
|
||||
}
|
||||
$this->success('识别成功,请核对信息', ['company_name' => (string)$data['Name'], 'license_no' => (string)$data['RegNum'], 'legal_person' => (string)($data['Person'] ?? '')]);
|
||||
} catch (\think\exception\HttpResponseException $e) {
|
||||
throw $e;
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('营业执照识别暂不可用,请手动填写');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,52 +212,10 @@ class User extends Api
|
||||
$this->error(__('Operation failed'), $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="newpassword", type="string", required=true, description="新密码")
|
||||
* @ApiParams (name="captcha", type="string", required=true, description="验证码")
|
||||
*/
|
||||
/** 密码找回暂不开放,保留旧路由返回明确提示。 */
|
||||
public function resetpwd()
|
||||
{
|
||||
$type = $this->request->post("type", "mobile");
|
||||
$mobile = $this->request->post("mobile");
|
||||
$email = $this->request->post("email");
|
||||
$newpassword = $this->request->post("newpassword");
|
||||
$captcha = $this->request->post("captcha");
|
||||
if (!$newpassword || !$captcha) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
//验证Token
|
||||
if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
|
||||
$this->error(__('Password must be 6 to 30 characters'));
|
||||
}
|
||||
if ($type == 'mobile') {
|
||||
$this->error('短信验证码通道已移除,暂不支持手机短信找回密码');
|
||||
} else {
|
||||
if (!Validate::is($email, "email")) {
|
||||
$this->error(__('Email is incorrect'));
|
||||
}
|
||||
$user = \app\common\model\User::getByEmail($email);
|
||||
if (!$user) {
|
||||
$this->error(__('User not found'));
|
||||
}
|
||||
$ret = Ems::check($email, $captcha, 'resetpwd', true);
|
||||
if (!$ret) {
|
||||
$this->error(__('Captcha is incorrect'));
|
||||
}
|
||||
Ems::flush($email, 'resetpwd');
|
||||
}
|
||||
//模拟一次登录
|
||||
$this->auth->direct($user->id);
|
||||
$ret = $this->auth->changepwd($newpassword, '', true);
|
||||
if ($ret) {
|
||||
$this->success(__('Reset password successful'));
|
||||
} else {
|
||||
$this->error($this->auth->getError());
|
||||
}
|
||||
$this->error('暂不支持找回密码');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
在新工单中引用
屏蔽一个用户