更新
This commit is contained in:
parent
ed217dc302
commit
4a316dc932
@ -65,4 +65,17 @@ class LoginController extends BaseApiController
|
||||
}
|
||||
return $this->success('绑定成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新用户头像昵称
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 11:15
|
||||
*/
|
||||
public function updateUser()
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck("updateUser");
|
||||
LoginLogic::updateUser($params, $this->userId);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
}
|
||||
|
38
app/api/controller/user/UserController.php
Normal file
38
app/api/controller/user/UserController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\UserLogic;
|
||||
use app\api\validate\PasswordValidate;
|
||||
use app\api\validate\SetUserInfoValidate;
|
||||
use app\api\validate\UserValidate;
|
||||
|
||||
/**
|
||||
* 用户控制器
|
||||
* Class UserController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class UserController extends BaseApiController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取小程序手机号
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 16:46
|
||||
*/
|
||||
public function getMobileByMnp()
|
||||
{
|
||||
$params = (new UserValidate())->post()->goCheck('getMobileByMnp');
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = UserLogic::getMobileByMnp($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
return $this->success('绑定成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -421,10 +421,16 @@ class LoginLogic extends BaseLogic
|
||||
*/
|
||||
public static function updateUser($params, $userId)
|
||||
{
|
||||
return User::where(['id' => $userId])->update([
|
||||
'nickname' => $params['nickname'],
|
||||
'avatar' => FileService::setFileUrl($params['avatar']),
|
||||
$data=[
|
||||
'mobile'=>$params['mobile'],
|
||||
'is_new_user' => YesNoEnum::NO
|
||||
]);
|
||||
];
|
||||
if(!empty($params['nickname'])){
|
||||
$data['nickname'] = $params['nickname'];
|
||||
}
|
||||
if(!empty($params['avatar'])){
|
||||
$data['avatar'] = FileService::setFileUrl($params['avatar']);
|
||||
}
|
||||
return User::where(['id' => $userId])->update($data);
|
||||
}
|
||||
}
|
64
app/api/logic/user/UserLogic.php
Normal file
64
app/api/logic/user/UserLogic.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\common\{enum\notice\NoticeEnum,
|
||||
enum\user\UserTerminalEnum,
|
||||
enum\YesNoEnum,
|
||||
logic\BaseLogic,
|
||||
model\user\User,
|
||||
model\user\UserAuth,
|
||||
service\sms\SmsDriver,
|
||||
service\wechat\WeChatMnpService};
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 会员逻辑层
|
||||
* Class UserLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class UserLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取小程序手机号
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
* @author 段誉
|
||||
* @date 2023/2/27 11:49
|
||||
*/
|
||||
public static function getMobileByMnp(array $params)
|
||||
{
|
||||
try {
|
||||
$response = (new WeChatMnpService())->getUserPhoneNumber($params['code']);
|
||||
$phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
|
||||
if (empty($phoneNumber)) {
|
||||
throw new \Exception('获取手机号码失败');
|
||||
}
|
||||
|
||||
$user = User::where([
|
||||
['mobile', '=', $phoneNumber],
|
||||
['id', '<>', $params['user_id']]
|
||||
])->findOrEmpty();
|
||||
|
||||
if (!$user->isEmpty()) {
|
||||
throw new \Exception('手机号已被其他账号绑定');
|
||||
}
|
||||
|
||||
// 绑定手机号
|
||||
User::update([
|
||||
'id' => $params['user_id'],
|
||||
'mobile' => $phoneNumber
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -76,8 +76,10 @@ class WechatUserService
|
||||
->findOrEmpty();
|
||||
|
||||
$this->user = $user;
|
||||
if(!$user->isEmpty()){
|
||||
$this->user->supplier=Supplier::where('uid',$user['id'])->field('id,mer_name')->find();
|
||||
}
|
||||
// $this->user->merchat=Merchant::where('uid',$user['id'])->find();
|
||||
$this->user->supplier=Supplier::where('uid',$user['id'])->field('id,mer_name')->find();
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -215,6 +217,7 @@ class WechatUserService
|
||||
*/
|
||||
public function authUserLogin(): self
|
||||
{
|
||||
|
||||
if ($this->user->isEmpty()) {
|
||||
$this->createUser();
|
||||
} else {
|
||||
|
50
app/api/validate/UserValidate.php
Normal file
50
app/api/validate/UserValidate.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 用户验证器
|
||||
* Class UserValidate
|
||||
* @package app\shopapi\validate
|
||||
*/
|
||||
class UserValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'code' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'code.require' => '参数缺失',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取小程序手机号场景
|
||||
* @return UserValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 16:44
|
||||
*/
|
||||
public function sceneGetMobileByMnp()
|
||||
{
|
||||
return $this->only(['code']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 绑定/变更 手机号
|
||||
* @return UserValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:37
|
||||
*/
|
||||
public function sceneBindMobile()
|
||||
{
|
||||
return $this->only(['mobile', 'code']);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -32,6 +32,7 @@ class WechatLoginValidate extends BaseValidate
|
||||
'access_token' => 'require',
|
||||
'terminal' => 'require',
|
||||
'avatar' => 'require',
|
||||
'mobile' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
@ -42,6 +43,7 @@ class WechatLoginValidate extends BaseValidate
|
||||
'access_token.require' => 'access_token缺少',
|
||||
'terminal.require' => '终端参数缺少',
|
||||
'avatar.require' => '头像缺少',
|
||||
'mobile.require' => '手机号',
|
||||
];
|
||||
|
||||
|
||||
@ -89,7 +91,7 @@ class WechatLoginValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneUpdateUser()
|
||||
{
|
||||
return $this->only(['nickname', 'avatar']);
|
||||
return $this->only(['mobile']);
|
||||
}
|
||||
|
||||
|
||||
|
261
app/common/enum/notice/NoticeEnum.php
Normal file
261
app/common/enum/notice/NoticeEnum.php
Normal file
@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\enum\notice;
|
||||
|
||||
/**
|
||||
* 通知枚举
|
||||
* Class NoticeEnum
|
||||
* @package app\common\enum
|
||||
*/
|
||||
class NoticeEnum
|
||||
{
|
||||
/**
|
||||
* 通知类型
|
||||
*/
|
||||
const SYSTEM = 1;
|
||||
const SMS = 2;
|
||||
const OA = 3;
|
||||
const MNP = 4;
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证码场景
|
||||
*/
|
||||
const LOGIN_CAPTCHA = 101;
|
||||
const BIND_MOBILE_CAPTCHA = 102;
|
||||
const CHANGE_MOBILE_CAPTCHA = 103;
|
||||
const FIND_LOGIN_PASSWORD_CAPTCHA = 104;
|
||||
|
||||
|
||||
/**
|
||||
* 验证码场景
|
||||
*/
|
||||
const SMS_SCENE = [
|
||||
self::LOGIN_CAPTCHA,
|
||||
self::BIND_MOBILE_CAPTCHA,
|
||||
self::CHANGE_MOBILE_CAPTCHA,
|
||||
self::FIND_LOGIN_PASSWORD_CAPTCHA,
|
||||
];
|
||||
|
||||
|
||||
//通知类型
|
||||
const BUSINESS_NOTIFICATION = 1;//业务通知
|
||||
const VERIFICATION_CODE = 2;//验证码
|
||||
|
||||
|
||||
/**
|
||||
* @notes 通知类型
|
||||
* @param bool $value
|
||||
* @return string|string[]
|
||||
* @author ljj
|
||||
* @date 2022/2/17 2:49 下午
|
||||
*/
|
||||
public static function getTypeDesc($value = true)
|
||||
{
|
||||
$data = [
|
||||
self::BUSINESS_NOTIFICATION => '业务通知',
|
||||
self::VERIFICATION_CODE => '验证码'
|
||||
];
|
||||
if ($value === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$value];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取场景描述
|
||||
* @param $sceneId
|
||||
* @param false $flag
|
||||
* @return string|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:33
|
||||
*/
|
||||
public static function getSceneDesc($sceneId, $flag = false)
|
||||
{
|
||||
$desc = [
|
||||
self::LOGIN_CAPTCHA => '登录验证码',
|
||||
self::BIND_MOBILE_CAPTCHA => '绑定手机验证码',
|
||||
self::CHANGE_MOBILE_CAPTCHA => '变更手机验证码',
|
||||
self::FIND_LOGIN_PASSWORD_CAPTCHA => '找回登录密码验证码',
|
||||
];
|
||||
|
||||
if ($flag) {
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return $desc[$sceneId] ?? '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更具标记获取场景
|
||||
* @param $tag
|
||||
* @return int|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 15:08
|
||||
*/
|
||||
public static function getSceneByTag($tag)
|
||||
{
|
||||
$scene = [
|
||||
// 手机验证码登录
|
||||
'YZMDL' => self::LOGIN_CAPTCHA,
|
||||
// 绑定手机号验证码
|
||||
'BDSJHM' => self::BIND_MOBILE_CAPTCHA,
|
||||
// 变更手机号验证码
|
||||
'BGSJHM' => self::CHANGE_MOBILE_CAPTCHA,
|
||||
// 找回登录密码
|
||||
'ZHDLMM' => self::FIND_LOGIN_PASSWORD_CAPTCHA,
|
||||
];
|
||||
return $scene[$tag] ?? '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取场景变量
|
||||
* @param $sceneId
|
||||
* @param false $flag
|
||||
* @return array|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:33
|
||||
*/
|
||||
public static function getVars($sceneId, $flag = false)
|
||||
{
|
||||
$desc = [
|
||||
self::LOGIN_CAPTCHA => '验证码:code',
|
||||
self::BIND_MOBILE_CAPTCHA => '验证码:code',
|
||||
self::CHANGE_MOBILE_CAPTCHA => '验证码:code',
|
||||
self::FIND_LOGIN_PASSWORD_CAPTCHA => '验证码:code',
|
||||
];
|
||||
|
||||
if ($flag) {
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return isset($desc[$sceneId]) ? ['可选变量 ' . $desc[$sceneId]] : [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取系统通知示例
|
||||
* @param $sceneId
|
||||
* @param false $flag
|
||||
* @return array|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:33
|
||||
*/
|
||||
public static function getSystemExample($sceneId, $flag = false)
|
||||
{
|
||||
$desc = [];
|
||||
|
||||
if ($flag) {
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return isset($desc[$sceneId]) ? [$desc[$sceneId]] : [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取短信通知示例
|
||||
* @param $sceneId
|
||||
* @param false $flag
|
||||
* @return array|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:33
|
||||
*/
|
||||
public static function getSmsExample($sceneId, $flag = false)
|
||||
{
|
||||
$desc = [
|
||||
self::LOGIN_CAPTCHA => '您正在登录,验证码${code},切勿将验证码泄露于他人,本条验证码有效期5分钟。',
|
||||
self::BIND_MOBILE_CAPTCHA => '您正在绑定手机号,验证码${code},切勿将验证码泄露于他人,本条验证码有效期5分钟。',
|
||||
self::CHANGE_MOBILE_CAPTCHA => '您正在变更手机号,验证码${code},切勿将验证码泄露于他人,本条验证码有效期5分钟。',
|
||||
self::FIND_LOGIN_PASSWORD_CAPTCHA => '您正在找回登录密码,验证码${code},切勿将验证码泄露于他人,本条验证码有效期5分钟。',
|
||||
];
|
||||
|
||||
if ($flag) {
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return isset($desc[$sceneId]) ? ['示例:' . $desc[$sceneId]] : [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取公众号模板消息示例
|
||||
* @param $sceneId
|
||||
* @param false $flag
|
||||
* @return array|string[]|\string[][]
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:33
|
||||
*/
|
||||
public static function getOaExample($sceneId, $flag = false)
|
||||
{
|
||||
$desc = [];
|
||||
|
||||
if ($flag) {
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return $desc[$sceneId] ?? [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取小程序订阅消息示例
|
||||
* @param $sceneId
|
||||
* @param false $flag
|
||||
* @return array|mixed
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:33
|
||||
*/
|
||||
public static function getMnpExample($sceneId, $flag = false)
|
||||
{
|
||||
$desc = [];
|
||||
|
||||
if ($flag) {
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return $desc[$sceneId] ?? [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 提示
|
||||
* @param $type
|
||||
* @param $sceneId
|
||||
* @return array|string|string[]|\string[][]
|
||||
* @author 段誉
|
||||
* @date 2022/3/29 11:33
|
||||
*/
|
||||
public static function getOperationTips($type, $sceneId)
|
||||
{
|
||||
// 场景变量
|
||||
$vars = self::getVars($sceneId);
|
||||
// 其他提示
|
||||
$other = [];
|
||||
// 示例
|
||||
switch ($type) {
|
||||
case self::SYSTEM:
|
||||
$example = self::getSystemExample($sceneId);
|
||||
break;
|
||||
case self::SMS:
|
||||
$other[] = '生效条件:1、管理后台完成短信设置。 2、第三方短信平台申请模板 3、若是腾讯云模板变量名须换成变量名出现顺序对应的数字(例:您好{nickname},您的订单{order_sn}已发货! 须改为 您好{1},您的订单{2}已发货!)';
|
||||
$example = self::getSmsExample($sceneId);
|
||||
break;
|
||||
case self::OA:
|
||||
$other[] = '配置路径:公众号后台 > 广告与服务 > 模板消息';
|
||||
$other[] = '推荐行业:主营行业:IT科技/互联网|电子商务 副营行业:消费品/消费品';
|
||||
$example = self::getOaExample($sceneId);
|
||||
break;
|
||||
case self::MNP:
|
||||
$other[] = '配置路径:小程序后台 > 功能 > 订阅消息';
|
||||
$example = self::getMnpExample($sceneId);
|
||||
break;
|
||||
}
|
||||
$tips = array_merge($vars, $example, $other);
|
||||
|
||||
return $tips;
|
||||
}
|
||||
}
|
@ -106,7 +106,9 @@ class User extends BaseModel
|
||||
*/
|
||||
public function getAvatarAttr($value)
|
||||
{
|
||||
return trim($value) ? FileService::getFileUrl($value) : '';
|
||||
if($value){
|
||||
return trim($value) ? FileService::getFileUrl($value) : '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user