Преглед изворни кода

Merge branch 'dev-shichen' of shop/php into dev

shishichen пре 11 месеци
родитељ
комит
7dc52ecdd5

+ 10 - 0
app/common/dao/user/UserDao.php

@@ -446,4 +446,14 @@ class UserDao extends BaseDao
446
             return [];
446
             return [];
447
         }
447
         }
448
     }
448
     }
449
+
450
+    /**
451
+     * @param $userId
452
+     * @return array
453
+     * 获取直推用户ID
454
+     */
455
+    public function getDirectUserIds($userId)
456
+    {
457
+        return $this::getModel()::getDB()->where('level_id', '=', $userId)->column('uid');
458
+    }
449
 }
459
 }

+ 17 - 0
app/common/dao/user/ZeroUserLineDao.php

@@ -0,0 +1,17 @@
1
+<?php
2
+/**
3
+ * zero user line dao
4
+ */
5
+namespace app\common\dao\user;
6
+
7
+
8
+use app\common\dao\BaseDao;
9
+use app\common\model\user\ZeroUserLine;
10
+
11
+class ZeroUserLineDao extends BaseDao
12
+{
13
+    protected function getModel(): string
14
+    {
15
+        return ZeroUserLine::class;
16
+    }
17
+}

+ 31 - 0
app/common/enum/user/ZeroUserEnum.php

@@ -0,0 +1,31 @@
1
+<?php
2
+
3
+namespace app\common\enum\user;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class ZeroUserEnum extends CommonEnum
8
+{
9
+    // 状态
10
+    const STATUS = [
11
+        0 => '失效',
12
+        1 => '正常',
13
+        2 => '合并',
14
+    ];
15
+    const STATUS_MAP = [
16
+        'FAILURE' => ['code' => 0, 'name' => '失效'],
17
+        'NORMAL' => ['code' => 1, 'name' => '正常'],
18
+        'MERGE' => ['code' => 2, 'name' => '合并'],
19
+    ];
20
+
21
+
22
+    // 是否带走团队
23
+    const IS_REMOVE = [
24
+        0 => '保留',
25
+        1 => '带走'
26
+    ];
27
+    const IS_REMOVE_MAP = [
28
+        'NO' => ['code' => 0, 'name' => '保留'],
29
+        'YES' => ['code' => 1, 'name' => '带走'],
30
+    ];
31
+}

+ 28 - 0
app/common/model/user/ZeroUserLine.php

@@ -0,0 +1,28 @@
1
+<?php
2
+/**
3
+ * user_zero_line
4
+ */
5
+namespace app\common\model\user;
6
+
7
+
8
+use app\common\model\BaseModel;
9
+
10
+class ZeroUserLine extends BaseModel
11
+{
12
+
13
+    /**
14
+     * @return string
15
+     */
16
+    public static function tablePk(): string
17
+    {
18
+        return 'id';
19
+    }
20
+
21
+    /**
22
+     * @return string
23
+     */
24
+    public static function tableName(): string
25
+    {
26
+        return 'user_zero_line';
27
+    }
28
+}

+ 73 - 0
app/common/repositories/user/ZeroUserRepository.php

@@ -0,0 +1,73 @@
1
+<?php
2
+
3
+namespace app\common\repositories\user;
4
+
5
+
6
+use app\common\dao\user\UserDao;
7
+use app\common\dao\user\ZeroUserLineDao;
8
+use app\common\repositories\BaseRepository;
9
+use think\db\exception\DbException;
10
+use think\facade\Db;
11
+
12
+class ZeroUserRepository extends BaseRepository
13
+{
14
+
15
+    private $systemUserId = 1;
16
+
17
+    /**
18
+     * @var ZeroUserLineDao
19
+     */
20
+    protected $dao;
21
+
22
+    /**
23
+     * UserGroupRepository constructor.
24
+     * @param  ZeroUserLineDao  $dao
25
+     */
26
+    public function __construct(ZeroUserLineDao $dao)
27
+    {
28
+        $this->dao = $dao;
29
+    }
30
+
31
+    /**
32
+     * 插入或更新零号线用户数据
33
+     *
34
+     * @param  int|null  $id  用户ID,为null时表示新增
35
+     * @param  array  $data  用户数据
36
+     * @return \app\common\dao\BaseDao|bool|\think\Model
37
+     * @throws DbException
38
+     */
39
+    public function insertOrUpdate(?int $id, array $data)
40
+    {
41
+        // 团队昵称为空时,取用户昵称
42
+        $userDao = new UserDao();
43
+        if (empty($data['team_name'])) {
44
+            $userData = $userDao->get($data['team_uid']);
45
+            $data['team_name'] = $userData->nickname;
46
+        }
47
+
48
+        // 判断是更新现有记录还是创建新记录
49
+        if ($data['id'] > 0) {
50
+            return $this->dao->update($id, $data);
51
+        }
52
+
53
+        try {
54
+            Db::startTrans();
55
+            // 0号线用户修改节点
56
+            $userDao->update($data['team_uid'], ['level_id' => $this->systemUserId]);
57
+
58
+            // 如果不带走团队,所有直推用户节点id修改成上级id
59
+            if ($data['is_remove'] != 1) {
60
+                $directUserIds = $userDao->getDirectUserIds($data['team_uid']);
61
+                $upLevelId = $userData->level_id;
62
+                $userDao->updates($directUserIds, ['level_id' => $upLevelId]);
63
+            }
64
+            $this->dao->create($data);
65
+
66
+            Db::commit();
67
+            return true;
68
+        } catch (\Exception $e) {
69
+            Db::rollback();
70
+            return false;
71
+        }
72
+    }
73
+}

+ 92 - 0
app/controller/admin/user/NewUser.php

@@ -0,0 +1,92 @@
1
+<?php
2
+
3
+namespace app\controller\admin\user;
4
+
5
+use app\common\repositories\user\ZeroUserRepository;
6
+use app\entity\admin\request\user\ZeroUserRequestEntity;
7
+use app\entity\admin\response\user\ZeroUserLineResponseEntity;
8
+use app\validate\admin\user\AddZeroUserValidate;
9
+use app\utils\EnumUtil;
10
+use think\response\Json;
11
+
12
+/**
13
+ * 零号线用户控制器
14
+ * 负责零号线用户的添加和更新操作
15
+ */
16
+class NewUser
17
+{
18
+    /**
19
+     * 用户仓库实例
20
+     * @var ZeroUserRepository
21
+     */
22
+    protected $repository;
23
+
24
+    /**
25
+     * 构造函数
26
+     *
27
+     * @param  ZeroUserRepository  $repository
28
+     */
29
+    public function __construct(ZeroUserRepository $repository)
30
+    {
31
+        $this->repository = $repository;
32
+    }
33
+
34
+    /**
35
+     * 添加或更新零号线用户
36
+     *
37
+     * @param  AddZeroUserValidate  $validate  验证器实例
38
+     * @return Json
39
+     */
40
+    public function addZeroUser(AddZeroUserValidate $validate): Json
41
+    {
42
+        // 执行验证
43
+        $validationResult = $validate->validate();
44
+        // 验证失败,返回错误信息
45
+        if ($validationResult['status'] === 'error') {
46
+            return app('json')->fail($validationResult['message']);
47
+        }
48
+
49
+        /** @var ZeroUserRequestEntity $entity 请求实体 */
50
+        $entity = $validationResult['data'];
51
+
52
+        // 自动验证枚举参数
53
+        $requestData = $entity->toUnderlineArray();
54
+        
55
+        // 使用智能枚举验证器自动验证,直接传递枚举类名
56
+        $validationResult = EnumUtil::autoValidate(\app\common\enum\user\ZeroUserEnum::class, $requestData);
57
+        if (!$validationResult['valid']) {
58
+            return app('json')->fail(implode('; ', $validationResult['errors']));
59
+        }
60
+        try {
61
+            // 执行插入或更新操作
62
+            $result = $this->repository->insertOrUpdate(
63
+                $entity->getId(),
64
+                $requestData
65
+            );
66
+            // 根据操作结果返回相应的响应
67
+            if ($result) {
68
+                $response = ZeroUserLineResponseEntity::success();
69
+                return app('json')->success($response->toResponseArray());
70
+            } else {
71
+                $response = ZeroUserLineResponseEntity::error();
72
+                return app('json')->fail($response->toResponseArray());
73
+            }
74
+        } catch (\Exception $e) {
75
+            // 记录详细异常日志
76
+            $errorMessage = '零号线用户操作异常: ' . $e->getMessage() .
77
+                           ' File: ' . $e->getFile() .
78
+                           ' Line: ' . $e->getLine();
79
+            \think\facade\Log::error($errorMessage);
80
+
81
+            // 根据环境返回不同的错误信息
82
+            $isDev = app()->isDebug();
83
+            if ($isDev) {
84
+                // 开发环境返回详细错误信息
85
+                return app('json')->fail('操作失败: ' . $e->getMessage());
86
+            } else {
87
+                // 生产环境返回友好提示
88
+                return app('json')->fail('系统繁忙,请稍后重试');
89
+            }
90
+        }
91
+    }
92
+}

+ 8 - 0
app/controller/api/store/merchant/TaskProfits.php

@@ -0,0 +1,8 @@
1
+<?php
2
+
3
+namespace app\controller\api\store\merchant;
4
+
5
+class TaskProfits
6
+{
7
+
8
+}

+ 140 - 0
app/entity/admin/request/user/ZeroUserRequestEntity.php

@@ -0,0 +1,140 @@
1
+<?php
2
+
3
+namespace app\entity\admin\request\user;
4
+
5
+use app\entity\request\RequestCommonEntity;
6
+
7
+/**
8
+ * 添加0号线用户请求参数
9
+ */
10
+class ZeroUserRequestEntity extends RequestCommonEntity
11
+{
12
+    // id
13
+    public $id;
14
+
15
+    // 万能验证码
16
+    public $customCode;
17
+
18
+    // 状态
19
+    public $status;
20
+
21
+    // 团队昵称
22
+    public $teamName;
23
+
24
+    // 团队长uid
25
+    public $teamUid;
26
+
27
+    // 是否移除团队
28
+    public $isRemove;
29
+
30
+    // 获取id
31
+    public function getId()
32
+    {
33
+        return $this->id;
34
+    }
35
+
36
+    // 设置id
37
+    public function setId($id)
38
+    {
39
+        $this->id = $id;
40
+        return $this;
41
+    }
42
+
43
+    // 获取万能验证码
44
+    public function getCustomCode()
45
+    {
46
+        return $this->customCode;
47
+    }
48
+
49
+    // 设置万能验证码
50
+    public function setCustomCode($customCode)
51
+    {
52
+        $this->customCode = $customCode ?? null;
53
+        return $this;
54
+    }
55
+
56
+    // 获取团队昵称
57
+    public function getStatus()
58
+    {
59
+        return $this->status;
60
+    }
61
+
62
+    public function setStatus($status)
63
+    {
64
+        $this->status = $status;
65
+        return $this;
66
+    }
67
+
68
+    // 获取团队昵称
69
+    public function getTeamName()
70
+    {
71
+        return $this->teamName ?? '';
72
+    }
73
+
74
+    public function setTeamName($teamName): ZeroUserRequestEntity
75
+    {
76
+        $this->teamName = $teamName;
77
+        return $this;
78
+    }
79
+
80
+    // 获取团队长uid
81
+    public function getTeamUid()
82
+    {
83
+        return $this->teamUid;
84
+    }
85
+
86
+    public function setTeamUid($teamUid): ZeroUserRequestEntity
87
+    {
88
+        $this->teamUid = $teamUid;
89
+        return $this;
90
+    }
91
+
92
+    // 获取是否移除
93
+    public function getIsRemove()
94
+    {
95
+        return $this->isRemove;
96
+    }
97
+
98
+    public function setIsRemove($isRemove): ZeroUserRequestEntity
99
+    {
100
+        $this->isRemove = $isRemove;
101
+        return $this;
102
+    }
103
+
104
+    /**
105
+     * 将请求参数转换为数组格式
106
+     * 用于数据库操作或API传输
107
+     * 动态获取当前类的所有公共属性,使用下划线分割的键名
108
+     *
109
+     * @return array
110
+     */
111
+    public function getArray(): array
112
+    {
113
+        $result = [];
114
+        $reflection = new \ReflectionClass($this);
115
+        $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
116
+        
117
+        foreach ($properties as $property) {
118
+            $propertyName = $property->getName();
119
+            // 跳过继承的属性
120
+            if ($property->getDeclaringClass()->getName() !== self::class) {
121
+                continue;
122
+            }
123
+            
124
+            // 将驼峰命名转换为下划线命名
125
+            $key = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $propertyName));
126
+            
127
+            // 获取对应的getter方法名
128
+            $getterMethod = 'get' . ucfirst($propertyName);
129
+            
130
+            if (method_exists($this, $getterMethod)) {
131
+                $result[$key] = $this->$getterMethod();
132
+            } else {
133
+                // 如果没有对应的getter方法,直接获取属性值
134
+                $result[$key] = $this->$propertyName;
135
+            }
136
+        }
137
+        
138
+        return $result;
139
+    }
140
+}

+ 171 - 0
app/entity/admin/response/AdminCommonResponseEntity.php

@@ -0,0 +1,171 @@
1
+<?php
2
+
3
+namespace app\entity\admin\response;
4
+
5
+use app\entity\CommonEntity;
6
+
7
+/**
8
+ * 管理员公共响应实体
9
+ * 用于统一接口返回格式
10
+ */
11
+class AdminCommonResponseEntity extends CommonEntity
12
+{
13
+    /**
14
+     * 状态码
15
+     * @var int
16
+     */
17
+    public $code;
18
+
19
+    /**
20
+     * 消息内容
21
+     * @var string
22
+     */
23
+    public $message;
24
+
25
+    /**
26
+     * 响应数据
27
+     * @var mixed
28
+     */
29
+    public $data;
30
+
31
+    /**
32
+     * 时间戳
33
+     * @var int
34
+     */
35
+    public $timestamp;
36
+
37
+    /**
38
+     * 获取状态码
39
+     * @return int
40
+     */
41
+    public function getCode(): int
42
+    {
43
+        return $this->code;
44
+    }
45
+
46
+    /**
47
+     * 设置状态码
48
+     * @param int $code
49
+     * @return AdminCommonResponseEntity
50
+     */
51
+    public function setCode(int $code): AdminCommonResponseEntity
52
+    {
53
+        $this->code = $code;
54
+        return $this;
55
+    }
56
+
57
+    /**
58
+     * 获取消息内容
59
+     * @return string
60
+     */
61
+    public function getMessage(): string
62
+    {
63
+        return $this->message;
64
+    }
65
+
66
+    /**
67
+     * 设置消息内容
68
+     * @param string $message
69
+     * @return AdminCommonResponseEntity
70
+     */
71
+    public function setMessage(string $message): AdminCommonResponseEntity
72
+    {
73
+        $this->message = $message;
74
+        return $this;
75
+    }
76
+
77
+    /**
78
+     * 获取响应数据
79
+     * @return mixed
80
+     */
81
+    public function getData()
82
+    {
83
+        return $this->data;
84
+    }
85
+
86
+    /**
87
+     * 设置响应数据
88
+     * @param mixed $data
89
+     * @return AdminCommonResponseEntity
90
+     */
91
+    public function setData($data): AdminCommonResponseEntity
92
+    {
93
+        $this->data = $data;
94
+        return $this;
95
+    }
96
+
97
+    /**
98
+     * 获取时间戳
99
+     * @return int
100
+     */
101
+    public function getTimestamp(): int
102
+    {
103
+        return $this->timestamp;
104
+    }
105
+
106
+    /**
107
+     * 设置时间戳
108
+     * @param int $timestamp
109
+     * @return AdminCommonResponseEntity
110
+     */
111
+    public function setTimestamp(int $timestamp): AdminCommonResponseEntity
112
+    {
113
+        $this->timestamp = $timestamp;
114
+        return $this;
115
+    }
116
+
117
+    /**
118
+     * 创建成功响应
119
+     * @param mixed $data 响应数据
120
+     * @param string $message 成功消息
121
+     * @param int $code 状态码
122
+     * @return AdminCommonResponseEntity
123
+     */
124
+    public static function success(string $message = '操作成功', int $code = 200, $data = null): AdminCommonResponseEntity
125
+    {
126
+        return (new self())
127
+            ->setCode($code)
128
+            ->setMessage($message)
129
+            ->setData($data)
130
+            ->setTimestamp(time());
131
+    }
132
+
133
+    /**
134
+     * 创建失败响应
135
+     * @param string $message 错误消息
136
+     * @param int $code 状态码
137
+     * @param mixed $data 额外数据
138
+     * @return AdminCommonResponseEntity
139
+     */
140
+    public static function error(string $message = '操作失败', int $code = 400, $data = null): AdminCommonResponseEntity
141
+    {
142
+        return (new self())
143
+            ->setCode($code)
144
+            ->setMessage($message)
145
+            ->setData($data)
146
+            ->setTimestamp(time());
147
+    }
148
+
149
+    /**
150
+     * 转换为数组格式
151
+     * @return array
152
+     */
153
+    public function toResponseArray(): array
154
+    {
155
+        return [
156
+            'code' => $this->code,
157
+            'message' => $this->message,
158
+            'data' => $this->data,
159
+            'timestamp' => $this->timestamp
160
+        ];
161
+    }
162
+
163
+    /**
164
+     * 转换为JSON字符串
165
+     * @return string
166
+     */
167
+    public function toJson(): string
168
+    {
169
+        return json_encode($this->toResponseArray(), JSON_UNESCAPED_UNICODE);
170
+    }
171
+}

+ 40 - 0
app/entity/admin/response/user/ZeroUserLineResponseEntity.php

@@ -0,0 +1,40 @@
1
+<?php
2
+
3
+namespace app\entity\admin\response\user;
4
+
5
+use app\entity\admin\response\AdminCommonResponseEntity;
6
+
7
+/**
8
+ * 零号线用户响应实体
9
+ * 继承自 AdminCommonResponseEntity,用于零号线用户相关操作的响应
10
+ * 此接口只需要返回成功或失败状态
11
+ */
12
+class ZeroUserLineResponseEntity extends AdminCommonResponseEntity
13
+{
14
+    // 直接使用父类的 success() 和 error() 方法
15
+    // 不需要额外字段,只需要返回操作状态
16
+    
17
+    /**
18
+     * 创建零号线用户操作成功响应
19
+     * @param  null  $data
20
+     * @param  string  $message
21
+     * @param  int  $code
22
+     * @return AdminCommonResponseEntity
23
+     */
24
+    public static function success(string $message = '零号线用户操作成功', int $code = 200, $data = null): AdminCommonResponseEntity
25
+    {
26
+        return parent::success($message);
27
+    }
28
+
29
+    /**
30
+     * 创建零号线用户操作失败响应
31
+     * @param  string  $message
32
+     * @param  int  $code
33
+     * @param  null  $data
34
+     * @return AdminCommonResponseEntity
35
+     */
36
+    public static function error(string $message = '零号线用户操作失败', int $code = 400, $data = null): AdminCommonResponseEntity
37
+    {
38
+        return parent::error($message, $code);
39
+    }
40
+}

+ 160 - 0
app/utils/EnumUtil.php

@@ -0,0 +1,160 @@
1
+<?php
2
+
3
+namespace app\utils;
4
+
5
+use ReflectionClass;
6
+use ReflectionException;
7
+
8
+/**
9
+ * 智能枚举验证器
10
+ * 自动发现并验证请求参数中的枚举字段
11
+ */
12
+class EnumUtil
13
+{
14
+    /**
15
+     * 自动验证请求参数中的枚举字段
16
+     *
17
+     * @param string|object $enumClassOrInstance 枚举类名或实例
18
+     * @param array $requestData 请求数据
19
+     * @return array 验证结果 ['valid' => bool, 'errors' => array]
20
+     */
21
+    public static function autoValidate($enumClassOrInstance, array $requestData): array
22
+    {
23
+        $errors = [];
24
+        
25
+        try {
26
+            $constants = self::getEnumConstants($enumClassOrInstance);
27
+
28
+            foreach ($constants as $constName => $enumValues) {
29
+                if (!self::isValidEnumArray($enumValues)) {
30
+                    continue;
31
+                }
32
+
33
+                $fieldName = self::constToFieldName($constName);
34
+
35
+                if (array_key_exists($fieldName, $requestData)) {
36
+                    $result = self::validateEnumValue($requestData[$fieldName], $enumValues, $constName);
37
+                    if (!$result['valid']) {
38
+                        $errors[] = $result['error'];
39
+                    }
40
+                }
41
+            }
42
+
43
+        } catch (ReflectionException $e) {
44
+            return [
45
+                'valid' => false,
46
+                'errors' => ["枚举验证异常: " . $e->getMessage()]
47
+            ];
48
+        }
49
+
50
+        return empty($errors) ? [
51
+            'valid' => true,
52
+            'errors' => []
53
+        ] : [
54
+            'valid' => false,
55
+            'errors' => $errors
56
+        ];
57
+    }
58
+
59
+    /**
60
+     * 获取枚举类的所有字段映射
61
+     *
62
+     * @param string|object $enumClassOrInstance 枚举类名或实例
63
+     * @return array 字段映射 [字段名 => 枚举值数组]
64
+     */
65
+    public static function getFieldMappings($enumClassOrInstance): array
66
+    {
67
+        $mappings = [];
68
+        
69
+        try {
70
+            $constants = self::getEnumConstants($enumClassOrInstance);
71
+
72
+            foreach ($constants as $constName => $enumValues) {
73
+                if (self::isValidEnumArray($enumValues)) {
74
+                    $mappings[self::constToFieldName($constName)] = $enumValues;
75
+                }
76
+            }
77
+
78
+        } catch (ReflectionException $e) {
79
+            // 忽略异常,返回空数组
80
+        }
81
+
82
+        return $mappings;
83
+    }
84
+
85
+    /**
86
+     * 获取枚举类的常量
87
+     *
88
+     * @param string|object $enumClassOrInstance
89
+     * @return array
90
+     * @throws ReflectionException
91
+     */
92
+    private static function getEnumConstants($enumClassOrInstance): array
93
+    {
94
+        return (new ReflectionClass($enumClassOrInstance))->getConstants();
95
+    }
96
+
97
+    /**
98
+     * 检查是否为有效的枚举数组(非MAP格式的数组)
99
+     *
100
+     * @param mixed $enumValues
101
+     * @return bool
102
+     */
103
+    private static function isValidEnumArray($enumValues): bool
104
+    {
105
+        return is_array($enumValues) && !empty($enumValues) && !self::isMapFormat($enumValues);
106
+    }
107
+
108
+    /**
109
+     * 将枚举常量名转换为字段名
110
+     *
111
+     * @param string $constName 常量名称
112
+     * @return string 字段名
113
+     */
114
+    private static function constToFieldName(string $constName): string
115
+    {
116
+        return strtolower($constName);
117
+    }
118
+
119
+    /**
120
+     * 验证单个枚举值
121
+     *
122
+     * @param mixed $value 要验证的值
123
+     * @param array $enumValues 枚举值数组
124
+     * @param string $constName 常量名称
125
+     * @return array 验证结果 ['valid' => bool, 'error' => string|null]
126
+     */
127
+    private static function validateEnumValue($value, array $enumValues, string $constName): array
128
+    {
129
+        $validValues = array_keys($enumValues);
130
+        $normalizedValue = is_numeric($value) ? (int)$value : $value;
131
+        
132
+        if (!in_array($normalizedValue, $validValues, true)) {
133
+            return [
134
+                'valid' => false,
135
+                'error' => self::constToFieldName($constName) . "参数错误,值:{$value}"
136
+            ];
137
+        }
138
+
139
+        return [
140
+            'valid' => true,
141
+            'error' => null
142
+        ];
143
+    }
144
+
145
+    /**
146
+     * 检查枚举值数组是否为MAP格式(包含code字段)
147
+     *
148
+     * @param array $enumValues 枚举值数组
149
+     * @return bool
150
+     */
151
+    private static function isMapFormat(array $enumValues): bool
152
+    {
153
+        if (empty($enumValues)) {
154
+            return false;
155
+        }
156
+        
157
+        $firstValue = reset($enumValues);
158
+        return is_array($firstValue) && isset($firstValue['code']);
159
+    }
160
+}

+ 57 - 0
app/validate/admin/user/AddZeroUserValidate.php

@@ -0,0 +1,57 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-05-09
7
+ *
8
+ *
9
+ */
10
+
11
+namespace app\validate\admin\user;
12
+
13
+use app\entity\admin\request\user\ZeroUserRequestEntity;
14
+use app\validate\CommonValidate;
15
+
16
+class AddZeroUserValidate extends CommonValidate
17
+{
18
+    protected $failException = true;
19
+
20
+    protected $rule = [
21
+        'custom_code|万能验证码' => 'in:4,6',
22
+        'status|状态' => 'require|integer',
23
+        'team_name|团队昵称' => 'max:20',
24
+        'team_uid|团队长' => 'require|integer',
25
+        'is_remove|是否移除团队' => 'require'
26
+    ];
27
+
28
+    protected $message = [
29
+        'custom_code.in' => '万能验证码错误',
30
+        'status.require' => '请选择状态',
31
+        'status.integer' => '请选择状态',
32
+        'team_uid.require' => '请输入团队长uid',
33
+        'team_uid.integer' => '请输入团队长uid',
34
+        'is_remove.require' => '请选择是否移除团队',
35
+    ];
36
+
37
+    /**
38
+     * 验证添加零用户请求
39
+     * 使用父类通用验证方法进行数据验证
40
+     *
41
+     * @return array
42
+     */
43
+    public function validate(): array
44
+    {
45
+        $data = $this->request->param();
46
+        if (!$this->check($data)) {
47
+            return [
48
+                'status' => 'error',
49
+                'message' => $this->getError()
50
+            ];
51
+        }
52
+        return [
53
+            'status' => 'success',
54
+            'data' => ZeroUserRequestEntity::newInstance($data)
55
+        ];
56
+    }
57
+}

+ 5 - 0
route/admin.php

@@ -471,6 +471,11 @@ Route::group(config('admin.api_admin_prefix') . '/', function () {
471
 
471
 
472
         })->prefix('admin.user.User');
472
         })->prefix('admin.user.User');
473
 
473
 
474
+
475
+        Route::group('newUser', function () {
476
+            Route::any('addZeroUser', '/addZeroUser')->name('addZeroUser');
477
+        })->prefix('admin.user.NewUser');
478
+
474
         Route::group('warehouse',function (){
479
         Route::group('warehouse',function (){
475
             Route::get('getProvince', '/getProvince');//省
480
             Route::get('getProvince', '/getProvince');//省
476
             Route::get('getCity/:id', '/getCity');//市
481
             Route::get('getCity/:id', '/getCity');//市