commit
d824ebaa3e
|
@ -10,7 +10,7 @@ class UserLogic extends BaseLogic
|
||||||
//用户详情
|
//用户详情
|
||||||
public static function detail(int $userId): array
|
public static function detail(int $userId): array
|
||||||
{
|
{
|
||||||
$field = ['id','user_account','user_nickname','user_avatar','user_realname','user_gender','user_phone','user_status','user_last_login_time','user_last_login_ip','create_time'];
|
$field = ['id','user_phone','user_avatar','user_name','user_gender','user_age','user_status','user_last_login_time','user_last_login_ip','create_time'];
|
||||||
$user = User::field($field)->where(['id' => $userId])->findOrEmpty();
|
$user = User::field($field)->where(['id' => $userId])->findOrEmpty();
|
||||||
$user['user_gender_text'] = $user->user_gender_text;
|
$user['user_gender_text'] = $user->user_gender_text;
|
||||||
$user['user_status_text'] = $user->user_status_text;
|
$user['user_status_text'] = $user->user_status_text;
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace app\api\controller;
|
||||||
|
|
||||||
use app\common\enum\notice\NoticeEnum;
|
use app\common\enum\notice\NoticeEnum;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
|
use think\facade\Log;
|
||||||
use think\response\Json;
|
use think\response\Json;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +47,8 @@ class IndexController extends BaseApiController
|
||||||
]);
|
]);
|
||||||
return $this->success($result[0]);
|
return $this->success($result[0]);
|
||||||
}catch(\Exception $e){
|
}catch(\Exception $e){
|
||||||
|
//记录日志
|
||||||
|
Log::error($e->getMessage());
|
||||||
return $this->fail($e->getMessage());
|
return $this->fail($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ class LoginController extends BaseApiController
|
||||||
public function register(): Json
|
public function register(): Json
|
||||||
{
|
{
|
||||||
$params = (new RegisterValidate())->post()->goCheck();
|
$params = (new RegisterValidate())->post()->goCheck();
|
||||||
$params['appid'] = $this->request->header('appid');
|
|
||||||
$result = LoginLogic::register($params);
|
$result = LoginLogic::register($params);
|
||||||
if (true === $result) {
|
if (true === $result) {
|
||||||
return $this->success('注册成功', [], 1, 1);
|
return $this->success('注册成功', [], 1, 1);
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller\user;
|
||||||
|
|
||||||
|
use app\api\controller\BaseApiController;
|
||||||
|
use app\common\model\user\User;
|
||||||
|
use app\common\model\user\UserBalance;
|
||||||
|
use app\common\validate\user\UserBalanceValidate;
|
||||||
|
use think\facade\Log;
|
||||||
|
use think\response\Json;
|
||||||
|
|
||||||
|
class UserBalanceController extends BaseApiController
|
||||||
|
{
|
||||||
|
public array $notNeedLogin = ['addBalanceRecord'];
|
||||||
|
public function addBalanceRecord(): Json
|
||||||
|
{
|
||||||
|
// 获取参数
|
||||||
|
$params = (new UserBalanceValidate())->post()->goCheck('add');
|
||||||
|
// 添加数据
|
||||||
|
try {
|
||||||
|
$result = UserBalance::create([
|
||||||
|
'user_id' => $params['user_id'],
|
||||||
|
'record_id' => $params['record_id'],
|
||||||
|
'record_table' => $params['record_table'],
|
||||||
|
'amount' => $params['amount'],
|
||||||
|
'type' => $params['type'],
|
||||||
|
'pay_type' => $params['pay_type'],
|
||||||
|
'mark' => $params['mark'],
|
||||||
|
'appid' => $this->request->header('appid'),
|
||||||
|
'create_time' => time(),
|
||||||
|
]);
|
||||||
|
if(!empty($result->id)){
|
||||||
|
return $this->success('添加成功');
|
||||||
|
}else{
|
||||||
|
return $this->fail('添加失败');
|
||||||
|
}
|
||||||
|
}catch (\Exception $e) {
|
||||||
|
//记录日志
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
return $this->fail('系统错误');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,18 +21,18 @@ class VerifySignMiddleware
|
||||||
return JsonService::fail('缺少请求头参数', [], 0);
|
return JsonService::fail('缺少请求头参数', [], 0);
|
||||||
}
|
}
|
||||||
//获取子系统信息
|
//获取子系统信息
|
||||||
$system = System::field('system_appid,system_appkey,system_url,system_status')->where('system_appid',$appid)->where('system_url',$url)->findOrEmpty();
|
$system = System::field('app_id,app_key,url,status')->where('app_id',$appid)->where('url',$url)->findOrEmpty();
|
||||||
if($system->isEmpty()){
|
if($system->isEmpty()){
|
||||||
return JsonService::fail('应用ID无效', [], 0);
|
return JsonService::fail('应用ID无效', [], 0);
|
||||||
}
|
}
|
||||||
if($url != $system['system_url']){
|
if($url != $system['url']){
|
||||||
return JsonService::fail('请求来源异常', [], 0);
|
return JsonService::fail('请求来源异常', [], 0);
|
||||||
}
|
}
|
||||||
if($system['system_status'] != 0){
|
if($system['status'] != 0){
|
||||||
return JsonService::fail('应用已被禁用或注销', [], 0);
|
return JsonService::fail('应用已被禁用或注销', [], 0);
|
||||||
}
|
}
|
||||||
//验证签名
|
//验证签名
|
||||||
$checkSign = ApiSignService::verifySign(['appid'=>$appid,'url'=>$url,'timestamp'=>$timestamp,'sign'=>$sign],$system['system_appkey']);
|
$checkSign = ApiSignService::verifySign(['appid'=>$appid,'url'=>$url,'timestamp'=>$timestamp,'sign'=>$sign],$system['app_key']);
|
||||||
if($checkSign['code'] == 0){
|
if($checkSign['code'] == 0){
|
||||||
return JsonService::fail($checkSign['msg'],[],0);
|
return JsonService::fail($checkSign['msg'],[],0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,12 @@ namespace app\api\logic;
|
||||||
use app\common\cache\UserTokenCache;
|
use app\common\cache\UserTokenCache;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\api\service\UserTokenService;
|
use app\api\service\UserTokenService;
|
||||||
use app\common\model\systems\System;
|
use app\common\model\auth\Admin;
|
||||||
use app\common\service\ConfigService;
|
use app\common\service\ConfigService;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录逻辑
|
* 登录逻辑
|
||||||
|
@ -19,33 +21,50 @@ class LoginLogic extends BaseLogic
|
||||||
// 账号密码注册
|
// 账号密码注册
|
||||||
public static function register(array $params): bool
|
public static function register(array $params): bool
|
||||||
{
|
{
|
||||||
//获取子系统信息
|
|
||||||
$system = System::field('id')->where('system_appid',$params['appid'])->findOrEmpty();
|
|
||||||
if($system->isEmpty()){
|
|
||||||
self::setError('应用appid错误');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//创建密码和默认头像
|
//创建密码和默认头像
|
||||||
$passwordSalt = Config::get('project.unique_identification');
|
$passwordSalt = Config::get('project.unique_identification');
|
||||||
$password = create_password($params['password'], $passwordSalt);
|
$adminPassword = create_password($params['phone'], $passwordSalt);
|
||||||
|
$userPassword = create_password($params['password'], $passwordSalt);
|
||||||
$avatar = env('project.web_domain').'/'.ConfigService::get('default_image', 'user_avatar');
|
$avatar = env('project.web_domain').'/'.ConfigService::get('default_image', 'user_avatar');
|
||||||
|
(new Db)->startTrans();
|
||||||
try {
|
try {
|
||||||
User::create([
|
//添加到管理员表
|
||||||
'user_phone' => $params['phone'],
|
$admin = Admin::create([
|
||||||
'user_password' => $password,
|
'root' => 0,
|
||||||
'user_avatar' => $avatar,
|
'name' => '用户'.$params['phone'],
|
||||||
'user_age' => $params['age'],
|
'avatar' => empty($params['avatar']) ? $avatar : $params['avatar'],
|
||||||
'user_gender' => $params['gender'],
|
'account' => $params['phone'],
|
||||||
'user_province' => $params['province'],
|
'password' => $adminPassword,
|
||||||
'user_city' => $params['city'],
|
'multipoint_login' => 1,
|
||||||
'user_area' => $params['area'],
|
'disable' => 0
|
||||||
'user_street' => $params['street'],
|
|
||||||
'user_village' => $params['village'],
|
|
||||||
'user_brigade' => $params['brigade'],
|
|
||||||
'user_address' => $params['address'],
|
|
||||||
]);
|
]);
|
||||||
|
//添加到用户表
|
||||||
|
$user = User::create([
|
||||||
|
'admin_id' => $admin['id'],
|
||||||
|
'phone' => $params['phone'],
|
||||||
|
'nickname' => '用户'.$params['phone'],
|
||||||
|
'password' => $userPassword,
|
||||||
|
'avatar' => empty($params['avatar']) ? $avatar : $params['avatar'],
|
||||||
|
'age' => $params['age'],
|
||||||
|
'gender' => $params['gender'],
|
||||||
|
'province' => $params['province'],
|
||||||
|
'city' => $params['city'],
|
||||||
|
'area' => $params['area'],
|
||||||
|
'street' => $params['street'],
|
||||||
|
'village' => $params['village'],
|
||||||
|
'brigade' => $params['brigade'],
|
||||||
|
'address' => $params['address'],
|
||||||
|
]);
|
||||||
|
if(!empty($admin['id']) && !empty($user['id'])){
|
||||||
|
(new Db)->commit();
|
||||||
return true;
|
return true;
|
||||||
|
}else{
|
||||||
|
(new Db)->rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
(new Db)->rollback();
|
||||||
|
Log::error($e->getMessage());
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -55,11 +74,11 @@ class LoginLogic extends BaseLogic
|
||||||
public static function login($params): bool|array
|
public static function login($params): bool|array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$where = ['user_phone' => $params['account']];
|
$where = ['phone' => $params['account']];
|
||||||
$user = User::field('id')->where($where)->findOrEmpty();
|
$user = User::field('id')->where($where)->findOrEmpty();
|
||||||
//更新登录信息
|
//更新登录信息
|
||||||
$user->user_last_login_time = time();
|
$user->last_login_time = time();
|
||||||
$user->user_last_login_ip = request()->ip();
|
$user->last_login_ip = request()->ip();
|
||||||
$user->save();
|
$user->save();
|
||||||
//设置token
|
//设置token
|
||||||
$userInfo = UserTokenService::setToken($user->id,0);
|
$userInfo = UserTokenService::setToken($user->id,0);
|
||||||
|
@ -69,6 +88,8 @@ class LoginLogic extends BaseLogic
|
||||||
'token' => $userInfo['token'],
|
'token' => $userInfo['token'],
|
||||||
];
|
];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
//记录日志
|
||||||
|
Log::error($e->getMessage());
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +121,8 @@ class LoginLogic extends BaseLogic
|
||||||
'token' => $userInfo['token'],
|
'token' => $userInfo['token'],
|
||||||
];
|
];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
//记录日志
|
||||||
|
Log::error($e->getMessage());
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,8 @@ class UserTokenCache extends BaseCache
|
||||||
$user = User::where('id', '=', $userSession->user_id)->find();
|
$user = User::where('id', '=', $userSession->user_id)->find();
|
||||||
$userInfo = [
|
$userInfo = [
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'phone' => $user->user_phone,
|
'phone' => $user->phone,
|
||||||
'avatar' => $user->user_avatar,
|
'avatar' => $user->avatar,
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
'terminal' => $userSession->terminal,
|
'terminal' => $userSession->terminal,
|
||||||
'expire_time' => $userSession->expire_time,
|
'expire_time' => $userSession->expire_time,
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\user;
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
class ShopMerchant extends BaseModel
|
||||||
|
{
|
||||||
|
protected $connection = 'mysql3';
|
||||||
|
protected $name = 'eb_merchant';
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\user;
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
class ShopUser extends BaseModel
|
||||||
|
{
|
||||||
|
protected $connection = 'mysql3';
|
||||||
|
protected $name = 'eb_user';
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\user;
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
class UserBalance extends BaseModel
|
||||||
|
{
|
||||||
|
protected $name = 'user_balance';
|
||||||
|
|
||||||
|
public function getTypeTextAttr($value,$data): string
|
||||||
|
{
|
||||||
|
$type = [0=>'支出',1=>'收入'];
|
||||||
|
return $type[$data['type']];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPayTypeTextAttr($value,$data): string
|
||||||
|
{
|
||||||
|
$pay_type = [ 0=>'微信支付', 2=>'支付宝支付', 3=>'银行卡支付', 4=>'余额支付', 5=>'其他'];
|
||||||
|
return $pay_type[$data['pay_type']];
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,19 +55,19 @@ class LoginAccountValidate extends BaseValidate
|
||||||
if (!$userAccountSafeCache->isSafe()) {
|
if (!$userAccountSafeCache->isSafe()) {
|
||||||
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
|
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
|
||||||
}
|
}
|
||||||
$userInfo = User::where('user_phone',$data['account'])->field('user_password,user_status')->findOrEmpty();
|
$userInfo = User::where('phone',$data['account'])->field('password,status')->findOrEmpty();
|
||||||
if ($userInfo->isEmpty()) {
|
if ($userInfo->isEmpty()) {
|
||||||
return '用户不存在';
|
return '用户不存在';
|
||||||
}
|
}
|
||||||
if ($userInfo['user_status'] != 0) {
|
if ($userInfo['status'] != 0) {
|
||||||
return '用户已冻结或删除';
|
return '用户已冻结或删除';
|
||||||
}
|
}
|
||||||
if (empty($userInfo['user_password'])) {
|
if (empty($userInfo['password'])) {
|
||||||
$userAccountSafeCache->record();
|
$userAccountSafeCache->record();
|
||||||
return '密码不存在';
|
return '密码不存在';
|
||||||
}
|
}
|
||||||
$passwordSalt = Config::get('project.unique_identification');
|
$passwordSalt = Config::get('project.unique_identification');
|
||||||
if ($userInfo['user_password'] !== create_password($password, $passwordSalt)) {
|
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
||||||
$userAccountSafeCache->record();
|
$userAccountSafeCache->record();
|
||||||
return '密码错误';
|
return '密码错误';
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,11 @@ class LoginAccountValidate extends BaseValidate
|
||||||
|
|
||||||
public function checkCode($code, $rule, $data): bool|string
|
public function checkCode($code, $rule, $data): bool|string
|
||||||
{
|
{
|
||||||
$userInfo = User::where('user_phone',$data['account'])->field('id,user_status')->findOrEmpty();
|
$userInfo = User::where('phone',$data['account'])->field('id,status')->findOrEmpty();
|
||||||
if ($userInfo->isEmpty()) {
|
if ($userInfo->isEmpty()) {
|
||||||
return '用户不存在';
|
return '用户不存在';
|
||||||
}
|
}
|
||||||
if ($userInfo['user_status'] != 0) {
|
if ($userInfo['status'] != 0) {
|
||||||
return '用户已冻结或删除';
|
return '用户已冻结或删除';
|
||||||
}
|
}
|
||||||
$smsDriver = new SmsDriver();
|
$smsDriver = new SmsDriver();
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\validate\user;
|
||||||
|
|
||||||
|
use app\common\model\user\User;
|
||||||
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
class UserBalanceValidate extends BaseValidate
|
||||||
|
{
|
||||||
|
protected $rule = [
|
||||||
|
'id' => 'require',
|
||||||
|
'user_id' => 'require|checkUser',
|
||||||
|
'record_id' => 'require',
|
||||||
|
'record_table' => 'require',
|
||||||
|
'amount' => 'require|float|gt:0',
|
||||||
|
'type' => 'require|in:0,1',
|
||||||
|
'pay_type' => 'require|in:0,1,2,3,4,5',
|
||||||
|
'mark' => 'require',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $message = [
|
||||||
|
'id.require' => '缺少数据主键',
|
||||||
|
'user_id.require' => '请选择用户',
|
||||||
|
'user_id.checkUser' => '用户不存在',
|
||||||
|
'record_id.require' => '请填写本地记录id',
|
||||||
|
'record_table.require' => '请填写本地记录表名',
|
||||||
|
'amount.require' => '请填写金额',
|
||||||
|
'amount.float' => '金额数据格式错误',
|
||||||
|
'amount.gt' => '金额必须大于零',
|
||||||
|
'type.require' => '请选择金额变更类型',
|
||||||
|
'type.in' => '金额变更类型值错误',
|
||||||
|
'pay_type.require' => '请选择支付方式',
|
||||||
|
'pay_type.in' => '支付方式值错误',
|
||||||
|
'mark.require' => '请填写金额变更具体详情',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function sceneAdd(): UserBalanceValidate
|
||||||
|
{
|
||||||
|
return $this->only(['user_id','record_id','record_table','amount','type','pay_type','mark']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sceneDetail(): UserBalanceValidate
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkUser($uid): bool
|
||||||
|
{
|
||||||
|
$userInfo = User::where('id',$uid)->field('id')->findOrEmpty();
|
||||||
|
if($userInfo->isEmpty()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,7 +25,7 @@ return [
|
||||||
// 单文件日志写入
|
// 单文件日志写入
|
||||||
'single' => false,
|
'single' => false,
|
||||||
// 独立日志级别
|
// 独立日志级别
|
||||||
'apart_level' => [],
|
'apart_level' => ['error','sql'],
|
||||||
// 最大日志文件数量
|
// 最大日志文件数量
|
||||||
'max_files' => 0,
|
'max_files' => 0,
|
||||||
// 使用JSON格式记录
|
// 使用JSON格式记录
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
*
|
|
||||||
!.gitignore
|
|
Loading…
Reference in New Issue