158 lines
4.9 KiB
PHP
158 lines
4.9 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\storeapi\logic;
|
||
|
||
|
||
use app\common\{enum\notice\NoticeEnum,
|
||
enum\user\UserTerminalEnum,
|
||
enum\YesNoEnum,
|
||
logic\BaseLogic,
|
||
model\teamaster\TeamasterCollect,
|
||
model\store\StoreUser,
|
||
model\user\UserAddress,
|
||
model\user\UserAuth,
|
||
model\user\UserCoupon,
|
||
model\user\UserMoneyLog,
|
||
model\user\UserStoreMoney,
|
||
service\FileService,
|
||
service\sms\SmsDriver,
|
||
service\wechat\WeChatMnpService};
|
||
use think\facade\{Db, Config};
|
||
/**
|
||
* 会员逻辑层
|
||
* Class UserLogic
|
||
* @package app\shopapi\logic
|
||
*/
|
||
class TeamUserLogic extends BaseLogic
|
||
{
|
||
|
||
/**
|
||
* @notes 个人中心
|
||
* @param array $userInfo
|
||
* @return array
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @author 段誉
|
||
* @date 2022/9/16 18:04
|
||
*/
|
||
public static function center(array $userInfo): array
|
||
{
|
||
$user = StoreUser::where(['id' => $userInfo['user_id']])
|
||
->field('id,sn,sex,account,nickname,real_name,avatar,mobile,create_time,is_new_user,user_money,password')
|
||
->findOrEmpty();
|
||
|
||
if (in_array($userInfo['terminal'], [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA])) {
|
||
$auth = UserAuth::where(['user_id' => $userInfo['user_id'], 'terminal' => $userInfo['terminal']])->find();
|
||
$user['is_auth'] = $auth ? YesNoEnum::YES : YesNoEnum::NO;
|
||
}
|
||
|
||
$user['has_password'] = !empty($user['password']);
|
||
$user->hidden(['password']);
|
||
return $user->toArray();
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 个人信息
|
||
* @param $userId
|
||
* @return array
|
||
* @author 段誉
|
||
* @date 2022/9/20 19:45
|
||
*/
|
||
public static function info(int $userId)
|
||
{
|
||
$user = User::where(['id' => $userId])
|
||
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time,user_money,member')
|
||
->findOrEmpty();
|
||
$user['has_password'] = !empty($user['password']);
|
||
$user['has_auth'] = self::hasWechatAuth($userId);
|
||
$user['version'] = config('project.version');
|
||
$user['collect_count'] = TeamasterCollect::where("user_id",$userId)
|
||
->where("status",1)
|
||
->count();
|
||
$user['coupon_count'] = UserCoupon::where("user_id",$userId)
|
||
->where("status",0)
|
||
->count();
|
||
$user->hidden(['password']);
|
||
return $user->toArray();
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 设置用户信息
|
||
* @param int $userId
|
||
* @param array $params
|
||
* @return User|false
|
||
* @author 段誉
|
||
* @date 2022/9/21 16:53
|
||
*/
|
||
public static function setInfo(int $userId, array $params)
|
||
{
|
||
|
||
try {
|
||
if ($params['field'] == "avatar") {
|
||
$params['value'] = FileService::setFileUrl($params['value']);
|
||
}
|
||
|
||
return User::update([
|
||
'id' => $userId,
|
||
$params['field'] => $params['value']]
|
||
);
|
||
} catch (\Exception $e) {
|
||
self::$error = $e->getMessage();
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* @notes 重置登录密码
|
||
* @param $params
|
||
* @return bool
|
||
* @author 段誉
|
||
* @date 2022/9/16 18:06
|
||
*/
|
||
public static function resetPassword(array $params)
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
// 校验验证码
|
||
$smsDriver = new SmsDriver();
|
||
if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA)) {
|
||
throw new \Exception('验证码错误');
|
||
}
|
||
|
||
// 重置密码
|
||
$passwordSalt = Config::get('project.unique_identification');
|
||
$password = create_password($params['password'], $passwordSalt);
|
||
if($params['password']!= $params['password_confirm']){
|
||
throw new \Exception('两次输入不正确');
|
||
}
|
||
// 更新
|
||
StoreUser::where('mobile', $params['mobile'])->update([
|
||
'password' => $password
|
||
]);
|
||
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
} |