1. 账号体系与数据库解耦: - 师傅表 fa_master 解除对 fa_user.id 的外键依赖,升级为独立认证账号主表; - 新增师傅端独立支撑表:fa_master_security、fa_master_token、fa_master_wechat、fa_master_agreement_read; - 新增工单超时未接单自动关闭与原路退款配置(order_unaccepted_close_days)。 2. 服务端(Server): - 新增师傅端独立 API 控制器与认证库(MasterAuth, MasterBase, MasterMessage, MasterSecurity, MasterToken); - WxLogin 支持双小程序端(user/master)独立换取 session_key、openid 与 access_token; - 新增控制台调度命令 php think order:autoclose,支持订单超时自动关闭与售后退款闭环; - 修复 PHP 8.5 兼容性问题(Request.php 的 (bool) 强制转换); - 系统业务配置全面收敛至数据库 fa_config 及 site.php。 3. 小程序端: - yjyf-app(用户端):彻底剥离师傅端路由、组件及静态资源,增加隐私授权弹窗与评价模块; - yjyf-master-app(师傅端):全新独立微信小程序工程(wx140d90ceda786107),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
845 行
34 KiB
PHP
845 行
34 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\common\controller\Backend;
|
||
use think\Db;
|
||
use Exception;
|
||
|
||
/**
|
||
* 师傅档案与资质管理
|
||
*
|
||
* @icon fa fa-wrench
|
||
*/
|
||
class Master extends Backend
|
||
{
|
||
/**
|
||
* Master模型对象
|
||
* @var \app\admin\model\Master
|
||
*/
|
||
protected $model = null;
|
||
protected $relationSearch = false;
|
||
protected $searchFields = 'id,realname,nickname,mobile,city';
|
||
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->model = new \app\admin\model\Master;
|
||
$this->view->assign("statusList", $this->model->getStatusList());
|
||
$this->view->assign("workStatusList", $this->model->getWorkStatusList());
|
||
$this->view->assign("verifyStatusList", $this->model->getVerifyStatusList());
|
||
}
|
||
|
||
public function index()
|
||
{
|
||
$this->request->filter(['strip_tags', 'trim']);
|
||
if (false === $this->request->isAjax()) {
|
||
return $this->view->fetch();
|
||
}
|
||
if ($this->request->request('keyField')) {
|
||
return $this->selectpage();
|
||
}
|
||
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
||
$list = $this->model
|
||
->where($where)
|
||
->order($sort, $order)
|
||
->paginate($limit);
|
||
|
||
$items = $list->items();
|
||
$masterIds = array_column($items, 'id');
|
||
$skillsGroup = [];
|
||
$wechatMap = [];
|
||
$securityMap = [];
|
||
if (!empty($masterIds)) {
|
||
$allSkills = Db::name('master_skill')
|
||
->where('master_id', 'in', $masterIds)
|
||
->where('status', 'normal')
|
||
->select();
|
||
foreach ($allSkills as $sk) {
|
||
$name = !empty($sk['skill_name']) ? $sk['skill_name'] : '';
|
||
if ($name) {
|
||
$skillsGroup[$sk['master_id']][] = $name;
|
||
}
|
||
}
|
||
|
||
$wechatRows = Db::name('master_wechat')
|
||
->where('master_id', 'in', $masterIds)
|
||
->field('master_id,openid,createtime')
|
||
->select();
|
||
foreach ($wechatRows as $wc) {
|
||
$wechatMap[(int)$wc['master_id']] = $wc;
|
||
}
|
||
|
||
$secRows = Db::name('master_security')
|
||
->where('master_id', 'in', $masterIds)
|
||
->field('master_id,payment_password_hash,failed_attempts,locked_until,payment_failed_attempts,payment_locked_until')
|
||
->select();
|
||
foreach ($secRows as $sr) {
|
||
$securityMap[(int)$sr['master_id']] = $sr;
|
||
}
|
||
}
|
||
$now = time();
|
||
foreach ($items as &$it) {
|
||
$mid = (int)$it['id'];
|
||
unset($it['password'], $it['salt']);
|
||
$it['skills_list'] = $skillsGroup[$mid] ?? [];
|
||
$wc = $wechatMap[$mid] ?? null;
|
||
$it['wechat_bound'] = !empty($wc['openid']);
|
||
$it['wechat_openid_mask'] = !empty($wc['openid'])
|
||
? (mb_substr($wc['openid'], 0, 6) . '****' . mb_substr($wc['openid'], -4))
|
||
: '';
|
||
$sec = $securityMap[$mid] ?? null;
|
||
$it['has_pay_password'] = !empty($sec['payment_password_hash']);
|
||
$it['is_locked'] = ((int)($sec['locked_until'] ?? 0) > $now)
|
||
|| ((int)($sec['payment_locked_until'] ?? 0) > $now);
|
||
}
|
||
unset($it);
|
||
|
||
return json(['total' => $list->total(), 'rows' => $items]);
|
||
}
|
||
|
||
/**
|
||
* 新增独立师傅账号与档案(不再绑定 fa_user)
|
||
*/
|
||
public function add()
|
||
{
|
||
if (false === $this->request->isPost()) {
|
||
return $this->view->fetch();
|
||
}
|
||
$params = $this->request->post('row/a', []);
|
||
if (!$params) {
|
||
$this->error(__('Parameter %s can not be empty', ''));
|
||
}
|
||
$params = $this->preExcludeFields($params);
|
||
unset($params['user_id']);
|
||
|
||
$mobile = trim((string)($params['mobile'] ?? ''));
|
||
if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
|
||
$this->error('请输入有效的11位手机号码');
|
||
}
|
||
if (Db::name('master')->where('mobile', $mobile)->count() > 0) {
|
||
$this->error('该手机号已注册过师傅端账号,请勿重复创建');
|
||
}
|
||
|
||
$realname = trim((string)($params['realname'] ?? ''));
|
||
if ($realname === '') {
|
||
$this->error('请填写师傅真实姓名');
|
||
}
|
||
|
||
$plainPassword = trim((string)($params['password'] ?? ''));
|
||
if ($plainPassword !== '' && mb_strlen($plainPassword) < 6) {
|
||
$this->error('登录密码长度不能少于6位');
|
||
}
|
||
$salt = \fast\Random::alnum();
|
||
if ($plainPassword === '') {
|
||
// 若管理员未指定初始密码,生成高强度随机盐与不可逆占位密码,师傅可通过微信或手机验证码登录
|
||
$plainPassword = \fast\Random::alnum(16);
|
||
}
|
||
$params['salt'] = $salt;
|
||
$params['password'] = \app\common\library\MasterAuth::instance()->getEncryptPassword($plainPassword, $salt);
|
||
|
||
if (empty($params['nickname'])) {
|
||
$params['nickname'] = $realname;
|
||
}
|
||
$params['mobile'] = $mobile;
|
||
$params['status'] = in_array($params['status'] ?? 'normal', ['normal', 'disabled'], true) ? $params['status'] : 'normal';
|
||
$params['money'] = 0.00;
|
||
$params['frozen_money'] = 0.00;
|
||
$params['order_count'] = 0;
|
||
$params['level'] = max(1, (int)($params['level'] ?? 1));
|
||
$params['score'] = 5.00;
|
||
$params['accept_rate'] = 100.00;
|
||
$params['ontime_rate'] = 100.00;
|
||
if ($params['status'] !== 'normal') {
|
||
$params['work_status'] = 'off';
|
||
}
|
||
|
||
$result = $this->model->allowField(true)->save($params);
|
||
if ($result !== false) {
|
||
$this->success();
|
||
}
|
||
$this->error($this->model->getError() ?: __('No rows were inserted'));
|
||
}
|
||
|
||
/**
|
||
* 删除保护:已产生承接工单、提现、申诉、评价、钱包余额或结算流水的师傅禁止物理删除
|
||
*/
|
||
public function del($ids = null)
|
||
{
|
||
if (false === $this->request->isPost()) {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
$ids = $ids ?: $this->request->post('ids');
|
||
$idArr = array_values(array_filter(array_map('intval', explode(',', (string)$ids))));
|
||
if (!$idArr) {
|
||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||
}
|
||
$hasOrder = Db::name('order')->where('master_id', 'in', $idArr)->count();
|
||
$hasFund = Db::name('master')->where('id', 'in', $idArr)->where('money > 0 OR frozen_money > 0')->count();
|
||
$hasSettle = Db::name('settle')->where('master_id', 'in', $idArr)->count();
|
||
$hasWithdraw = Db::name('withdraw')->where('master_id', 'in', $idArr)->count();
|
||
$hasAppeal = Db::name('appeal')->where('master_id', 'in', $idArr)->count();
|
||
if ($hasOrder > 0 || $hasFund > 0 || $hasSettle > 0 || $hasWithdraw > 0 || $hasAppeal > 0) {
|
||
$this->error('所选师傅已关联历史工单、提现、申诉、结算记录或存在钱包资金,禁止物理删除;如需停用请将账号状态设为已停用');
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
Db::name('master_skill')->where('master_id', 'in', $idArr)->delete();
|
||
Db::name('master_cert')->where('master_id', 'in', $idArr)->delete();
|
||
Db::name('master_token')->where('master_id', 'in', $idArr)->delete();
|
||
Db::name('master_wechat')->where('master_id', 'in', $idArr)->delete();
|
||
Db::name('master_security')->where('master_id', 'in', $idArr)->delete();
|
||
Db::name('master_agreement_read')->where('master_id', 'in', $idArr)->delete();
|
||
$deleted = Db::name('master')->where('id', 'in', $idArr)->delete();
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
if ($deleted) {
|
||
$this->success();
|
||
}
|
||
$this->error(__('No rows were deleted'));
|
||
}
|
||
|
||
/**
|
||
* 编辑师傅资料、独立账号状态与入驻资质审核
|
||
*/
|
||
public function edit($ids = null)
|
||
{
|
||
$row = $this->model->get($ids);
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
$oldVerify = (string)$row['verify_status'];
|
||
|
||
if ($this->request->isPost()) {
|
||
$params = $this->request->post("row/a");
|
||
if ($params) {
|
||
$params = $this->preExcludeFields($params);
|
||
// 禁止在师傅档案编辑中直接篡改钱包可用余额、冻结资金与累计完单数
|
||
unset($params['user_id'], $params['money'], $params['frozen_money'], $params['order_count'], $params['salt']);
|
||
|
||
if (isset($params['mobile'])) {
|
||
$mobile = trim((string)$params['mobile']);
|
||
if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
|
||
$this->error('请输入有效的11位手机号码');
|
||
}
|
||
$dup = Db::name('master')->where('mobile', $mobile)->where('id', '<>', (int)$row['id'])->count();
|
||
if ($dup > 0) {
|
||
$this->error('该手机号已被其他师傅账号占用');
|
||
}
|
||
$params['mobile'] = $mobile;
|
||
}
|
||
|
||
// 登录密码留空表示不修改,填写则重置盐值与加密密码并清理登录会话
|
||
$resetPassword = false;
|
||
if (array_key_exists('password', $params)) {
|
||
$plainPassword = trim((string)$params['password']);
|
||
if ($plainPassword === '') {
|
||
unset($params['password']);
|
||
} else {
|
||
if (mb_strlen($plainPassword) < 6) {
|
||
$this->error('重置的登录密码长度不能少于6位');
|
||
}
|
||
$salt = \fast\Random::alnum();
|
||
$params['salt'] = $salt;
|
||
$params['password'] = \app\common\library\MasterAuth::instance()->getEncryptPassword($plainPassword, $salt);
|
||
$resetPassword = true;
|
||
}
|
||
}
|
||
|
||
$kickToken = $resetPassword;
|
||
if (isset($params['status'])) {
|
||
$params['status'] = in_array($params['status'], ['normal', 'disabled'], true) ? $params['status'] : $row['status'];
|
||
if ($params['status'] === 'disabled') {
|
||
$params['work_status'] = 'off';
|
||
$kickToken = true;
|
||
}
|
||
}
|
||
|
||
// 若提交的身份证号包含脱敏星号 *,保留原数据库记录不覆盖;若为新填写明文则做合法性校验
|
||
if (isset($params['idcard_no'])) {
|
||
$idcardInput = trim((string)$params['idcard_no']);
|
||
if (strpos($idcardInput, '*') !== false) {
|
||
unset($params['idcard_no']);
|
||
} elseif ($idcardInput !== '' && !preg_match('/^(^\d{15}$)|(^\d{17}([0-9]|X|x)$)$/', $idcardInput)) {
|
||
$this->error('请输入正确的15位或18位身份证号码');
|
||
}
|
||
}
|
||
|
||
// 若 city-picker 因省市格式差异未选新值导致提交为空而原库有城市,保留原城市不清空
|
||
if (isset($params['city']) && trim((string)$params['city']) === '' && !empty($row['city'])) {
|
||
unset($params['city']);
|
||
}
|
||
|
||
if (isset($params['verify_status']) && $params['verify_status'] === 'reject') {
|
||
if (empty(trim((string)($params['audit_msg'] ?? '')))) {
|
||
$this->error('驳回实名认证时请填写审核意见说明');
|
||
}
|
||
$params['work_status'] = 'off';
|
||
}
|
||
if (isset($params['verify_status']) && in_array($params['verify_status'], ['pass', 'reject'], true)) {
|
||
$params['audittime'] = time();
|
||
$params['audit_admin_id'] = (int)$this->auth->id;
|
||
}
|
||
$result = false;
|
||
Db::startTrans();
|
||
try {
|
||
$result = $row->allowField(true)->save($params);
|
||
if ($kickToken) {
|
||
\app\common\library\MasterToken::clear((int)$row['id']);
|
||
}
|
||
$newVerify = isset($params['verify_status']) ? (string)$params['verify_status'] : $oldVerify;
|
||
if ($newVerify !== $oldVerify && in_array($newVerify, ['pass', 'reject'], true)) {
|
||
$now = time();
|
||
$title = $newVerify === 'pass' ? '师傅入驻审核通过' : '师傅入驻审核未通过';
|
||
$content = $newVerify === 'pass'
|
||
? '您的师傅实名认证已审核通过,现在可开启听单承接同城服务工单。'
|
||
: ('您的师傅认证申请未通过,原因:' . (trim((string)($params['audit_msg'] ?? '')) ?: '请核对资料后重新提交'));
|
||
Db::name('message')->insert([
|
||
'receive_type' => 'master',
|
||
'receive_id' => (int)$row['id'],
|
||
'type' => 'audit',
|
||
'title' => $title,
|
||
'content' => $content,
|
||
'order_id' => 0,
|
||
'is_read' => 0,
|
||
'createtime' => $now,
|
||
]);
|
||
}
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
if ($result !== false) {
|
||
$this->success();
|
||
}
|
||
$this->error(__('No rows were updated'));
|
||
}
|
||
$this->error(__('Parameter %s can not be empty', ''));
|
||
}
|
||
|
||
$this->view->assign("row", $row);
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 师傅服务技能管理(保留既有证书与元数据)
|
||
*/
|
||
public function skills($ids = null)
|
||
{
|
||
$row = $this->model->find($ids);
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
|
||
if ($this->request->isPost()) {
|
||
$selectedSkills = (array)$this->request->post('skills/a', []);
|
||
$customText = trim((string)$this->request->post('custom_text', ''));
|
||
|
||
$customNames = [];
|
||
if (!empty($customText)) {
|
||
$parts = preg_split('/[,,\s]+/u', $customText);
|
||
foreach ($parts as $p) {
|
||
$p = trim($p);
|
||
if (!empty($p) && !in_array($p, $customNames, true) && !in_array($p, $selectedSkills, true)) {
|
||
$customNames[] = $p;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 缓存师傅原有技能的证书图片与分类ID,防止保存时丢失证书
|
||
$existingRows = Db::name('master_skill')->where('master_id', $row['id'])->select();
|
||
$existingMap = [];
|
||
foreach ($existingRows as $er) {
|
||
$existingMap[(string)$er['skill_name']] = $er;
|
||
}
|
||
|
||
$dictRows = !empty($selectedSkills)
|
||
? Db::name('skill_dict')->where('name', 'in', $selectedSkills)->select()
|
||
: [];
|
||
$dictMap = [];
|
||
foreach ($dictRows as $dr) {
|
||
$dictMap[$dr['name']] = $dr;
|
||
}
|
||
|
||
$now = time();
|
||
Db::startTrans();
|
||
try {
|
||
Db::name('master_skill')->where('master_id', $row['id'])->delete();
|
||
|
||
foreach ($selectedSkills as $sName) {
|
||
$dict = $dictMap[$sName] ?? null;
|
||
$old = $existingMap[$sName] ?? null;
|
||
Db::name('master_skill')->insert([
|
||
'master_id' => $row['id'],
|
||
'cat_id' => $old ? (int)$old['cat_id'] : 0,
|
||
'skill_id' => $dict ? (int)$dict['id'] : ($old ? (int)$old['skill_id'] : 0),
|
||
'skill_name' => $sName,
|
||
'category' => $dict ? $dict['category'] : ($old && !empty($old['category']) ? $old['category'] : '服务技能'),
|
||
'is_custom' => 0,
|
||
'cert_image' => $old ? (string)$old['cert_image'] : '',
|
||
'status' => 'normal',
|
||
'createtime' => $old ? (int)$old['createtime'] : $now,
|
||
]);
|
||
}
|
||
|
||
foreach ($customNames as $cName) {
|
||
$exist = Db::name('skill_dict')->where('name', $cName)->find();
|
||
if (!$exist) {
|
||
$skillDictId = Db::name('skill_dict')->insertGetId([
|
||
'category_id' => 0,
|
||
'category' => '其他技能',
|
||
'name' => $cName,
|
||
'source' => 'custom',
|
||
'master_id' => $row['id'],
|
||
'weigh' => 0,
|
||
'status' => 'normal',
|
||
'createtime' => $now,
|
||
'updatetime' => $now,
|
||
]);
|
||
} else {
|
||
$skillDictId = (int)$exist['id'];
|
||
}
|
||
$old = $existingMap[$cName] ?? null;
|
||
Db::name('master_skill')->insert([
|
||
'master_id' => $row['id'],
|
||
'cat_id' => $old ? (int)$old['cat_id'] : 0,
|
||
'skill_id' => $skillDictId,
|
||
'skill_name' => $cName,
|
||
'category' => $exist && !empty($exist['category']) ? $exist['category'] : '其他技能',
|
||
'is_custom' => 1,
|
||
'cert_image' => $old ? (string)$old['cert_image'] : '',
|
||
'status' => 'normal',
|
||
'createtime' => $old ? (int)$old['createtime'] : $now,
|
||
]);
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
|
||
$this->success('技能配置更新成功');
|
||
}
|
||
|
||
$categories = Db::name('skill_category')->where('status', 'normal')->order('weigh desc')->select();
|
||
$allDictSkills = Db::name('skill_dict')->where('status', 'normal')->order('weigh desc')->select();
|
||
|
||
$catTree = [];
|
||
foreach ($categories as $cat) {
|
||
$catTree[$cat['name']] = [];
|
||
}
|
||
foreach ($allDictSkills as $item) {
|
||
$cName = $item['category'];
|
||
if (!isset($catTree[$cName])) {
|
||
$catTree[$cName] = [];
|
||
}
|
||
$catTree[$cName][] = $item;
|
||
}
|
||
|
||
$mySkills = Db::name('master_skill')->where('master_id', $row['id'])->select();
|
||
$selectedSkills = [];
|
||
$customArr = [];
|
||
foreach ($mySkills as $ms) {
|
||
if ((int)$ms['is_custom'] === 1 && !Db::name('skill_dict')->where('name', $ms['skill_name'])->where('source', '<>', 'custom')->count()) {
|
||
$customArr[] = $ms['skill_name'];
|
||
} else {
|
||
$selectedSkills[] = $ms['skill_name'];
|
||
}
|
||
}
|
||
|
||
$this->view->assign('row', $row);
|
||
$this->view->assign('catTree', $catTree);
|
||
$this->view->assign('selectedSkills', $selectedSkills);
|
||
$this->view->assign('customText', implode(' ', $customArr));
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 师傅全景档案画像
|
||
*/
|
||
public function detail($ids = null)
|
||
{
|
||
$row = $this->model->where('id', (int)$ids)->find();
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
|
||
$orderModel = new \app\admin\model\Order;
|
||
$statusMap = $orderModel->getStatusList();
|
||
|
||
// 1. 最近接单记录
|
||
$recentOrders = Db::name('order')
|
||
->where('master_id', $row['id'])
|
||
->order('id desc')
|
||
->limit(8)
|
||
->select();
|
||
foreach ($recentOrders as &$o) {
|
||
$o['status_label'] = $statusMap[(int)$o['status']] ?? ('状态' . $o['status']);
|
||
}
|
||
unset($o);
|
||
|
||
// 2. 提现流水
|
||
$recentWithdraws = Db::name('withdraw')
|
||
->where('master_id', $row['id'])
|
||
->order('id desc')
|
||
->limit(6)
|
||
->select();
|
||
|
||
// 3. 工单佣金结算记录
|
||
$recentSettles = Db::name('settle')
|
||
->alias('s')
|
||
->join('order o', 'o.id = s.order_id', 'LEFT')
|
||
->where('s.master_id', $row['id'])
|
||
->field('s.*, o.order_no, o.service_name')
|
||
->order('s.id desc')
|
||
->limit(6)
|
||
->select();
|
||
|
||
// 4. 客户评价记录
|
||
$recentReviews = Db::name('review')
|
||
->alias('r')
|
||
->join('order o', 'o.id = r.order_id', 'LEFT')
|
||
->join('user u', 'u.id = r.user_id', 'LEFT')
|
||
->where('r.master_id', $row['id'])
|
||
->field('r.*, o.order_no, o.service_name, u.nickname as user_nickname')
|
||
->order('r.id desc')
|
||
->limit(5)
|
||
->select();
|
||
|
||
// 5. 服务技能与认证证书
|
||
$skills = Db::name('master_skill')
|
||
->alias('s')
|
||
->join('service_cat c', 'c.id = s.cat_id', 'LEFT')
|
||
->where('s.master_id', $row['id'])
|
||
->field('s.*, c.name as cat_name')
|
||
->select();
|
||
|
||
// 5.5 技能证书记录
|
||
$certs = Db::name('master_cert')
|
||
->field('id,cert_code,cert_name,is_custom,cert_image,expire_date,is_long_term,status,audit_msg,updatetime')
|
||
->where('master_id', $row['id'])
|
||
->order('id desc')
|
||
->select();
|
||
|
||
// 6. 钱包资金变动流水
|
||
$walletLogs = Db::name('wallet_log')
|
||
->where('user_type', 'master')
|
||
->where('user_id', $row['id'])
|
||
->order('id desc')
|
||
->limit(6)
|
||
->select();
|
||
|
||
// 7. 证件防伪水印安全转换(方案1:腾讯云数据万象动态水印)
|
||
if (!empty($row['idcard_front'])) {
|
||
$row['idcard_front_watermark'] = \app\common\library\TencentVerifyService::getWatermarkUrl($row['idcard_front']);
|
||
}
|
||
if (!empty($row['idcard_back'])) {
|
||
$row['idcard_back_watermark'] = \app\common\library\TencentVerifyService::getWatermarkUrl($row['idcard_back']);
|
||
}
|
||
|
||
// 8. 独立账号安全、微信绑定与活跃会话状态
|
||
$wechatBind = Db::name('master_wechat')->where('master_id', $row['id'])->find();
|
||
$securityInfo = Db::name('master_security')->where('master_id', $row['id'])->find();
|
||
$activeTokens = Db::name('master_token')
|
||
->where('master_id', $row['id'])
|
||
->where(function ($q) {
|
||
$q->where('expiretime', 0)->whereOr('expiretime', '>', time());
|
||
})
|
||
->count();
|
||
$now = time();
|
||
$isLoginLocked = (int)($securityInfo['locked_until'] ?? 0) > $now;
|
||
$isPayLocked = (int)($securityInfo['payment_locked_until'] ?? 0) > $now;
|
||
|
||
$this->view->assign([
|
||
'row' => $row,
|
||
'wechatBind' => $wechatBind ?: [],
|
||
'securityInfo' => $securityInfo ?: [],
|
||
'activeTokens' => (int)$activeTokens,
|
||
'isLoginLocked' => $isLoginLocked,
|
||
'isPayLocked' => $isPayLocked,
|
||
'recentOrders' => $recentOrders,
|
||
'recentWithdraws' => $recentWithdraws,
|
||
'recentSettles' => $recentSettles,
|
||
'recentReviews' => $recentReviews,
|
||
'skills' => $skills,
|
||
'certs' => $certs,
|
||
'walletLogs' => $walletLogs,
|
||
]);
|
||
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 师傅入驻资质审核
|
||
*/
|
||
public function audit($ids = null)
|
||
{
|
||
$id = (int)($ids ?: $this->request->param('ids'));
|
||
$row = $this->model->where('id', $id)->find();
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
|
||
if (false === $this->request->isPost()) {
|
||
// 查询关联服务技能
|
||
$skills = Db::name('master_skill')
|
||
->alias('s')
|
||
->join('service_cat c', 'c.id = s.cat_id', 'LEFT')
|
||
->where('s.master_id', $row['id'])
|
||
->field('s.*, c.name as cat_name')
|
||
->select();
|
||
|
||
// 查询技能证书
|
||
$certs = Db::name('master_cert')
|
||
->field('id,cert_name,is_custom,cert_image,expire_date,is_long_term,status,audit_msg')
|
||
->where('master_id', $row['id'])
|
||
->order('id desc')
|
||
->select();
|
||
|
||
$wechatBind = Db::name('master_wechat')->where('master_id', $row['id'])->find();
|
||
|
||
// 证件防伪水印处理
|
||
if (!empty($row['idcard_front'])) {
|
||
$row['idcard_front_watermark'] = \app\common\library\TencentVerifyService::getWatermarkUrl($row['idcard_front']);
|
||
}
|
||
if (!empty($row['idcard_back'])) {
|
||
$row['idcard_back_watermark'] = \app\common\library\TencentVerifyService::getWatermarkUrl($row['idcard_back']);
|
||
}
|
||
|
||
$this->view->assign([
|
||
'row' => $row,
|
||
'wechatBind' => $wechatBind ?: [],
|
||
'skills' => $skills,
|
||
'certs' => $certs,
|
||
]);
|
||
return $this->view->fetch('audit');
|
||
}
|
||
|
||
$params = $this->request->post('row/a', []);
|
||
if (empty($params)) {
|
||
$this->error(__('Parameter %s can not be empty', ''));
|
||
}
|
||
|
||
$verifyStatus = trim((string)($params['verify_status'] ?? ''));
|
||
$auditMsg = trim((string)($params['audit_msg'] ?? ''));
|
||
$level = max(1, (int)($params['level'] ?? $row['level'] ?? 1));
|
||
|
||
if (!in_array($verifyStatus, ['pass', 'reject'], true)) {
|
||
$this->error('请选择有效的审核结果(通过或驳回)');
|
||
}
|
||
|
||
if ($verifyStatus === 'reject' && $auditMsg === '') {
|
||
$this->error('驳回入驻申请时,必须填写驳回原因说明');
|
||
}
|
||
|
||
$now = time();
|
||
$adminId = (int)$this->auth->id;
|
||
|
||
$updateData = [
|
||
'verify_status' => $verifyStatus,
|
||
'audit_msg' => $auditMsg,
|
||
'level' => $level,
|
||
'audittime' => $now,
|
||
'audit_admin_id' => $adminId,
|
||
'updatetime' => $now,
|
||
];
|
||
|
||
// 若驳回,出工状态必须设为 off
|
||
if ($verifyStatus === 'reject') {
|
||
$updateData['work_status'] = 'off';
|
||
}
|
||
|
||
Db::startTrans();
|
||
try {
|
||
Db::name('master')->where('id', $row['id'])->update($updateData);
|
||
|
||
// 发送审核结果通知给独立师傅端
|
||
$title = $verifyStatus === 'pass' ? '师傅入驻审核通过' : '师傅入驻审核未通过';
|
||
$content = $verifyStatus === 'pass'
|
||
? '恭喜您!您的师傅入驻与实名认证已审核通过,已获得接单资格,现在可开启听单承接同城订单。'
|
||
: ('您的师傅入驻认证申请未通过,原因:' . ($auditMsg ?: '证件材料不符合规范,请重新核对后提交。'));
|
||
|
||
Db::name('message')->insert([
|
||
'receive_type' => 'master',
|
||
'receive_id' => (int)$row['id'],
|
||
'type' => 'audit',
|
||
'title' => $title,
|
||
'content' => $content,
|
||
'order_id' => 0,
|
||
'is_read' => 0,
|
||
'createtime' => $now,
|
||
]);
|
||
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
|
||
$this->success('入驻审核处理成功');
|
||
}
|
||
|
||
/**
|
||
* 批量快捷审核通过
|
||
*/
|
||
public function batch_pass()
|
||
{
|
||
if (false === $this->request->isPost()) {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
$ids = $this->request->post('ids');
|
||
$idArr = array_values(array_filter(array_map('intval', explode(',', (string)$ids))));
|
||
if (!$idArr) {
|
||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||
}
|
||
|
||
$pendingMasters = Db::name('master')
|
||
->where('id', 'in', $idArr)
|
||
->where('verify_status', 'pending')
|
||
->select();
|
||
|
||
if (empty($pendingMasters)) {
|
||
$this->error('所选记录中没有待审核的师傅档案');
|
||
}
|
||
|
||
$now = time();
|
||
$adminId = (int)$this->auth->id;
|
||
|
||
Db::startTrans();
|
||
try {
|
||
$targetIds = array_column($pendingMasters, 'id');
|
||
Db::name('master')->where('id', 'in', $targetIds)->update([
|
||
'verify_status' => 'pass',
|
||
'audit_msg' => '管理员批量审核通过',
|
||
'audittime' => $now,
|
||
'audit_admin_id' => $adminId,
|
||
'updatetime' => $now,
|
||
]);
|
||
|
||
foreach ($pendingMasters as $m) {
|
||
$mId = (int)$m['id'];
|
||
$title = '师傅入驻审核通过';
|
||
$content = '恭喜您!您的师傅入驻与实名认证已审核通过,已获得接单资格,现在可开启听单承接同城订单。';
|
||
|
||
Db::name('message')->insert([
|
||
'receive_type' => 'master',
|
||
'receive_id' => $mId,
|
||
'type' => 'audit',
|
||
'title' => $title,
|
||
'content' => $content,
|
||
'order_id' => 0,
|
||
'is_read' => 0,
|
||
'createtime' => $now,
|
||
]);
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
|
||
$this->success('已成功批量审核通过 ' . count($pendingMasters) . ' 位师傅');
|
||
}
|
||
|
||
/**
|
||
* 解绑师傅端微信账号(清空 fa_master_wechat 并踢掉会话)
|
||
*/
|
||
public function unbind_wechat($ids = null)
|
||
{
|
||
if (false === $this->request->isPost()) {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
$masterId = (int)($ids ?: $this->request->post('ids'));
|
||
$row = $this->model->find($masterId);
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
Db::name('master_wechat')->where('master_id', $masterId)->delete();
|
||
\app\common\library\MasterToken::clear($masterId);
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
$this->success('已解绑该师傅的微信授权绑定');
|
||
}
|
||
|
||
/**
|
||
* 解除师傅登录/支付密码防爆破锁定
|
||
*/
|
||
public function unlock_security($ids = null)
|
||
{
|
||
if (false === $this->request->isPost()) {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
$masterId = (int)($ids ?: $this->request->post('ids'));
|
||
$row = $this->model->find($masterId);
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
$now = time();
|
||
Db::startTrans();
|
||
try {
|
||
Db::name('master')->where('id', $masterId)->update([
|
||
'loginfailure' => 0,
|
||
'loginfailuretime' => 0,
|
||
'updatetime' => $now,
|
||
]);
|
||
Db::name('master_security')->where('master_id', $masterId)->update([
|
||
'failed_attempts' => 0,
|
||
'locked_until' => 0,
|
||
'payment_failed_attempts' => 0,
|
||
'payment_locked_until' => 0,
|
||
]);
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
$this->success('已解除登录与支付防爆破锁定');
|
||
}
|
||
|
||
/**
|
||
* 停用 / 启用独立师傅账号(停用自动关闭听单并下线会话)
|
||
*/
|
||
public function toggle_status($ids = null)
|
||
{
|
||
if (false === $this->request->isPost()) {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
$masterId = (int)($ids ?: $this->request->post('ids'));
|
||
$row = $this->model->find($masterId);
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
$target = ($row['status'] ?? 'normal') === 'normal' ? 'disabled' : 'normal';
|
||
$update = [
|
||
'status' => $target,
|
||
'updatetime' => time(),
|
||
];
|
||
if ($target === 'disabled') {
|
||
$update['work_status'] = 'off';
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
Db::name('master')->where('id', $masterId)->update($update);
|
||
if ($target === 'disabled') {
|
||
\app\common\library\MasterToken::clear($masterId);
|
||
}
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
$this->success($target === 'disabled' ? '已停用该师傅账号并强制下线' : '已恢复启用该师傅账号');
|
||
}
|
||
}
|