Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘小敏
loveisland
Commits
a9df1ab5
Commit
a9df1ab5
authored
Jun 29, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(agent): 添加代理商申请功能;新增获取省份列表接口
parent
1ff825f6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
206 additions
and
3 deletions
+206
-3
Area.php
addons/shopro/controller/data/Area.php
+18
-1
User.php
addons/shopro/controller/user/User.php
+30
-0
ApplyService.php
addons/shopro/service/agent/ApplyService.php
+68
-0
User.php
addons/shopro/validate/user/User.php
+19
-2
Agent.php
application/admin/model/shopro/agent/Agent.php
+43
-0
Apply.php
application/admin/model/shopro/agent/Apply.php
+28
-0
No files found.
addons/shopro/controller/data/Area.php
View file @
a9df1ab5
...
...
@@ -8,7 +8,7 @@ use app\admin\model\shopro\data\Area as AreaModel;
class
Area
extends
Common
{
protected
$noNeedLogin
=
[
'index'
];
protected
$noNeedLogin
=
[
'index'
,
'provinces'
];
protected
$noNeedRight
=
[
'*'
];
public
function
index
()
...
...
@@ -21,4 +21,21 @@ class Area extends Common
$this
->
success
(
'获取成功'
,
$list
);
}
/**
* 获取省份列表(不含港澳)
* GET /api/data/area/provinces
*/
public
function
provinces
()
{
$excludeIds
=
[
71
,
81
,
82
];
// 台湾、香港、澳门
$list
=
AreaModel
::
where
(
'pid'
,
0
)
->
where
(
'id'
,
'not in'
,
$excludeIds
)
->
order
(
'id'
,
'asc'
)
->
field
(
'id, pid, level, name'
)
->
select
();
$this
->
success
(
'获取成功'
,
$list
);
}
}
addons/shopro/controller/user/User.php
View file @
a9df1ab5
...
...
@@ -398,6 +398,36 @@ class User extends Common
}
/**
* 申请成为代理商
*/
public
function
agentapply
()
{
if
(
!
$this
->
request
->
isPost
())
{
$this
->
error
(
''
);
}
$user
=
auth_user
();
$userId
=
$user
->
id
??
0
;
custom_log
(
'[agent.apply] 收到代理申请请求, user_id='
.
$userId
,
$userId
,
'share'
);
$params
=
$this
->
request
->
only
([
'province_id'
,
'real_name'
,
'id_card'
,
'id_card_images'
]);
custom_log
(
'[agent.apply] 解析参数: '
.
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$userId
,
'share'
);
$this
->
svalidate
(
$params
,
'.agentApply'
);
custom_log
(
'[agent.apply] 参数校验通过'
,
$userId
,
'share'
);
$service
=
new
\addons\shopro\service\agent\ApplyService
(
$user
);
try
{
$apply
=
$service
->
submit
(
$params
);
custom_log
(
'[agent.apply] 代理申请成功, apply_id='
.
(
$apply
->
id
??
''
),
$userId
,
'share'
);
$this
->
success
(
'申请已提交,请等待审核'
,
$apply
);
}
catch
(
\think\Exception
$e
)
{
custom_log
(
'[agent.apply] 代理申请失败: '
.
$e
->
getMessage
(),
$userId
,
'share'
,
'warning'
);
$this
->
error
(
$e
->
getMessage
());
}
}
/**
* 用户注销
* 物理删除用户,且未做业务上的逻辑判断,慎用
*/
...
...
addons/shopro/service/agent/ApplyService.php
0 → 100644
View file @
a9df1ab5
<?php
namespace
addons\shopro\service\agent
;
use
think\Db
;
use
app\admin\model\shopro\agent\Apply
as
ApplyModel
;
use
app\admin\model\shopro\agent\Agent
as
AgentModel
;
use
app\admin\model\shopro\data\Area
as
AreaModel
;
class
ApplyService
{
protected
$user
;
public
function
__construct
(
$user
)
{
$this
->
user
=
$user
;
}
/**
* 提交代理申请
*/
public
function
submit
(
$params
)
{
$userId
=
$this
->
user
->
id
;
// 1. 校验是否已有申请中的记录
$existApply
=
ApplyModel
::
where
(
'user_id'
,
$userId
)
->
where
(
'status'
,
ApplyModel
::
STATUS_PENDING
)
->
find
();
if
(
$existApply
)
{
throw
new
\think\Exception
(
'您已提交过代理申请,正在审核中,请耐心等待'
);
}
// 2. 校验是否已经是代理商
$existAgent
=
AgentModel
::
where
(
'user_id'
,
$userId
)
->
where
(
'status'
,
AgentModel
::
STATUS_NORMAL
)
->
find
();
if
(
$existAgent
)
{
throw
new
\think\Exception
(
'您已是代理商,无需重复申请'
);
}
// 3. 校验省份是否已被代理
if
(
AgentModel
::
hasActiveAgent
(
$params
[
'province_id'
]))
{
throw
new
\think\Exception
(
'该省份已有代理商'
);
}
// 4. 获取省份名称
$province
=
AreaModel
::
where
(
'id'
,
$params
[
'province_id'
])
->
where
(
'level'
,
'province'
)
->
find
();
if
(
!
$province
)
{
throw
new
\think\Exception
(
'省份不存在'
);
}
// 5. 写入申请记录
$apply
=
ApplyModel
::
create
([
'user_id'
=>
$userId
,
'province_id'
=>
$params
[
'province_id'
],
'province_name'
=>
$province
->
name
,
'real_name'
=>
$params
[
'real_name'
],
'id_card'
=>
$params
[
'id_card'
],
'id_card_images'
=>
$params
[
'id_card_images'
]
??
[],
'status'
=>
ApplyModel
::
STATUS_PENDING
,
]);
custom_log
(
'[agent.apply] 代理申请提交成功, apply_id='
.
$apply
->
id
.
', user_id='
.
$userId
.
', province='
.
$province
->
name
,
$userId
,
'share'
);
return
$apply
;
}
}
addons/shopro/validate/user/User.php
View file @
a9df1ab5
...
...
@@ -11,6 +11,7 @@ class User extends Validate
'notPureNumber'
=>
'^[a-zA-Z][a-zA-Z0-9_]{4,15}$'
,
'mobile'
=>
'/^1[3456789]\d{9}$/'
,
'date'
=>
'/^\d{4}\.\d{2}\.\d{2}$/'
,
'idCard'
=>
'/^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/'
,
];
protected
$rule
=
[
...
...
@@ -26,6 +27,11 @@ class User extends Validate
'code'
=>
'require'
,
'birthday'
=>
'regex:date'
,
'gender'
=>
'in:0,1,2'
,
// 代理申请
'province_id'
=>
'require|number|gt:0'
,
'real_name'
=>
'require|length:2,20'
,
'id_card'
=>
'require|regex:idCard'
,
];
protected
$message
=
[
...
...
@@ -63,6 +69,16 @@ class User extends Validate
'birthday.regex'
=>
'生日格式不正确'
,
'province_id.require'
=>
'请选择代理省份'
,
'province_id.number'
=>
'省份参数错误'
,
'province_id.gt'
=>
'请选择代理省份'
,
'real_name.require'
=>
'请填写真实姓名'
,
'real_name.length'
=>
'姓名长度需在2-20个字符'
,
'id_card.require'
=>
'请填写身份证号'
,
'id_card.regex'
=>
'身份证号格式不正确'
,
];
...
...
@@ -76,6 +92,7 @@ class User extends Validate
'changeMobile'
=>
[
'mobile'
=>
'require|regex:mobile|unique:user'
,
'code'
],
'changeUsername'
=>
[
'username'
],
'updateMpUserInfo'
=>
[
'avatar'
,
'nickname'
],
'update'
=>
[
'birthday'
,
'gender'
]
];
'update'
=>
[
'birthday'
,
'gender'
],
'agentApply'
=>
[
'province_id'
,
'real_name'
,
'id_card'
],
];
}
application/admin/model/shopro/agent/Agent.php
0 → 100644
View file @
a9df1ab5
<?php
namespace
app\admin\model\shopro\agent
;
use
app\admin\model\shopro\Common
;
use
app\admin\model\shopro\user\User
;
class
Agent
extends
Common
{
protected
$name
=
'shopro_agent'
;
protected
$type
=
[
'id_card_images'
=>
'json'
,
'total_commission'
=>
'decimal'
,
];
// 代理商状态
const
STATUS_NORMAL
=
'normal'
;
// 正常
const
STATUS_FROZEN
=
'frozen'
;
// 已冻结
public
function
statusList
()
{
return
[
self
::
STATUS_NORMAL
=>
'正常'
,
self
::
STATUS_FROZEN
=>
'已冻结'
,
];
}
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
,
'user_id'
,
'id'
)
->
field
(
'id, nickname, avatar, mobile'
);
}
/**
* 查询省份下是否已有正常代理
*/
public
static
function
hasActiveAgent
(
$provinceId
)
{
return
self
::
where
(
'province_id'
,
$provinceId
)
->
where
(
'status'
,
self
::
STATUS_NORMAL
)
->
find
();
}
}
application/admin/model/shopro/agent/Apply.php
0 → 100644
View file @
a9df1ab5
<?php
namespace
app\admin\model\shopro\agent
;
use
app\admin\model\shopro\Common
;
class
Apply
extends
Common
{
protected
$name
=
'shopro_agent_apply'
;
protected
$type
=
[
'id_card_images'
=>
'json'
,
];
// 审核状态
const
STATUS_PENDING
=
'pending'
;
// 审核中
const
STATUS_APPROVED
=
'approved'
;
// 已通过
const
STATUS_REJECTED
=
'rejected'
;
// 已驳回
public
function
statusList
()
{
return
[
self
::
STATUS_PENDING
=>
'审核中'
,
self
::
STATUS_APPROVED
=>
'已通过'
,
self
::
STATUS_REJECTED
=>
'已驳回'
,
];
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment