feat: 新增大量服务类图标及相关接口配置
- 新增20+家电维修类图标(电视、空调、冰箱等) - 新增短信发送、微信手机号登录接口 - 新增服务规格查询接口 - 更新后台配置与菜单结构 - 移除支付插件相关配置
这个提交包含在:
@@ -11,7 +11,7 @@ use think\Validate;
|
||||
*/
|
||||
class Auth extends Base
|
||||
{
|
||||
protected $noNeedLogin = ['login', 'wxlogin'];
|
||||
protected $noNeedLogin = ['login', 'wxlogin', 'wxPhoneLogin'];
|
||||
|
||||
/**
|
||||
* 手机号 + 验证码登录(兜底通道)
|
||||
@@ -21,8 +21,64 @@ class Auth extends Base
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$mobile = $this->request->post('mobile');
|
||||
$code = $this->request->post('code');
|
||||
$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', ''));
|
||||
|
||||
// 1. 手机号 + 密码登录(直连真实数据库)
|
||||
if ($password !== '' || ($mobile !== '' && $code === '')) {
|
||||
if ($mobile === '') {
|
||||
$this->error('请填写手机号');
|
||||
}
|
||||
if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
|
||||
$this->error('手机号格式不正确');
|
||||
}
|
||||
if ($password === '') {
|
||||
$this->error('请填写登录密码');
|
||||
}
|
||||
|
||||
// 直接查询真实数据库 fa_user 表
|
||||
$user = Db::name('user')->where('mobile', $mobile)->find();
|
||||
|
||||
if (!$user) {
|
||||
// 若数据库中无此手机号:直连数据库插入注册新会员
|
||||
$ret = $this->auth->register($mobile, $password, '', $mobile, []);
|
||||
if (!$ret) {
|
||||
$this->error($this->auth->getError() ?: '注册登录失败');
|
||||
}
|
||||
} else {
|
||||
if ($user['status'] !== 'normal') {
|
||||
$this->error('账号已被禁用');
|
||||
}
|
||||
// 若微信手机号快捷登录初始化的用户未设密码,直接落库更新密码
|
||||
if (empty($user['password'])) {
|
||||
$salt = Random::alnum();
|
||||
$encryptPassword = $this->auth->getEncryptPassword($password, $salt);
|
||||
Db::name('user')->where('id', $user['id'])->update([
|
||||
'password' => $encryptPassword,
|
||||
'salt' => $salt,
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
$this->auth->direct($user['id']);
|
||||
} else {
|
||||
$encryptPassword = $this->auth->getEncryptPassword($password, $user['salt']);
|
||||
if ($user['password'] !== $encryptPassword) {
|
||||
$this->error('手机号或密码不正确');
|
||||
}
|
||||
$this->auth->direct($user['id']);
|
||||
}
|
||||
}
|
||||
|
||||
// 直查真实数据库返回用户完整信息
|
||||
$this->success('登录成功', [
|
||||
'token' => $this->auth->getToken(),
|
||||
'expires' => 2592000,
|
||||
'userinfo' => $this->profileData(),
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. 手机号 + 验证码登录(向下兼容)
|
||||
if (!$mobile || !$code) {
|
||||
$this->error('请填写手机号和验证码');
|
||||
}
|
||||
@@ -162,6 +218,61 @@ class Auth extends Base
|
||||
* 切换角色(用户 / 师傅)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
|
||||
/**
|
||||
* 微信手机号授权快捷登录
|
||||
* @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('缺少微信手机号授权凭证');
|
||||
}
|
||||
|
||||
// 1. 换取手机号
|
||||
$phoneInfo = \app\common\library\WxLogin::getPhoneNumber($phoneCode);
|
||||
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('解析手机号失败');
|
||||
}
|
||||
|
||||
// 2. 如果传了 login_code,换取 openid
|
||||
$openid = '';
|
||||
$sessionKey = '';
|
||||
$unionid = '';
|
||||
if ($loginCode !== '') {
|
||||
$wx = \app\common\library\WxLogin::jscode2session($loginCode);
|
||||
if (!isset($wx['error']) && !empty($wx['openid'])) {
|
||||
$openid = $wx['openid'];
|
||||
$sessionKey = isset($wx['session_key']) ? $wx['session_key'] : '';
|
||||
$unionid = isset($wx['unionid']) ? $wx['unionid'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 落库与关联登录
|
||||
$ret = \app\common\library\WxLogin::provisionWithMobile(
|
||||
$mobile,
|
||||
$openid,
|
||||
$unionid,
|
||||
$sessionKey
|
||||
);
|
||||
|
||||
$this->auth->direct($ret['user_id']);
|
||||
|
||||
$this->success('登录成功', [
|
||||
'token' => $this->auth->getToken(),
|
||||
'expires' => 2592000,
|
||||
'userinfo' => $this->profileData(),
|
||||
'is_new' => $ret['is_new'],
|
||||
'mobile' => $mobile,
|
||||
]);
|
||||
}
|
||||
|
||||
public function switchRole()
|
||||
{
|
||||
$role = $this->request->post('role', 'user');
|
||||
|
||||
@@ -75,12 +75,48 @@ class Home extends Base
|
||||
$query->where('cat_id', $catId);
|
||||
}
|
||||
if ($keyword !== '') {
|
||||
$query->where('name', 'like', '%' . $keyword . '%');
|
||||
$specMatchingIds = Db::name('service_spec')
|
||||
->where('status', 'normal')
|
||||
->where('name|description', 'like', '%' . $keyword . '%')
|
||||
->column('service_id');
|
||||
$query->where(function($q) use ($keyword, $specMatchingIds) {
|
||||
$q->where('name', 'like', '%' . $keyword . '%');
|
||||
if (!empty($specMatchingIds)) {
|
||||
$q->whereOr('id', 'in', $specMatchingIds);
|
||||
}
|
||||
});
|
||||
}
|
||||
$list = $query->order('weigh desc,sales desc,id asc')->select();
|
||||
$this->success('', ['list' => $this->formatServices($list)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务商品规格列表
|
||||
*/
|
||||
public function specs()
|
||||
{
|
||||
$serviceId = (int)$this->request->param('service_id');
|
||||
if ($serviceId <= 0) {
|
||||
$this->error('请指定服务商品');
|
||||
}
|
||||
$specs = Db::name('service_spec')
|
||||
->where('service_id', $serviceId)
|
||||
->where('status', 'normal')
|
||||
->order('weigh desc, id asc')
|
||||
->select();
|
||||
$ret = [];
|
||||
foreach ($specs as $sp) {
|
||||
$ret[] = [
|
||||
'id' => (int)$sp['id'],
|
||||
'service_id' => (int)$sp['service_id'],
|
||||
'name' => $sp['name'],
|
||||
'description' => (string)$sp['description'],
|
||||
'base_price' => (float)$sp['base_price'],
|
||||
];
|
||||
}
|
||||
$this->success('', ['list' => $ret]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务详情
|
||||
*/
|
||||
@@ -389,9 +425,37 @@ class Home extends Base
|
||||
*/
|
||||
public function formatServices($list)
|
||||
{
|
||||
if (empty($list)) {
|
||||
return [];
|
||||
}
|
||||
$serviceIds = array_column($list, 'id');
|
||||
$specsMap = [];
|
||||
if (!empty($serviceIds)) {
|
||||
$specs = Db::name('service_spec')
|
||||
->where('service_id', 'in', $serviceIds)
|
||||
->where('status', 'normal')
|
||||
->order('weigh desc, id asc')
|
||||
->select();
|
||||
foreach ($specs as $sp) {
|
||||
$sid = (int)$sp['service_id'];
|
||||
if (!isset($specsMap[$sid])) {
|
||||
$specsMap[$sid] = [];
|
||||
}
|
||||
$specsMap[$sid][] = [
|
||||
'id' => (int)$sp['id'],
|
||||
'service_id' => $sid,
|
||||
'name' => $sp['name'],
|
||||
'description' => (string)$sp['description'],
|
||||
'base_price' => (float)$sp['base_price'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
foreach ($list as $row) {
|
||||
$ret[] = $this->formatService($row);
|
||||
$formatted = $this->formatService($row);
|
||||
$formatted['specs'] = isset($specsMap[$row['id']]) ? $specsMap[$row['id']] : [];
|
||||
$ret[] = $formatted;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户