Browse Source

feat:版本

super-yimizi 3 months ago
parent
commit
4e59d85650

+ 5 - 5
addons/epay/config.php

@@ -23,9 +23,9 @@ return [
             'app_id' => '',
             'app_secret' => '',
             'miniapp_id' => '',
-            'mch_id' => '',
-            'key' => '',
-            'key_v3' => '',
+            'mch_id' => '1625774482',
+            'key' => 'DRs2yi80exLRn6tI4cBhISMfj7SPYMQG',
+            'key_v3' => 'vnQynXQo9kp5hh0pvlfjN03uiQZ222AS',
             'mode' => 'normal',
             'sub_mch_id' => '',
             'sub_appid' => '',
@@ -48,13 +48,13 @@ return [
         'type' => 'array',
         'content' => [],
         'value' => [
-            'app_id' => '',
             'mode' => 'normal',
+            'pid' => '',
+            'app_id' => '',
             'notify_url' => '/addons/epay/api/notifyx/type/alipay',
             'return_url' => '/addons/epay/api/returnx/type/alipay',
             'private_key' => '',
             'signtype' => 'cert',
-            'pid' => '',
             'ali_public_key' => '',
             'app_cert_public_key' => '',
             'alipay_root_cert' => '',

+ 23 - 16
application/api/controller/User.php

@@ -85,27 +85,34 @@ class User extends Base
     public function profile()
     {
         $user = $this->auth->getUser();
-        $username = $this->request->post('username');
-        $nickname = $this->request->post('nickname');
-        $bio = $this->request->post('bio');
-        $avatar = $this->request->post('avatar');
-        if (!$username || !$nickname) {
-            $this->error("用户名和昵称不能为空");
+        $params = $this->request->param();
+        // 验证器
+        $validate = new \app\api\validate\User();
+        if (!$validate->check($params, [], 'profile')) {
+            $this->error($validate->getError());
         }
-        if (strlen($bio) > 100) {
-            $this->error("签名太长了!");
+        $username = $params['username'] ?? '';
+        $avatar   = $params['avatar'];
+        $nickname = $params['nickname'];
+        $bio      = $params['bio'] ??'';
+        $age = $params['age'];
+        $gender = $params['gender'];
+        $avatar = str_replace(cdnurl('', true), '', $avatar);
+        // username 不传,则不修改
+        if ($username) {
+            $user->username = $username;
+            $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
+            if ($exists) {
+                $this->error(__('Username already exists'));
+            }
         }
-        $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
-        if ($exists) {
-            $this->error(__('Username already exists'));
+        if ($bio) {
+            $user->bio = $bio;
         }
-
-        $avatar = str_replace(cdnurl('', true), '', $avatar);
-
-        $user->username = $username;
         $user->nickname = $nickname;
-        $user->bio = $bio;
         $user->avatar = $avatar;
+        $user->age = $age;
+        $user->gender = $gender;
         $user->save();
 
         $this->success('修改成功!');

+ 28 - 6
application/api/validate/User.php

@@ -3,26 +3,41 @@
 namespace app\api\validate;
 
 use think\Validate;
+use app\common\Enum\UserEnum;
 
 class User extends Validate
 {
+
+    public function __construct(array $rules = [], $message = [], $field = [])
+    {
+        // 动态设置枚举值
+        $this->rule['gender'] = 'require|in:' .implode(',', UserEnum::getGenderList());
+        parent::__construct($rules, $message, $field);
+    }
     /**
      * 验证规则
      */
     protected $rule = [
         'account'   => 'require|length:3,30',
-        'username'  => 'require|length:3,30',
+        'username'  => 'length:3,30',
         'nickname'  => 'require|length:3,30',
         'password'  => 'require|length:6,30',
         'mobile'    => 'require|regex:/^1\d{10}$/',
         'email'     => 'email',
-        'avatar'    => 'string',
-        'gender'    => 'in:0,1,2',
-        'bio'       => 'string|max:255',
+        // 验证头像  验证文件后缀
+
+        'avatar'    => [
+            'require',
+            'regex'=>'/^\/uploads\/.+\\.(?:jpg|jpeg|png|gif|bmp|webp)$/i'
+        ],
+
+        // 'gender'    => 'require|in:' .implode(',', UserEnum::getGenderList()),
+        'bio'       => 'max:255',
         'money'     => 'float|egt:0',
         'balance'   => 'float|egt:0',
         'score'     => 'integer|egt:0',
         'level'     => 'integer|egt:0',
+        'age'       => 'require|integer|egt:0|elt:200', 
         'captcha'   => 'require|length:4,6'
     ];
 
@@ -32,7 +47,7 @@ class User extends Validate
     protected $message = [
         'account.require'   => '账号不能为空',
         'account.length'    => '账号长度必须在3-30个字符之间',
-        'username.require'  => '用户名不能为空',
+        // 'username.require'  => '用户名不能为空',
         'username.length'   => '用户名长度必须在3-30个字符之间',
         'nickname.require'  => '昵称不能为空',
         'nickname.length'   => '昵称长度必须在3-30个字符之间',
@@ -41,7 +56,14 @@ class User extends Validate
         'mobile.regex'      => '手机号格式不正确',
         'mobile.require'    => '手机号不能为空',
         'email'             => '邮箱格式不正确',
+        'avatar.require'    => '头像不能为空',
+        'avatar.regex'      => '头像格式不正确',
         'gender.in'         => '性别只能是未知、男、女',
+        'gender.require'    => '性别不能为空',
+        'age.require'       => '年龄不能为空',
+        'age.integer'       => '年龄必须是整数',
+        'age.egt'           => '年龄不能为负数',
+        'age.elt'           => '年龄不能大于200',
         'bio.max'           => '个人简介最多255个字符',
         'money.float'       => '余额必须是数字',
         'money.egt'         => '余额不能为负数',
@@ -62,7 +84,7 @@ class User extends Validate
         'register'  => ['username', 'password', 'mobile', 'captcha'],
         'login'     => ['account', 'password'],
         'mobilelogin' => ['mobile', 'captcha'],
-        'profile'   => ['nickname', 'gender', 'bio', 'avatar'],
+        'profile'   => ['username', 'nickname', 'bio', 'avatar','age','gender'],
         'changeMobile' => ['mobile', 'captcha'],
     ];
 } 

+ 1 - 1
application/api/controller/Validate.php → application/api/validate/Validate.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace app\api\controller;
+namespace app\api\validate;
 
 use app\common\controller\Api;
 use app\common\model\User;