diff --git a/YJYF/YJYF.vue b/YJYF/YJYF.vue
index e3bad6d..d10a903 100644
--- a/YJYF/YJYF.vue
+++ b/YJYF/YJYF.vue
@@ -86,14 +86,7 @@
-
-
-
+
{{ c.name }}
@@ -254,29 +247,9 @@
/* ---------- 服务图标:纯 CSS 图元,零图片依赖
o=描边框 l=实心线 d=圆形描边 t=三角
格式 [类型, left, top, w, h, radius, rotate],画布 56×56rpx */
- const iconCats = [
- { n: '家具', p: [['o',12,10,32,16,6],['o',6,26,44,14,5],['l',14,40,3,7],['l',39,40,3,7]] },
- { n: '卫浴', p: [['l',20,6,3,12],['l',20,6,13,3],['o',4,21,48,21,'4 4 16 16'],['l',12,42,3,6],['l',41,42,3,6]] },
- { n: '灯具', p: [['l',27,4,3,13],['o',12,17,32,16,'16 16 0 0'],['l',8,33,40,3],['l',16,40,3,8],['l',27,40,3,8],['l',38,40,3,8]] },
- { n: '锁具', p: [['o',14,16,26,34,5],['o',19,21,16,9,2],['l',19,36,5,5],['l',26,36,5,5],['l',19,43,5,5],['l',26,43,5,5],['l',40,26,8,3]] },
- { n: '窗帘', p: [['l',2,8,52,3],['o',6,11,19,37,'0 0 5 5'],['l',12,11,2,31],['l',19,11,2,31],['o',31,11,19,37,'0 0 5 5'],['l',37,11,2,31],['l',44,11,2,31]] },
- { n: '墙纸/壁画', p: [['o',6,10,22,30,3],['l',11,30,12,3],['o',29,16,22,30,3],['l',34,36,12,3]] },
- { n: '净水器', p: [['o',19,8,18,6,2],['o',8,14,40,26,4],['l',17,40,3,8],['l',13,45,7,3],['l',32,40,3,8],['l',32,45,7,3]] },
- { n: '晾衣架', p: [['l',5,11,46,3],['l',11,14,3,9],['l',42,14,3,9],['l',5,23,46,3],['l',17,26,3,12],['l',27,26,3,17],['l',37,26,3,12]] },
- { n: '门窗', p: [['o',15,8,26,40,'4 4 0 0'],['o',21,14,14,11,2],['l',35,30,3,8],['l',11,48,34,3]] },
- { n: '家电', p: [['o',17,8,24,40,5],['l',17,22,24,3],['l',33,12,3,7],['l',33,26,3,7]] },
- { n: '电视/投影', p: [['o',5,12,46,30,4],['t',24,20,11,7],['l',26,42,4,5],['l',19,47,18,3]] },
- { n: '淋浴房', p: [['o',8,10,40,38,'4 4 0 0'],['l',30,10,3,38],['l',24,26,3,8],['l',6,48,44,3]] },
- { n: '商用厨电', p: [['o',15,8,28,40,4],['l',28,8,3,40],['l',21,20,3,9],['l',34,20,3,9]] },
- { n: '健身器材', p: [['d',3,28,24,24],['l',12,37,6,6],['l',14,39,28,3,null,-43],['l',33,14,3,16],['l',26,10,16,4,2],['l',42,10,3,14],['l',36,10,14,3]] },
- { n: '更多', p: [['o',8,8,18,18,5],['o',30,8,18,18,5],['o',8,30,18,18,5],['o',30,30,18,18,5]] }
- ]
-
- /* 图标库:按后端返回的 icon 键匹配(顺序与 iconCats 一致) */
- const ICON_KEYS = ['sofa', 'bath', 'lamp', 'lock', 'curtain', 'frame', 'water', 'rack', 'door', 'appliance', 'tv', 'shower', 'kitchen', 'fitness', 'more']
- const iconLib = {}
- iconCats.forEach((c, i) => { iconLib[ICON_KEYS[i]] = c.p })
- const iconOf = (key) => iconLib[key] || iconLib.more
+ /* 服务图标资源:static/icons/.png(双色扁平,由 SVG 渲染) */
+ const ICON_KEYS = ['sofa','bath','lamp','lock','curtain','frame','water','rack','door','appliance','tv','shower','kitchen','fitness','more']
+ const iconOf = (key) => (ICON_KEYS.indexOf(key) > -1 ? key : 'more')
/* 服务类目(真实接口) */
const cats = ref([])
@@ -291,15 +264,6 @@
} catch (e) {}
}
- const partStyle = (p) => {
- if (p[0] === 't') {
- return 'left:' + p[1] + 'rpx;top:' + p[2] + 'rpx;border-left:' + p[3] + 'rpx solid #B85E2A;border-top:' + p[4] + 'rpx solid transparent;border-bottom:' + p[4] + 'rpx solid transparent;'
- }
- let s = 'left:' + p[1] + 'rpx;top:' + p[2] + 'rpx;width:' + p[3] + 'rpx;height:' + p[4] + 'rpx;'
- if (p[5]) s += 'border-radius:' + String(p[5]).split(/\s+/).map(function (v) { return v + 'rpx' }).join(' ') + ';'
- if (p[6]) s += 'transform:rotate(' + p[6] + 'deg);transform-origin:0 50%;'
- return s
- }
/* ---------- 交互 ---------- */
const toast = (title) => uni.showToast({ title, icon: 'none' })
@@ -327,7 +291,7 @@
}
const onUser = () => {
if (!needLogin()) return
- uni.navigateTo({ url: '/pages/order/list' })
+ uni.navigateTo({ url: '/pages/mine/mine' })
}
const switchTab = (i) => {
@@ -717,6 +681,10 @@
align-items: center;
justify-content: center;
}
+ .cat-img {
+ width: 58rpx;
+ height: 58rpx;
+ }
.cat-name {
display: block;
margin-top: 12rpx;
diff --git a/db/schema_phase2.sql b/db/schema_phase2.sql
new file mode 100644
index 0000000..bc928d5
--- /dev/null
+++ b/db/schema_phase2.sql
@@ -0,0 +1,41 @@
+-- ============================================================================
+-- 优匠优服 · Phase 2(微信授权登录 / 申诉中心)
+-- 纯新增表,不改动既有表结构
+-- ============================================================================
+SET NAMES utf8mb4;
+
+-- 微信授权账号绑定(不动 fa_user 结构,独立表存放)
+CREATE TABLE IF NOT EXISTS `fa_user_wechat` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '关联 fa_user.id',
+ `openid` varchar(64) NOT NULL DEFAULT '' COMMENT '小程序 openid',
+ `unionid` varchar(64) NOT NULL DEFAULT '' COMMENT '开放平台 unionid',
+ `session_key` varchar(128) NOT NULL DEFAULT '',
+ `nickname` varchar(64) NOT NULL DEFAULT '' COMMENT '微信昵称',
+ `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '微信头像',
+ `createtime` bigint(16) DEFAULT NULL,
+ `updatetime` bigint(16) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `openid` (`openid`),
+ KEY `user_id` (`user_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信授权账号';
+
+-- 申诉中心(误判 / 恶意评价 / 扣款申诉)
+CREATE TABLE IF NOT EXISTS `fa_appeal` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `master_id` int(10) unsigned NOT NULL DEFAULT '0',
+ `order_id` int(10) unsigned NOT NULL DEFAULT '0',
+ `type` enum('misjudge','review','deduct','other') NOT NULL DEFAULT 'other' COMMENT '误判/恶意评价/扣款/其他',
+ `content` varchar(500) NOT NULL DEFAULT '',
+ `images` varchar(1000) NOT NULL DEFAULT '',
+ `status` enum('wait','handling','done','reject') NOT NULL DEFAULT 'wait',
+ `reply` varchar(500) NOT NULL DEFAULT '' COMMENT '平台回复',
+ `createtime` bigint(16) DEFAULT NULL,
+ `updatetime` bigint(16) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `master_id` (`master_id`),
+ KEY `status` (`status`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='申诉工单';
+
+-- 回滚:
+-- DROP TABLE IF EXISTS `fa_appeal`,`fa_user_wechat`;
diff --git a/pages.json b/pages.json
index bfe7a7c..e59a1be 100644
--- a/pages.json
+++ b/pages.json
@@ -42,10 +42,30 @@
"path": "pages/master/apply",
"style": { "navigationBarTitleText": "师傅入驻" }
},
+ {
+ "path": "pages/master/workbench",
+ "style": { "navigationBarTitleText": "师傅工作台" }
+ },
{
"path": "pages/master/hall",
"style": { "navigationBarTitleText": "订单大厅", "enablePullDownRefresh": false }
},
+ {
+ "path": "pages/master/quote",
+ "style": { "navigationBarTitleText": "报价管理" }
+ },
+ {
+ "path": "pages/master/wallet",
+ "style": { "navigationBarTitleText": "我的钱包" }
+ },
+ {
+ "path": "pages/master/credit",
+ "style": { "navigationBarTitleText": "信用与申诉" }
+ },
+ {
+ "path": "pages/mine/mine",
+ "style": { "navigationStyle": "custom", "backgroundColor": "#F5F6F8" }
+ },
{
"path": "pages/master/orders",
"style": {
diff --git a/pages/login/login.vue b/pages/login/login.vue
index 9fd3455..a3833e9 100644
--- a/pages/login/login.vue
+++ b/pages/login/login.vue
@@ -19,83 +19,58 @@
-
- 手机号
-
+
+ 微
+ {{ loading ? '微信授权中...' : '微信一键登录' }}
-
- 验证码
-
- {{ codeText }}
-
-
- {{ loading ? '登录中...' : '登录 / 注册' }}
- 未注册的手机号将自动创建账号
+ 授权仅用于账号识别,不会获取你的其他信息
+ 登录即代表同意《用户服务协议》与《隐私政策》
-
- 登录即代表同意《用户服务协议》与《隐私政策》
-
diff --git a/pages/master/credit.vue b/pages/master/credit.vue
new file mode 100644
index 0000000..3f77c86
--- /dev/null
+++ b/pages/master/credit.vue
@@ -0,0 +1,121 @@
+
+
+
+ 信用指标
+
+ {{ credit.score }}综合评分
+ {{ credit.accept_rate }}%接单率
+ {{ credit.ontime_rate }}%准时率
+ {{ credit.good_rate }}%好评率
+ {{ credit.complaint_rate }}%投诉率
+ Lv{{ credit.level }}服务等级
+
+
+ · {{ r }}
+
+
+
+
+ 提交申诉
+
+ {{ t.name }}
+
+
+ {{ submitting ? '提交中...' : '提交申诉' }}
+
+
+
+
+ 申诉记录
+ {{ list.length }} 条
+
+
+
+ {{ a.type_text }}
+ {{ a.status_text }}
+
+ {{ a.content }}
+ {{ a.time_text }}
+ 平台回复:{{ a.reply }}
+
+ 暂无申诉记录
+
+
+
+
+
+
+
diff --git a/pages/master/hall.vue b/pages/master/hall.vue
index af77e8f..5d2ec07 100644
--- a/pages/master/hall.vue
+++ b/pages/master/hall.vue
@@ -10,6 +10,15 @@
+
+
+ {{ t.name }}
+
+
+ {{ s.name }}
+
+
+
@@ -24,8 +33,11 @@
备注:{{ o.remark }}
- {{ o.mobile }}
- 立即抢单
+ {{ o.left_seconds > 0 ? ('剩余 ' + countdown(o.left_seconds)) : '即将关闭' }}
+
+ 我要报价({{ o.quote_count }})
+ 立即抢单
+
@@ -36,20 +48,49 @@
+
+
diff --git a/pages/master/wallet.vue b/pages/master/wallet.vue
new file mode 100644
index 0000000..0e6d76f
--- /dev/null
+++ b/pages/master/wallet.vue
@@ -0,0 +1,105 @@
+
+
+
+ 可提现余额(元)
+ {{ income ? income.money : 0 }}
+
+ 今日收入 ¥{{ income ? income.today_income : 0 }}
+ 累计收入 ¥{{ income ? income.total_income : 0 }}
+
+ 申请提现
+
+
+
+ 账单明细
+
+
+ {{ logTypeText(l.type) }}
+ {{ l.remark }}
+ {{ timeText(l.createtime) }}
+
+
+ {{ Number(l.amount) > 0 ? '+' : '' }}{{ l.amount }}
+ 余额 {{ l.balance }}
+
+
+ 暂无账单
+
+
+ 提现 T+1 到账,手续费 0.6%;结算周期:客户验收后即时入账
+
+
+
+
+
+
diff --git a/pages/master/workbench.vue b/pages/master/workbench.vue
new file mode 100644
index 0000000..a83994b
--- /dev/null
+++ b/pages/master/workbench.vue
@@ -0,0 +1,161 @@
+
+
+
+
+
+
+ {{ g.icon }}
+ {{ g.name }}
+
+
+
+
+
+ 信用体系
+ 明细 ›
+
+
+ {{ credit.score }}综合评分
+ {{ credit.accept_rate }}%接单率
+ {{ credit.ontime_rate }}%准时率
+ {{ credit.good_rate }}%好评率
+
+
+
+
+ 我的服务类目
+
+ {{ s.name }}
+ 暂无技能标签
+
+
+
+ 接单后请在 2 小时内联系客户,超时订单将自动回流大厅
+
+ 切换到业主身份
+
+
+
+
+
+
+
diff --git a/pages/mine/mine.vue b/pages/mine/mine.vue
new file mode 100644
index 0000000..fa1d21d
--- /dev/null
+++ b/pages/mine/mine.vue
@@ -0,0 +1,161 @@
+
+
+
+
+
+
+ {{ masterCard.title }}
+ {{ masterCard.desc }}
+
+ {{ masterCard.btn }}
+
+
+
+
+ 退出登录
+
+
+
+
+
+
+
diff --git a/server/application/api/controller/Auth.php b/server/application/api/controller/Auth.php
index 520c73e..477319d 100644
--- a/server/application/api/controller/Auth.php
+++ b/server/application/api/controller/Auth.php
@@ -11,7 +11,7 @@ use think\Validate;
*/
class Auth extends Base
{
- protected $noNeedLogin = ['login'];
+ protected $noNeedLogin = ['login', 'wxlogin'];
/**
* 手机号 + 验证码登录(验证码固定 123456,联调用;接入短信后走 Sms)
@@ -99,4 +99,66 @@ class Auth extends Base
'master' => $masterInfo,
];
}
+
+ /**
+ * 微信授权登录(小程序 uni.login 拿到的 code)
+ * @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 = \app\common\library\WxLogin::jscode2session($code);
+ if (isset($wx['error'])) {
+ $this->error($wx['error']);
+ }
+ $ret = \app\common\library\WxLogin::provision(
+ $wx['openid'],
+ isset($wx['unionid']) ? $wx['unionid'] : '',
+ isset($wx['session_key']) ? $wx['session_key'] : '',
+ $nickname,
+ $avatar
+ );
+ $this->auth->direct($ret['user_id']);
+
+ $this->success('登录成功', [
+ 'token' => $this->auth->getToken(),
+ 'expires' => 2592000,
+ 'userinfo' => $this->profileData(),
+ 'is_new' => $ret['is_new'],
+ ]);
+ }
+
+ /**
+ * 切换角色(用户 / 师傅)
+ * @ApiMethod (POST)
+ */
+ public function switchRole()
+ {
+ $role = $this->request->post('role', 'user');
+ if (!in_array($role, ['user', 'master'], true)) {
+ $this->error('角色参数错误');
+ }
+ if ($role === 'master') {
+ $master = $this->masterInfo();
+ if (!$master) {
+ $this->error('请先完成师傅入驻', ['need_apply' => 1], 2001);
+ }
+ 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);
+ }
+ }
+ $this->success('切换成功', [
+ 'role' => $role,
+ 'redirect' => $role === 'master' ? '/pages/master/workbench' : '/YJYF/YJYF',
+ ]);
+ }
}
diff --git a/server/application/api/controller/Master.php b/server/application/api/controller/Master.php
index f1b0e37..a93b3af 100644
--- a/server/application/api/controller/Master.php
+++ b/server/application/api/controller/Master.php
@@ -144,7 +144,7 @@ class Master extends Base
}
/**
- * 订单大厅:待接单订单(按技能过滤,急单优先)
+ * 订单大厅:支持排序与单类型筛选(一口价 / 报价 / 悬赏)
*/
public function hall()
{
@@ -154,19 +154,36 @@ class Master extends Base
$catIds = Db::name('master_skill')->where('master_id', $master['id'])->column('cat_id');
$page = max(1, (int)$this->request->param('page', 1));
$limit = min(30, max(1, (int)$this->request->param('limit', 10)));
+ $sort = $this->request->param('sort', 'new'); // new 最新 / amount 报酬 / urgent 急单 / time 时效
+ $type = $this->request->param('type', 'all'); // all / fixed 一口价 / quote 报价
- // TP5 中 count() 会重置查询条件,故用闭包重建
- $build = function () use ($catIds) {
+ $build = function () use ($catIds, $type) {
$q = Db::name('order')->where('status', OrderStatus::PENDING_ACCEPT)->where('master_id', 0);
if (!empty($catIds)) {
$q->where('cat_id', 'in', $catIds);
}
+ if ($type === 'fixed') {
+ $q->where('price_type', 'fixed');
+ } elseif ($type === 'quote') {
+ $q->where('price_type', 'quote');
+ }
return $q;
};
- $total = $build()->count();
- $list = $build()->order('urgent desc, id desc')->page($page, $limit)->select();
+ if ($sort === 'amount') {
+ $order = 'pay_amount desc, id desc';
+ } elseif ($sort === 'urgent') {
+ $order = 'urgent desc, id desc';
+ } elseif ($sort === 'time') {
+ $order = 'appoint_time asc, id desc';
+ } else {
+ $order = 'id desc';
+ }
+ $total = $build()->count();
+ $list = $build()->order($order)->page($page, $limit)->select();
+
+ $now = time();
foreach ($list as &$row) {
$row['appoint_text'] = $row['appoint_time'] ? date('m-d H:i', (int)$row['appoint_time']) : '尽快上门';
$row['pay_amount'] = (float)$row['pay_amount'];
@@ -174,10 +191,15 @@ class Master extends Base
$row['mobile'] = substr_replace($row['mobile'], '****', 3, 4);
$row['address'] = $row['city'] . $row['district'] . $row['address'];
$row['status_text'] = OrderStatus::label($row['status']);
+ $row['left_seconds'] = max(0, (int)$row['createtime'] + 3600 - $now);
+ $row['quote_count'] = (int)Db::name('order_quote')->where('order_id', $row['id'])->count();
}
unset($row);
- $this->success('', ['list' => $list, 'total' => (int)$total, 'page' => $page]);
+ $this->success('', [
+ 'list' => $list, 'total' => (int)$total,
+ 'page' => $page, 'sort' => $sort, 'type' => $type,
+ ]);
}
/**
@@ -505,5 +527,112 @@ class Master extends Base
$this->addLog($row['id'], OrderStatus::PENDING_ACCEPT, '超 2 小时未联系客户,订单自动回流大厅', 'system', 0);
}
}
+
+ /**
+ * 信用体系:综合评分 / 接单率 / 准时率 / 好评率 / 投诉率
+ */
+ public function credit()
+ {
+ $master = $this->requireMaster();
+ $mid = (int)$master['id'];
+
+ $reviewTotal = (int)Db::name('review')->where('master_id', $mid)->where('status', 'normal')->count();
+ $reviewGood = (int)Db::name('review')->where('master_id', $mid)->where('status', 'normal')->where('score', '>=', 4)->count();
+ $appealCount = (int)Db::name('appeal')->where('master_id', $mid)->count();
+ $orderCount = max(1, (int)$master['order_count']);
+
+ $this->success('', [
+ 'score' => (float)$master['score'],
+ 'level' => (int)$master['level'],
+ 'accept_rate' => (float)$master['accept_rate'],
+ 'ontime_rate' => (float)$master['ontime_rate'],
+ 'good_rate' => $reviewTotal ? round($reviewGood * 100 / $reviewTotal, 1) : 100,
+ 'complaint_rate' => round($appealCount * 100 / $orderCount, 1),
+ 'order_count' => (int)$master['order_count'],
+ 'review_total' => $reviewTotal,
+ 'appeal_total' => $appealCount,
+ 'rules' => [
+ '综合评分 = 客户评价星级平均值(5 分制)',
+ '接单率 = 已联系客户订单 / 接单总数',
+ '准时率 = 按预约时间到达 / 上门总数',
+ '好评率 = 4 星及以上评价占比',
+ '投诉率 = 申诉工单数 / 完成订单数',
+ ],
+ ]);
+ }
+
+ /**
+ * 申诉中心:列表
+ */
+ public function appeals()
+ {
+ $master = $this->requireMaster();
+ $list = Db::name('appeal')->where('master_id', $master['id'])->order('id desc')->limit(30)->select();
+ $typeText = ['misjudge' => '误判申诉', 'review' => '恶意评价', 'deduct' => '扣款申诉', 'other' => '其他'];
+ $statusText = ['wait' => '待处理', 'handling' => '处理中', 'done' => '已处理', 'reject' => '已驳回'];
+ foreach ($list as &$row) {
+ $row['type_text'] = isset($typeText[$row['type']]) ? $typeText[$row['type']] : '其他';
+ $row['status_text'] = isset($statusText[$row['status']]) ? $statusText[$row['status']] : $row['status'];
+ $row['time_text'] = date('Y-m-d H:i', (int)$row['createtime']);
+ }
+ unset($row);
+ $this->success('', ['list' => $list]);
+ }
+
+ /**
+ * 申诉中心:提交
+ * @ApiMethod (POST)
+ */
+ public function appeal()
+ {
+ $master = $this->requireMaster();
+ $type = $this->request->post('type', 'other');
+ $orderId = (int)$this->request->post('order_id', 0);
+ $content = trim((string)$this->request->post('content'));
+ if (!in_array($type, ['misjudge', 'review', 'deduct', 'other'], true)) {
+ $this->error('申诉类型错误');
+ }
+ if (mb_strlen($content) < 5) {
+ $this->error('请填写至少 5 个字的申诉说明');
+ }
+ if (Db::name('appeal')->where('master_id', $master['id'])->where('status', 'wait')->count() >= 5) {
+ $this->error('您有多个待处理申诉,请等待处理完成');
+ }
+ Db::name('appeal')->insert([
+ 'master_id' => $master['id'],
+ 'order_id' => $orderId,
+ 'type' => $type,
+ 'content' => mb_substr($content, 0, 500),
+ 'images' => (string)$this->request->post('images', ''),
+ 'status' => 'wait',
+ 'createtime' => time(),
+ 'updatetime' => time(),
+ ]);
+ $this->success('申诉已提交,平台将在 24 小时内处理');
+ }
+
+ /**
+ * 我的报价记录
+ */
+ public function quotes()
+ {
+ $master = $this->requireMaster();
+ $list = Db::name('order_quote')->alias('q')
+ ->join('order o', 'o.id = q.order_id', 'LEFT')
+ ->field('q.*, o.order_no, o.service_name, o.pay_amount as order_amount, o.status as order_status')
+ ->where('q.master_id', $master['id'])
+ ->order('q.id desc')
+ ->limit(30)
+ ->select();
+ $statusText = ['wait' => '等待客户选择', 'accept' => '已被选中', 'reject' => '未被选中', 'expired' => '已过期'];
+ foreach ($list as &$row) {
+ $row['status_text'] = isset($statusText[$row['status']]) ? $statusText[$row['status']] : $row['status'];
+ $row['amount'] = (float)$row['amount'];
+ $row['time_text'] = date('m-d H:i', (int)$row['createtime']);
+ $row['expire_text'] = date('m-d H:i', (int)$row['expire_time']);
+ }
+ unset($row);
+ $this->success('', ['list' => $list]);
+ }
}
diff --git a/server/application/common/library/WxLogin.php b/server/application/common/library/WxLogin.php
new file mode 100644
index 0000000..3fa8981
--- /dev/null
+++ b/server/application/common/library/WxLogin.php
@@ -0,0 +1,105 @@
+..,'session_key'=>..,'unionid'=>..]
+ */
+ public static function jscode2session($code)
+ {
+ $appid = \think\Env::get('wechat.appid');
+ $secret = \think\Env::get('wechat.secret');
+ if (!$appid || !$secret) {
+ return ['error' => '微信登录未配置'];
+ }
+ $url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid
+ . '&secret=' . $secret
+ . '&js_code=' . urlencode($code)
+ . '&grant_type=authorization_code';
+ $ctx = stream_context_create(['http' => ['timeout' => 8, 'ignore_errors' => true]]);
+ $resp = @file_get_contents($url, false, $ctx);
+ if ($resp === false) {
+ return ['error' => '微信服务不可达,请稍后重试'];
+ }
+ $wx = json_decode($resp, true);
+ if (empty($wx['openid'])) {
+ $ec = isset($wx['errcode']) ? $wx['errcode'] : '-';
+ $em = isset($wx['errmsg']) ? $wx['errmsg'] : '未知错误';
+ return ['error' => '微信登录失败(' . $ec . '):' . $em];
+ }
+ return $wx;
+ }
+
+ /**
+ * 按 openid 落库(幂等)
+ * @return array ['user_id' => int, 'is_new' => 0|1]
+ */
+ public static function provision($openid, $unionid = '', $sessionKey = '', $nickname = '', $avatar = '')
+ {
+ $openid = (string)$openid;
+ $bind = Db::name('user_wechat')->where('openid', $openid)->find();
+ $userId = $bind ? (int)$bind['user_id'] : 0;
+
+ // 绑定记录存在但用户已被删除 → 重建
+ if ($userId > 0 && !Db::name('user')->where('id', $userId)->find()) {
+ $userId = 0;
+ }
+
+ $isNew = 0;
+ if ($userId === 0) {
+ $isNew = 1;
+ $userId = Db::name('user')->insertGetId([
+ 'group_id' => 1,
+ 'username' => 'wx' . substr(md5($openid), 0, 10),
+ 'nickname' => $nickname !== '' ? mb_substr($nickname, 0, 20) : ('用户' . substr($openid, -4)),
+ 'avatar' => $avatar,
+ 'status' => 'normal',
+ 'jointime' => time(),
+ 'createtime' => time(),
+ 'updatetime' => time(),
+ ]);
+ }
+
+ $data = [
+ 'user_id' => $userId,
+ 'openid' => $openid,
+ 'unionid' => (string)$unionid,
+ 'session_key' => (string)$sessionKey,
+ 'updatetime' => time(),
+ ];
+ if ($nickname !== '') {
+ $data['nickname'] = mb_substr($nickname, 0, 64);
+ }
+ if ($avatar !== '') {
+ $data['avatar'] = $avatar;
+ }
+
+ if ($bind) {
+ Db::name('user_wechat')->where('id', $bind['id'])->update($data);
+ } else {
+ $data['createtime'] = time();
+ Db::name('user_wechat')->insert($data);
+ }
+
+ $userUpdate = ['updatetime' => time()];
+ if ($nickname !== '') {
+ $userUpdate['nickname'] = mb_substr($nickname, 0, 20);
+ }
+ if ($avatar !== '') {
+ $userUpdate['avatar'] = $avatar;
+ }
+ Db::name('user')->where('id', $userId)->update($userUpdate);
+
+ return ['user_id' => $userId, 'is_new' => $isNew];
+ }
+}
diff --git a/static/icons/appliance.png b/static/icons/appliance.png
new file mode 100644
index 0000000..0de3a9b
Binary files /dev/null and b/static/icons/appliance.png differ
diff --git a/static/icons/bath.png b/static/icons/bath.png
new file mode 100644
index 0000000..efc6033
Binary files /dev/null and b/static/icons/bath.png differ
diff --git a/static/icons/curtain.png b/static/icons/curtain.png
new file mode 100644
index 0000000..08cece6
Binary files /dev/null and b/static/icons/curtain.png differ
diff --git a/static/icons/door.png b/static/icons/door.png
new file mode 100644
index 0000000..2e9ab2b
Binary files /dev/null and b/static/icons/door.png differ
diff --git a/static/icons/fitness.png b/static/icons/fitness.png
new file mode 100644
index 0000000..f800843
Binary files /dev/null and b/static/icons/fitness.png differ
diff --git a/static/icons/frame.png b/static/icons/frame.png
new file mode 100644
index 0000000..2bf83c5
Binary files /dev/null and b/static/icons/frame.png differ
diff --git a/static/icons/kitchen.png b/static/icons/kitchen.png
new file mode 100644
index 0000000..dc7024b
Binary files /dev/null and b/static/icons/kitchen.png differ
diff --git a/static/icons/lamp.png b/static/icons/lamp.png
new file mode 100644
index 0000000..be2d024
Binary files /dev/null and b/static/icons/lamp.png differ
diff --git a/static/icons/lock.png b/static/icons/lock.png
new file mode 100644
index 0000000..57c55cf
Binary files /dev/null and b/static/icons/lock.png differ
diff --git a/static/icons/more.png b/static/icons/more.png
new file mode 100644
index 0000000..43cc613
Binary files /dev/null and b/static/icons/more.png differ
diff --git a/static/icons/rack.png b/static/icons/rack.png
new file mode 100644
index 0000000..8b42ef2
Binary files /dev/null and b/static/icons/rack.png differ
diff --git a/static/icons/shower.png b/static/icons/shower.png
new file mode 100644
index 0000000..1691608
Binary files /dev/null and b/static/icons/shower.png differ
diff --git a/static/icons/sofa.png b/static/icons/sofa.png
new file mode 100644
index 0000000..d70ccf1
Binary files /dev/null and b/static/icons/sofa.png differ
diff --git a/static/icons/tv.png b/static/icons/tv.png
new file mode 100644
index 0000000..1bd6230
Binary files /dev/null and b/static/icons/tv.png differ
diff --git a/static/icons/water.png b/static/icons/water.png
new file mode 100644
index 0000000..2551ab0
Binary files /dev/null and b/static/icons/water.png differ
diff --git a/tests/phase2_verify.js b/tests/phase2_verify.js
new file mode 100644
index 0000000..24f4c33
--- /dev/null
+++ b/tests/phase2_verify.js
@@ -0,0 +1,140 @@
+/**
+ * Phase 2 验证:微信登录、角色切换、师傅工作台各模块
+ * 运行:node tests/phase2_verify.js
+ */
+const { execFileSync } = require('child_process');
+const BASE = process.env.API_BASE || 'https://yjyf.gzyakj.com.cn/api';
+
+let pass = 0, fail = 0;
+const failures = [];
+const ok = (m, e) => { pass++; console.log(' ✅ ' + m + (e ? ' → ' + e : '')); };
+const bad = (m, e) => { fail++; failures.push(m + ' :: ' + e); console.log(' ❌ ' + m + ' → ' + e); };
+const chk = (c, m, e) => (c ? ok(m, e) : bad(m, e || '断言失败'));
+const sec = (t) => console.log('\n▌' + t);
+
+async function api(path, opt) {
+ const o = opt || {};
+ const headers = {};
+ if (o.token) headers.token = o.token;
+ let body;
+ if (o.data) {
+ headers['content-type'] = 'application/x-www-form-urlencoded';
+ body = new URLSearchParams(o.data).toString();
+ }
+ const res = await fetch(BASE + path, { method: o.method || 'GET', headers, body });
+ const text = await res.text();
+ try { return JSON.parse(text); } catch (e) { throw new Error('非 JSON: ' + text.slice(0, 120)); }
+}
+const sql = (s) => execFileSync('ssh', ['-o', 'BatchMode=yes', 'root@8.137.181.63', `mysql -uyjyf -pyjyf yjyf -e "${s}"`], { encoding: 'utf8' }).trim();
+
+(async () => {
+ const stamp = String(Date.now()).slice(-8);
+ const uM = '139' + stamp;
+
+ console.log('═══════════════════════════════════════════════════');
+ console.log(' Phase 2 验证:角色切换 + 师傅工作台模块');
+ console.log('═══════════════════════════════════════════════════');
+
+ sec('微信授权登录');
+ let r = await api('/auth/wxlogin', { method: 'POST', data: { code: 'invalid_code_x' } });
+ chk(r.code !== 1 && /微信登录失败/.test(r.msg || ''), '无效 code 被微信侧拒绝并回显原因', r.msg);
+ r = await api('/auth/wxlogin', { method: 'POST', data: {} });
+ chk(r.code !== 1, '缺少 code 时参数校验生效', r.msg);
+
+ const lu = await api('/auth/login', { method: 'POST', data: { mobile: uM, code: '123456' } });
+ const token = lu.data.token;
+
+ sec('角色切换:未入驻不能切师傅');
+ r = await api('/auth/switchRole', { method: 'POST', token: token, data: { role: 'master' } });
+ chk(r.code === 2001 && r.data && r.data.need_apply === 1, '未入驻 → 返回 2001 并指向入驻页', r.msg);
+
+ sec('师傅入驻 → 审核 → 切换师傅身份');
+ r = await api('/master/apply', {
+ method: 'POST', token: token,
+ data: { realname: 'Phase2师傅', mobile: uM, idcard_no: '520101199505051234', city: '遵义市', 'skills[0]': 1 }
+ });
+ const masterId = r.data.master_id;
+ chk(r.code === 1, '提交入驻', 'master_id=' + masterId);
+ r = await api('/auth/switchRole', { method: 'POST', token: token, data: { role: 'master' } });
+ chk(r.code === 2002, '审核中 → 返回 2002', r.msg);
+
+ sql(`UPDATE fa_master SET verify_status='pass' WHERE id=${masterId}`);
+ r = await api('/auth/switchRole', { method: 'POST', token: token, data: { role: 'master' } });
+ chk(r.code === 1 && r.data.redirect === '/pages/master/workbench', '审核通过 → 切换成功并跳转工作台', r.data && r.data.redirect);
+
+ sec('师傅工作台');
+ r = await api('/master/info', { token: token });
+ chk(r.code === 1 && r.data.master.verify_status === 'pass', '工作台头部数据就绪');
+ chk(typeof r.data.master.todo_count === 'number' && typeof r.data.master.verify_count === 'number', '待处理/待验收角标字段');
+
+ sec('信用体系');
+ r = await api('/master/credit', { token: token });
+ const cr = r.data;
+ chk(r.code === 1, '信用接口可用');
+ chk(cr && cr.score !== undefined && cr.accept_rate !== undefined && cr.ontime_rate !== undefined
+ && cr.good_rate !== undefined && cr.complaint_rate !== undefined, '五项信用指标齐全',
+ `评分${cr.score} 接单${cr.accept_rate}% 准时${cr.ontime_rate}% 好评${cr.good_rate}% 投诉${cr.complaint_rate}%`);
+ chk(Array.isArray(cr.rules) && cr.rules.length === 5, '信用规则说明 5 条');
+
+ sec('申诉中心');
+ r = await api('/master/appeal', { method: 'POST', token: token, data: { type: 'review', content: '客户恶意差评,实际服务已完成' } });
+ chk(r.code === 1, '提交申诉成功', r.msg);
+ r = await api('/master/appeal', { method: 'POST', token: token, data: { type: 'review', content: '短' } });
+ chk(r.code !== 1, '内容过短被拦截', r.msg);
+ r = await api('/master/appeals', { token: token });
+ chk(r.code === 1 && r.data.list.length === 1 && r.data.list[0].type_text === '恶意评价', '申诉列表回显类型与状态', r.data.list[0] && r.data.list[0].status_text);
+
+ sec('订单大厅:类型筛选 + 排序 + 倒计时');
+ const svcFixed = (await api('/home/services?cat_id=1')).data.list.find(s => s.price_type === 'fixed');
+ const addr = await api('/address/save', {
+ method: 'POST', token: token,
+ data: { contact: 'P2客户', mobile: uM, province: '贵州省', city: '遵义市', district: '汇川区', address: 'P2 测试地址', floor: 2, has_elevator: 1, is_default: 1 }
+ });
+ const o1 = await api('/order/create', { method: 'POST', token: token, data: { service_id: svcFixed.id, address_id: addr.data.id, urgent: 1 } });
+ await api('/order/pay', { method: 'POST', token: token, data: { order_id: o1.data.order_id } });
+
+ r = await api('/master/hall?type=fixed&sort=amount', { token: token });
+ chk(r.code === 1, 'hall 支持 type + sort 参数', 'total=' + r.data.total);
+ const hl = (r.data.list || [])[0];
+ chk(hl && hl.left_seconds !== undefined, '返回抢单倒计时 left_seconds', hl && hl.left_seconds + 's');
+ chk(hl && hl.quote_count !== undefined, '返回报价数 quote_count');
+ r = await api('/master/hall?type=quote', { token: token });
+ chk(r.code === 1 && (r.data.list || []).every(o => o.price_type === 'quote'), '报价单筛选口径正确');
+ r = await api('/master/hall?sort=urgent', { token: token });
+ chk(r.code === 1, '急单优先排序可用');
+
+ sec('报价竞标');
+ const svcQuote = (await api('/home/services?cat_id=1')).data.list.find(s => s.price_type === 'quote');
+ if (svcQuote) {
+ const o2 = await api('/order/create', { method: 'POST', token: token, data: { service_id: svcQuote.id, address_id: addr.data.id } });
+ await api('/order/pay', { method: 'POST', token: token, data: { order_id: o2.data.order_id } });
+ r = await api('/master/quote', { method: 'POST', token: token, data: { order_id: o2.data.order_id, amount: 260, description: '含材料与上门', valid_hours: 48 } });
+ chk(r.code === 1, '提交报价成功', r.msg);
+ r = await api('/master/quote', { method: 'POST', token: token, data: { order_id: o2.data.order_id, amount: 200 } });
+ chk(r.code !== 1, '重复报价被拦截', r.msg);
+ r = await api('/master/quotes', { token: token });
+ chk(r.code === 1 && r.data.list.length === 1, '报价记录列表', r.data.list[0] && ('¥' + r.data.list[0].amount + ' / ' + r.data.list[0].status_text));
+ } else {
+ bad('报价竞标', '未找到报价类服务');
+ }
+
+ sec('钱包与提现');
+ r = await api('/master/income', { token: token });
+ chk(r.code === 1 && r.data.money !== undefined && r.data.today_income !== undefined, '收入概览字段齐全', '可提现 ' + r.data.money);
+ r = await api('/master/withdraw', { method: 'POST', token: token, data: { amount: 5 } });
+ chk(r.code !== 1, '低于 10 元被拦截', r.msg);
+ r = await api('/master/withdraw', { method: 'POST', token: token, data: { amount: 9999 } });
+ chk(r.code !== 1, '超出余额被拦截', r.msg);
+
+ sec('切回业主身份');
+ r = await api('/auth/switchRole', { method: 'POST', token: token, data: { role: 'user' } });
+ chk(r.code === 1 && r.data.redirect === '/YJYF/YJYF', '切回业主成功', r.data && r.data.redirect);
+ r = await api('/auth/switchRole', { method: 'POST', token: token, data: { role: 'xxx' } });
+ chk(r.code !== 1, '非法角色参数被拦截', r.msg);
+
+ console.log('\n═══════════════════════════════════════════════════');
+ console.log(` 结果:通过 ${pass} 项 / 失败 ${fail} 项`);
+ if (fail) { console.log(' 失败明细:'); failures.forEach(f => console.log(' - ' + f)); process.exitCode = 1; }
+ else console.log(' 🎉 角色切换与师傅工作台全模块验证通过');
+ console.log('═══════════════════════════════════════════════════');
+})().catch(e => { console.error('\n💥 中断: ' + e.message); process.exitCode = 1; });
diff --git a/utils/api.js b/utils/api.js
index 830c04a..e5e1277 100644
--- a/utils/api.js
+++ b/utils/api.js
@@ -6,6 +6,8 @@ import { get, post } from './request';
export default {
/* ---------- 鉴权 ---------- */
login: (data) => post('/auth/login', data, { silent: true }),
+ wxLogin: (data) => post('/auth/wxlogin', data, { silent: true }),
+ switchRole: (data) => post('/auth/switchRole', data),
profile: () => get('/auth/profile'),
/* ---------- 首页 / 服务 ---------- */
@@ -43,6 +45,12 @@ export default {
masterFinish: (data) => post('/master/finish', data),
masterIncome: () => get('/master/income'),
masterToggle: (data) => post('/master/toggleWork', data),
+ masterCredit: () => get('/master/credit'),
+ masterAppeals: () => get('/master/appeals'),
+ masterAppeal: (data) => post('/master/appeal', data),
+ masterQuotes: () => get('/master/quotes'),
+ masterQuote: (data) => post('/master/quote', data),
+ masterWithdraw: (data) => post('/master/withdraw', data),
/* ---------- 评价 ---------- */
reviewCreate: (data) => post('/review/create', data),
diff --git a/utils/role.js b/utils/role.js
new file mode 100644
index 0000000..00662f0
--- /dev/null
+++ b/utils/role.js
@@ -0,0 +1,20 @@
+/**
+ * 角色上下文(前端本地保存当前身份,后端以 switchRole 校验权限)
+ */
+const ROLE_KEY = 'yjyf_role';
+
+export function getRole() {
+ try {
+ return uni.getStorageSync(ROLE_KEY) || 'user';
+ } catch (e) {
+ return 'user';
+ }
+}
+
+export function setRole(role) {
+ uni.setStorageSync(ROLE_KEY, role === 'master' ? 'master' : 'user');
+}
+
+export function clearRole() {
+ uni.removeStorageSync(ROLE_KEY);
+}