From 152d150774dc3d680e40e552920d9e0c2f5c0fc9 Mon Sep 17 00:00:00 2001 From: unknown <736250432@qq.com> Date: Mon, 18 Sep 2023 17:04:42 +0800 Subject: [PATCH] update --- app/adminapi/logic/user/UserLogic.php | 2 +- app/api/controller/IndexController.php | 3 + .../controller/user/UserBalanceController.php | 43 +++++++++++++++ app/api/logic/LoginLogic.php | 7 +++ app/common/model/user/ShopMerchant.php | 11 ++++ app/common/model/user/ShopUser.php | 11 ++++ app/common/model/user/UserBalance.php | 22 ++++++++ .../validate/user/UserBalanceValidate.php | 55 +++++++++++++++++++ config/log.php | 2 +- runtime/.gitignore | 2 - 10 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 app/api/controller/user/UserBalanceController.php create mode 100644 app/common/model/user/ShopMerchant.php create mode 100644 app/common/model/user/ShopUser.php create mode 100644 app/common/model/user/UserBalance.php create mode 100644 app/common/validate/user/UserBalanceValidate.php delete mode 100644 runtime/.gitignore diff --git a/app/adminapi/logic/user/UserLogic.php b/app/adminapi/logic/user/UserLogic.php index 98233090..f8a85dd5 100644 --- a/app/adminapi/logic/user/UserLogic.php +++ b/app/adminapi/logic/user/UserLogic.php @@ -10,7 +10,7 @@ class UserLogic extends BaseLogic //用户详情 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_gender_text'] = $user->user_gender_text; $user['user_status_text'] = $user->user_status_text; diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 9e0a216e..1eb5f392 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\common\enum\notice\NoticeEnum; use app\common\model\user\User; +use think\facade\Log; use think\response\Json; /** @@ -46,6 +47,8 @@ class IndexController extends BaseApiController ]); return $this->success($result[0]); }catch(\Exception $e){ + //记录日志 + Log::error($e->getMessage()); return $this->fail($e->getMessage()); } } diff --git a/app/api/controller/user/UserBalanceController.php b/app/api/controller/user/UserBalanceController.php new file mode 100644 index 00000000..6011972b --- /dev/null +++ b/app/api/controller/user/UserBalanceController.php @@ -0,0 +1,43 @@ +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('系统错误'); + } + } +} \ No newline at end of file diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index a2c500e0..b0913b91 100644 --- a/app/api/logic/LoginLogic.php +++ b/app/api/logic/LoginLogic.php @@ -8,6 +8,7 @@ use app\common\model\systems\System; use app\common\service\ConfigService; use app\common\model\user\User; use think\facade\Config; +use think\facade\Log; /** * 登录逻辑 @@ -46,6 +47,8 @@ class LoginLogic extends BaseLogic ]); return true; } catch (\Exception $e) { + //记录日志 + Log::error($e->getMessage()); self::setError($e->getMessage()); return false; } @@ -69,6 +72,8 @@ class LoginLogic extends BaseLogic 'token' => $userInfo['token'], ]; } catch (\Exception $e) { + //记录日志 + Log::error($e->getMessage()); self::setError($e->getMessage()); return false; } @@ -100,6 +105,8 @@ class LoginLogic extends BaseLogic 'token' => $userInfo['token'], ]; } catch (\Exception $e) { + //记录日志 + Log::error($e->getMessage()); self::setError($e->getMessage()); return false; } diff --git a/app/common/model/user/ShopMerchant.php b/app/common/model/user/ShopMerchant.php new file mode 100644 index 00000000..b80805ea --- /dev/null +++ b/app/common/model/user/ShopMerchant.php @@ -0,0 +1,11 @@ +'支出',1=>'收入']; + return $type[$data['type']]; + } + + public function getPayTypeTextAttr($value,$data): string + { + $pay_type = [ 0=>'微信支付', 2=>'支付宝支付', 3=>'银行卡支付', 4=>'余额支付', 5=>'其他']; + return $pay_type[$data['pay_type']]; + } +} \ No newline at end of file diff --git a/app/common/validate/user/UserBalanceValidate.php b/app/common/validate/user/UserBalanceValidate.php new file mode 100644 index 00000000..cb257f90 --- /dev/null +++ b/app/common/validate/user/UserBalanceValidate.php @@ -0,0 +1,55 @@ + '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; + } +} \ No newline at end of file diff --git a/config/log.php b/config/log.php index ea24ff9d..6bab73c0 100644 --- a/config/log.php +++ b/config/log.php @@ -25,7 +25,7 @@ return [ // 单文件日志写入 'single' => false, // 独立日志级别 - 'apart_level' => [], + 'apart_level' => ['error','sql'], // 最大日志文件数量 'max_files' => 0, // 使用JSON格式记录 diff --git a/runtime/.gitignore b/runtime/.gitignore deleted file mode 100644 index c96a04f0..00000000 --- a/runtime/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file