Compare commits
No commits in common. "d824ebaa3e967dfad24a59d7e8507886a44ead71" and "22d9a05e2b5302a04dffc8148f5dec34a12fa04d" have entirely different histories.
d824ebaa3e
...
22d9a05e2b
|
@ -10,7 +10,7 @@ class UserLogic extends BaseLogic
|
|||
//用户详情
|
||||
public static function detail(int $userId): array
|
||||
{
|
||||
$field = ['id','user_phone','user_avatar','user_name','user_gender','user_age','user_status','user_last_login_time','user_last_login_ip','create_time'];
|
||||
$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'];
|
||||
$user = User::field($field)->where(['id' => $userId])->findOrEmpty();
|
||||
$user['user_gender_text'] = $user->user_gender_text;
|
||||
$user['user_status_text'] = $user->user_status_text;
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace app\api\controller;
|
|||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\model\user\User;
|
||||
use think\facade\Log;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
|
@ -47,8 +46,6 @@ class IndexController extends BaseApiController
|
|||
]);
|
||||
return $this->success($result[0]);
|
||||
}catch(\Exception $e){
|
||||
//记录日志
|
||||
Log::error($e->getMessage());
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ class LoginController extends BaseApiController
|
|||
public function register(): Json
|
||||
{
|
||||
$params = (new RegisterValidate())->post()->goCheck();
|
||||
$params['appid'] = $this->request->header('appid');
|
||||
$result = LoginLogic::register($params);
|
||||
if (true === $result) {
|
||||
return $this->success('注册成功', [], 1, 1);
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
<?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);
|
||||
}
|
||||
//获取子系统信息
|
||||
$system = System::field('app_id,app_key,url,status')->where('app_id',$appid)->where('url',$url)->findOrEmpty();
|
||||
$system = System::field('system_appid,system_appkey,system_url,system_status')->where('system_appid',$appid)->where('system_url',$url)->findOrEmpty();
|
||||
if($system->isEmpty()){
|
||||
return JsonService::fail('应用ID无效', [], 0);
|
||||
}
|
||||
if($url != $system['url']){
|
||||
if($url != $system['system_url']){
|
||||
return JsonService::fail('请求来源异常', [], 0);
|
||||
}
|
||||
if($system['status'] != 0){
|
||||
if($system['system_status'] != 0){
|
||||
return JsonService::fail('应用已被禁用或注销', [], 0);
|
||||
}
|
||||
//验证签名
|
||||
$checkSign = ApiSignService::verifySign(['appid'=>$appid,'url'=>$url,'timestamp'=>$timestamp,'sign'=>$sign],$system['app_key']);
|
||||
$checkSign = ApiSignService::verifySign(['appid'=>$appid,'url'=>$url,'timestamp'=>$timestamp,'sign'=>$sign],$system['system_appkey']);
|
||||
if($checkSign['code'] == 0){
|
||||
return JsonService::fail($checkSign['msg'],[],0);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,10 @@ namespace app\api\logic;
|
|||
use app\common\cache\UserTokenCache;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\api\service\UserTokenService;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\systems\System;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\model\user\User;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
|
@ -21,50 +19,33 @@ class LoginLogic extends BaseLogic
|
|||
// 账号密码注册
|
||||
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');
|
||||
$adminPassword = create_password($params['phone'], $passwordSalt);
|
||||
$userPassword = create_password($params['password'], $passwordSalt);
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$avatar = env('project.web_domain').'/'.ConfigService::get('default_image', 'user_avatar');
|
||||
(new Db)->startTrans();
|
||||
try {
|
||||
//添加到管理员表
|
||||
$admin = Admin::create([
|
||||
'root' => 0,
|
||||
'name' => '用户'.$params['phone'],
|
||||
'avatar' => empty($params['avatar']) ? $avatar : $params['avatar'],
|
||||
'account' => $params['phone'],
|
||||
'password' => $adminPassword,
|
||||
'multipoint_login' => 1,
|
||||
'disable' => 0
|
||||
User::create([
|
||||
'user_phone' => $params['phone'],
|
||||
'user_password' => $password,
|
||||
'user_avatar' => $avatar,
|
||||
'user_age' => $params['age'],
|
||||
'user_gender' => $params['gender'],
|
||||
'user_province' => $params['province'],
|
||||
'user_city' => $params['city'],
|
||||
'user_area' => $params['area'],
|
||||
'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;
|
||||
}else{
|
||||
(new Db)->rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
(new Db)->rollback();
|
||||
Log::error($e->getMessage());
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
@ -74,11 +55,11 @@ class LoginLogic extends BaseLogic
|
|||
public static function login($params): bool|array
|
||||
{
|
||||
try {
|
||||
$where = ['phone' => $params['account']];
|
||||
$where = ['user_phone' => $params['account']];
|
||||
$user = User::field('id')->where($where)->findOrEmpty();
|
||||
//更新登录信息
|
||||
$user->last_login_time = time();
|
||||
$user->last_login_ip = request()->ip();
|
||||
$user->user_last_login_time = time();
|
||||
$user->user_last_login_ip = request()->ip();
|
||||
$user->save();
|
||||
//设置token
|
||||
$userInfo = UserTokenService::setToken($user->id,0);
|
||||
|
@ -88,8 +69,6 @@ class LoginLogic extends BaseLogic
|
|||
'token' => $userInfo['token'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
//记录日志
|
||||
Log::error($e->getMessage());
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
@ -121,8 +100,6 @@ class LoginLogic extends BaseLogic
|
|||
'token' => $userInfo['token'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
//记录日志
|
||||
Log::error($e->getMessage());
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ class UserTokenCache extends BaseCache
|
|||
$user = User::where('id', '=', $userSession->user_id)->find();
|
||||
$userInfo = [
|
||||
'user_id' => $user->id,
|
||||
'phone' => $user->phone,
|
||||
'avatar' => $user->avatar,
|
||||
'phone' => $user->user_phone,
|
||||
'avatar' => $user->user_avatar,
|
||||
'token' => $token,
|
||||
'terminal' => $userSession->terminal,
|
||||
'expire_time' => $userSession->expire_time,
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\user;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class ShopMerchant extends BaseModel
|
||||
{
|
||||
protected $connection = 'mysql3';
|
||||
protected $name = 'eb_merchant';
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\user;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class ShopUser extends BaseModel
|
||||
{
|
||||
protected $connection = 'mysql3';
|
||||
protected $name = 'eb_user';
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?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()) {
|
||||
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
|
||||
}
|
||||
$userInfo = User::where('phone',$data['account'])->field('password,status')->findOrEmpty();
|
||||
$userInfo = User::where('user_phone',$data['account'])->field('user_password,user_status')->findOrEmpty();
|
||||
if ($userInfo->isEmpty()) {
|
||||
return '用户不存在';
|
||||
}
|
||||
if ($userInfo['status'] != 0) {
|
||||
if ($userInfo['user_status'] != 0) {
|
||||
return '用户已冻结或删除';
|
||||
}
|
||||
if (empty($userInfo['password'])) {
|
||||
if (empty($userInfo['user_password'])) {
|
||||
$userAccountSafeCache->record();
|
||||
return '密码不存在';
|
||||
}
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
||||
if ($userInfo['user_password'] !== create_password($password, $passwordSalt)) {
|
||||
$userAccountSafeCache->record();
|
||||
return '密码错误';
|
||||
}
|
||||
|
@ -77,11 +77,11 @@ class LoginAccountValidate extends BaseValidate
|
|||
|
||||
public function checkCode($code, $rule, $data): bool|string
|
||||
{
|
||||
$userInfo = User::where('phone',$data['account'])->field('id,status')->findOrEmpty();
|
||||
$userInfo = User::where('user_phone',$data['account'])->field('id,user_status')->findOrEmpty();
|
||||
if ($userInfo->isEmpty()) {
|
||||
return '用户不存在';
|
||||
}
|
||||
if ($userInfo['status'] != 0) {
|
||||
if ($userInfo['user_status'] != 0) {
|
||||
return '用户已冻结或删除';
|
||||
}
|
||||
$smsDriver = new SmsDriver();
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
<?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,
|
||||
// 独立日志级别
|
||||
'apart_level' => ['error','sql'],
|
||||
'apart_level' => [],
|
||||
// 最大日志文件数量
|
||||
'max_files' => 0,
|
||||
// 使用JSON格式记录
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
Loading…
Reference in New Issue