feat: 用户端与师傅端双小程序架构解耦,新增师傅独立认证及超时自动关单机制

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),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
这个提交包含在:
2026-11-23 15:10:30 +08:00
父节点 d3cd6ba342
当前提交 14533eadb7
共有 270 个文件被更改,包括 9757 次插入 和 1392 次删除

查看文件

@@ -88,27 +88,10 @@ class Auth extends Base
{
$uid = $this->uid();
$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();
$unread = Db::name('message')->where('receive_type', 'user')->where('receive_id', $uid)->where('is_read', 0)->count();
$masterInfo = null;
if ($master) {
$masterInfo = [
'id' => (int)$master['id'],
'realname' => $master['realname'],
'verify_status' => $master['verify_status'],
'audit_msg' => $master['audit_msg'],
'work_status' => $master['work_status'],
'level' => (int)$master['level'],
'score' => (float)$master['score'],
'order_count' => (int)$master['order_count'],
'money' => (float)$master['money'],
'can_take' => $master['verify_status'] === 'pass',
];
}
$merchantRel = $this->merchantOf($uid);
$merchant = $merchantRel ? $merchantRel['merchant'] : null;
$merchantRole = $merchantRel ? $merchantRel['role'] : null;
@@ -175,8 +158,6 @@ class Auth extends Base
'coupon_count' => (int)$couponCount,
'unread_count' => (int)$unread,
'order_counts' => $orderCounts,
'is_master' => $master ? true : false,
'master' => $masterInfo,
'is_merchant' => $merchant ? true : false,
'merchant' => $merchantInfo,
];
@@ -382,44 +363,6 @@ class Auth extends Base
]);
}
public function switchRole()
{
$role = $this->request->post('role', 'user');
if (!in_array($role, ['user', 'master', 'merchant'], true)) {
$this->error('角色参数错误');
}
if ($role === 'master') {
$master = $this->masterInfo();
if (!$master) {
$this->error('请先完成师傅入驻', ['need_apply' => 1], 2001);
}
}
if ($role === 'merchant') {
$merchantRel = $this->merchantOf($this->uid());
$merchant = $merchantRel ? $merchantRel['merchant'] : null;
if (!$merchant) {
$this->error('请先完成商家入驻', ['need_apply' => 1], 2001);
}
if ($merchant['verify_status'] === 'pending') {
$this->error('商家资质审核中,请耐心等待', ['verify_status' => 'pending'], 2002);
}
if ($merchant['verify_status'] === 'reject') {
$this->error('资质未通过:' . $merchant['audit_msg'], ['verify_status' => 'reject'], 2003);
}
}
$redirect = '/pages/index/index';
if ($role === 'master') {
$redirect = '/pages/master/workbench';
} elseif ($role === 'merchant') {
$redirect = '/pages/mine/mine';
}
$this->success('切换成功', ['role' => $role, 'redirect' => $redirect]);
}
/**
* 当前用户的商家归属:主账号 / 关联账号
* 返回 ['merchant' => 商家行, 'role' => owner|member]

查看文件

@@ -7,8 +7,8 @@ use app\common\library\OrderStatus;
use think\Db;
/**
* 业务接口基类
* 统一处理:登录用户注入 / 师傅档案 / 订单归属校验 / 状态流转 / 通知
* 用户端业务接口基类
* 统一处理:登录用户注入 / 订单归属校验 / 状态流转 / 通知
*/
class Base extends Api
{
@@ -18,9 +18,6 @@ class Base extends Api
/** @var mixed 当前登录用户 */
protected $user = null;
/** @var array|false|null 师傅档案:null未查询 / false未入驻 / array已入驻 */
protected $master = null;
protected function _initialize()
{
parent::_initialize();
@@ -56,53 +53,10 @@ class Base extends Api
}
}
/**
* 师傅档案
*/
protected function masterInfo($reload = false)
{
if ($this->uid() <= 0) {
return false;
}
if ($this->master === null || $reload) {
$row = Db::name('master')->where('user_id', $this->uid())->find();
$this->master = $row ? $row : false;
}
return $this->master;
}
/**
* 要求拥有师傅档案,允许查看师傅端。
*/
protected function requireMasterProfile()
{
$master = $this->masterInfo();
if (!$master) {
$this->error('请先完成师傅入驻', ['need_apply' => 1], 2001);
}
return $master;
}
/** 要求师傅通过审核,供接单及敏感操作使用。 */
protected function requireMaster()
{
$master = $this->requireMasterProfile();
if ($master['verify_status'] === 'pending') {
$this->error('师傅资质审核中,请耐心等待', ['verify_status' => 'pending'], 2002);
}
if ($master['verify_status'] === 'reject') {
$this->error('资质未通过:' . $master['audit_msg'], ['verify_status' => 'reject'], 2003);
}
if ($master['verify_status'] !== 'pass') {
$this->error('师傅资质尚未审核通过,无法接单');
}
return $master;
}
/**
* 取本人订单(越权拦截)
* @param int $orderId
* @param string $side user|master
* @param string $side user
*/
protected function ownOrder($orderId, $side = 'user')
{
@@ -114,18 +68,12 @@ class Base extends Api
if (!$order) {
$this->error('订单不存在');
}
if ($side === 'user' && (int)$order['user_id'] !== $this->uid()) {
if ((int)$order['user_id'] !== $this->uid()) {
$team = $this->currentMerchantTeam();
if (!$team || !in_array((int)$order['user_id'], $team['user_ids'], true)) {
$this->error('无权操作该订单', null, 403);
}
}
if ($side === 'master') {
$master = $this->requireMaster();
if ((int)$order['master_id'] !== (int)$master['id']) {
$this->error('无权操作该订单', null, 403);
}
}
return $order;
}

查看文件

@@ -18,7 +18,7 @@ use think\Hook;
*/
class Common extends Api
{
protected $noNeedLogin = ['init', 'captcha', 'areas', 'expressCompanies', 'dicts'];
protected $noNeedLogin = ['init', 'captcha', 'areas', 'expressCompanies', 'dicts', 'upload'];
protected $noNeedRight = '*';
public function _initialize()
@@ -68,6 +68,13 @@ class Common extends Api
*/
public function upload()
{
if (!$this->auth->isLogin()) {
$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', ''));
$masterAuth = \app\common\library\MasterAuth::instance();
if (!$token || !$masterAuth->init($token)) {
$this->error(__('Please login first'), null, 401);
}
}
Config::set('default_return_type', 'json');
//必须设定cdnurl为空,否则cdnurl函数计算错误
Config::set('upload.cdnurl', '');

查看文件

@@ -1622,7 +1622,8 @@ class Home extends Base
public function agreement()
{
$type = trim((string)$this->request->param('type', 'user_service'));
$item = \app\common\library\AgreementService::getByType($type, $this->uid());
list($subjectId, $side) = $this->resolveAgreementSubject();
$item = \app\common\library\AgreementService::getByType($type, $subjectId, $side);
if (!$item) {
$this->error('协议内容暂未配置或已下线');
}
@@ -1631,7 +1632,7 @@ class Home extends Base
}
/**
* 记录用户已首次查看指定修订版本的协议(后续打开不再标背景色)
* 记录用户或师傅已首次查看指定修订版本的协议(后续打开不再标背景色)
*/
public function agreementRead()
{
@@ -1640,10 +1641,27 @@ class Home extends Base
}
$type = trim((string)$this->request->post('type', 'privacy'));
$revision = (int)$this->request->post('revision', 0);
$res = \app\common\library\AgreementService::markUserRead($this->uid(), $type, $revision);
list($subjectId, $side) = $this->resolveAgreementSubject();
$res = \app\common\library\AgreementService::markUserRead($subjectId, $type, $revision, $side);
$this->success('', $res);
}
protected function resolveAgreementSubject()
{
if ($this->uid() > 0) {
return [$this->uid(), 'user'];
}
$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', ''));
if ($token) {
$masterAuth = \app\common\library\MasterAuth::instance();
if ($masterAuth->init($token)) {
return [(int)$masterAuth->id(), 'master'];
}
}
$reqSide = trim((string)$this->request->param('side', ''));
return [0, $reqSide === 'master' ? 'master' : 'user'];
}
/**
* 官方系统图库(受下单所选类目控制,仅展示对应类目下的商品及参考图片;同源聚合系统图库表 + 细分规格图 + 商品主缩略图)
*/
@@ -1841,11 +1859,15 @@ class Home extends Base
*/
public function serviceConfig()
{
$userMini = \app\common\library\WxLogin::getMiniAppConfig('user');
$masterMini = \app\common\library\WxLogin::getMiniAppConfig('master');
$this->success('', [
'service_phone' => trim((string)(\think\Config::get('site.service_phone') ?: '')),
'service_work_time' => trim((string)(\think\Config::get('site.service_work_time') ?: '')),
'service_corp_id' => trim((string)(\think\Config::get('site.service_corp_id') ?: '')),
'service_kf_url' => trim((string)(\think\Config::get('site.service_kf_url') ?: '')),
'user_appid' => $userMini['appid'],
'master_appid' => $masterMini['appid'],
]);
}
}

查看文件

@@ -14,11 +14,11 @@ use app\common\library\WxPayV3Service;
use think\Db;
/**
* 师傅端:入驻 / 订单大厅 / 抢单 / 履约流转 / 收入
* 师傅端:入驻 / 订单大厅 / 抢单 / 履约流转 / 收入(继承独立 MasterBase,完全脱离 fa_user)
*/
class Master extends Base
class Master extends MasterBase
{
protected $noNeedLogin = [];
protected $noNeedLogin = ['hall', 'orderDetail', 'resolveLocation'];
/**
* 师傅入驻申请
@@ -94,10 +94,20 @@ class Master extends Base
$this->error('请至少选择一个服务类目');
}
$exist = Db::name('master')->where('user_id', $this->uid())->find();
if ($exist && $exist['verify_status'] === 'pass') {
$mid = $this->masterId();
$exist = Db::name('master')->where('id', $mid)->find();
if (!$exist) {
$this->error('师傅账号不存在,请重新登录');
}
if ($exist['verify_status'] === 'pass') {
$this->error('您已是认证师傅,无需重复入驻');
}
if ($mobile !== (string)($exist['mobile'] ?? '')) {
$conflict = Db::name('master')->where('mobile', $mobile)->where('id', '<>', $mid)->find();
if ($conflict) {
$this->error('该手机号已被其他师傅账号绑定,请更换手机号');
}
}
// 若是驳回后重提且未修改脱敏展示号,沿用原存储的完整身份证号;否则校验完整身份证号并真实入库
if (strpos($rawIdcard, '*') !== false) {
@@ -134,32 +144,27 @@ class Master extends Base
$catNameMap = Db::name('service_cat')->where('id', 'in', $skillCatIds)->column('name', 'id');
$save = [
'realname' => mb_substr($realname, 0, 50),
'mobile' => $mobile,
'idcard_no' => $finalIdcard,
'idcard_front' => $idcardFront,
'idcard_back' => $idcardBack,
'cert_images' => $certImages,
'city' => $normalizedCity,
'work_status' => 'off',
'verify_status' => 'pending',
'audit_msg' => '',
'audittime' => null,
'realname' => mb_substr($realname, 0, 50),
'nickname' => !empty($exist['nickname']) && strpos((string)$exist['nickname'], '师傅') !== 0 ? (string)$exist['nickname'] : mb_substr($realname, 0, 50),
'mobile' => $mobile,
'idcard_no' => $finalIdcard,
'idcard_front' => $idcardFront,
'idcard_back' => $idcardBack,
'cert_images' => $certImages,
'city' => $normalizedCity,
'work_status' => 'off',
'verify_status' => 'pending',
'audit_msg' => '',
'audittime' => null,
'audit_admin_id' => 0,
'updatetime' => time(),
'updatetime' => time(),
];
Db::startTrans();
try {
if ($exist) {
$masterId = (int)$exist['id'];
Db::name('master')->where('id', $masterId)->update($save);
Db::name('master_skill')->where('master_id', $masterId)->delete();
} else {
$save['user_id'] = $this->uid();
$save['createtime'] = time();
$masterId = Db::name('master')->insertGetId($save);
}
$masterId = $mid;
Db::name('master')->where('id', $masterId)->update($save);
Db::name('master_skill')->where('master_id', $masterId)->delete();
foreach ($skillCatIds as $catId) {
$cName = isset($catNameMap[$catId]) ? (string)$catNameMap[$catId] : '';
Db::name('master_skill')->insert([
@@ -217,8 +222,17 @@ class Master extends Base
public function info()
{
$master = $this->masterInfo();
if (!$master) {
$this->success('未入驻', ['applied' => false]);
if (!$master || ($master['verify_status'] ?? 'draft') === 'draft') {
$this->success('未入驻', [
'applied' => false,
'master' => $master ? [
'id' => (int)$master['id'],
'nickname' => (string)($master['nickname'] ?? ''),
'mobile' => (string)($master['mobile'] ?? ''),
'avatar' => !empty($master['avatar']) ? \app\common\library\MasterAvatar::url($master['avatar']) : '',
'verify_status' => 'draft',
] : null,
]);
}
$skillsRaw = Db::name('master_skill')->alias('s')
->join('service_cat c', 'c.id = s.cat_id', 'LEFT')
@@ -298,13 +312,19 @@ class Master extends Base
if (!preg_match('/^1\d{10}$/', $mobile)) {
$this->error('请输入正确的接单手机号');
}
if ($mobile !== (string)($master['mobile'] ?? '')) {
$conflict = Db::name('master')->where('mobile', $mobile)->where('id', '<>', (int)$master['id'])->find();
if ($conflict) {
$this->error('该手机号已被其他师傅账号绑定');
}
}
$update = ['mobile' => $mobile, 'updatetime' => time()];
$avatar = trim((string)$this->request->post('avatar', ''));
if ($avatar !== '') {
$this->validateAvatar($avatar);
$update['avatar'] = $avatar;
}
Db::name('master')->where('id', (int)$master['id'])->where('user_id', $this->uid())->update($update);
Db::name('master')->where('id', (int)$master['id'])->update($update);
$this->success('保存成功');
}
@@ -403,6 +423,41 @@ class Master extends Base
]);
}
/**
* 免登录只读位置逆解析(供未登录游客进大厅自动定位显示省市区与地标,不写库)
* @ApiMethod (GET)
*/
public function resolveLocation()
{
$rawLat = $this->request->param('lat', '');
$rawLng = $this->request->param('lng', '');
if (!$this->isValidCoord($rawLat, $rawLng)) {
$this->error('定位坐标无效');
}
$lat = round((float)$rawLat, 6);
$lng = round((float)$rawLng, 6);
$resolvedCity = '';
$resolvedDistrict = '';
$resolvedPoi = '';
$geo = TiandituService::regeocoder($lat, $lng);
if (is_array($geo)) {
$resolvedCity = trim((string)($geo['city'] ?: ($geo['province'] ?? '')));
$resolvedDistrict = trim((string)($geo['district'] ?? ''));
$resolvedPoi = trim((string)($geo['poi'] ?? ''));
}
$locationLabel = trim($resolvedCity . $resolvedDistrict . ($resolvedPoi !== '' ? ('·' . $resolvedPoi) : ''));
$this->success('', [
'lat' => $lat,
'lng' => $lng,
'location_city' => $resolvedCity,
'location_district' => $resolvedDistrict,
'location_label' => $locationLabel,
]);
}
/**
* 地点关键词检索(供定位受限或手动切换听单区域使用)
* @ApiMethod (GET)
@@ -545,14 +600,14 @@ class Master extends Base
}
/**
* 订单大厅:支持基于定位的智能推荐、离我最近与多种排序及单类型筛选
* 订单大厅:支持已认证师傅接单筛选,及未登录游客免登录公开脱敏浏览
*/
public function hall()
{
$master = $this->requireMasterProfile();
$master = $this->masterInfo();
$this->recycleExpired();
$catIds = $this->getMasterSkillCatIds((int)$master['id']);
$catIds = $master ? $this->getMasterSkillCatIds((int)$master['id']) : [];
$page = max(1, (int)$this->request->param('page', 1));
$limit = min(30, max(1, (int)$this->request->param('limit', 10)));
$sort = trim((string)$this->request->param('sort', 'recommend')); // recommend 智能推荐 / distance 离我最近 / new 最新 / amount 报酬 / urgent 急单 / time 时效
@@ -751,10 +806,12 @@ class Master extends Base
}
$now = time();
$qualificationCerts = OrderQualification::certificates((int)$master['id']);
$qualificationCerts = $master ? OrderQualification::certificates((int)$master['id']) : [];
$qualificationToday = date('Y-m-d');
foreach ($list as &$row) {
$row['qualification_allowed'] = OrderQualification::allows($row['qual_req'], $qualificationCerts, $qualificationToday);
$row['qualification_allowed'] = $master
? OrderQualification::allows($row['qual_req'], $qualificationCerts, $qualificationToday)
: true;
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'];
@@ -764,7 +821,15 @@ class Master extends Base
$row['commission'] = $hallSettleCalc['commission'];
$row['master_fee'] = $hallSettleCalc['settle_amount'];
$row['urgent'] = (int)$row['urgent'];
$row['mobile'] = substr_replace($row['mobile'], '****', 3, 4);
if (!$master) {
// 未登录浏览仅展示脱敏区域信息与项目,严禁下发客户手机与姓名全称
$row['user_id'] = 0;
$row['mobile'] = '';
$rawContact = trim((string)($row['contact'] ?? ''));
$row['contact'] = $rawContact !== '' ? (mb_substr($rawContact, 0, 1) . '**') : '业主';
} else {
$row['mobile'] = substr_replace($row['mobile'], '****', 3, 4);
}
$rawAddr = (string)$row['address'];
$maskedAddr = preg_replace('/\d+栋|\d+单元|\d+室|\d+号楼/', '**', $rawAddr);
@@ -873,6 +938,7 @@ class Master extends Base
'location_source' => $reqHasValidCoord ? 'realtime' : ($dbHasValidCoord ? 'saved' : 'none'),
'location_city' => $locationCity,
'serve_radius' => $serveRadius,
'guest_mode' => !$master,
'filter_options' => ['categories' => $filterCategories, 'service_types' => $filterTypes],
]);
}
@@ -892,9 +958,6 @@ class Master extends Base
if (!$order) {
$this->error('订单不存在');
}
if ((int)$order['user_id'] === (int)$this->uid()) {
$this->error('不能承接或报价自己发布的订单');
}
if ($order['price_type'] === 'quote') {
$this->error('该订单为师傅报价订单,请提交报价');
}
@@ -935,7 +998,7 @@ class Master extends Base
*/
public function contact()
{
$order = $this->ownOrder((int)$this->request->post('order_id'), 'master');
$order = $this->ownOrder((int)$this->request->post('order_id'));
if ((int)$order['contact_time'] > 0) {
$this->success('已记录');
}
@@ -950,7 +1013,7 @@ class Master extends Base
*/
public function schedule()
{
$order = $this->ownOrder((int)$this->request->post('order_id'), 'master');
$order = $this->ownOrder((int)$this->request->post('order_id'));
if (!in_array((int)$order['status'], [OrderStatus::ACCEPTED, OrderStatus::APPOINTED], true)) {
$this->error('当前状态(' . OrderStatus::label((int)$order['status']) . ')不可修改预约时间');
}
@@ -977,7 +1040,7 @@ class Master extends Base
*/
public function arrive()
{
$order = $this->ownOrder((int)$this->request->post('order_id'), 'master');
$order = $this->ownOrder((int)$this->request->post('order_id'));
$lng = trim((string)$this->request->post('lng', ''));
$lat = trim((string)$this->request->post('lat', ''));
$extra = ['arrive_time' => time()];
@@ -1002,7 +1065,7 @@ class Master extends Base
*/
public function startJob()
{
$order = $this->ownOrder((int)$this->request->post('order_id'), 'master');
$order = $this->ownOrder((int)$this->request->post('order_id'));
$this->transit($order, OrderStatus::WORKING, '师傅开始施工', ['start_time' => time()], 'master', (int)$order['master_id']);
$this->notify('user', (int)$order['user_id'], '师傅已开工', '师傅已开始服务,请留意进度', 'order', (int)$order['id']);
$this->success('已开工');
@@ -1014,7 +1077,7 @@ class Master extends Base
*/
public function finish()
{
$order = $this->ownOrder((int)$this->request->post('order_id'), 'master');
$order = $this->ownOrder((int)$this->request->post('order_id'));
$images = FinishImageUrls::normalize((array)$this->request->post('images/a', []));
$damage = trim((string)$this->request->post('damage_remark', ''));
@@ -1315,9 +1378,6 @@ class Master extends Base
if (!$order) {
$this->error('订单不存在');
}
if ((int)$order['user_id'] === (int)$this->uid()) {
$this->error('不能承接或报价自己发布的订单');
}
if ($order['price_type'] !== 'quote') {
$this->error('该订单不是报价竞价订单');
}
@@ -1393,7 +1453,7 @@ class Master extends Base
$openid = '';
if ($channel === 'wechat' && $wdCfg['transfer_mode'] === 'wx_mch_transfer') {
try {
$openid = PaymentService::resolveUserOpenid($this->uid(), $wxCode);
$openid = PaymentService::resolveMasterOpenid($this->masterId(), $wxCode);
} catch (\Throwable $oe) {
$this->error($oe->getMessage());
return;
@@ -1542,7 +1602,7 @@ class Master extends Base
$this->error('当前提现单状态(' . PaymentService::transferStateLabel($wd['transfer_state']) . ')暂不可拉起确认收款,请稍后重试');
}
$wxSvc = new WxPayV3Service();
$wxSvc = new WxPayV3Service(['side' => 'master']);
$this->success('', [
'already_done' => false,
'withdraw_id' => (int)$wd['id'],
@@ -2029,8 +2089,8 @@ class Master extends Base
public function orderDetail()
{
$master = $this->requireMasterProfile();
$masterId = (int)$master['id'];
$master = $this->masterInfo();
$masterId = $master ? (int)$master['id'] : 0;
$orderId = (int)$this->request->param('id') ?: (int)$this->request->param('order_id');
if ($orderId <= 0) {
$this->error('参数错误');
@@ -2061,7 +2121,9 @@ class Master extends Base
$mobile = (string)$order['mobile'];
$address = (string)$order['address'];
if (!$isMyOrder) {
$mobile = strlen($mobile) >= 7 ? substr_replace($mobile, '****', 3, 4) : $mobile;
$mobile = $masterId > 0
? (strlen($mobile) >= 7 ? substr_replace($mobile, '****', 3, 4) : $mobile)
: '';
$address = preg_replace('/\d+号|\d+栋|\d+单元|\d+室/', '***', $address);
if (mb_strlen($address) > 10) {
$address = mb_substr($address, 0, 8) . '****号';
@@ -2347,7 +2409,9 @@ class Master extends Base
$estCommission = $estCalc['commission'];
$estMasterFee = $estCalc['settle_amount'];
$qualificationAllowed = OrderQualification::forMaster($order['qual_req'] ?? '', $masterId);
$qualificationAllowed = $masterId > 0
? OrderQualification::forMaster($order['qual_req'] ?? '', $masterId)
: true;
$data = [
'id' => (int)$order['id'],
'order_no' => $order['order_no'],
@@ -2410,8 +2474,8 @@ class Master extends Base
'description' => $myQuote['description'],
'status' => $myQuote['status'],
] : null,
'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()),
'can_grab' => ($qualificationAllowed && $order['price_type'] !== 'quote' && (int)$order['status'] === OrderStatus::PENDING_ACCEPT && (int)$order['master_id'] === 0),
'can_quote' => ($qualificationAllowed && $order['price_type'] === 'quote' && in_array((int)$order['status'], [OrderStatus::PENDING_ACCEPT, OrderStatus::QUOTING], true) && (int)$order['master_id'] === 0 && !$myQuote),
];
// 本人已接工单:附带完整履约节点、增项补差、完工取证、结算入账与操作轨迹
@@ -3365,5 +3429,41 @@ class Master extends Base
];
}
}
/**
* 师傅端我的评价列表
*/
public function reviews()
{
$master = $this->requireMasterProfile();
$masterId = (int)$master['id'];
$list = Db::name('review')
->alias('r')
->join('user u', 'u.id = r.user_id', 'LEFT')
->field('r.id,r.score,r.tags,r.content,r.images,r.is_anonymous,r.reply,r.createtime,u.nickname,u.avatar')
->where('r.master_id', $masterId)
->where('r.status', 'normal')
->order('r.id desc')
->limit(50)
->select();
foreach ($list as &$row) {
if ((int)$row['is_anonymous'] === 1) {
$row['nickname'] = '匿名用户';
$row['avatar'] = '';
}
$row['time_text'] = date('Y-m-d H:i', (int)$row['createtime']);
}
unset($row);
$stat = Db::name('review')->where('master_id', $masterId)->where('status', 'normal')
->field('count(*) as total, avg(score) as avg_score')->find();
$this->success('', [
'list' => $list,
'total' => (int)$stat['total'],
'avg_score' => round((float)$stat['avg_score'], 2),
]);
}
}

查看文件

@@ -0,0 +1,334 @@
<?php
namespace app\api\controller;
use app\common\library\MasterSecurity;
use app\common\library\MasterToken;
use app\common\library\WxLogin;
use think\Db;
/**
* 师傅端独立登录 / 安全凭证 / 个人信息接口(完全独立于 fa_user)
*/
class MasterAuth extends MasterBase
{
protected $noNeedLogin = ['login', 'wxlogin', 'wxPhoneLogin'];
/**
* 师傅手机号 + 密码登录(H5调试/账号密码通道)
* @ApiMethod (POST)
*/
public function login()
{
$mobile = trim((string)$this->request->post('mobile', $this->request->post('account', '')));
$mobile = preg_replace('/[^\d]/', '', $mobile);
$password = (string)$this->request->post('password', '');
$code = trim((string)$this->request->post('code', ''));
if ($password === '' && $code !== '') {
$this->error('短信验证码通道已移除,请使用手机号密码或微信一键登录', null, 2010);
}
if ($mobile === '') {
$this->error('请填写手机号');
}
if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
$this->error('手机号格式不正确');
}
if ($password === '') {
$this->error('请填写登录密码');
}
$master = Db::name('master')->where('mobile', $mobile)->find();
if (!$master) {
if (!preg_match('/^\S{6,30}$/', $password)) {
$this->error('登录密码须为6至30位非空字符');
}
if (!$this->masterAuth->register($mobile, $password)) {
$this->error($this->masterAuth->getError() ?: '注册登录失败');
}
} else {
if (isset($master['status']) && $master['status'] !== 'normal') {
$this->error('师傅账号已被禁用');
}
if (empty($master['password'])) {
$this->error('该师傅账号尚未设置登录密码,请使用微信一键登录后在账号安全中设置密码');
}
try {
MasterSecurity::verify((int)$master['id'], 'login', $password);
} catch (\Throwable $e) {
$this->error($e->getMessage() === '密码不正确' ? '手机号或密码不正确' : $e->getMessage());
}
if (!$this->masterAuth->direct((int)$master['id'])) {
$this->error($this->masterAuth->getError() ?: '登录失败');
}
}
$this->success('登录成功', [
'token' => $this->masterAuth->getToken(),
'expires' => 2592000,
'masterinfo' => $this->profileData(),
]);
}
/**
* 师傅端微信小程序 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'],
]);
}
/**
* 师傅端微信手机号授权快捷登录
* @ApiMethod (POST)
*/
public function wxPhoneLogin()
{
$phoneCode = trim((string)$this->request->post('phone_code'));
$loginCode = trim((string)$this->request->post('login_code'));
if ($phoneCode === '') {
$this->error('缺少微信手机号授权凭证');
}
$phoneInfo = WxLogin::getPhoneNumber($phoneCode, 'master');
if (isset($phoneInfo['error'])) {
$this->error('获取微信手机号失败:' . $phoneInfo['error'], ['wx_errcode' => isset($phoneInfo['errcode']) ? (int)$phoneInfo['errcode'] : 0]);
}
$mobile = isset($phoneInfo['purePhoneNumber']) ? (string)$phoneInfo['purePhoneNumber'] : (string)($phoneInfo['phoneNumber'] ?? '');
if ($mobile === '') {
$this->error('解析手机号失败');
}
$openid = '';
$sessionKey = '';
$unionid = '';
if ($loginCode !== '') {
$wx = WxLogin::jscode2session($loginCode, 'master');
if (isset($wx['error']) || empty($wx['openid'])) {
$errMsg = isset($wx['error']) && $wx['error'] !== '' ? (string)$wx['error'] : '微信登录凭证换取 OpenID 失败,请重进小程序再试';
\think\Log::error('[MasterAuth::wxPhoneLogin] jscode2session 失败: ' . $errMsg);
$this->error($errMsg, ['wx_errcode' => isset($wx['errcode']) ? (int)$wx['errcode'] : 0]);
}
$openid = $wx['openid'];
$sessionKey = isset($wx['session_key']) ? $wx['session_key'] : '';
$unionid = isset($wx['unionid']) ? $wx['unionid'] : '';
}
$ret = WxLogin::provisionMasterWithMobile($mobile, $openid, $unionid, $sessionKey);
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'],
'mobile' => $mobile,
]);
}
/**
* 当前登录师傅基础信息
*/
public function profile()
{
$this->success('', $this->profileData());
}
/**
* 退出登录
* @ApiMethod (POST)
*/
public function logout()
{
$this->masterAuth->logout();
$this->success('已退出登录');
}
/**
* 安全状态查询(登录密码 / 支付密码)
*/
public function securityStatus()
{
$mid = $this->masterId();
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
$security = Db::name('master_security')->where('master_id', $mid)->find();
$this->success('', [
'has_login_password' => !empty($master['password']),
'has_payment_password' => $security && $security['payment_password_hash'] !== '',
]);
}
/**
* 设置或修改师傅登录密码
* @ApiMethod (POST)
*/
public function changeLoginPassword()
{
$mid = $this->masterId();
$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位非空字符');
}
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
if (!empty($master['password'])) {
try {
MasterSecurity::verify($mid, 'login', $old);
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
$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() ?: '设置失败');
}
MasterToken::clear($mid);
$this->success('登录密码已更新,请重新登录');
}
/**
* 首次设置师傅支付密码(支持已设登录密码走登录密码验证,或未设登录密码走绑定微信手机号验证)
* @ApiMethod (POST)
*/
public function setPaymentPassword()
{
$mid = $this->masterId();
$new = (string)$this->request->post('new_password', '');
if (!preg_match('/^\d{6}$/', $new)) {
$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)
->where('payment_password_hash', '')
->update(['payment_password_hash' => password_hash($new, PASSWORD_DEFAULT)]);
if (!$updated) {
$this->error('支付密码已设置,请使用修改功能');
}
$this->success('支付密码设置成功');
}
/**
* 修改师傅支付密码
* @ApiMethod (POST)
*/
public function changePaymentPassword()
{
$mid = $this->masterId();
$new = (string)$this->request->post('new_password', '');
if (!preg_match('/^\d{6}$/', $new)) {
$this->error('支付密码须为6位数字');
}
$oldHash = (string)Db::name('master_security')->where('master_id', $mid)->value('payment_password_hash');
try {
MasterSecurity::verify($mid, 'payment', (string)$this->request->post('old_password', ''));
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
$updated = Db::name('master_security')
->where('master_id', $mid)
->where('payment_password_hash', $oldHash)
->update(['payment_password_hash' => password_hash($new, PASSWORD_DEFAULT)]);
if (!$updated) {
$this->error('支付密码已变更,请重新操作');
}
$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();
$master = Db::name('master')->where('id', $mid)->find();
if (!$master) {
return null;
}
$unread = (int)Db::name('message')
->where('receive_type', 'master')
->where('receive_id', $mid)
->where('is_read', 0)
->count();
return [
'id' => (int)$master['id'],
'nickname' => !empty($master['nickname']) ? (string)$master['nickname'] : (!empty($master['realname']) ? (string)$master['realname'] : ('师傅' . substr((string)$master['mobile'], -4))),
'realname' => (string)$master['realname'],
'mobile' => (string)$master['mobile'],
'avatar' => !empty($master['avatar']) ? \app\common\library\MasterAvatar::url($master['avatar']) : '',
'city' => (string)$master['city'],
'verify_status' => (string)$master['verify_status'],
'audit_msg' => (string)$master['audit_msg'],
'work_status' => (string)$master['work_status'],
'level' => (int)$master['level'],
'score' => (float)$master['score'],
'order_count' => (int)$master['order_count'],
'money' => (float)$master['money'],
'frozen_money' => (float)$master['frozen_money'],
'can_take' => $master['verify_status'] === 'pass',
'needs_apply' => ($master['verify_status'] === 'draft'),
'unread_count' => $unread,
];
}
}

查看文件

@@ -0,0 +1,216 @@
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\library\MasterAuth;
use app\common\library\MasterSecurity;
use app\common\library\OrderStatus;
use think\Config;
use think\Db;
use think\Loader;
/**
* 师傅端 API 基类(完全独立于 fa_user,仅校验 fa_master_token -> fa_master)
*/
class MasterBase extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
/** @var MasterAuth */
protected $masterAuth = null;
/** @var array|null 当前登录师傅行记录 */
protected $master = null;
protected function _initialize()
{
check_cors_request();
check_ip_allowed();
$this->request->filter('trim,strip_tags,htmlspecialchars');
$this->masterAuth = MasterAuth::instance();
$controllername = Loader::parseName($this->request->controller());
$actionname = strtolower($this->request->action());
$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('master_token')));
$needLogin = true;
$arr = array_map('strtolower', (array)$this->noNeedLogin);
if (in_array('*', $arr, true) || in_array($actionname, $arr, true)) {
$needLogin = false;
}
if ($needLogin) {
$this->masterAuth->init($token);
if (!$this->masterAuth->isLogin()) {
$this->error(__('Please login first'), null, 401);
}
} elseif ($token) {
$this->masterAuth->init($token);
}
$this->master = $this->masterAuth->getMaster();
$upload = \app\common\model\Config::upload();
\think\Hook::listen('upload_config_init', $upload);
Config::set('upload', array_merge(Config::get('upload'), $upload));
$this->loadlang($controllername);
}
/**
* 当前登录师傅 ID
*/
protected function masterId()
{
return (int)$this->masterAuth->id();
}
/**
* 获取当前登录师傅完整档案
*/
protected function masterInfo($reload = false)
{
if ($this->masterId() <= 0) {
return false;
}
if ($this->master === null || $reload) {
$this->master = $this->masterAuth->reload();
}
return $this->master ?: false;
}
/**
* 要求师傅已提交过实名入驻资料(非 draft 草稿态)
*/
protected function requireMasterProfile()
{
$master = $this->masterInfo();
if (!$master || ($master['verify_status'] ?? 'draft') === 'draft') {
$this->error('请先完成师傅入驻', ['need_apply' => 1], 2001);
}
return $master;
}
/**
* 要求师傅已通过实名认证,供接单/报价/提现等敏感操作使用
*/
protected function requireMaster()
{
$master = $this->requireMasterProfile();
if ($master['verify_status'] === 'pending') {
$this->error('师傅资质审核中,请耐心等待', ['verify_status' => 'pending'], 2002);
}
if ($master['verify_status'] === 'reject') {
$this->error('资质未通过:' . $master['audit_msg'], ['verify_status' => 'reject'], 2003);
}
if ($master['verify_status'] !== 'pass') {
$this->error('师傅资质尚未审核通过,无法接单');
}
return $master;
}
/**
* 校验支付密码(用于提现)
*/
protected function requirePaymentPassword()
{
try {
MasterSecurity::verify($this->masterId(), 'payment', (string)$this->request->post('payment_password', ''));
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
}
/**
* 验证新头像属于当前师傅账号,且符合大小与格式要求
*/
protected function validateAvatar($url)
{
$attachment = Db::name('attachment')
->where('master_id', $this->masterId())
->where('category', 'avatar')
->where('url', $url)
->find();
if (
!$attachment
|| (int)$attachment['filesize'] > 10 * 1024 * 1024
|| !in_array(strtolower((string)$attachment['mimetype']), ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/bmp'], true)
) {
$this->error('头像无效,请重新上传不超过10MB的图片');
}
}
/**
* 取本师傅订单(越权拦截)
*/
protected function ownOrder($orderId)
{
$orderId = (int)$orderId;
if ($orderId <= 0) {
$this->error('订单参数错误');
}
$order = Db::name('order')->where('id', $orderId)->find();
if (!$order) {
$this->error('订单不存在');
}
$master = $this->requireMaster();
if ((int)$order['master_id'] !== (int)$master['id']) {
$this->error('无权操作该订单', null, 403);
}
return $order;
}
/**
* 订单状态流转:校验 -> 乐观锁更新 -> 写流水
*/
protected function transit(array $order, $to, $remark = '', $extra = [], $operatorType = 'master', $operatorId = 0)
{
$from = (int)$order['status'];
if (!OrderStatus::can($from, $to)) {
$this->error('订单状态「' . OrderStatus::label($from) . '」不允许变更为「' . OrderStatus::label($to) . '」');
}
$data = array_merge($extra, [
'status' => (int)$to,
'updatetime' => time(),
]);
$updated = Db::name('order')->where('id', (int)$order['id'])->where('status', $from)->update($data);
if (!$updated) {
$this->error('订单状态已变更,请刷新后重试');
}
$this->addLog((int)$order['id'], (int)$to, $remark, $operatorType, $operatorId ?: $this->masterId());
return array_merge($order, $data);
}
protected function addLog($orderId, $status, $remark = '', $operatorType = 'master', $operatorId = 0)
{
Db::name('order_log')->insert([
'order_id' => (int)$orderId,
'status' => (int)$status,
'remark' => mb_substr((string)$remark, 0, 255),
'operator_type' => $operatorType,
'operator_id' => (int)$operatorId,
'createtime' => time(),
]);
}
protected function notify($receiveType, $receiveId, $title, $content, $type = 'order', $orderId = 0)
{
if (!$receiveId) {
return;
}
Db::name('message')->insert([
'receive_type' => $receiveType,
'receive_id' => (int)$receiveId,
'type' => $type,
'title' => mb_substr((string)$title, 0, 100),
'content' => mb_substr((string)$content, 0, 500),
'order_id' => (int)$orderId,
'is_read' => 0,
'createtime' => time(),
]);
}
}

查看文件

@@ -0,0 +1,82 @@
<?php
namespace app\api\controller;
use think\Db;
/**
* 师傅端独立消息中心(严格隔离仅操作 receive_type = 'master' 且 receive_id = master_id)
*/
class MasterMessage extends MasterBase
{
public function index()
{
$category = $this->request->param('category', 'all');
$page = max(1, (int)$this->request->param('page', 1));
$limit = min(50, max(1, (int)$this->request->param('limit', 20)));
$mid = $this->masterId();
$build = function () use ($mid, $category) {
$q = Db::name('message')->where('receive_type', 'master')->where('receive_id', $mid);
if ($category !== 'all' && $category !== '') {
$q->where('type', $category);
}
return $q;
};
$total = $build()->count();
$list = $build()->order('id desc')->page($page, $limit)->select();
foreach ($list as &$row) {
$row['time_text'] = date('m-d H:i', (int)$row['createtime']);
$row['is_read'] = (int)$row['is_read'];
}
unset($row);
$this->success('', [
'list' => $list,
'total' => (int)$total,
'unread' => $this->unreadCount($mid),
'page' => $page,
]);
}
public function read()
{
$id = (int)$this->request->post('id');
$mid = $this->masterId();
$row = Db::name('message')->where('id', $id)->where('receive_type', 'master')->where('receive_id', $mid)->find();
if (!$row) {
$this->error('消息不存在');
}
Db::name('message')->where('id', $id)->update(['is_read' => 1]);
$this->success('已读');
}
public function readAll()
{
$mid = $this->masterId();
$affected = Db::name('message')
->where('receive_type', 'master')
->where('receive_id', $mid)
->where('is_read', 0)
->update(['is_read' => 1]);
$this->success('已全部标记为已读', ['count' => (int)$affected]);
}
public function unread()
{
$this->success('', ['unread' => $this->unreadCount($this->masterId())]);
}
protected function unreadCount($mid)
{
if ($mid <= 0) {
return 0;
}
return (int)Db::name('message')
->where('receive_type', 'master')
->where('receive_id', $mid)
->where('is_read', 0)
->count();
}
}

查看文件

@@ -5,27 +5,19 @@ namespace app\api\controller;
use think\Db;
/**
* 消息中心(用户 / 师傅共用)
* 用户端消息中心(仅限 user 身份,师傅端使用 MasterMessage)
*/
class Message extends Base
{
/**
* 消息列表
* @ApiParams (name="type", type="string", required=false, description="user|master,默认 user")
* @ApiParams (name="category", type="string", required=false, description="all|order|system|audit|remind")
*/
public function index()
{
$type = $this->request->param('type', 'user');
$type = $type === 'master' ? 'master' : 'user';
$category = $this->request->param('category', 'all');
$page = max(1, (int)$this->request->param('page', 1));
$limit = min(50, max(1, (int)$this->request->param('limit', 20)));
$receiveId = $this->receiveId($type);
$build = function () use ($type, $receiveId, $category) {
$q = Db::name('message')->where('receive_type', $type)->where('receive_id', $receiveId);
$uid = $this->uid();
$build = function () use ($uid, $category) {
$q = Db::name('message')->where('receive_type', 'user')->where('receive_id', $uid);
if ($category !== 'all' && $category !== '') {
$q->where('type', $category);
}
@@ -42,24 +34,19 @@ class Message extends Base
unset($row);
$this->success('', [
'list' => $list,
'total' => (int)$total,
'unread' => $this->unreadCount($type, $receiveId),
'page' => $page,
'list' => $list,
'total' => (int)$total,
'unread' => $this->unreadCount($uid),
'page' => $page,
]);
}
/**
* 标记单条已读
* @ApiMethod (POST)
*/
public function read()
{
$id = (int)$this->request->post('id');
$type = $this->request->post('type', 'user') === 'master' ? 'master' : 'user';
$receiveId = $this->receiveId($type);
$uid = $this->uid();
$row = Db::name('message')->where('id', $id)->where('receive_type', $type)->where('receive_id', $receiveId)->find();
$row = Db::name('message')->where('id', $id)->where('receive_type', 'user')->where('receive_id', $uid)->find();
if (!$row) {
$this->error('消息不存在');
}
@@ -67,48 +54,27 @@ class Message extends Base
$this->success('已读');
}
/**
* 全部标记已读
* @ApiMethod (POST)
*/
public function readAll()
{
$type = $this->request->post('type', 'user') === 'master' ? 'master' : 'user';
$receiveId = $this->receiveId($type);
$uid = $this->uid();
$affected = Db::name('message')
->where('receive_type', $type)->where('receive_id', $receiveId)->where('is_read', 0)
->where('receive_type', 'user')->where('receive_id', $uid)->where('is_read', 0)
->update(['is_read' => 1]);
$this->success('已全部标记为已读', ['count' => (int)$affected]);
}
/**
* 未读数(供 Tab 角标)
*/
public function unread()
{
$type = $this->request->param('type', 'user') === 'master' ? 'master' : 'user';
$this->success('', ['unread' => $this->unreadCount($type, $this->receiveId($type))]);
$this->success('', ['unread' => $this->unreadCount($this->uid())]);
}
/**
* 消息归属ID:用户=uid,师傅=master.id
*/
protected function receiveId($type)
protected function unreadCount($uid)
{
if ($type === 'master') {
$master = $this->masterInfo();
return $master ? (int)$master['id'] : 0;
}
return $this->uid();
}
protected function unreadCount($type, $receiveId)
{
if (!$receiveId) {
if (!$uid) {
return 0;
}
return (int)Db::name('message')
->where('receive_type', $type)->where('receive_id', $receiveId)->where('is_read', 0)
->where('receive_type', 'user')->where('receive_id', $uid)->where('is_read', 0)
->count();
}
}

查看文件

@@ -88,11 +88,14 @@ class Review extends Base
{
$masterId = (int)$this->request->param('master_id');
if ($masterId <= 0) {
$master = $this->masterInfo();
if (!$master) {
$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', ''));
$masterAuth = \app\common\library\MasterAuth::instance();
if ($token && $masterAuth->init($token)) {
$masterId = (int)$masterAuth->id();
}
if ($masterId <= 0) {
$this->error('师傅不存在');
}
$masterId = (int)$master['id'];
}
$list = Db::name('review')
->alias('r')