This commit is contained in:
unknown 2023-09-18 17:04:42 +08:00
parent 22d9a05e2b
commit 152d150774
10 changed files with 154 additions and 4 deletions

View File

@ -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;

View File

@ -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());
} }
} }

View File

@ -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('系统错误');
}
}
}

View File

@ -8,6 +8,7 @@ use app\common\model\systems\System;
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\Log;
/** /**
* 登录逻辑 * 登录逻辑
@ -46,6 +47,8 @@ class LoginLogic extends BaseLogic
]); ]);
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
//记录日志
Log::error($e->getMessage());
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }
@ -69,6 +72,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 +105,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;
} }

View File

@ -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';
}

View File

@ -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';
}

View File

@ -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']];
}
}

View File

@ -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;
}
}

View File

@ -25,7 +25,7 @@ return [
// 单文件日志写入 // 单文件日志写入
'single' => false, 'single' => false,
// 独立日志级别 // 独立日志级别
'apart_level' => [], 'apart_level' => ['error','sql'],
// 最大日志文件数量 // 最大日志文件数量
'max_files' => 0, 'max_files' => 0,
// 使用JSON格式记录 // 使用JSON格式记录

2
runtime/.gitignore vendored
View File

@ -1,2 +0,0 @@
*
!.gitignore